From 79b96c380d81a6ecbc528684bb0d2df072c766df Mon Sep 17 00:00:00 2001 From: GJ Date: Thu, 7 Feb 2013 22:01:14 -0500 Subject: [PATCH] Move handlePartyChangeEvent to PartyManager --- .../com/gmail/nossr50/party/PartyManager.java | 18 +++++++++++++ .../party/commands/PartyJoinCommand.java | 25 +++++-------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/party/PartyManager.java b/src/main/java/com/gmail/nossr50/party/PartyManager.java index 11bba388d..513eb5259 100644 --- a/src/main/java/com/gmail/nossr50/party/PartyManager.java +++ b/src/main/java/com/gmail/nossr50/party/PartyManager.java @@ -9,6 +9,8 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.mcMMO; 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.util.Misc; 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(); + } } diff --git a/src/main/java/com/gmail/nossr50/party/commands/PartyJoinCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PartyJoinCommand.java index bac51d0e7..f086c1d11 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/PartyJoinCommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyJoinCommand.java @@ -5,10 +5,8 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.McMMOPlayer; 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.locale.LocaleLoader; import com.gmail.nossr50.party.Party; @@ -49,11 +47,14 @@ public class PartyJoinCommand implements CommandExecutor { // Changing parties 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); } - else { - handlePartyChangeEvent(null, EventReason.JOINED_PARTY); + else if (!PartyManager.handlePartyChangeEvent(player, null, targetParty.getName(), EventReason.JOINED_PARTY)) { + return true; } PartyManager.joinParty(player, mcMMOPlayer, targetParty.getName(), password); @@ -108,18 +109,4 @@ public class PartyJoinCommand implements CommandExecutor { 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(); - } }