2013-01-22 18:43:25 +01:00
|
|
|
package com.gmail.nossr50.party.commands;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
import org.bukkit.ChatColor;
|
2013-02-09 14:34:53 +01:00
|
|
|
import org.bukkit.OfflinePlayer;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
import com.gmail.nossr50.commands.CommandHelper;
|
2013-02-01 06:38:25 +01:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-02-03 16:27:59 +01:00
|
|
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.party.Party;
|
2012-06-08 23:48:41 +02:00
|
|
|
import com.gmail.nossr50.party.PartyManager;
|
2013-02-08 17:12:32 +01:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.util.Users;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
public class PartyCommand implements CommandExecutor {
|
2013-02-03 16:27:59 +01:00
|
|
|
private McMMOPlayer mcMMOPlayer;
|
2013-01-28 15:16:19 +01:00
|
|
|
private Player player;
|
|
|
|
|
2013-02-08 03:46:12 +01:00
|
|
|
private CommandExecutor partyJoinCommand = new PartyJoinCommand();
|
2013-02-08 04:05:08 +01:00
|
|
|
private CommandExecutor partyAcceptCommand = new PartyAcceptCommand();
|
2013-02-08 04:54:15 +01:00
|
|
|
private CommandExecutor partyCreateCommand = new PartyCreateCommand();
|
2013-02-08 16:26:59 +01:00
|
|
|
private CommandExecutor partyQuitCommand = new PartyQuitCommand();
|
2013-02-08 17:51:06 +01:00
|
|
|
private CommandExecutor partyExpShareCommand = new PartyExpShareCommand();
|
2013-02-09 12:24:02 +01:00
|
|
|
private CommandExecutor partyItemShareCommand = new PartyItemShareCommand();
|
2013-02-08 22:56:54 +01:00
|
|
|
private CommandExecutor partyInviteCommand = new PartyInviteCommand();
|
2013-02-11 06:25:03 +01:00
|
|
|
private CommandExecutor partyKickCommand = new PartyKickCommand();
|
2013-02-11 21:19:41 +01:00
|
|
|
private CommandExecutor partyDisbandCommand = new PartyDisbandCommand();
|
2013-02-11 21:33:25 +01:00
|
|
|
private CommandExecutor partyChangeOwnerCommand = new PartyChangeOwnerCommand();
|
2013-02-11 23:31:09 +01:00
|
|
|
private CommandExecutor partyLockCommand = new PartyLockCommand();
|
2013-02-12 14:57:35 +01:00
|
|
|
private CommandExecutor partyChangePasswordCommand = new PartyChangePasswordCommand();
|
2013-02-12 15:22:57 +01:00
|
|
|
private CommandExecutor partyRenameCommand = new PartyRenameCommand();
|
2013-02-08 03:46:12 +01:00
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
if (CommandHelper.noConsoleUsage(sender)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-08 17:12:32 +01:00
|
|
|
if (!Permissions.hasPermission(sender, "mcmmo.commands.party")) {
|
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
2012-04-22 08:55:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 16:27:59 +01:00
|
|
|
player = (Player) sender;
|
|
|
|
mcMMOPlayer = Users.getPlayer(player);
|
2013-01-26 00:40:23 +01:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
if (args.length < 1 || args[0].equalsIgnoreCase("info")) {
|
|
|
|
return party();
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-26 00:40:23 +01:00
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
if (args[0].equalsIgnoreCase("join")) {
|
2013-02-08 03:46:12 +01:00
|
|
|
return partyJoinCommand.onCommand(sender, command, label, args);
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("accept")) {
|
2013-02-08 04:09:43 +01:00
|
|
|
return partyAcceptCommand.onCommand(sender, command, label, args);
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("create")) {
|
2013-02-08 04:54:15 +01:00
|
|
|
return partyCreateCommand.onCommand(sender, command, label, args);
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help")) {
|
2013-01-28 15:16:19 +01:00
|
|
|
return printHelp();
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
|
2013-02-08 17:12:32 +01:00
|
|
|
if (!mcMMOPlayer.inParty()) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
2013-02-12 07:45:56 +01:00
|
|
|
return true;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-28 15:16:19 +01:00
|
|
|
|
2013-02-08 17:12:32 +01:00
|
|
|
if (args[0].equalsIgnoreCase("quit") || args[0].equalsIgnoreCase("q") || args[0].equalsIgnoreCase("leave")) {
|
|
|
|
return partyQuitCommand.onCommand(sender, command, label, args);
|
|
|
|
}
|
2013-02-08 17:52:08 +01:00
|
|
|
else if (args[0].equalsIgnoreCase("expshare") || args[0].equalsIgnoreCase("xpshare") || args[0].equalsIgnoreCase("sharexp") || args[0].equalsIgnoreCase("shareexp")) {
|
2013-02-08 17:51:06 +01:00
|
|
|
return partyExpShareCommand.onCommand(sender, command, label, args);
|
2013-02-08 17:12:32 +01:00
|
|
|
}
|
2013-02-09 12:24:02 +01:00
|
|
|
else if (args[0].equalsIgnoreCase("itemshare") || args[0].equalsIgnoreCase("shareitem") || args[0].equalsIgnoreCase("shareitems")) {
|
|
|
|
return partyItemShareCommand.onCommand(sender, command, label, args);
|
2013-02-08 17:12:32 +01:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("invite")) {
|
2013-02-08 22:56:54 +01:00
|
|
|
return partyInviteCommand.onCommand(sender, command, label, args);
|
2013-02-08 17:12:32 +01:00
|
|
|
}
|
2013-02-12 07:41:51 +01:00
|
|
|
|
|
|
|
if (!mcMMOPlayer.getParty().getLeader().equals(player.getName())) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args[0].equalsIgnoreCase("kick")) {
|
2013-02-11 06:25:03 +01:00
|
|
|
return partyKickCommand.onCommand(sender, command, label, args);
|
2013-02-08 17:12:32 +01:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("disband")) {
|
2013-02-11 21:19:41 +01:00
|
|
|
return partyDisbandCommand.onCommand(sender, command, label, args);
|
2013-02-08 17:12:32 +01:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("owner")) {
|
2013-02-11 21:33:25 +01:00
|
|
|
return partyChangeOwnerCommand.onCommand(sender, command, label, args);
|
2013-02-08 17:12:32 +01:00
|
|
|
}
|
2013-02-11 23:31:09 +01:00
|
|
|
else if (args[0].equalsIgnoreCase("lock") || args[0].equalsIgnoreCase("unlock")) {
|
|
|
|
return partyLockCommand.onCommand(sender, command, label, args);
|
2013-02-08 17:12:32 +01:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("password")) {
|
2013-02-12 14:57:35 +01:00
|
|
|
return partyChangePasswordCommand.onCommand(sender, command, label, args);
|
2013-02-08 17:12:32 +01:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("rename")) {
|
2013-02-12 15:22:57 +01:00
|
|
|
return partyRenameCommand.onCommand(sender, command, label, args);
|
2013-02-08 17:12:32 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return printUsage();
|
|
|
|
}
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
private boolean printUsage() {
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.0"));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.2"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
private boolean party() {
|
2013-02-03 16:27:59 +01:00
|
|
|
if (mcMMOPlayer.inParty()) {
|
|
|
|
Party party = mcMMOPlayer.getParty();
|
2013-01-26 00:40:23 +01:00
|
|
|
String leader = party.getLeader();
|
2013-01-31 00:58:31 +01:00
|
|
|
StringBuilder tempList = new StringBuilder();
|
2013-01-26 00:40:23 +01:00
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
int membersNear = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange()).size();
|
2013-01-30 15:17:50 +01:00
|
|
|
int membersOnline = party.getOnlineMembers().size() - 1;
|
|
|
|
|
|
|
|
String ItemShare = "";
|
|
|
|
String ExpShare = "";
|
|
|
|
String Split = "";
|
|
|
|
|
2013-02-09 14:34:53 +01:00
|
|
|
for (OfflinePlayer otherMember : party.getMembers()) {
|
|
|
|
if (leader.equals(otherMember.getName())) {
|
2013-01-26 00:40:23 +01:00
|
|
|
tempList.append(ChatColor.GOLD);
|
|
|
|
}
|
2013-02-09 14:34:53 +01:00
|
|
|
else if (otherMember.isOnline()) {
|
2013-01-26 00:40:23 +01:00
|
|
|
tempList.append(ChatColor.WHITE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tempList.append(ChatColor.GRAY);
|
|
|
|
}
|
2013-02-09 14:34:53 +01:00
|
|
|
|
2013-02-09 15:54:03 +01:00
|
|
|
tempList.append(otherMember.getName()).append(" ");
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
String status = LocaleLoader.getString("Party.Status.Locked");
|
2013-01-30 15:17:50 +01:00
|
|
|
if (!party.isLocked()) {
|
2013-01-26 00:40:23 +01:00
|
|
|
status = LocaleLoader.getString("Party.Status.Unlocked");
|
2013-01-30 15:17:50 +01:00
|
|
|
}
|
2013-01-26 00:40:23 +01:00
|
|
|
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Header"));
|
2013-02-02 08:55:49 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Status", party.getName(), status));
|
2013-01-30 15:17:50 +01:00
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
boolean xpShareEnabled = Config.getInstance().getExpShareEnabled();
|
|
|
|
boolean itemShareEnabled = Config.getInstance().getItemShareEnabled();
|
|
|
|
|
|
|
|
if (xpShareEnabled) {
|
2013-02-02 08:55:49 +01:00
|
|
|
ExpShare = LocaleLoader.getString("Commands.Party.ExpShare", party.getXpShareMode().toString());
|
2013-01-30 15:17:50 +01:00
|
|
|
}
|
2013-02-01 06:38:25 +01:00
|
|
|
|
|
|
|
if (itemShareEnabled) {
|
2013-02-09 12:24:02 +01:00
|
|
|
ItemShare = LocaleLoader.getString("Commands.Party.ItemShare", party.getItemShareMode().toString());
|
2013-01-30 15:17:50 +01:00
|
|
|
}
|
2013-02-01 06:38:25 +01:00
|
|
|
|
|
|
|
if (xpShareEnabled && itemShareEnabled) {
|
2013-01-30 15:17:50 +01:00
|
|
|
Split = ChatColor.DARK_GRAY + " || ";
|
|
|
|
}
|
2013-02-01 06:38:25 +01:00
|
|
|
|
|
|
|
if (xpShareEnabled || itemShareEnabled) {
|
2013-01-30 15:17:50 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.ShareMode") + ExpShare + Split + ItemShare);
|
|
|
|
}
|
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Members.Header"));
|
2013-02-02 08:55:49 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.MembersNear", membersNear, membersOnline));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Members", tempList));
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-01-28 15:16:19 +01:00
|
|
|
return printUsage();
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
2013-02-09 14:34:53 +01:00
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
private boolean printHelp() {
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.3"));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.4"));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.5"));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.6"));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.7"));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.8"));
|
|
|
|
return true;
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|