mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-02 00:30:07 +01:00
Use an enum to handle our subcommands.
This commit is contained in:
parent
ab731302e0
commit
6acfba1315
@ -44,71 +44,85 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
player = (Player) sender;
|
player = (Player) sender;
|
||||||
mcMMOPlayer = Users.getPlayer(player);
|
mcMMOPlayer = Users.getPlayer(player);
|
||||||
|
|
||||||
if (args.length < 1 || args[0].equalsIgnoreCase("info")) {
|
if (args.length < 1) {
|
||||||
|
if (!mcMMOPlayer.inParty()) {
|
||||||
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
||||||
|
return printUsage();
|
||||||
|
}
|
||||||
|
|
||||||
return partyInfoCommand.onCommand(sender, command, label, args);
|
return partyInfoCommand.onCommand(sender, command, label, args);
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("join")) {
|
|
||||||
return partyJoinCommand.onCommand(sender, command, label, args);
|
PartySubcommand subcommand = PartySubcommand.getSubcommand(args[0]);
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("accept")) {
|
if (subcommand == null) {
|
||||||
return partyAcceptCommand.onCommand(sender, command, label, args);
|
return printUsage();
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("create")) {
|
|
||||||
return partyCreateCommand.onCommand(sender, command, label, args);
|
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help")) {
|
|
||||||
return printHelp();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (subcommand) {
|
||||||
|
case JOIN:
|
||||||
|
return partyJoinCommand.onCommand(sender, command, label, args);
|
||||||
|
case ACCEPT:
|
||||||
|
return partyAcceptCommand.onCommand(sender, command, label, args);
|
||||||
|
case CREATE:
|
||||||
|
return partyCreateCommand.onCommand(sender, command, label, args);
|
||||||
|
case HELP:
|
||||||
|
return printHelp();
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Party member commands
|
||||||
if (!mcMMOPlayer.inParty()) {
|
if (!mcMMOPlayer.inParty()) {
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
||||||
return true;
|
return printUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("quit") || args[0].equalsIgnoreCase("q") || args[0].equalsIgnoreCase("leave")) {
|
switch (subcommand) {
|
||||||
|
case INFO:
|
||||||
|
return partyInfoCommand.onCommand(sender, command, label, args);
|
||||||
|
case QUIT:
|
||||||
return partyQuitCommand.onCommand(sender, command, label, args);
|
return partyQuitCommand.onCommand(sender, command, label, args);
|
||||||
}
|
case INVITE:
|
||||||
else if (args[0].equalsIgnoreCase("expshare") || args[0].equalsIgnoreCase("xpshare") || args[0].equalsIgnoreCase("sharexp") || args[0].equalsIgnoreCase("shareexp")) {
|
|
||||||
return partyExpShareCommand.onCommand(sender, command, label, args);
|
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("itemshare") || args[0].equalsIgnoreCase("shareitem") || args[0].equalsIgnoreCase("shareitems")) {
|
|
||||||
return partyItemShareCommand.onCommand(sender, command, label, args);
|
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("invite")) {
|
|
||||||
return partyInviteCommand.onCommand(sender, command, label, args);
|
return partyInviteCommand.onCommand(sender, command, label, args);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Party leader commands
|
||||||
if (!mcMMOPlayer.getParty().getLeader().equals(player.getName())) {
|
if (!mcMMOPlayer.getParty().getLeader().equals(player.getName())) {
|
||||||
sender.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
sender.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("kick")) {
|
switch (subcommand) {
|
||||||
|
case EXPSHARE:
|
||||||
|
return partyExpShareCommand.onCommand(sender, command, label, args);
|
||||||
|
case ITEMSHARE:
|
||||||
|
return partyItemShareCommand.onCommand(sender, command, label, args);
|
||||||
|
case KICK:
|
||||||
return partyKickCommand.onCommand(sender, command, label, args);
|
return partyKickCommand.onCommand(sender, command, label, args);
|
||||||
}
|
case DISBAND:
|
||||||
else if (args[0].equalsIgnoreCase("disband")) {
|
|
||||||
return partyDisbandCommand.onCommand(sender, command, label, args);
|
return partyDisbandCommand.onCommand(sender, command, label, args);
|
||||||
}
|
case OWNER:
|
||||||
else if (args[0].equalsIgnoreCase("owner")) {
|
|
||||||
return partyChangeOwnerCommand.onCommand(sender, command, label, args);
|
return partyChangeOwnerCommand.onCommand(sender, command, label, args);
|
||||||
}
|
case LOCK:
|
||||||
else if (args[0].equalsIgnoreCase("lock") || args[0].equalsIgnoreCase("unlock")) {
|
case UNLOCK:
|
||||||
return partyLockCommand.onCommand(sender, command, label, args);
|
return partyLockCommand.onCommand(sender, command, label, args);
|
||||||
}
|
case PASSWORD:
|
||||||
else if (args[0].equalsIgnoreCase("password")) {
|
|
||||||
return partyChangePasswordCommand.onCommand(sender, command, label, args);
|
return partyChangePasswordCommand.onCommand(sender, command, label, args);
|
||||||
}
|
case RENAME:
|
||||||
else if (args[0].equalsIgnoreCase("rename")) {
|
|
||||||
return partyRenameCommand.onCommand(sender, command, label, args);
|
return partyRenameCommand.onCommand(sender, command, label, args);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return printUsage();
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean printUsage() {
|
private boolean printUsage() {
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Help.0"));
|
player.sendMessage(LocaleLoader.getString("Party.Help.0", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">", "[" + LocaleLoader.getString("Commands.Usage.Password") + "]"));
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
|
player.sendMessage(LocaleLoader.getString("Party.Help.1", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">", "[" + LocaleLoader.getString("Commands.Usage.Password") + "]"));
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Help.2"));
|
player.sendMessage(LocaleLoader.getString("Party.Help.2"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -22,11 +22,6 @@ public class PartyInfoCommand implements CommandExecutor {
|
|||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
player = (Player) sender;
|
player = (Player) sender;
|
||||||
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
|
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
|
||||||
|
|
||||||
if (!mcMMOPlayer.inParty()) {
|
|
||||||
sendUsageStrings(sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
playerParty = mcMMOPlayer.getParty();
|
playerParty = mcMMOPlayer.getParty();
|
||||||
|
|
||||||
displayPartyHeader();
|
displayPartyHeader();
|
||||||
@ -35,12 +30,6 @@ public class PartyInfoCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendUsageStrings(CommandSender sender) {
|
|
||||||
sender.sendMessage(LocaleLoader.getString("Party.Help.0", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">", "[" + LocaleLoader.getString("Commands.Usage.Password") + "]"));
|
|
||||||
sender.sendMessage(LocaleLoader.getString("Party.Help.1", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">", "[" + LocaleLoader.getString("Commands.Usage.Password") + "]"));
|
|
||||||
sender.sendMessage(LocaleLoader.getString("Party.Help.2"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String createMembersList() {
|
private String createMembersList() {
|
||||||
StringBuilder memberList = new StringBuilder();
|
StringBuilder memberList = new StringBuilder();
|
||||||
|
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.gmail.nossr50.party.commands;
|
||||||
|
|
||||||
|
public enum PartySubcommand {
|
||||||
|
JOIN,
|
||||||
|
ACCEPT,
|
||||||
|
CREATE,
|
||||||
|
HELP,
|
||||||
|
INFO,
|
||||||
|
QUIT,
|
||||||
|
EXPSHARE,
|
||||||
|
ITEMSHARE,
|
||||||
|
INVITE,
|
||||||
|
KICK,
|
||||||
|
DISBAND,
|
||||||
|
OWNER,
|
||||||
|
LOCK,
|
||||||
|
UNLOCK,
|
||||||
|
PASSWORD,
|
||||||
|
RENAME;
|
||||||
|
|
||||||
|
public static PartySubcommand getSubcommand(String commandName) {
|
||||||
|
for (PartySubcommand command : values()) {
|
||||||
|
if (command.name().equalsIgnoreCase(commandName)) {
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commandName.equalsIgnoreCase("?")) {
|
||||||
|
return HELP;
|
||||||
|
}
|
||||||
|
else if (commandName.equalsIgnoreCase("q") || commandName.equalsIgnoreCase("leave")) {
|
||||||
|
return QUIT;
|
||||||
|
}
|
||||||
|
else if (commandName.equalsIgnoreCase("xpshare") || commandName.equalsIgnoreCase("shareexp") || commandName.equalsIgnoreCase("sharexp")) {
|
||||||
|
return EXPSHARE;
|
||||||
|
}
|
||||||
|
else if (commandName.equalsIgnoreCase("shareitem") || commandName.equalsIgnoreCase("shareitems")) {
|
||||||
|
return ITEMSHARE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user