2012-01-09 11:00:13 -08:00
|
|
|
package com.gmail.nossr50.commands.party;
|
|
|
|
|
2012-03-27 17:09:23 -04:00
|
|
|
import org.bukkit.Bukkit;
|
2012-01-09 11:00:13 -08:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.Users;
|
|
|
|
import com.gmail.nossr50.mcPermissions;
|
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
2012-03-27 17:09:23 -04:00
|
|
|
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
|
|
|
|
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
|
2012-01-09 11:00:13 -08:00
|
|
|
import com.gmail.nossr50.locale.mcLocale;
|
|
|
|
import com.gmail.nossr50.party.Party;
|
|
|
|
|
|
|
|
public class AcceptCommand implements CommandExecutor {
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
|
|
|
|
if (!(sender instanceof Player)) {
|
2012-03-26 16:17:35 -04:00
|
|
|
sender.sendMessage("This command does not support console useage."); //TODO: Needs more locale.
|
2012-01-09 11:00:13 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player player = (Player) sender;
|
|
|
|
PlayerProfile PP = Users.getProfile(player);
|
|
|
|
|
|
|
|
if (!mcPermissions.getInstance().party(player)) {
|
|
|
|
player.sendMessage(ChatColor.YELLOW + "[mcMMO] " + ChatColor.DARK_RED + mcLocale.getString("mcPlayerListener.NoPermission"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PP.hasPartyInvite()) {
|
|
|
|
Party Pinstance = Party.getInstance();
|
|
|
|
|
|
|
|
if (PP.inParty()) {
|
2012-03-27 17:09:23 -04:00
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, PP.getParty(), PP.getInvite(), EventReason.CHANGED_PARTIES);
|
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-09 11:00:13 -08:00
|
|
|
Pinstance.removeFromParty(player, PP);
|
|
|
|
}
|
2012-03-27 17:09:23 -04:00
|
|
|
else {
|
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, PP.getInvite(), EventReason.JOINED_PARTY);
|
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PP.acceptInvite();
|
2012-04-03 00:06:30 -04:00
|
|
|
Pinstance.addToParty(player, PP, PP.getParty(), true, null);
|
2012-01-09 11:00:13 -08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
player.sendMessage(mcLocale.getString("mcPlayerListener.NoInvites"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|