From 288907cfd42a14a35b1dfaf6c42e644d54da692d Mon Sep 17 00:00:00 2001 From: GJ Date: Tue, 12 Feb 2013 08:57:35 -0500 Subject: [PATCH] Convert /party password to a subcommand. --- .../commands/PartyChangePasswordCommand.java | 55 +++++++++++++++++++ .../nossr50/party/commands/PartyCommand.java | 30 +--------- 2 files changed, 57 insertions(+), 28 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/party/commands/PartyChangePasswordCommand.java diff --git a/src/main/java/com/gmail/nossr50/party/commands/PartyChangePasswordCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PartyChangePasswordCommand.java new file mode 100644 index 000000000..7f42dfcf8 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyChangePasswordCommand.java @@ -0,0 +1,55 @@ +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.util.Permissions; +import com.gmail.nossr50.util.Users; + +public class PartyChangePasswordCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!Permissions.hasPermission(sender, "mcmmo.commands.party.password")) { + sender.sendMessage(command.getPermissionMessage()); + return true; + } + + Party playerParty = Users.getPlayer((Player) sender).getParty(); + switch (args.length) { + case 1: + unprotectParty(sender, playerParty); + return true; + + case 2: + if (args[1].equalsIgnoreCase("clear") || args[1].equalsIgnoreCase("reset")) { + unprotectParty(sender, playerParty); + return true; + } + + protectParty(sender, playerParty, args[1]); + return true; + + default: + sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "password", "[clear|reset]")); + sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "password", "<" + LocaleLoader.getString("Commands.Usage.Password") + ">")); + return true; + } + } + + private void unprotectParty(CommandSender sender, Party playerParty) { + playerParty.setLocked(true); + playerParty.setPassword(null); + sender.sendMessage(LocaleLoader.getString("Party.Password.Removed")); + } + + private void protectParty(CommandSender sender, Party playerParty, String password) { + playerParty.setLocked(true); + playerParty.setPassword(password); + sender.sendMessage(LocaleLoader.getString("Party.Password.Set", password)); + } +} 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 029784edc..064ccf349 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java @@ -34,6 +34,7 @@ public class PartyCommand implements CommandExecutor { private CommandExecutor partyDisbandCommand = new PartyDisbandCommand(); private CommandExecutor partyChangeOwnerCommand = new PartyChangeOwnerCommand(); private CommandExecutor partyLockCommand = new PartyLockCommand(); + private CommandExecutor partyChangePasswordCommand = new PartyChangePasswordCommand(); @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -102,7 +103,7 @@ public class PartyCommand implements CommandExecutor { return partyLockCommand.onCommand(sender, command, label, args); } else if (args[0].equalsIgnoreCase("password")) { - return changePassword(args); + return partyChangePasswordCommand.onCommand(sender, command, label, args); } else if (args[0].equalsIgnoreCase("rename")) { return rename(args); @@ -195,33 +196,6 @@ public class PartyCommand implements CommandExecutor { return true; } - private boolean changePassword(String[] args) { - if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.password")) { - return true; - } - - String playerName = player.getName(); - Party party = mcMMOPlayer.getParty(); - - if (!party.getLeader().equals(playerName)) { - player.sendMessage(LocaleLoader.getString("Party.NotOwner")); - return true; - } - - if (args.length < 2) { - party.setLocked(true); - party.setPassword(null); - player.sendMessage(LocaleLoader.getString("Party.Password.Removed")); - return true; - } - - party.setLocked(true); - party.setPassword(args[1]); - player.sendMessage(LocaleLoader.getString("Party.Password.Set", args[1])); - - return true; - } - /** * Rename the current party */