2012-01-09 11:00:13 -08:00
|
|
|
package com.gmail.nossr50.commands.party;
|
|
|
|
|
|
|
|
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;
|
2012-04-20 18:09:50 -04:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
|
|
|
import com.gmail.nossr50.commands.CommandHelper;
|
2012-01-09 11:00:13 -08:00
|
|
|
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 {
|
2012-04-20 18:09:50 -04:00
|
|
|
private final mcMMO plugin;
|
2012-01-09 11:00:13 -08:00
|
|
|
|
2012-04-20 18:09:50 -04:00
|
|
|
public AcceptCommand (mcMMO plugin) {
|
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
2012-01-09 11:00:13 -08:00
|
|
|
|
2012-04-20 18:09:50 -04:00
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
if (CommandHelper.noConsoleUsage(sender)) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-01-09 11:00:13 -08:00
|
|
|
|
2012-04-20 18:09:50 -04:00
|
|
|
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party")) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-01-09 11:00:13 -08:00
|
|
|
|
2012-04-20 18:09:50 -04:00
|
|
|
Player player = (Player) sender;
|
|
|
|
PlayerProfile PP = Users.getProfile(player);
|
|
|
|
|
|
|
|
if (PP.hasPartyInvite()) {
|
|
|
|
Party partyInstance = 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);
|
2012-04-20 18:09:50 -04:00
|
|
|
plugin.getServer().getPluginManager().callEvent(event);
|
2012-03-27 17:09:23 -04:00
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-20 18:09:50 -04:00
|
|
|
partyInstance.removeFromParty(player, PP);
|
|
|
|
}
|
|
|
|
else {
|
2012-03-27 17:09:23 -04:00
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, PP.getInvite(), EventReason.JOINED_PARTY);
|
2012-04-20 18:09:50 -04:00
|
|
|
plugin.getServer().getPluginManager().callEvent(event);
|
2012-03-27 17:09:23 -04:00
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-20 18:09:50 -04:00
|
|
|
}
|
2012-03-27 17:09:23 -04:00
|
|
|
PP.acceptInvite();
|
2012-04-20 18:09:50 -04:00
|
|
|
partyInstance.addToParty(player, PP, PP.getParty(), true, null);
|
2012-01-09 11:00:13 -08:00
|
|
|
|
2012-04-20 18:09:50 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.sendMessage(mcLocale.getString("mcMMO.NoInvites"));
|
|
|
|
}
|
2012-01-09 11:00:13 -08:00
|
|
|
|
2012-04-20 18:09:50 -04:00
|
|
|
return true;
|
|
|
|
}
|
2012-01-09 11:00:13 -08:00
|
|
|
}
|