2011-07-18 22:06:02 +02:00
|
|
|
package com.massivecraft.factions;
|
2011-02-06 13:36:11 +01:00
|
|
|
|
2011-07-27 22:56:45 +02:00
|
|
|
import java.io.File;
|
2011-03-18 17:33:23 +01:00
|
|
|
import java.lang.reflect.Modifier;
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
import java.lang.reflect.Type;
|
2011-03-18 17:33:23 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2011-03-22 18:48:09 +01:00
|
|
|
import java.util.Map;
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
import java.util.Set;
|
2011-03-18 17:33:23 +01:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
2011-03-23 17:39:56 +01:00
|
|
|
import org.bukkit.Location;
|
2011-03-18 17:33:23 +01:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2011-03-23 17:39:56 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2011-02-06 13:36:11 +01:00
|
|
|
import org.bukkit.event.Event;
|
2011-06-27 19:25:02 +02:00
|
|
|
import org.bukkit.event.player.PlayerChatEvent;
|
2011-03-18 17:33:23 +01:00
|
|
|
import org.bukkit.plugin.Plugin;
|
2011-02-06 13:36:11 +01:00
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2011-07-18 22:06:02 +02:00
|
|
|
import com.massivecraft.factions.commands.*;
|
|
|
|
import com.massivecraft.factions.listeners.FactionsBlockListener;
|
2011-07-24 13:09:58 +02:00
|
|
|
import com.massivecraft.factions.listeners.FactionsChatEarlyListener;
|
2011-07-18 22:06:02 +02:00
|
|
|
import com.massivecraft.factions.listeners.FactionsEntityListener;
|
|
|
|
import com.massivecraft.factions.listeners.FactionsPlayerListener;
|
2011-07-27 22:56:45 +02:00
|
|
|
import com.massivecraft.factions.util.JarLoader;
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
import com.massivecraft.factions.util.MapFLocToStringSetTypeAdapter;
|
|
|
|
import com.massivecraft.factions.util.MyLocationTypeAdapter;
|
2011-07-20 15:48:14 +02:00
|
|
|
|
2011-03-18 17:33:23 +01:00
|
|
|
import com.nijiko.permissions.PermissionHandler;
|
|
|
|
import com.nijikokun.bukkit.Permissions.Permissions;
|
2011-07-20 15:48:14 +02:00
|
|
|
import com.earth2me.essentials.chat.EssentialsChat;
|
|
|
|
import com.earth2me.essentials.chat.IEssentialsChatListener;
|
2011-07-27 22:56:45 +02:00
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.GsonBuilder;
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
import com.google.gson.reflect.TypeToken;
|
2011-03-18 17:33:23 +01:00
|
|
|
|
2011-03-22 22:31:04 +01:00
|
|
|
/**
|
|
|
|
* The data is saved to disk every 30min and on plugin disable.
|
|
|
|
*/
|
2011-02-06 13:36:11 +01:00
|
|
|
public class Factions extends JavaPlugin {
|
2011-03-18 17:33:23 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// Fields
|
|
|
|
// -------------------------------------------- //
|
|
|
|
public static Factions instance;
|
2011-04-06 12:04:57 +02:00
|
|
|
private Integer saveTask = null;
|
2011-03-18 17:33:23 +01:00
|
|
|
|
2011-07-27 22:56:45 +02:00
|
|
|
public Gson gson;
|
2011-02-06 13:36:11 +01:00
|
|
|
|
2011-03-22 17:20:21 +01:00
|
|
|
private final FactionsPlayerListener playerListener = new FactionsPlayerListener();
|
2011-07-24 13:09:58 +02:00
|
|
|
private final FactionsChatEarlyListener chatEarlyListener = new FactionsChatEarlyListener();
|
2011-03-22 17:20:21 +01:00
|
|
|
private final FactionsEntityListener entityListener = new FactionsEntityListener();
|
|
|
|
private final FactionsBlockListener blockListener = new FactionsBlockListener();
|
2011-03-18 17:33:23 +01:00
|
|
|
|
|
|
|
public static PermissionHandler Permissions;
|
2011-07-20 15:48:14 +02:00
|
|
|
public static EssentialsChat essChat;
|
2011-02-13 17:04:06 +01:00
|
|
|
|
2011-03-18 17:33:23 +01:00
|
|
|
// Commands
|
2011-03-22 15:45:41 +01:00
|
|
|
public List<FBaseCommand> commands = new ArrayList<FBaseCommand>();
|
2011-03-22 18:48:09 +01:00
|
|
|
|
|
|
|
private String baseCommand;
|
2011-03-18 17:33:23 +01:00
|
|
|
|
|
|
|
public Factions() {
|
|
|
|
Factions.instance = this;
|
2011-03-22 20:36:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
2011-07-27 22:56:45 +02:00
|
|
|
log("=== ENABLE START ===");
|
2011-03-22 20:36:33 +01:00
|
|
|
long timeInitStart = System.currentTimeMillis();
|
2011-03-22 18:48:09 +01:00
|
|
|
|
2011-07-27 22:56:45 +02:00
|
|
|
// Load the gson library we require
|
|
|
|
File gsonfile = new File("./lib/gson.jar");
|
|
|
|
if ( ! JarLoader.load(gsonfile)) {
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
log(Level.SEVERE, "Disabling myself as "+gsonfile.getPath()+" is missing from the root Minecraft server folder.");
|
2011-07-27 22:56:45 +02:00
|
|
|
this.getServer().getPluginManager().disablePlugin(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
Type mapFLocToStringSetType = new TypeToken<Map<FLocation, Set<String>>>(){}.getType();
|
|
|
|
|
2011-07-27 22:56:45 +02:00
|
|
|
gson = new GsonBuilder()
|
|
|
|
.setPrettyPrinting()
|
|
|
|
.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE)
|
|
|
|
.registerTypeAdapter(Location.class, new MyLocationTypeAdapter())
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
.registerTypeAdapter(mapFLocToStringSetType, new MapFLocToStringSetTypeAdapter())
|
2011-07-27 22:56:45 +02:00
|
|
|
.create();
|
|
|
|
|
2011-03-22 18:48:09 +01:00
|
|
|
// Add the commands
|
|
|
|
commands.add(new FCommandHelp());
|
|
|
|
commands.add(new FCommandAdmin());
|
2011-06-10 21:26:12 +02:00
|
|
|
commands.add(new FCommandAutoClaim());
|
|
|
|
commands.add(new FCommandAutoSafeclaim());
|
|
|
|
commands.add(new FCommandAutoWarclaim());
|
2011-04-06 12:04:57 +02:00
|
|
|
commands.add(new FCommandBypass());
|
2011-03-22 18:48:09 +01:00
|
|
|
commands.add(new FCommandChat());
|
|
|
|
commands.add(new FCommandClaim());
|
2011-07-22 14:25:12 +02:00
|
|
|
commands.add(new FCommandConfig());
|
2011-03-22 18:48:09 +01:00
|
|
|
commands.add(new FCommandCreate());
|
|
|
|
commands.add(new FCommandDeinvite());
|
|
|
|
commands.add(new FCommandDescription());
|
2011-05-08 17:44:00 +02:00
|
|
|
commands.add(new FCommandDisband());
|
2011-03-23 17:39:56 +01:00
|
|
|
commands.add(new FCommandHome());
|
2011-03-22 18:48:09 +01:00
|
|
|
commands.add(new FCommandInvite());
|
|
|
|
commands.add(new FCommandJoin());
|
|
|
|
commands.add(new FCommandKick());
|
|
|
|
commands.add(new FCommandLeave());
|
|
|
|
commands.add(new FCommandList());
|
2011-05-08 17:16:43 +02:00
|
|
|
commands.add(new FCommandLock());
|
2011-03-22 18:48:09 +01:00
|
|
|
commands.add(new FCommandMap());
|
|
|
|
commands.add(new FCommandMod());
|
|
|
|
commands.add(new FCommandOpen());
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
commands.add(new FCommandOwner());
|
|
|
|
commands.add(new FCommandOwnerList());
|
2011-07-25 20:16:14 +02:00
|
|
|
commands.add(new FCommandPower());
|
2011-03-22 18:48:09 +01:00
|
|
|
commands.add(new FCommandRelationAlly());
|
|
|
|
commands.add(new FCommandRelationEnemy());
|
|
|
|
commands.add(new FCommandRelationNeutral());
|
2011-05-08 17:16:43 +02:00
|
|
|
commands.add(new FCommandReload());
|
2011-03-23 17:39:56 +01:00
|
|
|
commands.add(new FCommandSafeclaim());
|
2011-05-29 23:28:29 +02:00
|
|
|
commands.add(new FCommandSafeunclaimall());
|
|
|
|
commands.add(new FCommandSaveAll());
|
2011-03-23 17:39:56 +01:00
|
|
|
commands.add(new FCommandSethome());
|
2011-03-22 18:48:09 +01:00
|
|
|
commands.add(new FCommandShow());
|
|
|
|
commands.add(new FCommandTag());
|
|
|
|
commands.add(new FCommandTitle());
|
|
|
|
commands.add(new FCommandUnclaim());
|
2011-04-08 16:22:00 +02:00
|
|
|
commands.add(new FCommandUnclaimall());
|
2011-03-22 18:48:09 +01:00
|
|
|
commands.add(new FCommandVersion());
|
2011-05-29 23:28:29 +02:00
|
|
|
commands.add(new FCommandWarclaim());
|
|
|
|
commands.add(new FCommandWarunclaimall());
|
|
|
|
commands.add(new FCommandWorldNoClaim());
|
|
|
|
commands.add(new FCommandWorldNoPowerLoss());
|
2011-03-18 17:33:23 +01:00
|
|
|
|
2011-05-08 17:16:43 +02:00
|
|
|
// Ensure base folder exists!
|
2011-03-22 18:48:09 +01:00
|
|
|
this.getDataFolder().mkdirs();
|
2011-02-06 13:36:11 +01:00
|
|
|
|
2011-03-22 20:36:33 +01:00
|
|
|
Conf.load();
|
2011-03-18 17:33:23 +01:00
|
|
|
FPlayer.load();
|
|
|
|
Faction.load();
|
|
|
|
Board.load();
|
2011-02-06 13:36:11 +01:00
|
|
|
|
2011-03-22 20:36:33 +01:00
|
|
|
setupPermissions();
|
2011-07-20 15:48:14 +02:00
|
|
|
integrateEssentialsChat();
|
2011-03-22 20:36:33 +01:00
|
|
|
|
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
|
|
|
Econ.monitorPlugins();
|
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
// Register events
|
2011-02-13 17:04:06 +01:00
|
|
|
PluginManager pm = this.getServer().getPluginManager();
|
2011-02-12 18:05:05 +01:00
|
|
|
pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.Highest, this);
|
2011-07-24 13:09:58 +02:00
|
|
|
pm.registerEvent(Event.Type.PLAYER_CHAT, this.chatEarlyListener, Event.Priority.Lowest, this);
|
2011-03-30 06:37:32 +02:00
|
|
|
pm.registerEvent(Event.Type.PLAYER_INTERACT, this.playerListener, Event.Priority.Normal, this);
|
2011-02-06 13:36:11 +01:00
|
|
|
pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Event.Priority.Normal, this);
|
2011-03-23 17:39:56 +01:00
|
|
|
pm.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Event.Priority.Normal, this);
|
2011-05-29 23:28:29 +02:00
|
|
|
pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Event.Priority.Normal, this);
|
2011-03-23 17:39:56 +01:00
|
|
|
pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Event.Priority.High, this);
|
2011-03-30 11:23:20 +02:00
|
|
|
pm.registerEvent(Event.Type.PLAYER_BUCKET_EMPTY, this.playerListener, Event.Priority.Normal, this);
|
|
|
|
pm.registerEvent(Event.Type.PLAYER_BUCKET_FILL, this.playerListener, Event.Priority.Normal, this);
|
2011-02-06 13:36:11 +01:00
|
|
|
pm.registerEvent(Event.Type.ENTITY_DEATH, this.entityListener, Event.Priority.Normal, this);
|
2011-03-30 06:37:32 +02:00
|
|
|
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Event.Priority.Normal, this);
|
2011-03-06 21:13:48 +01:00
|
|
|
pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Event.Priority.Normal, this);
|
2011-03-23 17:39:56 +01:00
|
|
|
pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Event.Priority.Normal, this);
|
|
|
|
pm.registerEvent(Event.Type.ENTITY_TARGET, this.entityListener, Event.Priority.Normal, this);
|
2011-04-28 22:45:43 +02:00
|
|
|
pm.registerEvent(Event.Type.PAINTING_BREAK, this.entityListener, Event.Priority.Normal, this);
|
|
|
|
pm.registerEvent(Event.Type.PAINTING_PLACE, this.entityListener, Event.Priority.Normal, this);
|
2011-03-30 06:37:32 +02:00
|
|
|
pm.registerEvent(Event.Type.BLOCK_BREAK, this.blockListener, Event.Priority.Normal, this);
|
|
|
|
pm.registerEvent(Event.Type.BLOCK_DAMAGE, this.blockListener, Event.Priority.Normal, this);
|
|
|
|
pm.registerEvent(Event.Type.BLOCK_PLACE, this.blockListener, Event.Priority.Normal, this);
|
2011-07-20 19:22:03 +02:00
|
|
|
pm.registerEvent(Event.Type.BLOCK_PISTON_EXTEND, this.blockListener, Event.Priority.Normal, this);
|
|
|
|
pm.registerEvent(Event.Type.BLOCK_PISTON_RETRACT, this.blockListener, Event.Priority.Normal, this);
|
2011-03-22 22:31:04 +01:00
|
|
|
|
|
|
|
// Register recurring tasks
|
|
|
|
long saveTicks = 20 * 60 * 30; // Approximately every 30 min
|
2011-04-06 12:04:57 +02:00
|
|
|
if (saveTask == null)
|
|
|
|
saveTask = this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new SaveTask(), saveTicks, saveTicks);
|
2011-02-06 13:36:11 +01:00
|
|
|
|
2011-07-27 22:56:45 +02:00
|
|
|
log("=== ENABLE DONE (Took "+(System.currentTimeMillis()-timeInitStart)+"ms) ===");
|
2011-03-18 17:33:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
2011-04-06 12:04:57 +02:00
|
|
|
if (saveTask != null) {
|
|
|
|
this.getServer().getScheduler().cancelTask(saveTask);
|
|
|
|
saveTask = null;
|
|
|
|
}
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
if (gson != null) {
|
|
|
|
saveAll();
|
|
|
|
}
|
2011-07-20 15:48:14 +02:00
|
|
|
unhookEssentialsChat();
|
2011-03-18 17:33:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// Integration with other plugins
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
private void setupPermissions() {
|
|
|
|
if (Permissions != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
Plugin test = this.getServer().getPluginManager().getPlugin("Permissions");
|
|
|
|
|
2011-03-18 17:33:23 +01:00
|
|
|
if (test != null) {
|
|
|
|
Permissions = ((Permissions)test).getHandler();
|
|
|
|
Factions.log("Found and will use plugin "+((Permissions)test).getDescription().getFullName());
|
|
|
|
} else {
|
|
|
|
Factions.log("Permission system not detected, defaulting to OP");
|
|
|
|
}
|
|
|
|
}
|
2011-06-12 00:29:24 +02:00
|
|
|
|
2011-07-20 15:48:14 +02:00
|
|
|
private void integrateEssentialsChat() {
|
|
|
|
if (essChat != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Plugin test = this.getServer().getPluginManager().getPlugin("EssentialsChat");
|
|
|
|
|
|
|
|
if (test != null) {
|
2011-07-21 02:31:28 +02:00
|
|
|
try {
|
|
|
|
essChat = (EssentialsChat)test;
|
|
|
|
essChat.addEssentialsChatListener("Factions", new IEssentialsChatListener() {
|
|
|
|
public boolean shouldHandleThisChat(PlayerChatEvent event)
|
|
|
|
{
|
|
|
|
return shouldLetFactionsHandleThisChat(event);
|
|
|
|
}
|
|
|
|
public String modifyMessage(PlayerChatEvent event, Player target, String message)
|
|
|
|
{
|
|
|
|
return message.replace("{FACTION}", getPlayerFactionTagRelation(event.getPlayer(), target)).replace("{FACTION_TITLE}", getPlayerTitle(event.getPlayer()));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Factions.log("Found and will integrate chat with "+test.getDescription().getFullName());
|
|
|
|
}
|
|
|
|
catch (NoSuchMethodError ex) {
|
|
|
|
essChat = null;
|
|
|
|
}
|
2011-07-20 15:48:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private void unhookEssentialsChat() {
|
|
|
|
if (essChat != null) {
|
|
|
|
essChat.removeEssentialsChatListener("Factions");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-12 00:29:24 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// Functions for other plugins to hook into
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2011-06-29 01:25:00 +02:00
|
|
|
// This value will be updated whenever new hooks are added
|
|
|
|
public int hookSupportVersion() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-06-27 19:25:02 +02:00
|
|
|
// If another plugin is handling insertion of chat tags, this should be used to notify Factions
|
|
|
|
public void handleFactionTagExternally(boolean notByFactions) {
|
|
|
|
Conf.chatTagHandledByAnotherPlugin = notByFactions;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simply put, should this chat event be left for Factions to handle? For now, that means players with Faction Chat
|
|
|
|
// enabled or use of the Factions f command without a slash; combination of isPlayerFactionChatting() and isFactionsCommand()
|
2011-06-29 03:00:08 +02:00
|
|
|
public boolean shouldLetFactionsHandleThisChat(PlayerChatEvent event) {
|
2011-06-29 01:25:00 +02:00
|
|
|
if (event == null)
|
|
|
|
return false;
|
2011-06-27 19:25:02 +02:00
|
|
|
return (isPlayerFactionChatting(event.getPlayer()) || isFactionsCommand(event.getMessage()));
|
|
|
|
}
|
|
|
|
|
2011-06-12 00:29:24 +02:00
|
|
|
// Does player have Faction Chat enabled? If so, chat plugins should preferably not do channels,
|
|
|
|
// local chat, or anything else which targets individual recipients, so Faction Chat can be done
|
2011-06-23 03:12:37 +02:00
|
|
|
public boolean isPlayerFactionChatting(Player player) {
|
2011-06-12 00:29:24 +02:00
|
|
|
if (player == null)
|
|
|
|
return false;
|
|
|
|
FPlayer me = FPlayer.get(player);
|
|
|
|
if (me == null)
|
|
|
|
return false;
|
|
|
|
return me.isFactionChatting();
|
|
|
|
}
|
|
|
|
|
2011-06-23 03:12:37 +02:00
|
|
|
// Is this chat message actually a Factions command, and thus should be left alone by other plugins?
|
|
|
|
public boolean isFactionsCommand(String check) {
|
2011-06-29 03:00:08 +02:00
|
|
|
if (check == null || check.isEmpty())
|
2011-06-29 01:25:00 +02:00
|
|
|
return false;
|
2011-06-29 03:00:08 +02:00
|
|
|
return (Conf.allowNoSlashCommand && (check.startsWith(instance.getBaseCommand()+" ") || check.equals(instance.getBaseCommand())));
|
2011-06-23 03:12:37 +02:00
|
|
|
}
|
|
|
|
|
2011-06-12 00:29:24 +02:00
|
|
|
// Get a player's faction tag (faction name), mainly for usage by chat plugins for local/channel chat
|
2011-06-23 03:12:37 +02:00
|
|
|
public String getPlayerFactionTag(Player player) {
|
2011-06-12 00:29:24 +02:00
|
|
|
return getPlayerFactionTagRelation(player, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same as above, but with relation (enemy/neutral/ally) coloring potentially added to the tag
|
2011-06-23 03:12:37 +02:00
|
|
|
public String getPlayerFactionTagRelation(Player speaker, Player listener) {
|
2011-06-29 03:00:08 +02:00
|
|
|
String tag = "~";
|
|
|
|
|
2011-06-12 00:29:24 +02:00
|
|
|
if (speaker == null)
|
2011-06-29 03:00:08 +02:00
|
|
|
return tag;
|
2011-06-12 00:29:24 +02:00
|
|
|
|
|
|
|
FPlayer me = FPlayer.get(speaker);
|
|
|
|
if (me == null)
|
2011-06-29 03:00:08 +02:00
|
|
|
return tag;
|
2011-06-12 00:29:24 +02:00
|
|
|
|
|
|
|
// if listener isn't set, or config option is disabled, give back uncolored tag
|
2011-06-29 03:00:08 +02:00
|
|
|
if (listener == null || !Conf.chatTagRelationColored) {
|
|
|
|
tag = me.getChatTag().trim();
|
|
|
|
} else {
|
|
|
|
FPlayer you = FPlayer.get(listener);
|
|
|
|
if (you == null)
|
|
|
|
tag = me.getChatTag().trim();
|
|
|
|
else // everything checks out, give the colored tag
|
|
|
|
tag = me.getChatTag(you).trim();
|
|
|
|
}
|
|
|
|
if (tag.isEmpty())
|
|
|
|
tag = "~";
|
2011-06-12 00:29:24 +02:00
|
|
|
|
2011-06-29 03:00:08 +02:00
|
|
|
return tag;
|
2011-06-12 00:29:24 +02:00
|
|
|
}
|
|
|
|
|
2011-06-21 07:20:36 +02:00
|
|
|
// Get a player's title within their faction, mainly for usage by chat plugins for local/channel chat
|
2011-06-23 03:12:37 +02:00
|
|
|
public String getPlayerTitle(Player player) {
|
2011-06-21 07:20:36 +02:00
|
|
|
if (player == null)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
FPlayer me = FPlayer.get(player);
|
|
|
|
if (me == null)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
return me.getTitle().trim();
|
|
|
|
}
|
|
|
|
|
2011-03-23 17:39:56 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// Test rights
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
public static boolean hasPermParticipate(CommandSender sender) {
|
2011-07-18 18:46:14 +02:00
|
|
|
return hasPerm(sender, "factions.participate");
|
2011-03-23 17:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean hasPermCreate(CommandSender sender) {
|
2011-07-18 18:46:14 +02:00
|
|
|
return hasPerm(sender, "factions.create");
|
2011-03-23 17:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean hasPermManageSafeZone(CommandSender sender) {
|
2011-07-18 18:46:14 +02:00
|
|
|
return hasPerm(sender, "factions.manageSafeZone");
|
2011-03-23 17:39:56 +01:00
|
|
|
}
|
2011-05-29 23:28:29 +02:00
|
|
|
|
|
|
|
public static boolean hasPermManageWarZone(CommandSender sender) {
|
2011-07-18 18:46:14 +02:00
|
|
|
return hasPerm(sender, "factions.manageWarZone");
|
2011-05-29 23:28:29 +02:00
|
|
|
}
|
2011-04-04 14:16:53 +02:00
|
|
|
|
|
|
|
public static boolean hasPermAdminBypass(CommandSender sender) {
|
2011-07-18 18:46:14 +02:00
|
|
|
return hasPerm(sender, "factions.adminBypass");
|
2011-04-04 14:16:53 +02:00
|
|
|
}
|
2011-03-23 17:39:56 +01:00
|
|
|
|
2011-05-08 17:16:43 +02:00
|
|
|
public static boolean hasPermReload(CommandSender sender) {
|
2011-07-18 18:46:14 +02:00
|
|
|
return hasPerm(sender, "factions.reload");
|
2011-05-08 17:16:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean hasPermSaveAll(CommandSender sender) {
|
2011-07-18 18:46:14 +02:00
|
|
|
return hasPerm(sender, "factions.saveall");
|
2011-05-08 17:16:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean hasPermLock(CommandSender sender) {
|
2011-07-18 18:46:14 +02:00
|
|
|
return hasPerm(sender, "factions.lock");
|
2011-05-08 17:16:43 +02:00
|
|
|
}
|
|
|
|
|
2011-07-22 14:25:12 +02:00
|
|
|
public static boolean hasPermConfigure(CommandSender sender) {
|
|
|
|
return hasPerm(sender, "factions.config");
|
|
|
|
}
|
|
|
|
|
2011-05-08 17:44:00 +02:00
|
|
|
public static boolean hasPermDisband(CommandSender sender) {
|
2011-07-18 18:46:14 +02:00
|
|
|
return hasPerm(sender, "factions.disband");
|
2011-05-08 17:44:00 +02:00
|
|
|
}
|
|
|
|
|
2011-05-29 23:28:29 +02:00
|
|
|
public static boolean hasPermWorlds(CommandSender sender) {
|
2011-07-18 18:46:14 +02:00
|
|
|
return hasPerm(sender, "factions.worldOptions");
|
2011-05-29 23:28:29 +02:00
|
|
|
}
|
|
|
|
|
2011-07-25 20:16:14 +02:00
|
|
|
public static boolean hasPermViewAnyPower(CommandSender sender) {
|
|
|
|
return hasPerm(sender, "factions.viewAnyPower");
|
|
|
|
}
|
|
|
|
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
public static boolean hasPermOwnershipBypass(CommandSender sender) {
|
|
|
|
return hasPerm(sender, "factions.ownershipBypass");
|
|
|
|
}
|
|
|
|
|
2011-07-20 23:22:54 +02:00
|
|
|
public static boolean isCommandDisabled(CommandSender sender, String command) {
|
|
|
|
return (hasPerm(sender, "factions.commandDisable."+command) && !hasPerm(sender, "factions.commandDisable.none"));
|
|
|
|
}
|
|
|
|
|
2011-07-18 18:46:14 +02:00
|
|
|
private static boolean hasPerm(CommandSender sender, String permNode) {
|
2011-03-23 17:39:56 +01:00
|
|
|
if (Factions.Permissions == null || ! (sender instanceof Player)) {
|
2011-07-18 18:46:14 +02:00
|
|
|
return sender.isOp() || sender.hasPermission(permNode);
|
2011-03-18 17:33:23 +01:00
|
|
|
}
|
|
|
|
|
2011-07-18 18:46:14 +02:00
|
|
|
Player player = (Player)sender;
|
|
|
|
return Factions.Permissions.has(player, permNode);
|
2011-03-18 17:33:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// Commands
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2011-03-22 18:48:09 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public String getBaseCommand() {
|
|
|
|
if (this.baseCommand != null) {
|
|
|
|
return this.baseCommand;
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, Object> Commands = (Map<String, Object>)this.getDescription().getCommands();
|
|
|
|
this.baseCommand = Commands.keySet().iterator().next();
|
|
|
|
return this.baseCommand;
|
|
|
|
}
|
|
|
|
|
2011-03-18 17:33:23 +01:00
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
|
|
|
List<String> parameters = new ArrayList<String>(Arrays.asList(args));
|
|
|
|
this.handleCommand(sender, parameters);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void handleCommand(CommandSender sender, List<String> parameters) {
|
|
|
|
if (parameters.size() == 0) {
|
|
|
|
this.commands.get(0).execute(sender, parameters);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String commandName = parameters.get(0).toLowerCase();
|
|
|
|
parameters.remove(0);
|
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
for (FBaseCommand fcommand : this.commands) {
|
2011-03-18 17:33:23 +01:00
|
|
|
if (fcommand.getAliases().contains(commandName)) {
|
|
|
|
fcommand.execute(sender, parameters);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-08 16:03:04 +02:00
|
|
|
sender.sendMessage(Conf.colorSystem+"Unknown faction command \""+commandName+"\". Try "+Conf.colorCommand+"/"+this.getBaseCommand()+" help");
|
2011-03-18 17:33:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// Logging
|
|
|
|
// -------------------------------------------- //
|
|
|
|
public static void log(String msg) {
|
|
|
|
log(Level.INFO, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void log(Level level, String msg) {
|
|
|
|
Logger.getLogger("Minecraft").log(level, "["+instance.getDescription().getFullName()+"] "+msg);
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
2011-03-22 22:31:04 +01:00
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// Save all
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
public static void saveAll() {
|
|
|
|
FPlayer.save();
|
|
|
|
Faction.save();
|
|
|
|
Board.save();
|
2011-03-23 17:39:56 +01:00
|
|
|
Conf.save();
|
2011-03-22 22:31:04 +01:00
|
|
|
}
|
2011-05-08 17:16:43 +02:00
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|