mcMMO/src/main/java/com/gmail/nossr50/party/commands/PartyCommand.java

366 lines
14 KiB
Java
Raw Normal View History

package com.gmail.nossr50.party.commands;
2012-01-09 20:00:13 +01:00
import org.bukkit.ChatColor;
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;
import com.gmail.nossr50.mcMMO;
2012-04-22 08:55:58 +02:00
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
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 {
private McMMOPlayer mcMMOPlayer;
private Player player;
2013-02-08 03:46:12 +01:00
private CommandExecutor partyJoinCommand = new PartyJoinCommand();
private CommandExecutor partyAcceptCommand = new PartyAcceptCommand();
private CommandExecutor partyCreateCommand = new PartyCreateCommand();
2013-02-08 16:26:59 +01:00
private CommandExecutor partyQuitCommand = new PartyQuitCommand();
private CommandExecutor partyExpShareCommand = new PartyExpShareCommand();
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-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;
}
player = (Player) sender;
mcMMOPlayer = Users.getPlayer(player);
if (args.length < 1 || args[0].equalsIgnoreCase("info")) {
return party();
2013-01-26 23:01:55 +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")) {
return partyCreateCommand.onCommand(sender, command, label, args);
2013-01-26 23:01:55 +01:00
}
else if (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help")) {
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"));
return printUsage();
2013-01-26 23:01:55 +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")) {
return partyExpShareCommand.onCommand(sender, command, label, args);
2013-02-08 17:12:32 +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
}
else 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")) {
return changeOwner(args);
}
else if (args[0].equalsIgnoreCase("lock")) {
return lock();
}
else if (args[0].equalsIgnoreCase("unlock")) {
return unlock();
}
else if (args[0].equalsIgnoreCase("password")) {
return changePassword(args);
}
else if (args[0].equalsIgnoreCase("rename")) {
return rename(args);
}
else {
return printUsage();
}
}
private boolean printUsage() {
player.sendMessage(LocaleLoader.getString("Party.Help.0"));
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
player.sendMessage(LocaleLoader.getString("Party.Help.2"));
return true;
}
private boolean party() {
if (mcMMOPlayer.inParty()) {
Party party = mcMMOPlayer.getParty();
String leader = party.getLeader();
2013-01-31 00:58:31 +01:00
StringBuilder tempList = new StringBuilder();
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 = "";
for (OfflinePlayer otherMember : party.getMembers()) {
if (leader.equals(otherMember.getName())) {
tempList.append(ChatColor.GOLD);
}
else if (otherMember.isOnline()) {
tempList.append(ChatColor.WHITE);
}
else {
tempList.append(ChatColor.GRAY);
}
tempList.append(otherMember.getName()).append(" ");
}
String status = LocaleLoader.getString("Party.Status.Locked");
2013-01-30 15:17:50 +01:00
if (!party.isLocked()) {
status = LocaleLoader.getString("Party.Status.Unlocked");
2013-01-30 15:17:50 +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
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
}
if (itemShareEnabled) {
ItemShare = LocaleLoader.getString("Commands.Party.ItemShare", party.getItemShareMode().toString());
2013-01-30 15:17:50 +01:00
}
if (xpShareEnabled && itemShareEnabled) {
2013-01-30 15:17:50 +01:00
Split = ChatColor.DARK_GRAY + " || ";
}
if (xpShareEnabled || itemShareEnabled) {
2013-01-30 15:17:50 +01:00
player.sendMessage(LocaleLoader.getString("Commands.Party.ShareMode") + ExpShare + Split + ItemShare);
}
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 {
return printUsage();
}
return true;
}
private boolean printHelp() {
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;
}
/**
* Change the owner of the current party
*/
private boolean changeOwner(String[] args) {
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.owner")) {
return true;
2013-01-26 23:01:55 +01:00
}
String playerName = player.getName();
Party party = mcMMOPlayer.getParty();
if (args.length < 2) {
player.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "owner", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]"));
return true;
}
2013-01-26 23:01:55 +01:00
if (party.getLeader().equals(playerName)) {
if (!party.getMembers().contains(mcMMO.p.getServer().getOfflinePlayer(args[1]))) {
2013-02-02 08:55:49 +01:00
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", args[1]));
return true;
}
2013-01-26 23:01:55 +01:00
PartyManager.setPartyLeader(args[1], party);
}
2013-01-26 23:01:55 +01:00
return true;
}
/**
* Lock the current party
*/
private boolean lock() {
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.lock")) {
return true;
2013-01-26 23:01:55 +01:00
}
String playerName = player.getName();
Party party = mcMMOPlayer.getParty();
2013-02-05 13:23:12 +01:00
if (party == null) {
player.sendMessage("Commands.Party.None");
2013-02-05 13:23:12 +01:00
return true;
2013-01-26 23:01:55 +01:00
}
2013-02-05 13:23:12 +01:00
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;
2013-01-26 23:01:55 +01:00
}
2012-04-22 08:55:58 +02:00
String playerName = player.getName();
Party party = mcMMOPlayer.getParty();
2013-02-05 13:23:12 +01:00
if (party == null) {
player.sendMessage("Commands.Party.None");
2013-02-05 13:23:12 +01:00
return true;
}
if (!party.getLeader().equals(playerName)) {
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
return true;
2013-01-26 23:01:55 +01:00
}
2013-02-05 13:23:12 +01:00
if (!party.isLocked()) {
player.sendMessage(LocaleLoader.getString("Party.IsntLocked"));
}
else {
party.setLocked(false);
player.sendMessage(LocaleLoader.getString("Party.Unlocked"));
}
return true;
}
2012-01-09 20:00:13 +01:00
private boolean changePassword(String[] args) {
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.password")) {
2012-04-22 08:55:58 +02:00
return true;
2013-01-26 23:01:55 +01:00
}
2012-04-22 08:55:58 +02:00
String playerName = player.getName();
Party party = mcMMOPlayer.getParty();
if (!party.getLeader().equals(playerName)) {
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
2012-04-22 08:55:58 +02:00
return true;
}
if (args.length < 2) {
party.setLocked(true);
party.setPassword(null);
player.sendMessage(LocaleLoader.getString("Party.Password.Removed"));
return true;
2013-01-26 23:01:55 +01:00
}
party.setLocked(true);
party.setPassword(args[1]);
2013-02-02 08:55:49 +01:00
player.sendMessage(LocaleLoader.getString("Party.Password.Set", args[1]));
return true;
2012-04-22 08:55:58 +02:00
}
2013-01-26 19:31:17 +01:00
/**
* Rename the current party
*/
private boolean rename(String[] args) {
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.rename")) {
2013-01-26 19:31:17 +01:00
return true;
2013-01-26 23:01:55 +01:00
}
2013-01-26 19:31:17 +01:00
String playerName = player.getName();
Party party = mcMMOPlayer.getParty();
String leader = party.getLeader();
2013-01-26 19:31:17 +01:00
if (party.getLeader().equals(playerName)) {
2013-01-26 23:01:55 +01:00
if (args.length < 2) {
2013-02-02 08:55:49 +01:00
player.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "rename", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">"));
2013-01-26 19:31:17 +01:00
return true;
2013-01-26 23:01:55 +01:00
}
String newPartyName = args[1];
2013-01-26 23:01:55 +01:00
// This is to prevent party leaders from spamming other players with the rename message
if (!party.getName().equals(newPartyName)) {
Party newParty = PartyManager.getParty(newPartyName);
2013-01-26 19:31:17 +01:00
// Check to see if the party exists, and if it does cancel renaming the party
if (newParty != null) {
2013-02-02 08:55:49 +01:00
player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", newPartyName));
return true;
}
2013-01-26 19:31:17 +01:00
for (Player onlineMembers : party.getOnlineMembers()) {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(onlineMembers, party.getName(), newPartyName, EventReason.CHANGED_PARTIES);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
2013-01-26 19:31:17 +01:00
}
2013-01-26 23:01:55 +01:00
if (!onlineMembers.getName().equals(leader)) {
2013-02-02 08:55:49 +01:00
onlineMembers.sendMessage(LocaleLoader.getString("Party.InformedOnNameChange", leader, newPartyName));
}
2013-01-26 19:31:17 +01:00
}
2013-01-26 23:01:55 +01:00
party.setName(newPartyName);
2013-01-26 19:31:17 +01:00
}
2013-02-02 08:55:49 +01:00
player.sendMessage(LocaleLoader.getString("Commands.Party.Rename", newPartyName));
2013-01-26 19:31:17 +01:00
}
2013-01-26 23:01:55 +01:00
else {
2013-01-26 19:31:17 +01:00
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
2013-01-26 23:01:55 +01:00
}
2013-01-26 19:31:17 +01:00
return true;
}
2012-01-09 20:00:13 +01:00
}