From 291393d45dac18c2395d45a77ecede69c6bb0080 Mon Sep 17 00:00:00 2001 From: GJ Date: Thu, 7 Feb 2013 22:54:15 -0500 Subject: [PATCH] Update /party create to be a subcommand --- .../nossr50/party/commands/PartyCommand.java | 57 +-------------- .../party/commands/PartyCreateCommand.java | 71 +++++++++++++++++++ 2 files changed, 73 insertions(+), 55 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/party/commands/PartyCreateCommand.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 e8993e944..abc3969b8 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java @@ -25,6 +25,7 @@ public class PartyCommand implements CommandExecutor { private CommandExecutor partyJoinCommand = new PartyJoinCommand(); private CommandExecutor partyAcceptCommand = new PartyAcceptCommand(); + private CommandExecutor partyCreateCommand = new PartyCreateCommand(); @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -50,7 +51,7 @@ public class PartyCommand implements CommandExecutor { return partyAcceptCommand.onCommand(sender, command, label, args); } else if (args[0].equalsIgnoreCase("create")) { - return create(args); + return partyCreateCommand.onCommand(sender, command, label, args); } else if (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help")) { return printHelp(); @@ -172,60 +173,6 @@ public class PartyCommand implements CommandExecutor { return true; } - private boolean create(String[] args) { - if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.create")) { - return true; - } - - String playerName = player.getName(); - Party party = mcMMOPlayer.getParty(); - - if (args.length < 2) { - player.sendMessage(LocaleLoader.getString("Party.Help.1")); - return true; - } - - String partyname = args[1]; - String password = null; - - if (args.length > 2) { - password = args[2]; - } - - Party newParty = PartyManager.getParty(partyname); - // Check to see if the party exists, and if it does cancel creating a new party - if (newParty != null) { - player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", partyname)); - return true; - } - - if (mcMMOPlayer.inParty()) { - String oldPartyName = party.getName(); - McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, oldPartyName, partyname, EventReason.CHANGED_PARTIES); - mcMMO.p.getServer().getPluginManager().callEvent(event); - - if (event.isCancelled()) { - return true; - } - - PartyManager.removeFromParty(playerName, party); - PartyManager.createParty(player, mcMMOPlayer, partyname, password); - } - else { - McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, partyname, EventReason.JOINED_PARTY); - mcMMO.p.getServer().getPluginManager().callEvent(event); - - if (event.isCancelled()) { - return true; - } - - PartyManager.createParty(player, mcMMOPlayer, partyname, password); - return true; - } - - return true; - } - private boolean quit() { if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.quit")) { return true; diff --git a/src/main/java/com/gmail/nossr50/party/commands/PartyCreateCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PartyCreateCommand.java new file mode 100644 index 000000000..3ae192344 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyCreateCommand.java @@ -0,0 +1,71 @@ +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.datatypes.McMMOPlayer; +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.util.Permissions; +import com.gmail.nossr50.util.Users; + +public class PartyCreateCommand implements CommandExecutor { + private McMMOPlayer mcMMOPlayer; + 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.create")) { + sender.sendMessage(command.getPermissionMessage()); + return true; + } + + switch (args.length) { + case 2: + case 3: + Party newParty = PartyManager.getParty(args[1]); + + // Check to see if the party exists, and if it does cancel creating a new party + if (newParty != null) { + player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", args[1])); + return true; + } + + player = (Player) sender; + mcMMOPlayer = Users.getPlayer(player); + + // Changing parties + if (mcMMOPlayer.inParty()) { + playerParty = mcMMOPlayer.getParty(); + if (!PartyManager.handlePartyChangeEvent(player, playerParty.getName(), args[1], EventReason.CHANGED_PARTIES)) { + return true; + } + + PartyManager.removeFromParty(player.getName(), playerParty); + } + else if (!PartyManager.handlePartyChangeEvent(player, null, args[1], EventReason.JOINED_PARTY)) { + return true; + } + + PartyManager.createParty(player, mcMMOPlayer, args[1], getPassword(args)); + return true; + + default: + sender.sendMessage(LocaleLoader.getString("Commands.Usage.3", "party", "create", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">", "[" + LocaleLoader.getString("Commands.Usage.Password") + "]")); + return true; + } + } + + private String getPassword(String[] args) { + if (args.length == 3) { + return args[2]; + } + + return null; + } +}