diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/NoCheatPlus.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/NoCheatPlus.java index 8bd8bb60..9818093a 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/NoCheatPlus.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/NoCheatPlus.java @@ -49,6 +49,7 @@ import fr.neatmonster.nocheatplus.compat.MCAccessFactory; import fr.neatmonster.nocheatplus.components.ComponentWithName; import fr.neatmonster.nocheatplus.components.ConsistencyChecker; import fr.neatmonster.nocheatplus.components.INeedConfig; +import fr.neatmonster.nocheatplus.components.JoinLeaveListener; import fr.neatmonster.nocheatplus.components.MCAccessHolder; import fr.neatmonster.nocheatplus.components.NCPListener; import fr.neatmonster.nocheatplus.components.NameSetPermState; @@ -307,6 +308,9 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI { protected int consistencyCheckerTaskId = -1; + /** Listeners for players joining and leaving (monitor level) */ + protected final List joinLeaveListeners = new ArrayList(); + /** All registered components. */ protected Set allComponents = new LinkedHashSet(50); @@ -347,6 +351,10 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI { consistencyCheckers.add((ConsistencyChecker) obj); added = true; } + if (obj instanceof JoinLeaveListener){ + joinLeaveListeners.add((JoinLeaveListener) obj); + added = true; + } // Also add to DataManager, which will pick what it needs. // TODO: This is fishy in principle, something more concise? if (dataMan.addComponent(obj)) added = true; @@ -404,6 +412,9 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI { if (obj instanceof ConsistencyChecker){ consistencyCheckers.remove(obj); } + if (obj instanceof JoinLeaveListener){ + joinLeaveListeners.remove((JoinLeaveListener) obj); + } dataMan.removeComponent(obj); allComponents.remove(obj); } @@ -798,21 +809,7 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI { @SuppressWarnings("unused") @EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(final PlayerJoinEvent event) { - final Player player = event.getPlayer(); - - updatePermStateReceivers(player); - - if (nameSetPerms.hasPermission(player.getName(), Permissions.ADMINISTRATION_NOTIFY)){ - // Login notifications... - - // Update available. - if (updateAvailable) player.sendMessage(ChatColor.RED + "NCP: " + ChatColor.WHITE + "A new update of NoCheatPlus is available.\n" + "Download it at http://nocheatplus.org/update"); - - // Outdated config. - if (configOutdated) player.sendMessage(ChatColor.RED + "NCP: " + ChatColor.WHITE + "Your configuration might be outdated.\n" + "Some settings could have changed, you should regenerate it!"); - - } - ModUtil.checkModsMessage(player); + onJoin(event.getPlayer()); } @SuppressWarnings("unused") @@ -837,10 +834,44 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI { }; } + protected void onJoin(final Player player){ + updatePermStateReceivers(player); + + if (nameSetPerms.hasPermission(player.getName(), Permissions.ADMINISTRATION_NOTIFY)){ + // Login notifications... + + // Update available. + if (updateAvailable) player.sendMessage(ChatColor.RED + "NCP: " + ChatColor.WHITE + "A new update of NoCheatPlus is available.\n" + "Download it at http://nocheatplus.org/update"); + + // Outdated config. + if (configOutdated) player.sendMessage(ChatColor.RED + "NCP: " + ChatColor.WHITE + "Your configuration might be outdated.\n" + "Some settings could have changed, you should regenerate it!"); + + } + ModUtil.checkModsMessage(player); + for (final JoinLeaveListener jlListener : joinLeaveListeners){ + try{ + jlListener.playerJoins(player); + } + catch(Throwable t){ + LogUtil.logSevere("[NoCheatPlus] JoinLeaveListener(" + jlListener.getClass().getName() + ") generated an exception (join): " + t.getClass().getSimpleName()); + LogUtil.logSevere(t); + } + } + } + protected void onLeave(final Player player) { for (final PermStateReceiver pr : permStateReceivers) { pr.removePlayer(player.getName()); } + for (final JoinLeaveListener jlListener : joinLeaveListeners){ + try{ + jlListener.playerLeaves(player); + } + catch(Throwable t){ + LogUtil.logSevere("[NoCheatPlus] JoinLeaveListener(" + jlListener.getClass().getName() + ") generated an exception (leave): " + t.getClass().getSimpleName()); + LogUtil.logSevere(t); + } + } } protected void updatePermStateReceivers(final Player player) { diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/components/JoinLeaveListener.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/components/JoinLeaveListener.java new file mode 100644 index 00000000..9b5f229a --- /dev/null +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/components/JoinLeaveListener.java @@ -0,0 +1,23 @@ +package fr.neatmonster.nocheatplus.components; + +import org.bukkit.entity.Player; + +/** + * Receive calls for players joining and leaving (quit/kick). + * @author mc_dev + * + */ +public interface JoinLeaveListener { + + /** + * Called on join (monitor level). + * @param player + */ + public void playerJoins(final Player player); + + /** + * Called both on quit/kick (monitor level). + * @param player + */ + public void playerLeaves(final Player player); +}