From d7c1d0fce380f2985fb55c752adc4527c1515dfb Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 22 Mar 2011 15:45:41 +0100 Subject: [PATCH] More refactoring... the commands are refactored now :) --- plugin.yml | 2 +- src/com/bukkit/mcteam/factions/Board.java | 2 +- src/com/bukkit/mcteam/factions/FPlayer.java | 104 +++++---------- src/com/bukkit/mcteam/factions/Faction.java | 9 +- src/com/bukkit/mcteam/factions/Factions.java | 23 ++-- .../{FCommand.java => FBaseCommand.java} | 77 +++++++++-- .../factions/commands/FCommandAdmin.java | 66 ++++++++++ .../factions/commands/FCommandChat.java | 34 +++++ .../factions/commands/FCommandClaim.java | 78 +++++++++++ .../factions/commands/FCommandCreate.java | 5 +- .../factions/commands/FCommandDeinvite.java | 54 ++++++++ .../commands/FCommandDescription.java | 41 ++++++ .../factions/commands/FCommandHelp.java | 123 ++++++++++++++++++ .../factions/commands/FCommandInvite.java | 55 ++++++++ .../factions/commands/FCommandJoin.java | 5 +- .../factions/commands/FCommandKick.java | 58 +++++++++ .../factions/commands/FCommandLeave.java | 6 +- .../factions/commands/FCommandList.java | 89 +++++++++++++ .../mcteam/factions/commands/FCommandMap.java | 47 +++++++ .../mcteam/factions/commands/FCommandMod.java | 63 +++++++++ .../factions/commands/FCommandOpen.java | 46 +++++++ .../commands/FCommandRelationAlly.java | 11 ++ .../commands/FCommandRelationEnemy.java | 11 ++ .../commands/FCommandRelationNeutral.java | 11 ++ .../factions/commands/FCommandShow.java | 117 +++++++++++++++++ .../mcteam/factions/commands/FCommandTag.java | 63 +++++++++ .../factions/commands/FCommandTitle.java | 50 +++++++ .../factions/commands/FCommandUnclaim.java | 47 +++++++ .../factions/commands/FCommandVersion.java | 24 ++++ .../factions/commands/FRelationCommand.java | 61 +++++++++ .../CommandsOld.java} | 12 +- .../factions/{ => entities}/CoordOld.java | 2 +- .../bukkit/mcteam/factions/util/TextUtil.java | 4 +- 33 files changed, 1278 insertions(+), 122 deletions(-) rename src/com/bukkit/mcteam/factions/commands/{FCommand.java => FBaseCommand.java} (74%) create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandAdmin.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandChat.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandClaim.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandDeinvite.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandDescription.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandHelp.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandInvite.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandKick.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandList.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandMap.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandMod.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandOpen.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandRelationAlly.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandRelationEnemy.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandRelationNeutral.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandShow.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandTag.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandTitle.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandUnclaim.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FCommandVersion.java create mode 100644 src/com/bukkit/mcteam/factions/commands/FRelationCommand.java rename src/com/bukkit/mcteam/factions/{Commands.java => entities/CommandsOld.java} (99%) rename src/com/bukkit/mcteam/factions/{ => entities}/CoordOld.java (96%) diff --git a/plugin.yml b/plugin.yml index b6c8d696..103abde5 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,3 +1,3 @@ name: Factions -version: 1.0 beta7 +version: 1.0 beta8 main: com.bukkit.mcteam.factions.Factions \ No newline at end of file diff --git a/src/com/bukkit/mcteam/factions/Board.java b/src/com/bukkit/mcteam/factions/Board.java index 95406fc1..5c4caa8f 100644 --- a/src/com/bukkit/mcteam/factions/Board.java +++ b/src/com/bukkit/mcteam/factions/Board.java @@ -124,7 +124,7 @@ public class Board { * north is in the direction of decreasing x * east is in the direction of decreasing z */ - public ArrayList getMap(Faction faction, FLocation flocation, double inDegrees) { + public static ArrayList getMap(Faction faction, FLocation flocation, double inDegrees) { ArrayList ret = new ArrayList(); ret.add(TextUtil.titleize("("+flocation+") "+getFactionAt(flocation).getTag(faction))); diff --git a/src/com/bukkit/mcteam/factions/FPlayer.java b/src/com/bukkit/mcteam/factions/FPlayer.java index 726a3150..d0ea9f50 100644 --- a/src/com/bukkit/mcteam/factions/FPlayer.java +++ b/src/com/bukkit/mcteam/factions/FPlayer.java @@ -14,11 +14,23 @@ import com.bukkit.mcteam.factions.struct.Role; import com.bukkit.mcteam.gson.reflect.TypeToken; import com.bukkit.mcteam.util.DiscUtil; +/** + * Logged in players always have exactly one FPlayer instance. + * Logged out players may or may not have an FPlayer instance. They will always have one if they are part of a faction. + * This is because only players with a faction are saved to disk (in order to not waste disk space). + * + * The FPlayer is linked to a minecraft player using the player name in lowercase form. + * Lowercase is enforced while loading from disk TODO + * + * The same instance is always returned for the same player. + * This means you can use the == operator. No .equals method necessary. + */ + public class FPlayer { public static transient Map instances = new HashMap(); public static transient File file = new File(Factions.instance.getDataFolder(), "players.json"); - public transient String playername; + public transient String playerName; public transient FLocation lastStoodAt = new FLocation(); // Where did this player stand the last time we checked? public int factionId; @@ -26,15 +38,15 @@ public class FPlayer { private String title; private double power; private long lastPowerUpdateTime; - private boolean mapAutoUpdating; + private transient boolean mapAutoUpdating; private boolean factionChatting; public FPlayer(Player player) { - this.playername = player.getName(); + this.playerName = player.getName().toLowerCase(); } - public FPlayer(String playername) { - this.playername = playername; + public FPlayer(String playerName) { + this.playerName = playerName.toLowerCase(); } // GSON need this noarg constructor. @@ -53,11 +65,11 @@ public class FPlayer { } public Player getPlayer() { - return Factions.instance.getServer().getPlayer(playername); + return Factions.instance.getServer().getPlayer(playerName); } public String getPlayerName() { - return this.playername; + return this.playerName; } // -------------------------------------------- // @@ -65,7 +77,7 @@ public class FPlayer { // -------------------------------------------- // public boolean isOnline() { - return Factions.instance.getServer().getPlayer(playername) != null; + return Factions.instance.getServer().getPlayer(playerName) != null; } public boolean isOffline() { @@ -109,7 +121,7 @@ public class FPlayer { } public String getName() { - return this.playername; + return this.playerName; } public String getTag() { @@ -316,70 +328,17 @@ public class FPlayer { return factionId != 0; } - public ArrayList invite(FPlayer follower) { - ArrayList errors = new ArrayList(); - - //Log.debug("this.role: "+this.role); - //Log.debug("this.role.value: "+this.role.value); - //Log.debug("FactionRole.MODERATOR.value: "+FactionRole.MODERATOR.value); - - if (this.role.value < Role.MODERATOR.value) { - errors.add(Conf.colorSystem+"You must be a moderator to invite."); - } - - if(errors.size() > 0) { - return errors; - } - - return this.getFaction().invite(follower); - } - - public ArrayList deinvite(FPlayer follower) { - ArrayList errors = new ArrayList(); - - if (this.role.value < Role.MODERATOR.value) { - errors.add(Conf.colorSystem+"You must be a moderator to deinvite."); - } - - if(errors.size() > 0) { - return errors; - } - - return this.getFaction().deinvite(follower); - } - - public ArrayList kick(FPlayer follower) { - ArrayList errors = new ArrayList(); - - if ( ! follower.getFaction().equals(this.getFaction())) { - errors.add(follower.getNameAndRelevant(this)+Conf.colorSystem+" is not a member of "+Conf.colorMember+this.getFaction().getTag()); - } else if (follower.equals(this)) { - errors.add(Conf.colorSystem+"You cannot kick yourself."); - errors.add(Conf.colorSystem+"You might want to "+Conf.colorCommand+Conf.aliasBase.get(0)+" "+Conf.aliasLeave.get(0)); - } else if (follower.role.value >= this.role.value) { // TODO add more informative messages. - errors.add(Conf.colorSystem+"Your rank is too low to kick this player."); - } - - if(errors.size() > 0) { - return errors; - } - - return follower.getFaction().kick(follower); - } - // -------------------------------------------- // // Get and search - // You can only get a "skin" for online players. - // The same object is always returned for the same player. - // This means you can use the == operator. No .equals method necessary. // -------------------------------------------- // - public static FPlayer get(String playername) { - if (instances.containsKey(playername)) { - return instances.get(playername); + public static FPlayer get(String playerName) { + playerName = playerName.toLowerCase(); + if (instances.containsKey(playerName)) { + return instances.get(playerName); } - FPlayer vplayer = new FPlayer(playername); - instances.put(playername, vplayer); + FPlayer vplayer = new FPlayer(playerName); + instances.put(playerName, vplayer); return vplayer; } @@ -460,7 +419,12 @@ public class FPlayer { try { Type type = new TypeToken>(){}.getType(); - instances = Factions.gson.fromJson(DiscUtil.read(file), type); + Map instancesFromFile = Factions.gson.fromJson(DiscUtil.read(file), type); + + instances = new HashMap(); + for (Entry instanceFromFile : instancesFromFile.entrySet()) { + instances.put(instanceFromFile.getKey().toLowerCase(), instanceFromFile.getValue()); + } } catch (IOException e) { e.printStackTrace(); return false; @@ -473,7 +437,7 @@ public class FPlayer { public static void fillPlayernames() { for(Entry entry : instances.entrySet()) { - entry.getValue().playername = entry.getKey(); + entry.getValue().playerName = entry.getKey(); } } diff --git a/src/com/bukkit/mcteam/factions/Faction.java b/src/com/bukkit/mcteam/factions/Faction.java index 30109554..33878e2c 100644 --- a/src/com/bukkit/mcteam/factions/Faction.java +++ b/src/com/bukkit/mcteam/factions/Faction.java @@ -24,7 +24,7 @@ public class Faction { public transient int id; protected Map relationWish; - protected Set invites; // Where string is a follower id (lower case name) + public Set invites; // Where string is a follower id (lower case name) protected boolean open; protected String tag; protected String description; @@ -118,7 +118,7 @@ public class Faction { // ------------------------------- - public ArrayList invite(FPlayer follower) { // TODO Move out + /*public ArrayList invite(FPlayer follower) { // TODO Move out ArrayList errors = new ArrayList(); if (follower.getFaction().equals(this)) { // error här? @@ -149,7 +149,7 @@ public class Faction { this.invites.remove(follower.id); this.save(); return errors; - } + }*/ public ArrayList kick(FPlayer follower) { ArrayList errors = new ArrayList(); @@ -198,6 +198,7 @@ public class Faction { return ret; } + /* public void removeFollower(FPlayer follower) { if (this.id != follower.factionId) { return; // safety check @@ -207,7 +208,7 @@ public class Faction { follower.resetFactionData(); follower.save(); this.save(); - } + }*/ public ArrayList getOnlinePlayers() { ArrayList ret = new ArrayList(); diff --git a/src/com/bukkit/mcteam/factions/Factions.java b/src/com/bukkit/mcteam/factions/Factions.java index f27fca4d..5cbc9ab6 100644 --- a/src/com/bukkit/mcteam/factions/Factions.java +++ b/src/com/bukkit/mcteam/factions/Factions.java @@ -16,7 +16,7 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -import com.bukkit.mcteam.factions.commands.FCommand; +import com.bukkit.mcteam.factions.commands.FBaseCommand; import com.bukkit.mcteam.factions.listeners.FactionsBlockListener; import com.bukkit.mcteam.factions.listeners.FactionsEntityListener; import com.bukkit.mcteam.factions.listeners.FactionsPlayerListener; @@ -47,7 +47,7 @@ public class Factions extends JavaPlugin { public static Help helpPlugin; // Commands - public List commands = new ArrayList(); + public List commands = new ArrayList(); public Factions() { Factions.instance = this; @@ -106,12 +106,12 @@ public class Factions extends JavaPlugin { // -------------------------------------------- // private void setupPermissions() { - Plugin test = this.getServer().getPluginManager().getPlugin("Permissions"); - if (Permissions != null) { return; } + Plugin test = this.getServer().getPluginManager().getPlugin("Permissions"); + if (test != null) { Permissions = ((Permissions)test).getHandler(); Factions.log("Found and will use plugin "+((Permissions)test).getDescription().getFullName()); @@ -121,21 +121,18 @@ public class Factions extends JavaPlugin { } private void setupHelp() { - Plugin test = this.getServer().getPluginManager().getPlugin("Help"); - if (helpPlugin != null) { return; } + Plugin test = this.getServer().getPluginManager().getPlugin("Help"); + if (test != null) { helpPlugin = ((Help) test); Factions.log("Found and will use plugin "+helpPlugin.getDescription().getFullName()); - for(FCommand fcommand : commands) { - fcommand.helpRegister(); - } - helpPlugin.registerCommand("help vampire", "help for the vampire plugin.", helpPlugin, true); - } else { - Factions.log(Level.WARNING, "'Help' plugin isn't detected. No /help support."); + + // TODO not hardcoded: + helpPlugin.registerCommand("f help *[page]", "Factions plugin help.", helpPlugin, true); } } @@ -160,7 +157,7 @@ public class Factions extends JavaPlugin { String commandName = parameters.get(0).toLowerCase(); parameters.remove(0); - for (FCommand fcommand : this.commands) { + for (FBaseCommand fcommand : this.commands) { if (fcommand.getAliases().contains(commandName)) { fcommand.execute(sender, parameters); return; diff --git a/src/com/bukkit/mcteam/factions/commands/FCommand.java b/src/com/bukkit/mcteam/factions/commands/FBaseCommand.java similarity index 74% rename from src/com/bukkit/mcteam/factions/commands/FCommand.java rename to src/com/bukkit/mcteam/factions/commands/FBaseCommand.java index f5e93d33..5b896dc7 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommand.java +++ b/src/com/bukkit/mcteam/factions/commands/FBaseCommand.java @@ -11,8 +11,9 @@ import com.bukkit.mcteam.factions.FPlayer; import com.bukkit.mcteam.factions.Faction; import com.bukkit.mcteam.factions.Factions; import com.bukkit.mcteam.factions.struct.Role; +import com.bukkit.mcteam.factions.util.TextUtil; -public class FCommand { +public class FBaseCommand { public List requiredParameters; public List optionalParameters; @@ -29,7 +30,7 @@ public class FCommand { public List parameters; - public FCommand() { + public FBaseCommand() { requiredParameters = new ArrayList(); optionalParameters = new ArrayList(); @@ -81,10 +82,6 @@ public class FCommand { } - public void helpRegister() { - Factions.helpPlugin.registerCommand(this.getBaseName()+ " " +this.helpNameAndParams, this.helpDescription, Factions.instance, false, permissions); - } - public void sendMessage(String message) { sender.sendMessage(Conf.colorSystem+message); } @@ -96,6 +93,7 @@ public class FCommand { } // Test if the number of params is correct. + // TODO print usage public boolean validateCall() { if( ! testPermission(sender)) { sendMessage("You do not have sufficient permissions to use this command."); @@ -108,13 +106,7 @@ public class FCommand { } if (parameters.size() < requiredParameters.size()) { - int missing = requiredParameters.size() - parameters.size(); - sendMessage("Missing parameters. You must enter "+missing+" more."); - return false; - } - - if (parameters.size() > requiredParameters.size() + optionalParameters.size()) { - sendMessage("To many parameters."); + sendMessage("Usage: "+this.getUseageTemplate(true)); return false; } @@ -142,6 +134,65 @@ public class FCommand { return Factions.Permissions.has(player, this.permissions); } + // -------------------------------------------- // + // Help and usage description + // -------------------------------------------- // + public String getUseageTemplate(boolean withColor) { + String ret = ""; + + if (withColor) { + ret += Conf.colorCommand; + } + + ret += this.getBaseName()+ " " +TextUtil.implode(this.getAliases(), ",")+" "; + + List parts = new ArrayList(); + + for (String requiredParameter : this.requiredParameters) { + parts.add("["+requiredParameter+"]"); + } + + for (String optionalParameter : this.optionalParameters) { + parts.add("*["+optionalParameter+"]"); + } + + if (withColor) { + ret += Conf.colorParameter; + } + + ret += TextUtil.implode(parts, " "); + return ret; + } + + public String getUseageTemplate() { + return getUseageTemplate(true); + } + + public void helpRegister() { + Factions.helpPlugin.registerCommand(this.getUseageTemplate(false), this.helpDescription, Factions.instance, false, permissions); + } + + // -------------------------------------------- // + // Assertions + // -------------------------------------------- // + + public boolean assertHasFaction() { + if ( ! me.hasFaction()) { + sendMessage("You are not member of any faction."); + return false; + } + return true; + } + + public boolean assertMinRole(Role role) { + if (me.role.value < role.value) { + sendMessage("You must be "+role+" to "+this.helpDescription+"."); + return false; + } + + return true; + } + // -------------------------------------------- // // Commonly used logic // -------------------------------------------- // diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandAdmin.java b/src/com/bukkit/mcteam/factions/commands/FCommandAdmin.java new file mode 100644 index 00000000..f9271bc6 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandAdmin.java @@ -0,0 +1,66 @@ +package com.bukkit.mcteam.factions.commands; + +import java.util.ArrayList; + +import com.bukkit.mcteam.factions.Conf; +import com.bukkit.mcteam.factions.FPlayer; +import com.bukkit.mcteam.factions.Faction; +import com.bukkit.mcteam.factions.struct.Role; + +public class FCommandAdmin extends FBaseCommand { + + public FCommandAdmin() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + requiredParameters.add("player name"); + + permissions = ""; + + senderMustBePlayer = true; + + helpDescription = "Hand over your admin rights"; + } + + public void perform() { + if ( ! assertHasFaction()) { + return; + } + + if ( ! assertMinRole(Role.ADMIN)) { + return; + } + + String playerName = parameters.get(0); + + FPlayer you = findFPlayer(playerName, false); + if (you == null) { + return; + } + + Faction myFaction = me.getFaction(); + + if (you.getFaction() != myFaction) { + sendMessage(you.getNameAndRelevant(me)+Conf.colorSystem+" is not a member in your faction."); + return; + } + + if (you == me) { + sendMessage("The target player musn't be yourself."); + return; + } + + + me.role = Role.MODERATOR; + you.role = Role.ADMIN; + + // Inform all players + for (FPlayer fplayer : FPlayer.getAllOnline()) { + if (fplayer.factionId == me.factionId) { + fplayer.sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" gave "+you.getNameAndRelevant(me)+Conf.colorSystem+" the leadership of your faction."); + } else { + fplayer.sendMessage(me.getNameAndRelevant(fplayer)+Conf.colorSystem+" gave "+you.getNameAndRelevant(fplayer)+Conf.colorSystem+" the leadership of "+myFaction.getTag(fplayer)); + } + } + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandChat.java b/src/com/bukkit/mcteam/factions/commands/FCommandChat.java new file mode 100644 index 00000000..ad129b87 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandChat.java @@ -0,0 +1,34 @@ +package com.bukkit.mcteam.factions.commands; + +import java.util.ArrayList; + +public class FCommandChat extends FBaseCommand { + + public FCommandChat() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + + permissions = ""; + + senderMustBePlayer = true; + + helpDescription = "Switch faction only chat on and off"; + } + + public void perform() { + if ( ! assertHasFaction()) { + return; + } + + if ( ! me.isFactionChatting()) { + // Turn on + me.setFactionChatting(true); + sendMessage("Faction-only chat ENABLED."); + } else { + // Turn off + me.setFactionChatting(false); + sendMessage("Faction-only chat DISABLED."); + } + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandClaim.java b/src/com/bukkit/mcteam/factions/commands/FCommandClaim.java new file mode 100644 index 00000000..30527531 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandClaim.java @@ -0,0 +1,78 @@ +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; +import com.bukkit.mcteam.factions.Faction; +import com.bukkit.mcteam.factions.struct.Relation; +import com.bukkit.mcteam.factions.struct.Role; + +public class FCommandClaim extends FBaseCommand { + + public FCommandClaim() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + + permissions = ""; + + senderMustBePlayer = true; + + helpDescription = "Claim the land where you are standing"; + } + + public void perform() { + if ( ! assertHasFaction()) { + return; + } + + Faction myFaction = me.getFaction(); + FLocation flocation = new FLocation(me); + Faction otherFaction = Board.getFactionAt(flocation); + + if (myFaction == otherFaction) { + sendMessage("You already own this land."); + return; + } + + if ( ! assertMinRole(Role.MODERATOR)) { + return; + } + + + if (myFaction.getLandRounded() >= myFaction.getPowerRounded()) { + sendMessage("You can't claim more land! You need more power!"); + return; + } + + if (otherFaction.getRelation(me) == Relation.ALLY) { + sendMessage("You can't claim the land of your allies."); + return; + } + + if (otherFaction.id != 0) { + if ( ! otherFaction.hasLandInflation()) { // TODO more messages WARN current faction most importantly + sendMessage(me.getRelationColor(otherFaction)+otherFaction.getTag()+Conf.colorSystem+" owns this land and is strong enough to keep it."); + return; + } + + if ( ! Board.isBorderLocation(flocation)) { + sendMessage("You must start claiming land at the border of the territory."); + return; + } + } + + if (otherFaction.id == 0) { + myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some new land :D"); + } else { + // ASDF claimed some of your land 450 blocks NNW of you. + // ASDf claimed some land from FACTION NAME + otherFaction.sendMessage(me.getNameAndRelevant(otherFaction)+Conf.colorSystem+" stole some of your land :O"); + myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some land from "+otherFaction.getTag(myFaction)); + } + + Board.setFactionAt(myFaction, flocation); + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandCreate.java b/src/com/bukkit/mcteam/factions/commands/FCommandCreate.java index ba49e723..a385515c 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandCreate.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandCreate.java @@ -7,7 +7,7 @@ import com.bukkit.mcteam.factions.FPlayer; import com.bukkit.mcteam.factions.Faction; import com.bukkit.mcteam.factions.struct.Role; -public class FCommandCreate extends FCommand { +public class FCommandCreate extends FBaseCommand { public FCommandCreate() { requiredParameters = new ArrayList(); @@ -18,8 +18,7 @@ public class FCommandCreate extends FCommand { senderMustBePlayer = true; - helpNameAndParams = "create [faction tag]"; - helpDescription = "Create new faction"; + helpDescription = "Create a new faction"; } public void perform() { diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandDeinvite.java b/src/com/bukkit/mcteam/factions/commands/FCommandDeinvite.java new file mode 100644 index 00000000..d77bd3b2 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandDeinvite.java @@ -0,0 +1,54 @@ +package com.bukkit.mcteam.factions.commands; + +import java.util.ArrayList; + +import com.bukkit.mcteam.factions.Conf; +import com.bukkit.mcteam.factions.FPlayer; +import com.bukkit.mcteam.factions.Faction; +import com.bukkit.mcteam.factions.struct.Role; + +public class FCommandDeinvite extends FBaseCommand { + + public FCommandDeinvite() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + requiredParameters.add("player name"); + + permissions = ""; + + senderMustBePlayer = true; + + helpDescription = "Remove a pending invitation"; + } + + public void perform() { + if ( ! assertHasFaction()) { + return; + } + + String playerName = parameters.get(0); + + FPlayer you = findFPlayer(playerName, false); + if (you == null) { + return; + } + + Faction myFaction = me.getFaction(); + + if ( ! assertMinRole(Role.MODERATOR)) { + return; + } + + if (you.getFaction() == myFaction) { + sendMessage(you.getName()+" is already a member of "+myFaction.getTag()); + return; + } + + myFaction.invites.remove(you.playerName); + Faction.save(); + + you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" revoked your invitation to "+myFaction.getTag(you)); + myFaction.sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" revoked "+you.getNameAndRelevant(me)+"'s"+Conf.colorSystem+" invitation."); + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandDescription.java b/src/com/bukkit/mcteam/factions/commands/FCommandDescription.java new file mode 100644 index 00000000..70081975 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandDescription.java @@ -0,0 +1,41 @@ +package com.bukkit.mcteam.factions.commands; + +import java.util.ArrayList; + +import com.bukkit.mcteam.factions.Conf; +import com.bukkit.mcteam.factions.FPlayer; +import com.bukkit.mcteam.factions.struct.Role; +import com.bukkit.mcteam.factions.util.TextUtil; + +public class FCommandDescription extends FBaseCommand { + + public FCommandDescription() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + requiredParameters.add("description"); + + permissions = ""; + + senderMustBePlayer = true; + + helpDescription = "Change the faction description"; + } + + public void perform() { + if ( ! assertHasFaction()) { + return; + } + + if ( ! assertMinRole(Role.MODERATOR)) { + return; + } + + me.getFaction().setDescription(TextUtil.implode(parameters)); + // Broadcast the description to everyone + for (FPlayer fplayer : FPlayer.getAllOnline()) { + fplayer.sendMessage("The faction "+fplayer.getRelationColor(me)+me.getFaction().getTag()+Conf.colorSystem+" changed their description to:"); + fplayer.sendMessage(me.getFaction().getDescription()); + } + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandHelp.java b/src/com/bukkit/mcteam/factions/commands/FCommandHelp.java new file mode 100644 index 00000000..ab3863b3 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandHelp.java @@ -0,0 +1,123 @@ +package com.bukkit.mcteam.factions.commands; + +import java.util.ArrayList; + +import com.bukkit.mcteam.factions.Conf; +import com.bukkit.mcteam.factions.util.TextUtil; + +public class FCommandHelp extends FBaseCommand { + + public FCommandHelp() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + optionalParameters.add("page"); + + permissions = ""; + + senderMustBePlayer = false; + + helpDescription = "Display a help page"; + } + + public void perform() { + int page = 1; + if (parameters.size() > 0) { + try { + page = Integer.parseInt(parameters.get(0)); + } catch (NumberFormatException e) { + // wasn't an integer + } + } + sendMessage(TextUtil.titleize("Factions Help ("+page+"/"+helpPages.size()+")")); + page -= 1; + if (page < 0 || page >= helpPages.size()) { + sendMessage("This page does not exist"); + return; + } + sendMessage(helpPages.get(page)); + } + + //----------------------------------------------// + // Build the help pages + //----------------------------------------------// + + public static ArrayList> helpPages; + + static { + helpPages = new ArrayList>(); + 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() ); + + 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() ); + + helpPages.add(pageLines); + pageLines = new ArrayList(); + + pageLines.add( new FCommandRelationAlly().getUseageTemplate() ); + pageLines.add( new FCommandRelationNeutral().getUseageTemplate() ); + pageLines.add( new FCommandRelationEnemy().getUseageTemplate() ); + 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."); + pageLines.add(""); + pageLines.add(Conf.colorSystem+"If BOTH factions choose \"ally\" you will be allies."); + pageLines.add(Conf.colorSystem+"If ONE faction chooses \"enemy\" you will be enemies."); + + helpPages.add(pageLines); + pageLines = new ArrayList(); + + pageLines.add(Conf.colorSystem+"You can never hurt members or allies."); + pageLines.add(Conf.colorSystem+"You can not hurt neutrals in their own territory."); + pageLines.add(Conf.colorSystem+"You can always hurt enemies and players without faction."); + pageLines.add(""); + pageLines.add(Conf.colorSystem+"Damage from enemies is reduced in your own territory."); + pageLines.add(Conf.colorSystem+"When you die you lose power. It is restored over time."); + pageLines.add(Conf.colorSystem+"The power of a faction is the sum of all member power."); + pageLines.add(Conf.colorSystem+"The power of a faction determines how much land it can hold."); + pageLines.add(Conf.colorSystem+"You can claim land from factions with too little power."); + + helpPages.add(pageLines); + pageLines = new ArrayList(); + + pageLines.add(Conf.colorSystem+"Only faction members can build and destroy in their own"); + pageLines.add(Conf.colorSystem+"territory. Usage of the following items is also restricted:"); + pageLines.add(Conf.colorSystem+"Door, Chest, Furnace and Dispenser."); + pageLines.add(" "); + pageLines.add(Conf.colorSystem+"Make sure to put pressure plates in front of doors for your"); + pageLines.add(Conf.colorSystem+"guest visitors. Otherwise they can't get through. You can "); + pageLines.add(Conf.colorSystem+"also use this to create member only areas."); + pageLines.add(Conf.colorSystem+"As dispensers are protected, you can create traps without"); + pageLines.add(Conf.colorSystem+"worrying about those arrows getting stolen."); + + helpPages.add(pageLines); + pageLines = new ArrayList(); + + pageLines.add( new FCommandVersion().getUseageTemplate() ); + + helpPages.add(pageLines); + } + +} + diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandInvite.java b/src/com/bukkit/mcteam/factions/commands/FCommandInvite.java new file mode 100644 index 00000000..2257119b --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandInvite.java @@ -0,0 +1,55 @@ +package com.bukkit.mcteam.factions.commands; + +import java.util.ArrayList; + +import com.bukkit.mcteam.factions.Conf; +import com.bukkit.mcteam.factions.FPlayer; +import com.bukkit.mcteam.factions.Faction; +import com.bukkit.mcteam.factions.struct.Role; + +public class FCommandInvite extends FBaseCommand { + + public FCommandInvite() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + requiredParameters.add("player name"); + + permissions = ""; + + senderMustBePlayer = true; + + helpDescription = "Invite a player"; + } + + public void perform() { + if ( ! assertHasFaction()) { + return; + } + + if ( ! assertMinRole(Role.MODERATOR)) { + return; + } + + String playerName = parameters.get(0); + + FPlayer you = findFPlayer(playerName, false); + if (you == null) { + return; + } + + Faction myFaction = me.getFaction(); + + 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()); + return; + } + + myFaction.invites.add(you.playerName); + Faction.save(); + + you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" invited you to "+myFaction.getTag(you)); + myFaction.sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" invited "+you.getNameAndRelevant(me)+Conf.colorSystem+" to your faction."); + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandJoin.java b/src/com/bukkit/mcteam/factions/commands/FCommandJoin.java index 590b14f1..400bb27a 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandJoin.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandJoin.java @@ -6,7 +6,7 @@ import com.bukkit.mcteam.factions.Conf; import com.bukkit.mcteam.factions.FPlayer; import com.bukkit.mcteam.factions.Faction; -public class FCommandJoin extends FCommand { +public class FCommandJoin extends FBaseCommand { public FCommandJoin() { requiredParameters = new ArrayList(); @@ -17,7 +17,6 @@ public class FCommandJoin extends FCommand { senderMustBePlayer = true; - helpNameAndParams = "join [faction name]"; helpDescription = "Join a faction"; } @@ -50,7 +49,7 @@ public class FCommandJoin extends FCommand { me.resetFactionData(); me.factionId = faction.id; - faction.deinvite(me); + faction.invites.remove(me.playerName); FPlayer.save(); } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandKick.java b/src/com/bukkit/mcteam/factions/commands/FCommandKick.java new file mode 100644 index 00000000..fcd0fe72 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandKick.java @@ -0,0 +1,58 @@ +package com.bukkit.mcteam.factions.commands; + +import java.util.ArrayList; + +import com.bukkit.mcteam.factions.Conf; +import com.bukkit.mcteam.factions.FPlayer; +import com.bukkit.mcteam.factions.Faction; + +public class FCommandKick extends FBaseCommand { + + public FCommandKick() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + requiredParameters.add("player name"); + + permissions = ""; + + senderMustBePlayer = true; + + helpDescription = "Kick a player from the faction"; + } + + public void perform() { + String playerName = parameters.get(0); + + FPlayer you = findFPlayer(playerName, false); + if (you == null) { + return; + } + + Faction myFaction = me.getFaction(); + + if (you.getFaction() != myFaction) { + sendMessage(you.getNameAndRelevant(me)+Conf.colorSystem+" is not a member of "+myFaction.getTag(me)); + return; + } + + if (me == you) { + sendMessage("You cannot kick yourself."); + sendMessage("You might want to "+Conf.colorCommand+Conf.aliasBase.get(0)+" "+Conf.aliasLeave.get(0)); + return; + } + + if (you.role.value >= me.role.value) { // TODO add more informative messages. + sendMessage("Your rank is too low to kick this player."); + return; + } + + myFaction.invites.remove(you.playerName); + you.resetFactionData(); + FPlayer.save(); + Faction.save(); + + myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" kicked "+you.getNameAndRelevant(myFaction)+Conf.colorSystem+" from the faction! :O"); + you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" kicked you from "+myFaction.getTag(you)+Conf.colorSystem+"! :O"); + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandLeave.java b/src/com/bukkit/mcteam/factions/commands/FCommandLeave.java index 248268e6..9ab97344 100644 --- a/src/com/bukkit/mcteam/factions/commands/FCommandLeave.java +++ b/src/com/bukkit/mcteam/factions/commands/FCommandLeave.java @@ -7,7 +7,7 @@ import com.bukkit.mcteam.factions.FPlayer; import com.bukkit.mcteam.factions.Faction; import com.bukkit.mcteam.factions.struct.Role; -public class FCommandLeave extends FCommand { +public class FCommandLeave extends FBaseCommand { public FCommandLeave() { requiredParameters = new ArrayList(); @@ -17,13 +17,11 @@ public class FCommandLeave extends FCommand { senderMustBePlayer = true; - helpNameAndParams = "leave"; helpDescription = "Leave your faction"; } public void perform() { - if ( ! me.hasFaction()) { - sendMessage("You are not member of any faction."); + if ( ! assertHasFaction()) { return; } diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandList.java b/src/com/bukkit/mcteam/factions/commands/FCommandList.java new file mode 100644 index 00000000..74696010 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandList.java @@ -0,0 +1,89 @@ +package com.bukkit.mcteam.factions.commands; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; + +import com.bukkit.mcteam.factions.Conf; +import com.bukkit.mcteam.factions.Faction; +import com.bukkit.mcteam.factions.util.TextUtil; + +public class FCommandList extends FBaseCommand { + + public FCommandList() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + optionalParameters.add("page"); + + permissions = ""; + + senderMustBePlayer = true; + + helpDescription = "Show a list of the factions"; + } + + // TODO put the 0 faction at the highest position + public void perform() { + ArrayList FactionList = new ArrayList(Faction.getAll()); + + int page = 1; + if (parameters.size() > 0) { + try { + page = Integer.parseInt(parameters.get(0)); + } catch (NumberFormatException e) { + // wasn't an integer + } + } + page -= 1; + + // Sort by total followers first + Collections.sort(FactionList, new Comparator(){ + @Override + public int compare(Faction f1, Faction f2) { + if (f1.id == 0) + return 1; + else if (f2.id == 0) + return -1; + else if (f1.getFPlayers().size() < f2.getFPlayers().size()) + return 1; + else if (f1.getFPlayers().size() > f2.getFPlayers().size()) + return -1; + return 0; + } + }); + + // Then sort by how many members are online now + Collections.sort(FactionList, new Comparator(){ + @Override + public int compare(Faction f1, Faction f2) { + if (f1.getFPlayersWhereOnline(true).size() < f2.getFPlayersWhereOnline(true).size()) + return 1; + else if (f1.getFPlayersWhereOnline(true).size() > f2.getFPlayersWhereOnline(true).size()) + return -1; + return 0; + } + }); + + int maxPage = (int)Math.floor((double)FactionList.size() / 9D); + if (page < 0 || page > maxPage) { + sendMessage("The faction list is only " + (maxPage+1) + " page(s) long"); + return; + } + + String header = "Faction List"; + if (maxPage > 1) header += " (page " + (page+1) + " of " + (maxPage+1) + ")"; + sendMessage(TextUtil.titleize(header)); + + int maxPos = (page+1) * 9; + if (maxPos > FactionList.size()) maxPos = FactionList.size(); + for (int pos = page * 9; pos < maxPos; pos++) { + Faction faction = FactionList.get(pos); + if (faction.id == 0) { + sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size() + " online"); + } else { + sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size()+"/"+faction.getFPlayers().size()+" online, "+faction.getLandRounded()+"/"+faction.getPowerRounded()+"/"+faction.getPowerMaxRounded()); + } + } + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandMap.java b/src/com/bukkit/mcteam/factions/commands/FCommandMap.java new file mode 100644 index 00000000..029c4f48 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandMap.java @@ -0,0 +1,47 @@ +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() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + optionalParameters.add("on|off"); + + permissions = ""; + + senderMustBePlayer = true; + + helpDescription = "Show territory map, set optional auto update"; + } + + public void perform() { + if (parameters.size() > 0) { + String mapAutoUpdating = parameters.get(0); + if (Conf.aliasTrue.contains(mapAutoUpdating.toLowerCase())) { + // Turn on + me.setMapAutoUpdating(true); + sendMessage("Map auto update ENABLED."); + + // And show the map once + showMap(); + } else { + // Turn off + me.setMapAutoUpdating(false); + sendMessage("Map auto update DISABLED."); + } + } else { + showMap(); + } + } + + public void showMap() { + sendMessage(Board.getMap(me.getFaction(), new FLocation(me), me.getPlayer().getLocation().getYaw())); + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandMod.java b/src/com/bukkit/mcteam/factions/commands/FCommandMod.java new file mode 100644 index 00000000..f5faad95 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandMod.java @@ -0,0 +1,63 @@ +package com.bukkit.mcteam.factions.commands; + +import java.util.ArrayList; + +import com.bukkit.mcteam.factions.Conf; +import com.bukkit.mcteam.factions.FPlayer; +import com.bukkit.mcteam.factions.Faction; +import com.bukkit.mcteam.factions.struct.Role; + +public class FCommandMod extends FBaseCommand { + + public FCommandMod() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + requiredParameters.add("player name"); + + permissions = ""; + + senderMustBePlayer = true; + + helpDescription = "Give or revoke moderator rights"; + } + + public void perform() { + if ( ! assertHasFaction()) { + return; + } + + if ( ! assertMinRole(Role.ADMIN)) { + return; + } + + String playerName = parameters.get(0); + + FPlayer you = findFPlayer(playerName, false); + if (you == null) { + return; + } + + Faction myFaction = me.getFaction(); + + if (you.getFaction() != myFaction) { + sendMessage(you.getNameAndRelevant(me)+Conf.colorSystem+" is not a member in your faction."); + return; + } + + if (you == me) { + sendMessage("The target player musn't be yourself."); + return; + } + + if (you.role == Role.MODERATOR) { + // Revoke + you.role = Role.NORMAL; + myFaction.sendMessage(you.getNameAndRelevant(myFaction)+Conf.colorSystem+" is no longer moderator in your faction."); + } else { + // Give + you.role = Role.MODERATOR; + myFaction.sendMessage(you.getNameAndRelevant(myFaction)+Conf.colorSystem+" was promoted to moderator in your faction."); + } + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandOpen.java b/src/com/bukkit/mcteam/factions/commands/FCommandOpen.java new file mode 100644 index 00000000..eabe29b0 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandOpen.java @@ -0,0 +1,46 @@ +package com.bukkit.mcteam.factions.commands; + +import java.util.ArrayList; + +import com.bukkit.mcteam.factions.Conf; +import com.bukkit.mcteam.factions.Faction; +import com.bukkit.mcteam.factions.struct.Role; + +public class FCommandOpen extends FBaseCommand { + + public FCommandOpen() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + + permissions = ""; + + senderMustBePlayer = true; + + helpDescription = "Switch if invitation is required to join"; + } + + public void perform() { + if ( ! assertHasFaction()) { + return; + } + + if ( ! assertMinRole(Role.MODERATOR)) { + return; + } + + Faction myFaction = me.getFaction(); + myFaction.setOpen( ! me.getFaction().getOpen()); + + String open = myFaction.getOpen() ? "open" : "closed"; + + // Inform + myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed the faction to "+open); + for (Faction faction : Faction.getAll()) { + if (faction.id == me.factionId) { + continue; + } + faction.sendMessage(Conf.colorSystem+"The faction "+myFaction.getTag(faction)+Conf.colorSystem+" is now "+open); + } + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandRelationAlly.java b/src/com/bukkit/mcteam/factions/commands/FCommandRelationAlly.java new file mode 100644 index 00000000..3478dee6 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandRelationAlly.java @@ -0,0 +1,11 @@ +package com.bukkit.mcteam.factions.commands; + +import com.bukkit.mcteam.factions.struct.Relation; + +public class FCommandRelationAlly extends FRelationCommand { + + 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 new file mode 100644 index 00000000..fcd69d82 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandRelationEnemy.java @@ -0,0 +1,11 @@ +package com.bukkit.mcteam.factions.commands; + +import com.bukkit.mcteam.factions.struct.Relation; + +public class FCommandRelationEnemy extends FRelationCommand { + + 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 new file mode 100644 index 00000000..f600d9c9 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandRelationNeutral.java @@ -0,0 +1,11 @@ +package com.bukkit.mcteam.factions.commands; + +import com.bukkit.mcteam.factions.struct.Relation; + +public class FCommandRelationNeutral extends FRelationCommand { + + 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 new file mode 100644 index 00000000..17de6687 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandShow.java @@ -0,0 +1,117 @@ +package com.bukkit.mcteam.factions.commands; + +import java.util.ArrayList; +import java.util.Collection; + +import com.bukkit.mcteam.factions.Conf; +import com.bukkit.mcteam.factions.FPlayer; +import com.bukkit.mcteam.factions.Faction; +import com.bukkit.mcteam.factions.struct.Relation; +import com.bukkit.mcteam.factions.struct.Role; +import com.bukkit.mcteam.factions.util.TextUtil; + +public class FCommandShow extends FBaseCommand { + + public FCommandShow() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + optionalParameters.add("faction tag"); + + permissions = ""; + + senderMustBePlayer = true; + + helpDescription = "Show faction information"; + } + + public void perform() { + Faction faction; + if (parameters.size() > 0) { + faction = findFaction(parameters.get(0), true); + } else { + faction = me.getFaction(); + } + + Collection admins = faction.getFPlayersWhereRole(Role.ADMIN); + Collection mods = faction.getFPlayersWhereRole(Role.MODERATOR); + Collection normals = faction.getFPlayersWhereRole(Role.NORMAL); + + sendMessage(TextUtil.titleize(faction.getTag(me))); + sendMessage(Conf.colorChrome+"Description: "+Conf.colorSystem+faction.getDescription()); + if (faction.id == 0) { + return; + } + + if(faction.getOpen()) { + sendMessage(Conf.colorChrome+"Joining: "+Conf.colorSystem+"no invitation is needed"); + } else { + sendMessage(Conf.colorChrome+"Joining: "+Conf.colorSystem+"invitation is required"); + } + sendMessage(Conf.colorChrome+"Land / Power / Maxpower: "+Conf.colorSystem+ faction.getLandRounded()+" / "+faction.getPowerRounded()+" / "+faction.getPowerMaxRounded()); + + String listpart; + + // List relation + String allyList = Conf.colorChrome+"Allies: "; + String enemyList = Conf.colorChrome+"Enemies: "; + for (Faction otherFaction : Faction.getAll()) { + if (otherFaction == faction) { + continue; + } + listpart = otherFaction.getTag(me)+Conf.colorSystem+", "; + if (otherFaction.getRelation(faction) == Relation.ALLY) { + allyList += listpart; + } else if (otherFaction.getRelation(faction) == Relation.ENEMY) { + enemyList += listpart; + } + } + if (allyList.endsWith(", ")) { + allyList = allyList.substring(0, allyList.length()-2); + } + if (enemyList.endsWith(", ")) { + enemyList = enemyList.substring(0, enemyList.length()-2); + } + + sendMessage(allyList); + sendMessage(enemyList); + + // List the members... + String onlineList = Conf.colorChrome+"Members online: "; + String offlineList = Conf.colorChrome+"Members offline: "; + for (FPlayer follower : admins) { + listpart = follower.getNameAndTitle(me)+Conf.colorSystem+", "; + if (follower.isOnline()) { + onlineList += listpart; + } else { + offlineList += listpart; + } + } + for (FPlayer follower : mods) { + listpart = follower.getNameAndTitle(me)+Conf.colorSystem+", "; + if (follower.isOnline()) { + onlineList += listpart; + } else { + offlineList += listpart; + } + } + for (FPlayer follower : normals) { + listpart = follower.getNameAndTitle(me)+Conf.colorSystem+", "; + if (follower.isOnline()) { + onlineList += listpart; + } else { + offlineList += listpart; + } + } + + if (onlineList.endsWith(", ")) { + onlineList = onlineList.substring(0, onlineList.length()-2); + } + if (offlineList.endsWith(", ")) { + offlineList = offlineList.substring(0, offlineList.length()-2); + } + + sendMessage(onlineList); + sendMessage(offlineList); + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandTag.java b/src/com/bukkit/mcteam/factions/commands/FCommandTag.java new file mode 100644 index 00000000..10586d4b --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandTag.java @@ -0,0 +1,63 @@ +package com.bukkit.mcteam.factions.commands; + +import java.util.ArrayList; + +import com.bukkit.mcteam.factions.Conf; +import com.bukkit.mcteam.factions.Faction; +import com.bukkit.mcteam.factions.struct.Role; +import com.bukkit.mcteam.factions.util.TextUtil; + +public class FCommandTag extends FBaseCommand { + + public FCommandTag() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + requiredParameters.add("faction tag"); + + permissions = ""; + + senderMustBePlayer = true; + + helpDescription = "Change the faction tag"; + } + + public void perform() { + if ( ! assertHasFaction()) { + return; + } + + if ( ! assertMinRole(Role.MODERATOR)) { + return; + } + + String tag = parameters.get(0); + + // TODO does not first test cover selfcase? + if (Faction.isTagTaken(tag) && ! TextUtil.getComparisonString(tag).equals(me.getFaction().getComparisonTag())) { + sendMessage("That tag is already taken"); + return; + } + + ArrayList errors = new ArrayList(); + errors.addAll(Faction.validateTag(tag)); + if (errors.size() > 0) { + sendMessage(errors); + return; + } + + Faction myFaction = me.getFaction(); + + String oldtag = myFaction.getTag(); + myFaction.setTag(tag); + + // Inform + myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed your faction tag to "+Conf.colorMember+myFaction.getTag()); + for (Faction faction : Faction.getAll()) { + if (faction.id == me.factionId) { + continue; + } + faction.sendMessage(Conf.colorSystem+"The faction "+me.getRelationColor(faction)+oldtag+Conf.colorSystem+" chainged their name to "+myFaction.getTag(faction)); + } + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandTitle.java b/src/com/bukkit/mcteam/factions/commands/FCommandTitle.java new file mode 100644 index 00000000..3927e9df --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandTitle.java @@ -0,0 +1,50 @@ +package com.bukkit.mcteam.factions.commands; + +import java.util.ArrayList; + +import com.bukkit.mcteam.factions.Conf; +import com.bukkit.mcteam.factions.FPlayer; +import com.bukkit.mcteam.factions.Faction; +import com.bukkit.mcteam.factions.util.TextUtil; + +public class FCommandTitle extends FBaseCommand { + + public FCommandTitle() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + requiredParameters.add("player name"); + optionalParameters.add("title"); + + permissions = ""; + + senderMustBePlayer = true; + + helpDescription = "Set or remove a players title"; + } + + public void perform() { + if ( ! assertHasFaction()) { + return; + } + + String playerName = parameters.get(0); + parameters.remove(0); + String title = TextUtil.implode(parameters); + + FPlayer you = findFPlayer(playerName, false); + if (you == null) { + return; + } + + if ( ! canIAdministerYou(me, you)) { + return; + } + + you.setTitle(title); + + // Inform + Faction myFaction = me.getFaction(); + myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed a title: "+you.getNameAndRelevant(myFaction)); + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandUnclaim.java b/src/com/bukkit/mcteam/factions/commands/FCommandUnclaim.java new file mode 100644 index 00000000..6e3f384e --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandUnclaim.java @@ -0,0 +1,47 @@ +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; +import com.bukkit.mcteam.factions.Faction; +import com.bukkit.mcteam.factions.struct.Role; + +public class FCommandUnclaim extends FBaseCommand { + + public FCommandUnclaim() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + + permissions = ""; + + senderMustBePlayer = true; + + helpDescription = "Unclaim the land where you are standing"; + } + + public void perform() { + if ( ! assertHasFaction()) { + return; + } + + if ( ! assertMinRole(Role.MODERATOR)) { + return; + } + + Faction myFaction = me.getFaction(); + FLocation flocation = new FLocation(me); + Faction otherFaction = Board.getFactionAt(flocation); + + if ( myFaction != otherFaction) { + sendMessage("You don't own this land."); + return; + } + + Board.removeAt(flocation); + + myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" unclaimed some land."); + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FCommandVersion.java b/src/com/bukkit/mcteam/factions/commands/FCommandVersion.java new file mode 100644 index 00000000..9affbc77 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FCommandVersion.java @@ -0,0 +1,24 @@ +package com.bukkit.mcteam.factions.commands; + +import java.util.ArrayList; + +import com.bukkit.mcteam.factions.Factions; + +public class FCommandVersion extends FBaseCommand { + + public FCommandVersion() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + + permissions = ""; + + senderMustBePlayer = false; + + helpDescription = "Which version are you using?"; + } + + public void perform() { + sendMessage("You are running "+Factions.instance.getDescription().getFullName()); + } + +} diff --git a/src/com/bukkit/mcteam/factions/commands/FRelationCommand.java b/src/com/bukkit/mcteam/factions/commands/FRelationCommand.java new file mode 100644 index 00000000..1fa63142 --- /dev/null +++ b/src/com/bukkit/mcteam/factions/commands/FRelationCommand.java @@ -0,0 +1,61 @@ +package com.bukkit.mcteam.factions.commands; + +import java.util.ArrayList; + +import org.bukkit.ChatColor; + +import com.bukkit.mcteam.factions.Conf; +import com.bukkit.mcteam.factions.Faction; +import com.bukkit.mcteam.factions.struct.Relation; +import com.bukkit.mcteam.factions.struct.Role; + +public class FRelationCommand extends FBaseCommand { + + public FRelationCommand() { + requiredParameters = new ArrayList(); + optionalParameters = new ArrayList(); + requiredParameters.add("faction tag"); + helpDescription = "Declare your factions relation wish to another faction"; + permissions = ""; + + senderMustBePlayer = true; + } + + public void relation(Relation whishedRelation, String otherFactionName) { + if ( ! assertHasFaction()) { + return; + } + + if ( ! assertMinRole(Role.MODERATOR)) { + return; + } + + Faction myFaction = me.getFaction(); + Faction otherFaction = findFaction(otherFactionName, false); + if (otherFaction == null) { + return; + } + + if (otherFaction.id == 0) { + sendMessage("Nope! You can't :) The default faction is not a real faction."); + return; + } + + if (otherFaction == myFaction) { + sendMessage("Nope! You can't declare a relation to yourself :)"); + return; + } + + myFaction.setRelationWish(otherFaction, whishedRelation); + Relation currentRelation = myFaction.getRelation(otherFaction); + ChatColor currentRelationColor = currentRelation.getColor(); + if (whishedRelation == currentRelation) { + otherFaction.sendMessage(Conf.colorSystem+"Your faction is now "+currentRelationColor+whishedRelation.toString()+Conf.colorSystem+" to "+currentRelationColor+myFaction.getTag()); + 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."); + 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/Commands.java b/src/com/bukkit/mcteam/factions/entities/CommandsOld.java similarity index 99% rename from src/com/bukkit/mcteam/factions/Commands.java rename to src/com/bukkit/mcteam/factions/entities/CommandsOld.java index f915ef9b..15c20a2f 100644 --- a/src/com/bukkit/mcteam/factions/Commands.java +++ b/src/com/bukkit/mcteam/factions/entities/CommandsOld.java @@ -1,4 +1,4 @@ -package com.bukkit.mcteam.factions; +package com.bukkit.mcteam.factions.entities; import java.util.*; @@ -8,7 +8,7 @@ import com.bukkit.mcteam.factions.entities.*; import com.bukkit.mcteam.factions.struct.*; import com.bukkit.mcteam.factions.util.*; -public class Commands { +public class CommandsOld { public static ArrayList> helpPages; //----------------------------------------------// @@ -18,7 +18,6 @@ public class Commands { static { helpPages = new ArrayList>(); ArrayList pageLines; - pageLines = new ArrayList(); pageLines.add(TextUtil.commandHelp(Conf.aliasHelp, "*[page]", "Display a help page")); @@ -313,7 +312,7 @@ public class Commands { me.sendMessage(Conf.colorSystem+"Now update your faction description. Use:"); me.sendMessage(Conf.colorCommand+Conf.aliasBase.get(0)+" "+Conf.aliasDescription.get(0)+" "+"[description]"); } - */ + public static void tag(FPlayer me, String tag) { ArrayList errors = new ArrayList(); @@ -356,8 +355,7 @@ public class Commands { int page = 1; try { page = Integer.parseInt(inPage); - } - catch (NumberFormatException e) { + } catch (NumberFormatException e) { // wasn't an integer } page -= 1; @@ -833,7 +831,7 @@ public class Commands { public static void version(FPlayer me) { me.sendMessage(Conf.colorSystem+"You are running "+Factions.instance.getDescription().getFullName()); - } + }*/ } diff --git a/src/com/bukkit/mcteam/factions/CoordOld.java b/src/com/bukkit/mcteam/factions/entities/CoordOld.java similarity index 96% rename from src/com/bukkit/mcteam/factions/CoordOld.java rename to src/com/bukkit/mcteam/factions/entities/CoordOld.java index 16345745..177c9aea 100644 --- a/src/com/bukkit/mcteam/factions/CoordOld.java +++ b/src/com/bukkit/mcteam/factions/entities/CoordOld.java @@ -1,4 +1,4 @@ -package com.bukkit.mcteam.factions; +package com.bukkit.mcteam.factions.entities; import org.bukkit.Location; import org.bukkit.block.Block; diff --git a/src/com/bukkit/mcteam/factions/util/TextUtil.java b/src/com/bukkit/mcteam/factions/util/TextUtil.java index 88deb96b..f5ae4a51 100644 --- a/src/com/bukkit/mcteam/factions/util/TextUtil.java +++ b/src/com/bukkit/mcteam/factions/util/TextUtil.java @@ -38,7 +38,7 @@ public class TextUtil { return implode(list, " "); } - public static String commandHelp(List aliases, String param, String desc) { + /*public static String commandHelp(List aliases, String param, String desc) { ArrayList parts = new ArrayList(); parts.add(Conf.colorCommand+Conf.aliasBase.get(0)); parts.add(TextUtil.implode(aliases, ", ")); @@ -50,7 +50,7 @@ public class TextUtil { } //Log.debug(TextUtil.implode(parts, " ")); return TextUtil.implode(parts, " "); - } + }*/ public static String getMaterialName(Material material) { String ret = material.toString();