mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-30 00:56:47 +01:00
Convert /party password to a subcommand.
This commit is contained in:
parent
c822be4a53
commit
288907cfd4
@ -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));
|
||||||
|
}
|
||||||
|
}
|
@ -34,6 +34,7 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
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();
|
private CommandExecutor partyLockCommand = new PartyLockCommand();
|
||||||
|
private CommandExecutor partyChangePasswordCommand = new PartyChangePasswordCommand();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
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);
|
return partyLockCommand.onCommand(sender, command, label, args);
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("password")) {
|
else if (args[0].equalsIgnoreCase("password")) {
|
||||||
return changePassword(args);
|
return partyChangePasswordCommand.onCommand(sender, command, label, args);
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("rename")) {
|
else if (args[0].equalsIgnoreCase("rename")) {
|
||||||
return rename(args);
|
return rename(args);
|
||||||
@ -195,33 +196,6 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
return true;
|
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
|
* Rename the current party
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user