From 73a5143a17f4aaf842e47a34fd8540c77c41fee1 Mon Sep 17 00:00:00 2001 From: Daniel Naylor Date: Sat, 29 Dec 2012 12:39:36 +0000 Subject: [PATCH] Check to see if players are eligible to join a party before the mcMMOPartyChangeEvent is fired --- .../nossr50/commands/party/PartyCommand.java | 21 +++++++++++++++++++ .../com/gmail/nossr50/party/PartyManager.java | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java b/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java index 15fcff382..22ed2bcbb 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java @@ -137,6 +137,13 @@ public class PartyCommand implements CommandExecutor { } } else { + Party newParty = partyManagerInstance.getParty(args[0]); + + // Check to see if the party exists, and if it does, can the player join it? + if (newParty != null && !partyManagerInstance.checkJoinability(player, playerProfile, newParty, null)) { + return true; // End before any event is fired. + } + if (party != null) { McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), args[0], EventReason.CHANGED_PARTIES); plugin.getServer().getPluginManager().callEvent(event); @@ -208,6 +215,13 @@ public class PartyCommand implements CommandExecutor { } } else { + Party newParty = partyManagerInstance.getParty(args[0]); + + // Check to see if the party exists, and if it does, can the player join it? + if (newParty != null && !partyManagerInstance.checkJoinability(player, playerProfile, newParty, args[1])) { + return true; // End before any event is fired. + } + McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), args[0], EventReason.CHANGED_PARTIES); plugin.getServer().getPluginManager().callEvent(event); @@ -220,6 +234,13 @@ public class PartyCommand implements CommandExecutor { } } else { + Party newParty = partyManagerInstance.getParty(args[0]); + + // Check to see if the party exists, and if it does, can the player join it? + if (newParty != null && !partyManagerInstance.checkJoinability(player, playerProfile, newParty, args[1])) { + return true; // End before any event is fired. + } + McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, args[0], EventReason.JOINED_PARTY); plugin.getServer().getPluginManager().callEvent(event); diff --git a/src/main/java/com/gmail/nossr50/party/PartyManager.java b/src/main/java/com/gmail/nossr50/party/PartyManager.java index 404b7099b..408c18f8a 100644 --- a/src/main/java/com/gmail/nossr50/party/PartyManager.java +++ b/src/main/java/com/gmail/nossr50/party/PartyManager.java @@ -241,7 +241,7 @@ public class PartyManager { * @param password The password provided by the player * @return true if the player can join the party */ - private boolean checkJoinability(Player player, PlayerProfile playerProfile, Party party, String password) { + public boolean checkJoinability(Player player, PlayerProfile playerProfile, Party party, String password) { //Don't care about passwords if it isn't locked if (party.isLocked()) { String partyPassword = party.getPassword();