Convert /party lock & /party unlock to a subcommand.

This commit is contained in:
GJ 2013-02-11 17:31:09 -05:00
parent 2d6fb72b9d
commit 98a64a0948
2 changed files with 102 additions and 68 deletions

View File

@ -33,6 +33,7 @@ public class PartyCommand implements CommandExecutor {
private CommandExecutor partyKickCommand = new PartyKickCommand(); private CommandExecutor partyKickCommand = new PartyKickCommand();
private CommandExecutor partyDisbandCommand = new PartyDisbandCommand(); private CommandExecutor partyDisbandCommand = new PartyDisbandCommand();
private CommandExecutor partyChangeOwnerCommand = new PartyChangeOwnerCommand(); private CommandExecutor partyChangeOwnerCommand = new PartyChangeOwnerCommand();
private CommandExecutor partyLockCommand = new PartyLockCommand();
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -91,11 +92,8 @@ public class PartyCommand implements CommandExecutor {
else if (args[0].equalsIgnoreCase("owner")) { else if (args[0].equalsIgnoreCase("owner")) {
return partyChangeOwnerCommand.onCommand(sender, command, label, args); return partyChangeOwnerCommand.onCommand(sender, command, label, args);
} }
else if (args[0].equalsIgnoreCase("lock")) { else if (args[0].equalsIgnoreCase("lock") || args[0].equalsIgnoreCase("unlock")) {
return lock(); return partyLockCommand.onCommand(sender, command, label, args);
}
else if (args[0].equalsIgnoreCase("unlock")) {
return unlock();
} }
else if (args[0].equalsIgnoreCase("password")) { else if (args[0].equalsIgnoreCase("password")) {
return changePassword(args); return changePassword(args);
@ -191,69 +189,6 @@ public class PartyCommand implements CommandExecutor {
return true; return true;
} }
/**
* Lock the current party
*/
private boolean lock() {
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.lock")) {
return true;
}
String playerName = player.getName();
Party party = mcMMOPlayer.getParty();
if (party == null) {
player.sendMessage("Commands.Party.None");
return true;
}
if (!party.getLeader().equals(playerName)) {
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
return true;
}
if (party.isLocked()) {
player.sendMessage(LocaleLoader.getString("Party.IsLocked"));
}
else {
party.setLocked(true);
player.sendMessage(LocaleLoader.getString("Party.Locked"));
}
return true;
}
/**
* Unlock the current party
*/
private boolean unlock() {
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.unlock")) {
return true;
}
String playerName = player.getName();
Party party = mcMMOPlayer.getParty();
if (party == null) {
player.sendMessage("Commands.Party.None");
return true;
}
if (!party.getLeader().equals(playerName)) {
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
return true;
}
if (!party.isLocked()) {
player.sendMessage(LocaleLoader.getString("Party.IsntLocked"));
}
else {
party.setLocked(false);
player.sendMessage(LocaleLoader.getString("Party.Unlocked"));
}
return true;
}
private boolean changePassword(String[] args) { private boolean changePassword(String[] args) {
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.password")) { if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.password")) {
return true; return true;

View File

@ -0,0 +1,99 @@
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 PartyLockCommand implements CommandExecutor {
private Player player;
private Party playerParty;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
player = (Player) sender;
playerParty = Users.getPlayer(player).getParty();
if (!playerParty.getLeader().equals(player.getName())) {
sender.sendMessage(LocaleLoader.getString("Party.NotOwner"));
return true;
}
switch (args.length) {
case 1:
if (args[0].equalsIgnoreCase("lock")) {
lockParty(sender, command);
}
else if (args[0].equalsIgnoreCase("unlock")) {
unlockParty(sender, command);
}
return true;
case 2:
if (!args[0].equalsIgnoreCase("lock")) {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "lock", "[on|off]"));
return true;
}
if (args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("true")) {
lockParty(sender, command);
}
else if (args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("false")) {
unlockParty(sender, command);
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "lock", "[on|off]"));
}
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "lock", "[on|off]"));
return true;
}
}
/**
* Handle locking a party.
*/
private void lockParty(CommandSender sender, Command command) {
if (!Permissions.hasPermission(sender, "mcmmo.commands.party.lock")) {
sender.sendMessage(command.getPermissionMessage());
return;
}
if (playerParty.isLocked()) {
sender.sendMessage(LocaleLoader.getString("Party.IsLocked"));
return;
}
playerParty.setLocked(true);
sender.sendMessage(LocaleLoader.getString("Party.Locked"));
}
/**
* Handle unlocking a party.
*
* @return true if party is successfully unlocked, false otherwise.
*/
private void unlockParty(CommandSender sender, Command command) {
if (!Permissions.hasPermission(sender, "mcmmo.commands.party.unlock")) {
sender.sendMessage(command.getPermissionMessage());
return;
}
if (!playerParty.isLocked()) {
player.sendMessage(LocaleLoader.getString("Party.IsntLocked"));
return;
}
playerParty.setLocked(false);
player.sendMessage(LocaleLoader.getString("Party.Unlocked"));
}
}