2012-01-09 20:00:13 +01:00
|
|
|
package com.gmail.nossr50.commands.party;
|
|
|
|
|
|
|
|
import org.bukkit.ChatColor;
|
2012-06-11 07:45:14 +02:00
|
|
|
import org.bukkit.Server;
|
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-06-07 00:02:22 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-04-22 08:55:58 +02:00
|
|
|
import com.gmail.nossr50.commands.CommandHelper;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
2012-03-27 23:09:23 +02:00
|
|
|
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;
|
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 {
|
2012-06-07 00:02:22 +02:00
|
|
|
private final mcMMO plugin;
|
2012-04-21 00:09:50 +02:00
|
|
|
|
2012-06-07 00:02:22 +02:00
|
|
|
public PartyCommand (mcMMO plugin) {
|
2012-04-21 00:09:50 +02:00
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player player = (Player) sender;
|
|
|
|
String playerName = player.getName();
|
2012-06-08 23:48:41 +02:00
|
|
|
PlayerProfile playerProfile = Users.getProfile(player);
|
2012-04-22 08:55:58 +02:00
|
|
|
|
2012-06-08 23:48:41 +02:00
|
|
|
PartyManager partyManagerInstance = PartyManager.getInstance();
|
|
|
|
Party party = playerProfile.getParty();
|
2012-04-22 08:55:58 +02:00
|
|
|
|
|
|
|
switch (args.length) {
|
|
|
|
case 0:
|
2012-06-08 23:48:41 +02:00
|
|
|
if (party == null) {
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.0"));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.2"));
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-06-11 07:45:14 +02:00
|
|
|
Server server = plugin.getServer();
|
|
|
|
String leader = party.getLeader();
|
|
|
|
StringBuffer tempList = new StringBuffer();
|
2012-04-22 08:55:58 +02:00
|
|
|
|
2012-06-08 23:48:41 +02:00
|
|
|
for (String otherPlayerName : party.getMembers()) {
|
2012-06-11 07:45:14 +02:00
|
|
|
if (leader.equals(otherPlayerName)) {
|
|
|
|
tempList.append(ChatColor.GOLD);
|
|
|
|
}
|
|
|
|
else if (server.getPlayer(otherPlayerName) != null) {
|
|
|
|
tempList.append(ChatColor.WHITE);
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
2012-06-11 07:45:14 +02:00
|
|
|
else {
|
|
|
|
tempList.append(ChatColor.GRAY);
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
2012-06-11 07:45:14 +02:00
|
|
|
|
|
|
|
tempList.append(otherPlayerName + " ");
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
|
2012-06-08 23:48:41 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.InParty", new Object[] {party.getName()}));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Members", new Object[] {tempList}));
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-03-27 23:09:23 +02:00
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
case 1:
|
|
|
|
if (args[0].equalsIgnoreCase("q")) {
|
2012-06-08 23:48:41 +02:00
|
|
|
if (party != null) {
|
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), null, EventReason.LEFT_PARTY);
|
2012-04-22 08:55:58 +02:00
|
|
|
plugin.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:45:14 +02:00
|
|
|
partyManagerInstance.removeFromParty(playerName, party);
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Leave"));
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.sendMessage("Commands.Party.None");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (args[0].equals("?")) {
|
2012-04-27 11:47:11 +02: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"));
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("lock")) {
|
2012-06-08 23:48:41 +02:00
|
|
|
if (party != null) {
|
|
|
|
if (party.getLeader().equals(playerName)) {
|
|
|
|
if (party.isLocked()) {
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.IsLocked"));
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-06-08 23:48:41 +02:00
|
|
|
party.setLocked(true);
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Locked"));
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.sendMessage("Commands.Party.None");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("unlock")) {
|
2012-06-08 23:48:41 +02:00
|
|
|
if (party != null) {
|
|
|
|
if (party.getLeader().equals(playerName)) {
|
|
|
|
if (!party.isLocked()) {
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.IsntLocked"));
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-06-08 23:48:41 +02:00
|
|
|
party.setLocked(false);
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Unlocked"));
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.sendMessage("Commands.Party.None");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-06-08 23:48:41 +02:00
|
|
|
if (party != null) {
|
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), args[0], EventReason.CHANGED_PARTIES);
|
2012-04-22 08:55:58 +02:00
|
|
|
plugin.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:45:14 +02:00
|
|
|
partyManagerInstance.removeFromParty(playerName, party);
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-03-27 23:09:23 +02:00
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, args[0], EventReason.JOINED_PARTY);
|
2012-04-21 00:09:50 +02:00
|
|
|
plugin.getServer().getPluginManager().callEvent(event);
|
2012-03-27 23:09:23 +02:00
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
|
2012-06-11 07:45:14 +02:00
|
|
|
partyManagerInstance.joinParty(player, playerProfile, args[0], null);
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case 2:
|
2012-06-08 23:48:41 +02:00
|
|
|
if (playerProfile.inParty()) {
|
2012-04-22 08:55:58 +02:00
|
|
|
if (args[0].equalsIgnoreCase("password")) {
|
2012-06-08 23:48:41 +02:00
|
|
|
if (party.getLeader().equals(playerName)) {
|
|
|
|
party.setLocked(true);
|
|
|
|
party.setPassword(args[1]);
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.PasswordSet", new Object[] {args[1]}));
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("kick")) {
|
2012-06-08 23:48:41 +02:00
|
|
|
if (party.getLeader().equals(playerName)) {
|
2012-06-11 08:26:48 +02:00
|
|
|
if (!party.getMembers().contains(args[1])) {
|
2012-06-11 07:45:14 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] {args[1]}));
|
2012-04-22 08:55:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
2012-06-08 23:48:41 +02:00
|
|
|
String partyName = party.getName();
|
2012-04-22 08:55:58 +02:00
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, partyName, null, EventReason.KICKED_FROM_PARTY);
|
2012-06-11 07:45:14 +02:00
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
plugin.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:45:14 +02:00
|
|
|
partyManagerInstance.removeFromParty(args[1], party);
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("owner")) {
|
2012-06-08 23:48:41 +02:00
|
|
|
if (party.getLeader().equals(playerName)) {
|
2012-06-11 08:26:48 +02:00
|
|
|
if (!party.getMembers().contains(args[1])) {
|
2012-06-11 07:45:14 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] {args[1]}));
|
2012-04-22 08:55:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
2012-06-11 07:45:14 +02:00
|
|
|
partyManagerInstance.setPartyLeader(args[1], party);
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-06-08 23:48:41 +02:00
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), args[0], EventReason.CHANGED_PARTIES);
|
2012-04-22 08:55:58 +02:00
|
|
|
plugin.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:45:14 +02:00
|
|
|
partyManagerInstance.removeFromParty(playerName, party);
|
|
|
|
partyManagerInstance.joinParty(player, playerProfile, args[0], args[1]);
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, args[0], EventReason.JOINED_PARTY);
|
2012-04-21 00:09:50 +02:00
|
|
|
plugin.getServer().getPluginManager().callEvent(event);
|
2012-03-27 23:09:23 +02:00
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-22 08:55:58 +02:00
|
|
|
|
2012-06-11 07:45:14 +02:00
|
|
|
partyManagerInstance.joinParty(player, playerProfile, args[0], args[1]);
|
2012-03-27 23:09:23 +02:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.0"));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.2"));
|
2012-04-22 08:55:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|