From 1c062c9c79420ced86b69c566b1d337bbf236868 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 22 Mar 2011 18:48:09 +0100 Subject: [PATCH] Now it compiles. Time to fix runtime errors... --- plugin.yml | 8 +- src/com/bukkit/mcteam/factions/Conf.java | 102 +----------------- src/com/bukkit/mcteam/factions/Faction.java | 86 +++++++-------- src/com/bukkit/mcteam/factions/Factions.java | 95 ++++++++++++---- .../factions/commands/FBaseCommand.java | 37 ++++--- .../factions/commands/FCommandAdmin.java | 3 + .../factions/commands/FCommandChat.java | 4 + .../factions/commands/FCommandClaim.java | 3 + .../factions/commands/FCommandCreate.java | 7 +- .../factions/commands/FCommandDeinvite.java | 5 + .../commands/FCommandDescription.java | 5 +- .../factions/commands/FCommandHelp.java | 51 +++++---- .../factions/commands/FCommandInvite.java | 7 +- .../factions/commands/FCommandJoin.java | 3 + .../factions/commands/FCommandKick.java | 6 +- .../factions/commands/FCommandLeave.java | 3 + .../factions/commands/FCommandList.java | 4 + .../mcteam/factions/commands/FCommandMap.java | 6 +- .../mcteam/factions/commands/FCommandMod.java | 3 + .../factions/commands/FCommandOpen.java | 4 + .../commands/FCommandRelationAlly.java | 7 ++ .../commands/FCommandRelationEnemy.java | 7 ++ .../commands/FCommandRelationNeutral.java | 7 ++ .../factions/commands/FCommandShow.java | 4 + .../mcteam/factions/commands/FCommandTag.java | 3 + .../factions/commands/FCommandTitle.java | 3 + .../factions/commands/FCommandUnclaim.java | 4 + .../factions/commands/FCommandVersion.java | 3 + .../factions/commands/FRelationCommand.java | 5 +- .../listeners/FactionsPlayerListener.java | 102 +++++++----------- 30 files changed, 312 insertions(+), 275 deletions(-) diff --git a/plugin.yml b/plugin.yml index 103abde5..7f628b2c 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,3 +1,7 @@ name: Factions -version: 1.0 beta8 -main: com.bukkit.mcteam.factions.Factions \ No newline at end of file +version: 1.1 +main: com.bukkit.mcteam.factions.Factions +commands: + f: + description: All of the Factions commands + usage: See documentation. \ No newline at end of file diff --git a/src/com/bukkit/mcteam/factions/Conf.java b/src/com/bukkit/mcteam/factions/Conf.java index 3a7109c6..b9238cff 100644 --- a/src/com/bukkit/mcteam/factions/Conf.java +++ b/src/com/bukkit/mcteam/factions/Conf.java @@ -50,112 +50,14 @@ public class Conf { public static boolean territoryBlockFireballs = false; public static List territoryProtectedMaterials = new ArrayList(); - - // Command names / aliases - public static List aliasBase = new ArrayList(); - public static List aliasHelp = new ArrayList(); - - public static List aliasList = new ArrayList(); - public static List aliasShow = new ArrayList(); - - public static List aliasMap = new ArrayList(); - - public static List aliasJoin = new ArrayList(); - public static List aliasLeave = new ArrayList(); - - public static List aliasCreate = new ArrayList(); - public static List aliasTag = new ArrayList(); - public static List aliasDescription = new ArrayList(); - public static List aliasChat = new ArrayList(); - - public static List aliasTitle = new ArrayList(); - public static List aliasInvite = new ArrayList(); - public static List aliasDeinvite = new ArrayList(); - public static List aliasOpen = new ArrayList(); - - public static List aliasKick = new ArrayList(); - public static List aliasModerator = new ArrayList(); - public static List aliasAdmin = new ArrayList(); - - public static List aliasClaim = new ArrayList(); - public static List aliasUnclaim = new ArrayList(); - - public static List aliasRelationAlly = new ArrayList(); - public static List aliasRelationNeutral = new ArrayList(); - public static List aliasRelationEnemy = new ArrayList(); - - public static List aliasVersion = new ArrayList(); - - // Value aliases - public static List aliasTrue = new ArrayList(); + + public static boolean allowNoSlashCommand = true; static { territoryProtectedMaterials.add(Material.WOODEN_DOOR); territoryProtectedMaterials.add(Material.DISPENSER); territoryProtectedMaterials.add(Material.CHEST); territoryProtectedMaterials.add(Material.FURNACE); - - aliasBase.add("/f"); - aliasBase.add("f"); - - aliasHelp.add("help"); - aliasHelp.add("h"); - aliasHelp.add("?"); - - aliasList.add("list"); - aliasList.add("ls"); - - aliasShow.add("show"); - aliasShow.add("who"); - - aliasMap.add("map"); - - aliasJoin.add("join"); - - aliasLeave.add("leave"); - - aliasCreate.add("create"); - aliasCreate.add("new"); - aliasTag.add("tag"); - aliasDescription.add("desc"); - - aliasChat.add("chat"); - aliasChat.add("c"); - - aliasTitle.add("title"); - - aliasInvite.add("invite"); - aliasInvite.add("inv"); - - aliasDeinvite.add("deinvite"); - aliasDeinvite.add("deinv"); - - aliasOpen.add("open"); - aliasOpen.add("close"); - - aliasKick.add("kick"); - - aliasModerator.add("mod"); - - aliasAdmin.add("admin"); - - aliasClaim.add("claim"); - - aliasUnclaim.add("unclaim"); - aliasUnclaim.add("declaim"); - - aliasRelationAlly.add("ally"); - aliasRelationNeutral.add("neutral"); - aliasRelationEnemy.add("enemy"); - - aliasVersion.add("version"); - - aliasTrue.add("true"); - aliasTrue.add("yes"); - aliasTrue.add("y"); - aliasTrue.add("ok"); - aliasTrue.add("on"); - aliasTrue.add("+"); } // -------------------------------------------- // diff --git a/src/com/bukkit/mcteam/factions/Faction.java b/src/com/bukkit/mcteam/factions/Faction.java index 0f30a172..8eb2e31a 100644 --- a/src/com/bukkit/mcteam/factions/Faction.java +++ b/src/com/bukkit/mcteam/factions/Faction.java @@ -53,6 +53,44 @@ public class Faction { return this.id; } + public boolean getOpen() { + return open; + } + + public void setOpen(boolean isOpen) { + open = isOpen; + save(); + } + + public String getTag() { + return this.getTag(""); + } + public String getTag(String prefix) { + return prefix+this.tag; + } + public String getTag(Faction otherFaction) { + return this.getTag(otherFaction.getRelationColor(this).toString()); + } + public String getTag(FPlayer otherFollower) { + return this.getTag(otherFollower.getRelationColor(this).toString()); + } + public void setTag(String str) { + if (Conf.factionTagForceUpperCase) { + str = str.toUpperCase(); + } + this.tag = str; + save(); + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String value) { + this.description = value; + save(); + } + // ------------------------------- // Invites // ------------------------------- @@ -106,49 +144,6 @@ public class Faction { return getRelation(follower.getFaction()); } - - - // ------------------------------- - // Information - // ------------------------------- - public String getTag() { - return this.getTag(""); - } - public String getTag(String prefix) { - return prefix+this.tag; - } - public String getTag(Faction otherFaction) { - return this.getTag(otherFaction.getRelationColor(this).toString()); - } - public String getTag(FPlayer otherFollower) { - return this.getTag(otherFollower.getRelationColor(this).toString()); - } - public void setTag(String str) { - if (Conf.factionTagForceUpperCase) { - str = str.toUpperCase(); - } - this.tag = str; - this.save(); - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String value) { - this.description = value; - this.save(); - } - - public boolean getOpen() { - return open; - } - - public void setOpen(boolean isOpen) { - open = isOpen; - this.save(); - } - //----------------------------------------------// // Power //----------------------------------------------// @@ -336,11 +331,10 @@ public class Faction { if ( ! file.exists()) { Factions.log("No factions to load from disk. Creating new file."); save(); - return true; } try { - Type type = new TypeToken>(){}.getType(); + Type type = new TypeToken>(){}.getType(); instances = Factions.gson.fromJson(DiscUtil.read(file), type); } catch (IOException e) { e.printStackTrace(); @@ -357,7 +351,7 @@ public class Faction { faction.id = 0; instances.put(faction.id, faction); } - + return true; } diff --git a/src/com/bukkit/mcteam/factions/Factions.java b/src/com/bukkit/mcteam/factions/Factions.java index 46be31ba..6976e93a 100644 --- a/src/com/bukkit/mcteam/factions/Factions.java +++ b/src/com/bukkit/mcteam/factions/Factions.java @@ -4,6 +4,7 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -17,6 +18,29 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import com.bukkit.mcteam.factions.commands.FBaseCommand; +import com.bukkit.mcteam.factions.commands.FCommandAdmin; +import com.bukkit.mcteam.factions.commands.FCommandChat; +import com.bukkit.mcteam.factions.commands.FCommandClaim; +import com.bukkit.mcteam.factions.commands.FCommandCreate; +import com.bukkit.mcteam.factions.commands.FCommandDeinvite; +import com.bukkit.mcteam.factions.commands.FCommandDescription; +import com.bukkit.mcteam.factions.commands.FCommandHelp; +import com.bukkit.mcteam.factions.commands.FCommandInvite; +import com.bukkit.mcteam.factions.commands.FCommandJoin; +import com.bukkit.mcteam.factions.commands.FCommandKick; +import com.bukkit.mcteam.factions.commands.FCommandLeave; +import com.bukkit.mcteam.factions.commands.FCommandList; +import com.bukkit.mcteam.factions.commands.FCommandMap; +import com.bukkit.mcteam.factions.commands.FCommandMod; +import com.bukkit.mcteam.factions.commands.FCommandOpen; +import com.bukkit.mcteam.factions.commands.FCommandRelationAlly; +import com.bukkit.mcteam.factions.commands.FCommandRelationEnemy; +import com.bukkit.mcteam.factions.commands.FCommandRelationNeutral; +import com.bukkit.mcteam.factions.commands.FCommandShow; +import com.bukkit.mcteam.factions.commands.FCommandTag; +import com.bukkit.mcteam.factions.commands.FCommandTitle; +import com.bukkit.mcteam.factions.commands.FCommandUnclaim; +import com.bukkit.mcteam.factions.commands.FCommandVersion; import com.bukkit.mcteam.factions.listeners.FactionsBlockListener; import com.bukkit.mcteam.factions.listeners.FactionsEntityListener; import com.bukkit.mcteam.factions.listeners.FactionsPlayerListener; @@ -48,31 +72,50 @@ public class Factions extends JavaPlugin { // Commands public List commands = new ArrayList(); + + private String baseCommand; public Factions() { Factions.instance = this; + + // Add the commands + commands.add(new FCommandHelp()); + commands.add(new FCommandAdmin()); + commands.add(new FCommandChat()); + commands.add(new FCommandClaim()); + commands.add(new FCommandCreate()); + commands.add(new FCommandDeinvite()); + commands.add(new FCommandDescription()); + commands.add(new FCommandInvite()); + commands.add(new FCommandJoin()); + commands.add(new FCommandKick()); + commands.add(new FCommandLeave()); + commands.add(new FCommandList()); + commands.add(new FCommandMap()); + commands.add(new FCommandMod()); + commands.add(new FCommandOpen()); + commands.add(new FCommandRelationAlly()); + commands.add(new FCommandRelationEnemy()); + commands.add(new FCommandRelationNeutral()); + commands.add(new FCommandShow()); + commands.add(new FCommandTag()); + commands.add(new FCommandTitle()); + commands.add(new FCommandUnclaim()); + commands.add(new FCommandVersion()); } @Override public void onEnable() { - // Add the commands - /*commands.add(new VCommandBlood()); - commands.add(new VCommandInfect()); - commands.add(new VCommandLoad()); - commands.add(new VCommandSave()); - commands.add(new VCommandTime()); - commands.add(new VCommandTurn()); - commands.add(new VCommandCure()); - commands.add(new VCommandList()); - commands.add(new VCommandVersion());*/ - - setupPermissions(); - setupHelp(); - log("=== INIT START ==="); long timeInitStart = System.currentTimeMillis(); + setupHelp(); + setupPermissions(); + + // Ensure basefolder exists! + this.getDataFolder().mkdirs(); + FPlayer.load(); Faction.load(); Board.load(); @@ -97,8 +140,10 @@ public class Factions extends JavaPlugin { @Override public void onDisable() { - // TODO Auto-generated method stub - + FPlayer.save(); + Faction.save(); + Board.save(); + log("Disabled"); } // -------------------------------------------- // @@ -130,9 +175,7 @@ public class Factions extends JavaPlugin { if (test != null) { helpPlugin = ((Help) test); Factions.log("Found and will use plugin "+helpPlugin.getDescription().getFullName()); - - // TODO not hardcoded: - helpPlugin.registerCommand("f help *[page]", "Factions plugin help.", helpPlugin, true); + helpPlugin.registerCommand(this.getBaseCommand()+" help *[page]", "Factions plugin help.", helpPlugin, true); } } @@ -141,6 +184,17 @@ public class Factions extends JavaPlugin { // Commands // -------------------------------------------- // + @SuppressWarnings("unchecked") + public String getBaseCommand() { + if (this.baseCommand != null) { + return this.baseCommand; + } + + Map Commands = (Map)this.getDescription().getCommands(); + this.baseCommand = Commands.keySet().iterator().next(); + return this.baseCommand; + } + @Override public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { List parameters = new ArrayList(Arrays.asList(args)); @@ -164,8 +218,7 @@ public class Factions extends JavaPlugin { } } - sender.sendMessage(Conf.colorSystem+"Unknown faction command \""+commandName+"\". Try /help faction"); // TODO test help messages exists.... - //TODO should we use internal help system instead? + sender.sendMessage(Conf.colorSystem+"Unknown faction command \""+commandName+"\". Try "+Conf.colorCommand+"/f help"); } // -------------------------------------------- // diff --git a/src/com/bukkit/mcteam/factions/commands/FBaseCommand.java b/src/com/bukkit/mcteam/factions/commands/FBaseCommand.java index 16625421..0b202fb2 100644 --- a/src/com/bukkit/mcteam/factions/commands/FBaseCommand.java +++ b/src/com/bukkit/mcteam/factions/commands/FBaseCommand.java @@ -14,6 +14,8 @@ import com.bukkit.mcteam.factions.struct.Role; import com.bukkit.mcteam.factions.util.TextUtil; public class FBaseCommand { + public List aliases; + public List requiredParameters; public List optionalParameters; @@ -42,17 +44,7 @@ public class FBaseCommand { helpDescription = "no description"; } - public ArrayList getAliases() { - String name = this.getClass().getName().toLowerCase(); - if (name.lastIndexOf('.') > 0) { - name = name.substring(name.lastIndexOf('.')+1); - } - - name = name.substring(8); - - ArrayList aliases = new ArrayList(); - aliases.add(name); - + public List getAliases() { return aliases; } @@ -66,7 +58,6 @@ public class FBaseCommand { this.parameters = parameters; if ( ! validateCall()) { - sendMessage("try /help factions"); return; } @@ -137,7 +128,7 @@ public class FBaseCommand { // -------------------------------------------- // // Help and usage description // -------------------------------------------- // - public String getUseageTemplate(boolean withColor) { + public String getUseageTemplate(boolean withColor, boolean withDescription) { String ret = ""; if (withColor) { @@ -161,9 +152,17 @@ public class FBaseCommand { } ret += TextUtil.implode(parts, " "); + + if (withDescription) { + ret += " "+Conf.colorSystem + this.helpDescription; + } return ret; } + public String getUseageTemplate(boolean withColor) { + return getUseageTemplate(withColor, false); + } + public String getUseageTemplate() { return getUseageTemplate(true); } @@ -260,4 +259,16 @@ public class FBaseCommand { return false; } + + public boolean parseBool(String str) { + List aliasTrue = new ArrayList(); + aliasTrue.add("true"); + aliasTrue.add("yes"); + aliasTrue.add("y"); + aliasTrue.add("ok"); + aliasTrue.add("on"); + aliasTrue.add("+"); + + return aliasTrue.contains(str.toLowerCase()); + } } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandAdmin.java b/src/com/bukkit/mcteam/factions/commands/FCommandAdmin.java index d89c9892..b2a39628 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandAdmin.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandAdmin.java @@ -10,6 +10,9 @@ import com.bukkit.mcteam.factions.struct.Role; public class FCommandAdmin extends FBaseCommand { public FCommandAdmin() { + aliases = new ArrayList(); + aliases.add("admin"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); requiredParameters.add("player name"); diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandChat.java b/src/com/bukkit/mcteam/factions/commands/FCommandChat.java index ad129b87..42c66b5e 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandChat.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandChat.java @@ -5,6 +5,10 @@ import java.util.ArrayList; public class FCommandChat extends FBaseCommand { public FCommandChat() { + aliases = new ArrayList(); + aliases.add("chat"); + aliases.add("c"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandClaim.java b/src/com/bukkit/mcteam/factions/commands/FCommandClaim.java index b66eaf8d..d2ac1630 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandClaim.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandClaim.java @@ -12,6 +12,9 @@ import com.bukkit.mcteam.factions.struct.Role; public class FCommandClaim extends FBaseCommand { public FCommandClaim() { + aliases = new ArrayList(); + aliases.add("claim"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandCreate.java b/src/com/bukkit/mcteam/factions/commands/FCommandCreate.java index 2b40f0d9..2e7ce1c5 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandCreate.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandCreate.java @@ -10,6 +10,9 @@ import com.bukkit.mcteam.factions.struct.Role; public class FCommandCreate extends FBaseCommand { public FCommandCreate() { + aliases = new ArrayList(); + aliases.add("create"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); requiredParameters.add("faction tag"); @@ -51,8 +54,8 @@ public class FCommandCreate extends FBaseCommand { follower.sendMessage(me.getNameAndRelevant(follower)+Conf.colorSystem+" created a new faction "+faction.getTag(follower)); } - sendMessage("Now update your faction description. Use:"); - sendMessage(Conf.colorCommand+Conf.aliasBase.get(0)+" "+Conf.aliasDescription.get(0)+" "+"[description]"); + sendMessage("You should now:"); + sendMessage( new FCommandDescription().getUseageTemplate() ); } } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandDeinvite.java b/src/com/bukkit/mcteam/factions/commands/FCommandDeinvite.java index c6302fb4..f01c0211 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandDeinvite.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandDeinvite.java @@ -10,6 +10,10 @@ import com.bukkit.mcteam.factions.struct.Role; public class FCommandDeinvite extends FBaseCommand { public FCommandDeinvite() { + aliases = new ArrayList(); + aliases.add("deinvite"); + aliases.add("deinv"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); requiredParameters.add("player name"); @@ -41,6 +45,7 @@ public class FCommandDeinvite extends FBaseCommand { if (you.getFaction() == myFaction) { sendMessage(you.getName()+" is already a member of "+myFaction.getTag()); + sendMessage(new FCommandKick().getUseageTemplate()); return; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandDescription.java b/src/com/bukkit/mcteam/factions/commands/FCommandDescription.java index 70081975..920de432 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandDescription.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandDescription.java @@ -10,9 +10,12 @@ import com.bukkit.mcteam.factions.util.TextUtil; public class FCommandDescription extends FBaseCommand { public FCommandDescription() { + aliases = new ArrayList(); + aliases.add("desc"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); - requiredParameters.add("description"); + requiredParameters.add("desc"); permissions = ""; diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandHelp.java b/src/com/bukkit/mcteam/factions/commands/FCommandHelp.java index ab3863b3..ddcbcf48 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandHelp.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandHelp.java @@ -8,6 +8,11 @@ import com.bukkit.mcteam.factions.util.TextUtil; public class FCommandHelp extends FBaseCommand { public FCommandHelp() { + aliases = new ArrayList(); + aliases.add("help"); + aliases.add("h"); + aliases.add("?"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); optionalParameters.add("page"); @@ -48,36 +53,36 @@ public class FCommandHelp extends FBaseCommand { ArrayList pageLines; pageLines = new ArrayList(); - pageLines.add( new FCommandHelp().getUseageTemplate() ); - pageLines.add( new FCommandList().getUseageTemplate() ); - pageLines.add( new FCommandShow().getUseageTemplate() ); - pageLines.add( new FCommandMap().getUseageTemplate() ); - pageLines.add( new FCommandJoin().getUseageTemplate() ); - pageLines.add( new FCommandLeave().getUseageTemplate() ); - pageLines.add( new FCommandChat().getUseageTemplate() ); - pageLines.add( new FCommandCreate().getUseageTemplate() ); - pageLines.add( new FCommandTag().getUseageTemplate() ); - pageLines.add( new FCommandDescription().getUseageTemplate() ); + pageLines.add( new FCommandHelp().getUseageTemplate(true, true) ); + pageLines.add( new FCommandList().getUseageTemplate(true, true) ); + pageLines.add( new FCommandShow().getUseageTemplate(true, true) ); + pageLines.add( new FCommandMap().getUseageTemplate(true, true) ); + pageLines.add( new FCommandJoin().getUseageTemplate(true, true) ); + pageLines.add( new FCommandLeave().getUseageTemplate(true, true) ); + pageLines.add( new FCommandChat().getUseageTemplate(true, true) ); + pageLines.add( new FCommandCreate().getUseageTemplate(true, true) ); + pageLines.add( new FCommandTag().getUseageTemplate(true, true) ); + pageLines.add( new FCommandDescription().getUseageTemplate(true, true) ); helpPages.add(pageLines); pageLines = new ArrayList(); - pageLines.add( new FCommandOpen().getUseageTemplate() ); - pageLines.add( new FCommandTitle().getUseageTemplate() ); - pageLines.add( new FCommandInvite().getUseageTemplate() ); - pageLines.add( new FCommandDeinvite().getUseageTemplate() ); - pageLines.add( new FCommandClaim().getUseageTemplate() ); - pageLines.add( new FCommandUnclaim().getUseageTemplate() ); - pageLines.add( new FCommandKick().getUseageTemplate() ); - pageLines.add( new FCommandMod().getUseageTemplate() ); - pageLines.add( new FCommandAdmin().getUseageTemplate() ); + pageLines.add( new FCommandOpen().getUseageTemplate(true, true) ); + pageLines.add( new FCommandTitle().getUseageTemplate(true, true) ); + pageLines.add( new FCommandInvite().getUseageTemplate(true, true) ); + pageLines.add( new FCommandDeinvite().getUseageTemplate(true, true) ); + pageLines.add( new FCommandClaim().getUseageTemplate(true, true) ); + pageLines.add( new FCommandUnclaim().getUseageTemplate(true, true) ); + pageLines.add( new FCommandKick().getUseageTemplate(true, true) ); + pageLines.add( new FCommandMod().getUseageTemplate(true, true) ); + pageLines.add( new FCommandAdmin().getUseageTemplate(true, true) ); helpPages.add(pageLines); pageLines = new ArrayList(); - pageLines.add( new FCommandRelationAlly().getUseageTemplate() ); - pageLines.add( new FCommandRelationNeutral().getUseageTemplate() ); - pageLines.add( new FCommandRelationEnemy().getUseageTemplate() ); + pageLines.add( new FCommandRelationAlly().getUseageTemplate(true, true) ); + pageLines.add( new FCommandRelationNeutral().getUseageTemplate(true, true) ); + pageLines.add( new FCommandRelationEnemy().getUseageTemplate(true, true) ); pageLines.add(""); pageLines.add(Conf.colorSystem+"Set the relation you WISH to have with another faction."); pageLines.add(Conf.colorSystem+"Your default relation with other factions will be neutral."); @@ -114,7 +119,7 @@ public class FCommandHelp extends FBaseCommand { helpPages.add(pageLines); pageLines = new ArrayList(); - pageLines.add( new FCommandVersion().getUseageTemplate() ); + pageLines.add( new FCommandVersion().getUseageTemplate(true, true) ); helpPages.add(pageLines); } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandInvite.java b/src/com/bukkit/mcteam/factions/commands/FCommandInvite.java index 5a8289b7..0a694079 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandInvite.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandInvite.java @@ -10,6 +10,10 @@ import com.bukkit.mcteam.factions.struct.Role; public class FCommandInvite extends FBaseCommand { public FCommandInvite() { + aliases = new ArrayList(); + aliases.add("invite"); + aliases.add("inv"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); requiredParameters.add("player name"); @@ -41,7 +45,8 @@ public class FCommandInvite extends FBaseCommand { if (you.getFaction() == myFaction) { sendMessage(you.getName()+" is already a member of "+myFaction.getTag()); - sendMessage("You might want to "+Conf.colorCommand+Conf.aliasBase.get(0)+" "+Conf.aliasKick.get(0)+Conf.colorParameter+" "+you.getName()); + sendMessage("You might want to :"); + sendMessage(new FCommandKick().getUseageTemplate()); return; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandJoin.java b/src/com/bukkit/mcteam/factions/commands/FCommandJoin.java index b9159cb5..2fbb1b92 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandJoin.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandJoin.java @@ -9,6 +9,9 @@ import com.bukkit.mcteam.factions.Faction; public class FCommandJoin extends FBaseCommand { public FCommandJoin() { + aliases = new ArrayList(); + aliases.add("join"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); requiredParameters.add("faction name"); diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandKick.java b/src/com/bukkit/mcteam/factions/commands/FCommandKick.java index b02f9781..20f78095 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandKick.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandKick.java @@ -9,6 +9,9 @@ import com.bukkit.mcteam.factions.Faction; public class FCommandKick extends FBaseCommand { public FCommandKick() { + aliases = new ArrayList(); + aliases.add("kick"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); requiredParameters.add("player name"); @@ -37,7 +40,8 @@ public class FCommandKick extends FBaseCommand { if (me == you) { sendMessage("You cannot kick yourself."); - sendMessage("You might want to "+Conf.colorCommand+Conf.aliasBase.get(0)+" "+Conf.aliasLeave.get(0)); + sendMessage("You might want to:"); + sendMessage(new FCommandLeave().getUseageTemplate()); return; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandLeave.java b/src/com/bukkit/mcteam/factions/commands/FCommandLeave.java index 44a1c33d..18947ba2 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandLeave.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandLeave.java @@ -10,6 +10,9 @@ import com.bukkit.mcteam.factions.struct.Role; public class FCommandLeave extends FBaseCommand { public FCommandLeave() { + aliases = new ArrayList(); + aliases.add("leave"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandList.java b/src/com/bukkit/mcteam/factions/commands/FCommandList.java index 580b977e..15b46d76 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandList.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandList.java @@ -11,6 +11,10 @@ import com.bukkit.mcteam.factions.util.TextUtil; public class FCommandList extends FBaseCommand { public FCommandList() { + aliases = new ArrayList(); + aliases.add("list"); + aliases.add("ls"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); optionalParameters.add("page"); diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandMap.java b/src/com/bukkit/mcteam/factions/commands/FCommandMap.java index 029c4f48..71bc048d 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandMap.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandMap.java @@ -3,12 +3,14 @@ package com.bukkit.mcteam.factions.commands; import java.util.ArrayList; import com.bukkit.mcteam.factions.Board; -import com.bukkit.mcteam.factions.Conf; import com.bukkit.mcteam.factions.FLocation; public class FCommandMap extends FBaseCommand { public FCommandMap() { + aliases = new ArrayList(); + aliases.add("map"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); optionalParameters.add("on|off"); @@ -23,7 +25,7 @@ public class FCommandMap extends FBaseCommand { public void perform() { if (parameters.size() > 0) { String mapAutoUpdating = parameters.get(0); - if (Conf.aliasTrue.contains(mapAutoUpdating.toLowerCase())) { + if (parseBool(mapAutoUpdating)) { // Turn on me.setMapAutoUpdating(true); sendMessage("Map auto update ENABLED."); diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandMod.java b/src/com/bukkit/mcteam/factions/commands/FCommandMod.java index 681736df..07c40869 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandMod.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandMod.java @@ -10,6 +10,9 @@ import com.bukkit.mcteam.factions.struct.Role; public class FCommandMod extends FBaseCommand { public FCommandMod() { + aliases = new ArrayList(); + aliases.add("mod"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); requiredParameters.add("player name"); diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandOpen.java b/src/com/bukkit/mcteam/factions/commands/FCommandOpen.java index 3fe44555..3e05eaa7 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandOpen.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandOpen.java @@ -9,6 +9,10 @@ import com.bukkit.mcteam.factions.struct.Role; public class FCommandOpen extends FBaseCommand { public FCommandOpen() { + aliases = new ArrayList(); + aliases.add("open"); + aliases.add("close"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandRelationAlly.java b/src/com/bukkit/mcteam/factions/commands/FCommandRelationAlly.java index 3478dee6..514ed393 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandRelationAlly.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandRelationAlly.java @@ -1,9 +1,16 @@ package com.bukkit.mcteam.factions.commands; +import java.util.ArrayList; + import com.bukkit.mcteam.factions.struct.Relation; public class FCommandRelationAlly extends FRelationCommand { + public FCommandRelationAlly() { + aliases = new ArrayList(); + aliases.add("ally"); + } + public void perform() { relation(Relation.ALLY, parameters.get(0)); } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandRelationEnemy.java b/src/com/bukkit/mcteam/factions/commands/FCommandRelationEnemy.java index fcd69d82..8e173f53 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandRelationEnemy.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandRelationEnemy.java @@ -1,9 +1,16 @@ package com.bukkit.mcteam.factions.commands; +import java.util.ArrayList; + import com.bukkit.mcteam.factions.struct.Relation; public class FCommandRelationEnemy extends FRelationCommand { + public FCommandRelationEnemy() { + aliases = new ArrayList(); + aliases.add("enemy"); + } + public void perform() { relation(Relation.ENEMY, parameters.get(0)); } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandRelationNeutral.java b/src/com/bukkit/mcteam/factions/commands/FCommandRelationNeutral.java index f600d9c9..4f5f982e 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandRelationNeutral.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandRelationNeutral.java @@ -1,9 +1,16 @@ package com.bukkit.mcteam.factions.commands; +import java.util.ArrayList; + import com.bukkit.mcteam.factions.struct.Relation; public class FCommandRelationNeutral extends FRelationCommand { + public FCommandRelationNeutral() { + aliases = new ArrayList(); + aliases.add("neutral"); + } + public void perform() { relation(Relation.NEUTRAL, parameters.get(0)); } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandShow.java b/src/com/bukkit/mcteam/factions/commands/FCommandShow.java index 2e9e3656..5fb7fd0f 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandShow.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandShow.java @@ -13,6 +13,10 @@ import com.bukkit.mcteam.factions.util.TextUtil; public class FCommandShow extends FBaseCommand { public FCommandShow() { + aliases = new ArrayList(); + aliases.add("show"); + aliases.add("who"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); optionalParameters.add("faction tag"); diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandTag.java b/src/com/bukkit/mcteam/factions/commands/FCommandTag.java index 03c5af5e..3af48ba6 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandTag.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandTag.java @@ -10,6 +10,9 @@ import com.bukkit.mcteam.factions.util.TextUtil; public class FCommandTag extends FBaseCommand { public FCommandTag() { + aliases = new ArrayList(); + aliases.add("tag"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); requiredParameters.add("faction tag"); diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandTitle.java b/src/com/bukkit/mcteam/factions/commands/FCommandTitle.java index 3927e9df..8e701b0b 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandTitle.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandTitle.java @@ -10,6 +10,9 @@ import com.bukkit.mcteam.factions.util.TextUtil; public class FCommandTitle extends FBaseCommand { public FCommandTitle() { + aliases = new ArrayList(); + aliases.add("title"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); requiredParameters.add("player name"); diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandUnclaim.java b/src/com/bukkit/mcteam/factions/commands/FCommandUnclaim.java index 6e3f384e..2ea08b95 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandUnclaim.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandUnclaim.java @@ -11,6 +11,10 @@ import com.bukkit.mcteam.factions.struct.Role; public class FCommandUnclaim extends FBaseCommand { public FCommandUnclaim() { + aliases = new ArrayList(); + aliases.add("unclaim"); + aliases.add("declaim"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandVersion.java b/src/com/bukkit/mcteam/factions/commands/FCommandVersion.java index 9affbc77..6f54b751 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandVersion.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandVersion.java @@ -7,6 +7,9 @@ import com.bukkit.mcteam.factions.Factions; public class FCommandVersion extends FBaseCommand { public FCommandVersion() { + aliases = new ArrayList(); + aliases.add("version"); + requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); diff --git a/src/com/bukkit/mcteam/factions/commands/FRelationCommand.java b/src/com/bukkit/mcteam/factions/commands/FRelationCommand.java index c750105e..4884997b 100644 --- a/src/com/bukkit/mcteam/factions/commands/FRelationCommand.java +++ b/src/com/bukkit/mcteam/factions/commands/FRelationCommand.java @@ -6,6 +6,7 @@ import org.bukkit.ChatColor; import com.bukkit.mcteam.factions.Conf; import com.bukkit.mcteam.factions.Faction; +import com.bukkit.mcteam.factions.Factions; import com.bukkit.mcteam.factions.struct.Relation; import com.bukkit.mcteam.factions.struct.Role; @@ -15,7 +16,7 @@ public class FRelationCommand extends FBaseCommand { requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); requiredParameters.add("faction tag"); - helpDescription = "Declare your factions relation wish to another faction"; + helpDescription = "Set relation wish to another faction"; permissions = ""; senderMustBePlayer = true; @@ -54,7 +55,7 @@ public class FRelationCommand extends FBaseCommand { myFaction.sendMessage(Conf.colorSystem+"Your faction is now "+currentRelationColor+whishedRelation.toString()+Conf.colorSystem+" to "+currentRelationColor+otherFaction.getTag()); } else { otherFaction.sendMessage(currentRelationColor+myFaction.getTag()+Conf.colorSystem+ " wishes to be your "+whishedRelation.getColor()+whishedRelation.toString()); - otherFaction.sendMessage(Conf.colorSystem+"Type "+Conf.colorCommand+Conf.aliasBase.get(0)+" "+whishedRelation+" "+myFaction.getTag()+Conf.colorSystem+" to accept."); + otherFaction.sendMessage(Conf.colorSystem+"Type "+Conf.colorCommand+Factions.instance.getBaseCommand()+" "+whishedRelation+" "+myFaction.getTag()+Conf.colorSystem+" to accept."); myFaction.sendMessage(currentRelationColor+otherFaction.getTag()+Conf.colorSystem+ " were informed that you wish to be "+whishedRelation.getColor()+whishedRelation); } } diff --git a/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java index 62b36bba..5ba13634 100644 --- a/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java @@ -1,10 +1,14 @@ package com.bukkit.mcteam.factions.listeners; -import java.util.*; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.logging.Logger; import org.bukkit.block.Block; -import org.bukkit.entity.*; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerItemEvent; @@ -13,6 +17,7 @@ import org.bukkit.event.player.PlayerMoveEvent; import com.bukkit.mcteam.factions.Board; import com.bukkit.mcteam.factions.Conf; +import com.bukkit.mcteam.factions.FLocation; import com.bukkit.mcteam.factions.FPlayer; import com.bukkit.mcteam.factions.Faction; import com.bukkit.mcteam.factions.Factions; @@ -21,43 +26,31 @@ import com.bukkit.mcteam.factions.util.TextUtil; public class FactionsPlayerListener extends PlayerListener{ - /** - * If someone says something that starts with the factions base command - * we handle that command. - */ - @Override - public void onPlayerCommandPreprocess(PlayerChatEvent event) { - Player player = event.getPlayer(); - String msg = event.getMessage(); - - if (handleCommandOrChat(player, msg)) { - event.setCancelled(true); - } - } - @Override public void onPlayerChat(PlayerChatEvent event) { + if ((event.getMessage().startsWith(Factions.instance.getBaseCommand()+" ") || event.getMessage().equals(Factions.instance.getBaseCommand())) && Conf.allowNoSlashCommand) { + List parameters = TextUtil.split(event.getMessage().trim()); + parameters.remove(0); + CommandSender sender = event.getPlayer(); + Factions.instance.handleCommand(sender, parameters); + event.setCancelled(true); + return; + } + if (event.isCancelled()) { - return; // Some other plugin ate this... + return; } Player talkingPlayer = event.getPlayer(); String msg = event.getMessage(); - // Is this a faction command?... - if ( handleCommandOrChat(talkingPlayer, msg) ) { - // ... Yes it was! We should choke the chat message. - event.setCancelled(true); - return; - } - // ... it was not a command. This means that it is a chat message! FPlayer me = FPlayer.get(talkingPlayer); // Is it a faction chat message? if (me.isFactionChatting()) { String message = String.format(Conf.factionChatFormat, me.getNameAndRelevant(me), msg); - me.getFaction().sendMessage(message, false); + me.getFaction().sendMessage(message); Logger.getLogger("Minecraft").info("FactionChat "+me.getFaction().getTag()+": "+message); event.setCancelled(true); return; @@ -95,27 +88,16 @@ public class FactionsPlayerListener extends PlayerListener{ } } - public boolean handleCommandOrChat(Player player, String msg) { - ArrayList tokens = TextUtil.split(msg.trim()); - if (Conf.aliasBase.contains(tokens.get(0))) { - tokens.remove(0); - FPlayer follower = FPlayer.get(player); - Commands.base(follower, tokens); - return true; - } - return false; - } - @Override public void onPlayerJoin(PlayerEvent event) { - //Follower.get(event.getPlayer()).sendJoinInfo(); + // Make sure that all online players do have a fplayer. + FPlayer.get(event.getPlayer()); } @Override public void onPlayerQuit(PlayerEvent event) { - FPlayer follower = FPlayer.get(event.getPlayer()); - Log.debug("Saved follower on player quit: "+follower.getName()); - follower.save(); // We save the followers on logout in order to save their non autosaved state like power. + // Save all players on player quit. + FPlayer.save(); } @Override @@ -123,22 +105,23 @@ public class FactionsPlayerListener extends PlayerListener{ FPlayer me = FPlayer.get(event.getPlayer()); // Did we change coord? - Coord coordFrom = me.lastStoodAt; - Coord coordTo = Coord.from(event.getTo()); - if (coordFrom.equals(coordTo)) { + FLocation from = me.getLastStoodAt(); + FLocation to = new FLocation(event.getTo()); + + if (from.equals(to)) { return; } // Yes we did change coord (: - me.lastStoodAt = coordTo; - Board board = Board.get(event.getPlayer().getWorld()); + + me.setLastStoodAt(to); if (me.isMapAutoUpdating()) { - me.sendMessage(board.getMap(me.getFaction(), Coord.from(me), me.getPlayer().getLocation().getYaw()), false); + me.sendMessage(Board.getMap(me.getFaction(), to, me.getPlayer().getLocation().getYaw())); } else { // Did we change "host"(faction)? - Faction factionFrom = board.getFactionAt(coordFrom); - Faction factionTo = board.getFactionAt(coordTo); + Faction factionFrom = Board.getFactionAt(from); + Faction factionTo = Board.getFactionAt(to); if ( factionFrom != factionTo) { me.sendFactionHereMessage(); } @@ -147,17 +130,15 @@ public class FactionsPlayerListener extends PlayerListener{ @Override public void onPlayerItem(PlayerItemEvent event) { - // debug - //event.getPlayer().sendMessage("Item in hand: " + event.getItem().getTypeId() + " Block clicked: " + event.getBlockClicked().getTypeId() + "(" + event.getBlockClicked().getType().toString() + ")"); - - if (event.isCancelled()) + if (event.isCancelled()) { return; - - if (event.getBlockClicked() == null) + } + + if (event.getBlockClicked() == null) { return; // right-clicked on air, not a block; no worries then + } - if (!this.playerCanUseItemHere(event.getPlayer(), event.getBlockClicked(), event.getItem().getTypeId())) - { + if ( ! this.playerCanUseItemHere(event.getPlayer(), event.getBlockClicked(), event.getItem().getTypeId())) { event.setCancelled(true); return; } @@ -171,14 +152,13 @@ public class FactionsPlayerListener extends PlayerListener{ public boolean playerCanUseItemHere(Player player, Block block, int itemId) { - if (!badItems.contains(new Integer(itemId))) { + if ( ! badItems.contains(new Integer(itemId))) { return true; // Item isn't one we're preventing. } - Coord coord = Coord.parseCoord(block); - Faction otherFaction = Board.get(player.getWorld()).getFactionAt(coord); + Faction otherFaction = Board.getFactionAt(new FLocation(block)); - if (otherFaction == null || otherFaction.id == 0) { + if (otherFaction == null || otherFaction.getId() == 0) { return true; // This is not faction territory. Use whatever you like here. } @@ -187,7 +167,7 @@ public class FactionsPlayerListener extends PlayerListener{ // Cancel if we are not in our own territory if (myFaction != otherFaction) { - me.sendMessage(Conf.colorSystem+"You can't use that in the territory of "+otherFaction.getTag(myFaction)); + me.sendMessage("You can't use that in the territory of "+otherFaction.getTag(myFaction)); return false; }