mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-01-19 00:45:27 +01:00
Convert /party lock & /party unlock to a subcommand.
This commit is contained in:
parent
2d6fb72b9d
commit
98a64a0948
@ -33,6 +33,7 @@ public class PartyCommand implements CommandExecutor {
|
||||
private CommandExecutor partyKickCommand = new PartyKickCommand();
|
||||
private CommandExecutor partyDisbandCommand = new PartyDisbandCommand();
|
||||
private CommandExecutor partyChangeOwnerCommand = new PartyChangeOwnerCommand();
|
||||
private CommandExecutor partyLockCommand = new PartyLockCommand();
|
||||
|
||||
@Override
|
||||
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")) {
|
||||
return partyChangeOwnerCommand.onCommand(sender, command, label, args);
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("lock")) {
|
||||
return lock();
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("unlock")) {
|
||||
return unlock();
|
||||
else if (args[0].equalsIgnoreCase("lock") || args[0].equalsIgnoreCase("unlock")) {
|
||||
return partyLockCommand.onCommand(sender, command, label, args);
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("password")) {
|
||||
return changePassword(args);
|
||||
@ -191,69 +189,6 @@ public class PartyCommand implements CommandExecutor {
|
||||
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) {
|
||||
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.password")) {
|
||||
return true;
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user