2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.commands.party;
|
|
|
|
|
2013-04-06 12:18:10 +02:00
|
|
|
import com.gmail.nossr50.commands.chat.PartyChatCommand;
|
2013-10-28 14:01:44 +01:00
|
|
|
import com.gmail.nossr50.commands.party.alliance.PartyAllianceCommand;
|
2013-03-28 17:57:49 +01:00
|
|
|
import com.gmail.nossr50.commands.party.teleport.PtpCommand;
|
2014-03-03 18:27:45 +01:00
|
|
|
import com.gmail.nossr50.datatypes.party.Party;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
import com.gmail.nossr50.util.commands.CommandUtils;
|
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
2013-03-28 17:57:49 +01:00
|
|
|
import com.google.common.collect.ImmutableList;
|
2019-01-15 07:11:58 +01:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.command.TabExecutor;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.util.StringUtil;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-28 17:57:49 +01:00
|
|
|
public class PartyCommand implements TabExecutor {
|
|
|
|
private static final List<String> PARTY_SUBCOMMANDS;
|
2013-11-11 17:42:57 +01:00
|
|
|
private static final List<String> XPSHARE_COMPLETIONS = ImmutableList.of("none", "equal");
|
2013-04-18 14:11:47 +02:00
|
|
|
private static final List<String> ITEMSHARE_COMPLETIONS = ImmutableList.of("none", "equal", "random", "loot", "mining", "herbalism", "woodcutting", "misc");
|
2013-03-28 17:57:49 +01:00
|
|
|
|
|
|
|
static {
|
|
|
|
ArrayList<String> subcommands = new ArrayList<String>();
|
|
|
|
|
|
|
|
for (PartySubcommandType subcommand : PartySubcommandType.values()) {
|
|
|
|
subcommands.add(subcommand.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
Collections.sort(subcommands);
|
|
|
|
PARTY_SUBCOMMANDS = ImmutableList.copyOf(subcommands);
|
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
private CommandExecutor partyJoinCommand = new PartyJoinCommand();
|
|
|
|
private CommandExecutor partyAcceptCommand = new PartyAcceptCommand();
|
|
|
|
private CommandExecutor partyCreateCommand = new PartyCreateCommand();
|
|
|
|
private CommandExecutor partyQuitCommand = new PartyQuitCommand();
|
2013-11-11 17:42:57 +01:00
|
|
|
private CommandExecutor partyXpShareCommand = new PartyXpShareCommand();
|
2013-03-01 06:52:01 +01:00
|
|
|
private CommandExecutor partyItemShareCommand = new PartyItemShareCommand();
|
|
|
|
private CommandExecutor partyInviteCommand = new PartyInviteCommand();
|
|
|
|
private CommandExecutor partyKickCommand = new PartyKickCommand();
|
|
|
|
private CommandExecutor partyDisbandCommand = new PartyDisbandCommand();
|
|
|
|
private CommandExecutor partyChangeOwnerCommand = new PartyChangeOwnerCommand();
|
|
|
|
private CommandExecutor partyLockCommand = new PartyLockCommand();
|
|
|
|
private CommandExecutor partyChangePasswordCommand = new PartyChangePasswordCommand();
|
|
|
|
private CommandExecutor partyRenameCommand = new PartyRenameCommand();
|
|
|
|
private CommandExecutor partyInfoCommand = new PartyInfoCommand();
|
|
|
|
private CommandExecutor partyHelpCommand = new PartyHelpCommand();
|
2014-04-21 14:54:09 +02:00
|
|
|
private CommandExecutor partyTeleportCommand = new PtpCommand();
|
2013-04-06 12:18:10 +02:00
|
|
|
private CommandExecutor partyChatCommand = new PartyChatCommand();
|
2013-10-28 14:01:44 +01:00
|
|
|
private CommandExecutor partyAllianceCommand = new PartyAllianceCommand();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
if (CommandUtils.noConsoleUsage(sender)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Permissions.party(sender)) {
|
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
Player player = (Player) sender;
|
2014-08-20 06:23:19 +02:00
|
|
|
|
|
|
|
if (!UserManager.hasPlayerDataKey(player)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-13 00:17:05 +02:00
|
|
|
if(UserManager.getPlayer(player) == null)
|
|
|
|
{
|
|
|
|
player.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
if (args.length < 1) {
|
|
|
|
if (!mcMMOPlayer.inParty()) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
2013-10-29 20:38:20 +01:00
|
|
|
return printUsage(player);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return partyInfoCommand.onCommand(sender, command, label, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
PartySubcommandType subcommand = PartySubcommandType.getSubcommand(args[0]);
|
|
|
|
|
|
|
|
if (subcommand == null) {
|
2013-10-29 20:38:20 +01:00
|
|
|
return printUsage(player);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Can't use this for lock/unlock since they're handled by the same command
|
|
|
|
if (subcommand != PartySubcommandType.LOCK && subcommand != PartySubcommandType.UNLOCK && !Permissions.partySubcommand(sender, subcommand)) {
|
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 partyHelpCommand.onCommand(sender, command, label, args);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Party member commands
|
|
|
|
if (!mcMMOPlayer.inParty()) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
2013-10-29 20:38:20 +01:00
|
|
|
return printUsage(player);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (subcommand) {
|
|
|
|
case INFO:
|
|
|
|
return partyInfoCommand.onCommand(sender, command, label, args);
|
|
|
|
case QUIT:
|
|
|
|
return partyQuitCommand.onCommand(sender, command, label, args);
|
|
|
|
case INVITE:
|
|
|
|
return partyInviteCommand.onCommand(sender, command, label, args);
|
|
|
|
case TELEPORT:
|
|
|
|
return partyTeleportCommand.onCommand(sender, command, label, extractArgs(args));
|
|
|
|
case CHAT:
|
|
|
|
return partyChatCommand.onCommand(sender, command, label, extractArgs(args));
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Party leader commands
|
2014-07-12 19:44:47 +02:00
|
|
|
if (!mcMMOPlayer.getParty().getLeader().getUniqueId().equals(player.getUniqueId())) {
|
2013-03-01 06:52:01 +01:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (subcommand) {
|
2013-11-11 17:42:57 +01:00
|
|
|
case XPSHARE:
|
|
|
|
return partyXpShareCommand.onCommand(sender, command, label, args);
|
2013-03-01 06:52:01 +01:00
|
|
|
case ITEMSHARE:
|
|
|
|
return partyItemShareCommand.onCommand(sender, command, label, args);
|
|
|
|
case KICK:
|
|
|
|
return partyKickCommand.onCommand(sender, command, label, args);
|
|
|
|
case DISBAND:
|
|
|
|
return partyDisbandCommand.onCommand(sender, command, label, args);
|
|
|
|
case OWNER:
|
|
|
|
return partyChangeOwnerCommand.onCommand(sender, command, label, args);
|
|
|
|
case LOCK:
|
|
|
|
case UNLOCK:
|
|
|
|
return partyLockCommand.onCommand(sender, command, label, args);
|
|
|
|
case PASSWORD:
|
|
|
|
return partyChangePasswordCommand.onCommand(sender, command, label, args);
|
|
|
|
case RENAME:
|
|
|
|
return partyRenameCommand.onCommand(sender, command, label, args);
|
2013-10-28 14:01:44 +01:00
|
|
|
case ALLIANCE:
|
|
|
|
return partyAllianceCommand.onCommand(sender, command, label, args);
|
2013-03-01 06:52:01 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-28 17:57:49 +01:00
|
|
|
@Override
|
|
|
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
|
|
|
switch (args.length) {
|
|
|
|
case 1:
|
|
|
|
return StringUtil.copyPartialMatches(args[0], PARTY_SUBCOMMANDS, new ArrayList<String>(PARTY_SUBCOMMANDS.size()));
|
|
|
|
case 2:
|
|
|
|
PartySubcommandType subcommand = PartySubcommandType.getSubcommand(args[0]);
|
|
|
|
|
|
|
|
if (subcommand == null) {
|
|
|
|
return ImmutableList.of();
|
|
|
|
}
|
|
|
|
|
2013-04-28 07:11:44 +02:00
|
|
|
switch (subcommand) {
|
2013-03-28 17:57:49 +01:00
|
|
|
case JOIN:
|
|
|
|
case INVITE:
|
|
|
|
case KICK:
|
|
|
|
case OWNER:
|
2014-02-28 21:55:32 +01:00
|
|
|
List<String> playerNames = CommandUtils.getOnlinePlayerNames(sender);
|
2013-03-28 17:57:49 +01:00
|
|
|
return StringUtil.copyPartialMatches(args[1], playerNames, new ArrayList<String>(playerNames.size()));
|
2013-11-11 17:42:57 +01:00
|
|
|
case XPSHARE:
|
|
|
|
return StringUtil.copyPartialMatches(args[1], XPSHARE_COMPLETIONS, new ArrayList<String>(XPSHARE_COMPLETIONS.size()));
|
2013-03-28 17:57:49 +01:00
|
|
|
case ITEMSHARE:
|
|
|
|
return StringUtil.copyPartialMatches(args[1], ITEMSHARE_COMPLETIONS, new ArrayList<String>(ITEMSHARE_COMPLETIONS.size()));
|
|
|
|
case LOCK:
|
|
|
|
case CHAT:
|
|
|
|
return StringUtil.copyPartialMatches(args[1], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList<String>(CommandUtils.TRUE_FALSE_OPTIONS.size()));
|
|
|
|
case PASSWORD:
|
|
|
|
return StringUtil.copyPartialMatches(args[1], CommandUtils.RESET_OPTIONS, new ArrayList<String>(CommandUtils.RESET_OPTIONS.size()));
|
|
|
|
case TELEPORT:
|
|
|
|
List<String> matches = StringUtil.copyPartialMatches(args[1], PtpCommand.TELEPORT_SUBCOMMANDS, new ArrayList<String>(PtpCommand.TELEPORT_SUBCOMMANDS.size()));
|
|
|
|
|
|
|
|
if (matches.size() == 0) {
|
2014-02-28 21:55:32 +01:00
|
|
|
Player player = (Player) sender;
|
2019-04-13 00:17:05 +02:00
|
|
|
|
|
|
|
//Not Loaded
|
|
|
|
if(UserManager.getPlayer(player) == null)
|
|
|
|
{
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
|
|
|
|
return ImmutableList.of();
|
|
|
|
}
|
|
|
|
|
2014-02-28 21:55:32 +01:00
|
|
|
Party party = UserManager.getPlayer(player).getParty();
|
|
|
|
|
|
|
|
playerNames = party.getOnlinePlayerNames(player);
|
2013-03-28 17:57:49 +01:00
|
|
|
return StringUtil.copyPartialMatches(args[1], playerNames, new ArrayList<String>(playerNames.size()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return matches;
|
|
|
|
default:
|
|
|
|
return ImmutableList.of();
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
if (PartySubcommandType.getSubcommand(args[0]) == PartySubcommandType.ITEMSHARE && isItemShareCategory(args[1])) {
|
|
|
|
return StringUtil.copyPartialMatches(args[2], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList<String>(CommandUtils.TRUE_FALSE_OPTIONS.size()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ImmutableList.of();
|
|
|
|
default:
|
|
|
|
return ImmutableList.of();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
private boolean printUsage(Player player) {
|
2013-03-01 06:52:01 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.0", "/party join"));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.1", "/party create"));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.2", "/party ?"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private String[] extractArgs(String[] args) {
|
2014-02-09 17:15:42 +01:00
|
|
|
return Arrays.copyOfRange(args, 1, args.length);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-03-28 17:57:49 +01:00
|
|
|
|
|
|
|
private boolean isItemShareCategory(String category) {
|
2013-04-18 14:11:47 +02:00
|
|
|
return category.equalsIgnoreCase("loot") || category.equalsIgnoreCase("mining") || category.equalsIgnoreCase("herbalism") || category.equalsIgnoreCase("woodcutting") || category.equalsIgnoreCase("misc");
|
2013-03-28 17:57:49 +01:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-03-28 17:57:49 +01:00
|
|
|
|