Move handlePartyChangeEvent to PartyManager

This commit is contained in:
GJ 2013-02-07 22:01:14 -05:00
parent 3ccf79cff5
commit 79b96c380d
2 changed files with 24 additions and 19 deletions

View File

@ -9,6 +9,8 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
@ -494,4 +496,20 @@ public final class PartyManager {
} }
} }
} }
/**
* Handle party change event.
*
* @param player The player changing parties
* @param oldPartyName The name of the old party
* @param newPartyName The name of the new party
* @param reason The reason for changing parties
* @return true if the change event was successful, false otherwise
*/
public static boolean handlePartyChangeEvent(Player player, String oldPartyName, String newPartyName, EventReason reason) {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, oldPartyName, newPartyName, reason);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return !event.isCancelled();
}
} }

View File

@ -5,10 +5,8 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason; import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
@ -49,11 +47,14 @@ public class PartyJoinCommand implements CommandExecutor {
// Changing parties // Changing parties
if (mcMMOPlayer.inParty()) { if (mcMMOPlayer.inParty()) {
handlePartyChangeEvent(playerParty.getName(), EventReason.CHANGED_PARTIES); if (!PartyManager.handlePartyChangeEvent(player, playerParty.getName(), targetParty.getName(), EventReason.CHANGED_PARTIES)) {
return true;
}
PartyManager.removeFromParty(player.getName(), playerParty); PartyManager.removeFromParty(player.getName(), playerParty);
} }
else { else if (!PartyManager.handlePartyChangeEvent(player, null, targetParty.getName(), EventReason.JOINED_PARTY)) {
handlePartyChangeEvent(null, EventReason.JOINED_PARTY); return true;
} }
PartyManager.joinParty(player, mcMMOPlayer, targetParty.getName(), password); PartyManager.joinParty(player, mcMMOPlayer, targetParty.getName(), password);
@ -108,18 +109,4 @@ public class PartyJoinCommand implements CommandExecutor {
return true; return true;
} }
/**
* Handle party change event.
*
* @param partyName The name of the old party
* @param reason The reason for changing parties
* @return true if the change event was successful, false otherwise
*/
private boolean handlePartyChangeEvent(String oldPartyName, EventReason reason) {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, oldPartyName, targetParty.getName(), reason);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return !event.isCancelled();
}
} }