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;
|
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;
|
2013-01-30 15:17:50 +01:00
|
|
|
import com.gmail.nossr50.party.ShareHandler;
|
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-01-28 15:16:19 +01:00
|
|
|
private Player player;
|
|
|
|
private PlayerProfile playerProfile;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
this.player = (Player) sender;
|
|
|
|
this.playerProfile = Users.getProfile(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-01-28 15:16:19 +01:00
|
|
|
return join(args);
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("accept")) {
|
2013-01-28 15:16:19 +01:00
|
|
|
return accept();
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("create")) {
|
2013-01-28 15:16:19 +01:00
|
|
|
return create(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-01-26 00:40:23 +01:00
|
|
|
if (playerProfile.inParty()) {
|
2013-01-28 15:16:19 +01:00
|
|
|
if (args[0].equalsIgnoreCase("quit") || args[0].equalsIgnoreCase("q") || args[0].equalsIgnoreCase("leave")) {
|
|
|
|
return quit();
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-28 15:16:19 +01:00
|
|
|
else if (args[0].equalsIgnoreCase("expshare")) {
|
2013-01-30 15:17:50 +01:00
|
|
|
return shareExp(args);
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-28 15:16:19 +01:00
|
|
|
else if (args[0].equalsIgnoreCase("itemshare")) {
|
|
|
|
return shareItem();
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-28 15:16:19 +01:00
|
|
|
else if (args[0].equalsIgnoreCase("invite")) {
|
|
|
|
return invite(args);
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-28 15:16:19 +01:00
|
|
|
else if (args[0].equalsIgnoreCase("kick")) {
|
|
|
|
return kick(args[1]);
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-28 15:16:19 +01:00
|
|
|
else if (args[0].equalsIgnoreCase("disband")) {
|
|
|
|
return disband();
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-28 15:16:19 +01:00
|
|
|
else if (args[0].equalsIgnoreCase("owner")) {
|
|
|
|
return changeOwner(args);
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-28 15:16:19 +01:00
|
|
|
else if (args[0].equalsIgnoreCase("lock")) {
|
|
|
|
return lock();
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-28 15:16:19 +01:00
|
|
|
else if (args[0].equalsIgnoreCase("unlock")) {
|
|
|
|
return unlock();
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-28 15:16:19 +01:00
|
|
|
else if (args[0].equalsIgnoreCase("password")) {
|
|
|
|
return changePassword(args);
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-28 15:16:19 +01:00
|
|
|
else if (args[0].equalsIgnoreCase("rename")) {
|
|
|
|
return rename(args);
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-01-28 15:16:19 +01:00
|
|
|
return printUsage();
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
}
|
2013-01-28 15:16:19 +01:00
|
|
|
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
|
|
|
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-01-26 00:40:23 +01:00
|
|
|
if (playerProfile.inParty()) {
|
|
|
|
Party party = playerProfile.getParty();
|
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
Server server = mcMMO.p.getServer();
|
2013-01-26 00:40:23 +01:00
|
|
|
String leader = party.getLeader();
|
|
|
|
StringBuffer tempList = new StringBuffer();
|
|
|
|
|
2013-01-30 15:17:50 +01:00
|
|
|
int membersNear = PartyManager.getNearMembers(player, party, ShareHandler.partyShareRange).size();
|
|
|
|
int membersOnline = party.getOnlineMembers().size() - 1;
|
|
|
|
|
|
|
|
String ItemShare = "";
|
|
|
|
String ExpShare = "";
|
|
|
|
String Split = "";
|
|
|
|
String itemShareMode = "NONE";
|
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
for (String otherPlayerName : party.getMembers()) {
|
|
|
|
if (leader.equals(otherPlayerName)) {
|
|
|
|
tempList.append(ChatColor.GOLD);
|
|
|
|
}
|
|
|
|
else if (server.getPlayer(otherPlayerName) != null) {
|
|
|
|
tempList.append(ChatColor.WHITE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tempList.append(ChatColor.GRAY);
|
|
|
|
}
|
|
|
|
tempList.append(otherPlayerName + " ");
|
|
|
|
}
|
|
|
|
|
|
|
|
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"));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Status", new Object[] {party.getName(), status}));
|
2013-01-30 15:17:50 +01:00
|
|
|
|
|
|
|
if (ShareHandler.expShareEnabled) {
|
|
|
|
ExpShare = LocaleLoader.getString("Commands.Party.ExpShare", new Object[] { party.getExpShareMode() });
|
|
|
|
}
|
|
|
|
if (ShareHandler.itemShareEnabled) {
|
|
|
|
ItemShare = LocaleLoader.getString("Commands.Party.ItemShare", new Object[] { itemShareMode });
|
|
|
|
}
|
|
|
|
if (ShareHandler.expShareEnabled && ShareHandler.itemShareEnabled) {
|
|
|
|
Split = ChatColor.DARK_GRAY + " || ";
|
|
|
|
}
|
|
|
|
if (ShareHandler.expShareEnabled || ShareHandler.itemShareEnabled) {
|
|
|
|
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-01-30 15:17:50 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.MembersNear", new Object[] { membersNear, membersOnline }));
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Members", new Object[] {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
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
private boolean join(String[] args) {
|
|
|
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.join")) {
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
String playerName = player.getName();
|
2012-06-08 23:48:41 +02:00
|
|
|
Party party = playerProfile.getParty();
|
2012-04-22 08:55:58 +02:00
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
if (args.length < 2) {
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.0"));
|
|
|
|
return true;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
Player target = mcMMO.p.getServer().getPlayer(args[1]);
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
if (target == null) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.NotOnline", new Object[] {args[1]}));
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-28 00:35:06 +01:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
if (!Users.getProfile(target).inParty()) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.PlayerNotInParty", new Object[] {args[1]}));
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
if (player.equals(target)) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Join.Self"));
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-22 08:55:58 +02:00
|
|
|
|
2013-01-29 13:16:28 +01:00
|
|
|
if (party != null && party.equals(Users.getProfile(target).getParty())) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Join.Self"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
String password = null;
|
|
|
|
|
|
|
|
if (args.length > 2) {
|
|
|
|
password = args[2];
|
|
|
|
}
|
2012-03-27 23:09:23 +02:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
String partyTarget = PartyManager.getPlayerParty(target.getName()).getName();
|
|
|
|
Party newParty = PartyManager.getParty(args[0]);
|
2012-04-22 08:55:58 +02:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
// Check to see if the party exists, and if it does, can the player join it?
|
|
|
|
if (newParty != null && !PartyManager.checkJoinability(player, newParty, null)) {
|
|
|
|
return true; // End before any event is fired.
|
|
|
|
}
|
2012-04-22 08:55:58 +02:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
if (party != null) {
|
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), partyTarget, EventReason.CHANGED_PARTIES);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
2013-01-26 00:40:23 +01:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
PartyManager.removeFromParty(playerName, party);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, partyTarget, EventReason.JOINED_PARTY);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
2013-01-26 00:40:23 +01:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
2013-01-28 15:16:19 +01:00
|
|
|
|
|
|
|
PartyManager.joinParty(player, playerProfile, partyTarget, password);
|
|
|
|
return true;
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
private boolean accept() {
|
|
|
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.accept")) {
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-26 00:40:23 +01:00
|
|
|
|
|
|
|
if (playerProfile.hasPartyInvite()) {
|
|
|
|
if (playerProfile.inParty()) {
|
|
|
|
Party party = playerProfile.getParty();
|
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), playerProfile.getInvite().getName(), EventReason.CHANGED_PARTIES);
|
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
2013-01-26 00:40:23 +01:00
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
2013-01-26 00:40:23 +01:00
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
PartyManager.removeFromParty(player.getName(), party);
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-01-26 00:40:23 +01:00
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, playerProfile.getInvite().getName(), EventReason.JOINED_PARTY);
|
2013-01-26 23:01:55 +01:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
2012-12-29 13:39:36 +01:00
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
2012-12-29 13:39:36 +01:00
|
|
|
}
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
|
|
|
PartyManager.joinInvitedParty(player, playerProfile);
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.sendMessage(LocaleLoader.getString("mcMMO.NoInvites"));
|
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
private boolean create(String[] args) {
|
|
|
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.create")) {
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-26 00:40:23 +01:00
|
|
|
|
|
|
|
String playerName = player.getName();
|
|
|
|
Party party = playerProfile.getParty();
|
2012-12-29 13:39:36 +01:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
if (args.length < 2) {
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
|
|
|
|
return true;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2012-04-22 08:55:58 +02:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
String partyname = args[1];
|
|
|
|
String password = null;
|
2012-04-22 08:55:58 +02:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
if (args.length > 2) {
|
|
|
|
password = args[2];
|
|
|
|
}
|
2012-03-27 23:09:23 +02:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
Party newParty = PartyManager.getParty(partyname);
|
|
|
|
// Check to see if the party exists, and if it does cancel creating a new party
|
|
|
|
if (newParty != null) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", new Object[] {partyname}));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (playerProfile.inParty()) {
|
|
|
|
String oldPartyName = party.getName();
|
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, oldPartyName, partyname, EventReason.CHANGED_PARTIES);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-26 00:40:23 +01:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
PartyManager.removeFromParty(playerName, party);
|
|
|
|
PartyManager.createParty(player, playerProfile, partyname, password);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, partyname, EventReason.JOINED_PARTY);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
2012-04-22 08:55:58 +02:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
if (event.isCancelled()) {
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
2013-01-28 15:16:19 +01:00
|
|
|
|
|
|
|
PartyManager.createParty(player, playerProfile, partyname, password);
|
|
|
|
return true;
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
private boolean quit() {
|
|
|
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.quit")) {
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-26 00:40:23 +01:00
|
|
|
|
|
|
|
String playerName = player.getName();
|
|
|
|
Party party = playerProfile.getParty();
|
|
|
|
|
|
|
|
if (party != null) {
|
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), null, EventReason.LEFT_PARTY);
|
2013-01-26 23:01:55 +01:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
2013-01-26 00:40:23 +01:00
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
PartyManager.removeFromParty(playerName, party);
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Leave"));
|
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
else {
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-30 15:17:50 +01:00
|
|
|
private boolean shareExp(String[] args) {
|
|
|
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.expshare"))
|
|
|
|
return true;
|
|
|
|
String playerName = player.getName();
|
|
|
|
PlayerProfile playerProfile = Users.getProfile(player);
|
|
|
|
Party party = playerProfile.getParty();
|
|
|
|
|
|
|
|
if (args.length < 2) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Usage.2", new Object[] {"party", "expshare", "[sharemode]"}));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (party.getLeader().equals(playerName)) {
|
|
|
|
if(args[1].equalsIgnoreCase("noshare") || args[1].equalsIgnoreCase("none") || args[1].equalsIgnoreCase("false")) {
|
|
|
|
party.setExpShareMode("NONE");
|
|
|
|
for (Player onlineMembers : party.getOnlineMembers()) {
|
|
|
|
onlineMembers.sendMessage(LocaleLoader.getString("Commands.Party.SetSharing", new Object[] {LocaleLoader.getString("Party.ShareType.Exp"), LocaleLoader.getString("Party.ShareMode.NoShare")}));
|
|
|
|
}
|
|
|
|
} else if(args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even")) {
|
|
|
|
party.setExpShareMode("EQUAL");
|
|
|
|
for (Player onlineMembers : party.getOnlineMembers()) {
|
|
|
|
onlineMembers.sendMessage(LocaleLoader.getString("Commands.Party.SetSharing", new Object[] {LocaleLoader.getString("Party.ShareType.Exp"), LocaleLoader.getString("Party.ShareMode.Equal")}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
private boolean shareItem() {
|
|
|
|
return (!CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.itemshare"));
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
2012-04-22 08:55:58 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
private boolean invite(String[] args) {
|
|
|
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.invite")) {
|
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
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
switch (args.length) {
|
2012-04-22 08:55:58 +02:00
|
|
|
case 2:
|
2013-01-26 00:40:23 +01:00
|
|
|
if (!playerProfile.inParty()) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
Player target = mcMMO.p.getServer().getPlayer(args[1]);
|
2013-01-26 00:40:23 +01:00
|
|
|
|
|
|
|
if (target != null) {
|
2013-01-26 23:01:55 +01:00
|
|
|
if (PartyManager.inSameParty(player, target)) {
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Player.InSameParty"));
|
|
|
|
return true;
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
if (PartyManager.canInvite(player, playerProfile)) {
|
2013-01-26 00:40:23 +01:00
|
|
|
Party party = playerProfile.getParty();
|
|
|
|
|
|
|
|
Users.getProfile(target).setInvite(party);
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
|
|
|
|
target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.0", new Object[] {party.getName(), player.getName()}));
|
|
|
|
target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.1"));
|
|
|
|
return true;
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
2012-12-29 13:39:36 +01:00
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Locked"));
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2013-01-28 15:16:19 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Usage.2", new Object[] {"party", "invite", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"}));
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Kick a party member
|
|
|
|
*/
|
2013-01-28 15:16:19 +01:00
|
|
|
private boolean kick(String targetName) {
|
|
|
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.kick")) {
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
String playerName = player.getName();
|
|
|
|
Party party = playerProfile.getParty();
|
2012-12-29 13:39:36 +01:00
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
if (party.getLeader().equals(playerName)) {
|
2013-01-28 15:16:19 +01:00
|
|
|
if (!party.getMembers().contains(targetName)) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] {targetName}));
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
2012-04-22 08:55:58 +02:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
Player target = mcMMO.p.getServer().getOfflinePlayer(targetName).getPlayer();
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
if (target != null) {
|
|
|
|
String partyName = party.getName();
|
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(target, partyName, null, EventReason.KICKED_FROM_PARTY);
|
2012-04-22 08:55:58 +02:00
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
2013-01-26 00:40:23 +01:00
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
target.sendMessage(LocaleLoader.getString("Commands.Party.Kick", new Object[] {partyName}));
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
PartyManager.removeFromParty(targetName, party);
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
else {
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
2012-12-29 13:39:36 +01:00
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
/**
|
|
|
|
* Disband the current party, kicks out all party members.
|
|
|
|
*/
|
2013-01-28 15:16:19 +01:00
|
|
|
private boolean disband() {
|
|
|
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.disband")) {
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2012-12-29 13:39:36 +01:00
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
String playerName = player.getName();
|
|
|
|
Party party = playerProfile.getParty();
|
|
|
|
|
|
|
|
if (party.getLeader().equals(playerName)) {
|
|
|
|
for (Player onlineMembers : party.getOnlineMembers()) {
|
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(onlineMembers, party.getName(), null, EventReason.KICKED_FROM_PARTY);
|
2013-01-26 23:01:55 +01:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
2012-03-27 23:09:23 +02:00
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
onlineMembers.sendMessage(LocaleLoader.getString("Party.Disband"));
|
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
|
|
|
PartyManager.disbandParty(party);
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
else {
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the owner of the current party
|
|
|
|
*/
|
2013-01-28 15:16:19 +01:00
|
|
|
private boolean changeOwner(String[] args) {
|
|
|
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.owner")) {
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-26 00:40:23 +01:00
|
|
|
|
|
|
|
String playerName = player.getName();
|
|
|
|
Party party = playerProfile.getParty();
|
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
if (args.length < 2) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Usage.2", new Object[] {"party", "owner", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]"}));
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
if (party.getLeader().equals(playerName)) {
|
|
|
|
if (!party.getMembers().contains(args[1])) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] {args[1]}));
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
|
|
|
PartyManager.setPartyLeader(args[1], party);
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lock the current party
|
|
|
|
*/
|
2013-01-28 15:16:19 +01:00
|
|
|
private boolean lock() {
|
|
|
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.lock")) {
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-26 00:40:23 +01:00
|
|
|
|
|
|
|
String playerName = player.getName();
|
|
|
|
Party party = playerProfile.getParty();
|
|
|
|
|
|
|
|
if (party != null) {
|
|
|
|
if (party.getLeader().equals(playerName)) {
|
|
|
|
if (party.isLocked()) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.IsLocked"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
party.setLocked(true);
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Locked"));
|
|
|
|
}
|
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
else {
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
else {
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage("Commands.Party.None");
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unlock the current party
|
|
|
|
*/
|
2013-01-28 15:16:19 +01:00
|
|
|
private boolean unlock() {
|
|
|
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.unlock")) {
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2012-04-22 08:55:58 +02:00
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
String playerName = player.getName();
|
|
|
|
Party party = playerProfile.getParty();
|
|
|
|
|
|
|
|
if (party != null) {
|
|
|
|
if (party.getLeader().equals(playerName)) {
|
|
|
|
if (!party.isLocked()) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.IsntLocked"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
party.setLocked(false);
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Unlocked"));
|
|
|
|
}
|
2012-03-27 23:09:23 +02:00
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
else {
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
else {
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage("Commands.Party.None");
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2013-01-28 15:16:19 +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
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
String playerName = player.getName();
|
|
|
|
Party party = playerProfile.getParty();
|
|
|
|
|
2013-01-29 13:16:28 +01:00
|
|
|
if (!party.getLeader().equals(playerName)) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
2012-04-22 08:55:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-26 00:40:23 +01:00
|
|
|
|
2013-01-29 13:16:28 +01:00
|
|
|
if (args.length < 2) {
|
2013-01-26 00:40:23 +01:00
|
|
|
party.setLocked(true);
|
2013-01-29 13:16:28 +01:00
|
|
|
party.setPassword(null);
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Password.Removed"));
|
|
|
|
return true;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
|
2013-01-29 13:16:28 +01:00
|
|
|
party.setLocked(true);
|
|
|
|
party.setPassword(args[1]);
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Password.Set", new Object[] {args[1]}));
|
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
return true;
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
2013-01-26 19:31:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rename the current party
|
|
|
|
*/
|
2013-01-28 15:16:19 +01:00
|
|
|
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 = playerProfile.getParty();
|
2013-01-26 19:40:20 +01:00
|
|
|
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-01-26 19:31:17 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Usage.2", new Object[] {"party", "rename", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">"}));
|
|
|
|
return true;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
String newPartyName = args[1];
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-01-28 15:16:19 +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
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
// Check to see if the party exists, and if it does cancel renaming the party
|
|
|
|
if (newParty != null) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", new Object[] {newPartyName}));
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-26 19:31:17 +01:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
for (Player onlineMembers : party.getOnlineMembers()) {
|
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(onlineMembers, party.getName(), newPartyName, EventReason.CHANGED_PARTIES);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
2013-01-26 19:40:20 +01:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
2013-01-26 19:31:17 +01:00
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
if (!onlineMembers.getName().equals(leader)) {
|
|
|
|
onlineMembers.sendMessage(LocaleLoader.getString("Party.InformedOnNameChange", new Object[] {leader, newPartyName}));
|
|
|
|
}
|
2013-01-26 19:31:17 +01:00
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-01-28 15:16:19 +01:00
|
|
|
party.setName(newPartyName);
|
2013-01-26 19:31:17 +01:00
|
|
|
}
|
2013-01-28 15:16:19 +01:00
|
|
|
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Rename", new Object[] {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
|
|
|
}
|