From e14f8ad93ceac78c0b9f99d1576910763707c99d Mon Sep 17 00:00:00 2001 From: GJ Date: Fri, 8 Feb 2013 11:48:24 -0500 Subject: [PATCH] Convert /party shareexp to a subcommand --- .../nossr50/party/commands/PartyCommand.java | 41 +----------- .../party/commands/PartyShareExpCommand.java | 62 +++++++++++++++++++ .../resources/locale/locale_en_US.properties | 2 +- 3 files changed, 65 insertions(+), 40 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/party/commands/PartyShareExpCommand.java diff --git a/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java index 9d9cf86d0..fea0b7fc5 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java @@ -16,7 +16,6 @@ import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.PartyManager; -import com.gmail.nossr50.party.ShareHandler; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; @@ -28,6 +27,7 @@ public class PartyCommand implements CommandExecutor { private CommandExecutor partyAcceptCommand = new PartyAcceptCommand(); private CommandExecutor partyCreateCommand = new PartyCreateCommand(); private CommandExecutor partyQuitCommand = new PartyQuitCommand(); + private CommandExecutor partyShareExpCommand = new PartyShareExpCommand(); @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -69,7 +69,7 @@ public class PartyCommand implements CommandExecutor { return partyQuitCommand.onCommand(sender, command, label, args); } else if (args[0].equalsIgnoreCase("expshare")) { - return shareExp(args); + return partyShareExpCommand.onCommand(sender, command, label, args); } else if (args[0].equalsIgnoreCase("itemshare")) { return shareItem(); @@ -176,43 +176,6 @@ public class PartyCommand implements CommandExecutor { return true; } - private boolean shareExp(String[] args) { - if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.expshare")) { - return true; - } - - if (args.length < 2) { - player.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "expshare", "[NONE / EQUAL]")); - return true; - } - - String playerName = player.getName(); - Party party = mcMMOPlayer.getParty(); - - if (party.getLeader().equals(playerName)) { - if (args[1].equalsIgnoreCase("none") || args[1].equalsIgnoreCase("false")) { - party.setXpShareMode(ShareHandler.XpShareMode.NONE); - - for (Player onlineMembers : party.getOnlineMembers()) { - onlineMembers.sendMessage(LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Exp"), LocaleLoader.getString("Party.ShareMode.NoShare"))); - } - } - else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even")) { - party.setXpShareMode(ShareHandler.XpShareMode.EQUAL); - - for (Player onlineMembers : party.getOnlineMembers()) { - onlineMembers.sendMessage(LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Exp"), LocaleLoader.getString("Party.ShareMode.Equal"))); - } - } - else { - player.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "expshare", "[NONE / EQUAL]")); - return true; - } - } - - return true; - } - private boolean shareItem() { return (!CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.itemshare")); } diff --git a/src/main/java/com/gmail/nossr50/party/commands/PartyShareExpCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PartyShareExpCommand.java new file mode 100644 index 000000000..a0241c25a --- /dev/null +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyShareExpCommand.java @@ -0,0 +1,62 @@ +package com.gmail.nossr50.party.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.party.Party; +import com.gmail.nossr50.party.ShareHandler; +import com.gmail.nossr50.party.ShareHandler.XpShareMode; +import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.util.Permissions; +import com.gmail.nossr50.util.Users; + +public class PartyShareExpCommand implements CommandExecutor { + private Player player; + private Party playerParty; + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!Permissions.hasPermission(sender, "mcmmo.commands.party.expshare")) { + sender.sendMessage(command.getPermissionMessage()); + return true; + } + + switch (args.length) { + case 2: + player = (Player) sender; + playerParty = Users.getPlayer(player).getParty(); + + if (!playerParty.getLeader().equals(player.getName())) { + sender.sendMessage(LocaleLoader.getString("Party.NotOwner")); + return true; + } + + if (args[1].equalsIgnoreCase("none") || args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("false")) { + handleChangingShareMode(XpShareMode.NONE); + } + else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even") || args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("true")) { + handleChangingShareMode(XpShareMode.EQUAL); + } + else { + sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "expshare", "[NONE | EQUAL]")); + } + + return true; + + default: + sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "expshare", "[NONE | EQUAL]")); + return true; + } + } + + private void handleChangingShareMode(ShareHandler.XpShareMode mode) { + playerParty.setXpShareMode(mode); + + for (Player member : playerParty.getOnlineMembers()) { + member.sendMessage(LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Exp"), LocaleLoader.getString("Party.ShareMode." + Misc.getCapitalized(mode.toString())))); + } + } +} diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index c1a6a4372..51f719705 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -550,7 +550,7 @@ Party.Status.Locked=[[DARK_RED]](INVITE-ONLY) Party.Status.Unlocked=[[DARK_GREEN]](OPEN) Party.ShareType.Exp=EXP Party.ShareType.Item=ITEM -Party.ShareMode.NoShare=NONE +Party.ShareMode.None=NONE Party.ShareMode.Equal=EQUAL Party.ShareMode.Random=RANDOM