mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-03 19:00:30 +02:00
Add JoinLeaveListener component.
This commit is contained in:
parent
157e957122
commit
be49a7855c
|
@ -49,6 +49,7 @@ import fr.neatmonster.nocheatplus.compat.MCAccessFactory;
|
||||||
import fr.neatmonster.nocheatplus.components.ComponentWithName;
|
import fr.neatmonster.nocheatplus.components.ComponentWithName;
|
||||||
import fr.neatmonster.nocheatplus.components.ConsistencyChecker;
|
import fr.neatmonster.nocheatplus.components.ConsistencyChecker;
|
||||||
import fr.neatmonster.nocheatplus.components.INeedConfig;
|
import fr.neatmonster.nocheatplus.components.INeedConfig;
|
||||||
|
import fr.neatmonster.nocheatplus.components.JoinLeaveListener;
|
||||||
import fr.neatmonster.nocheatplus.components.MCAccessHolder;
|
import fr.neatmonster.nocheatplus.components.MCAccessHolder;
|
||||||
import fr.neatmonster.nocheatplus.components.NCPListener;
|
import fr.neatmonster.nocheatplus.components.NCPListener;
|
||||||
import fr.neatmonster.nocheatplus.components.NameSetPermState;
|
import fr.neatmonster.nocheatplus.components.NameSetPermState;
|
||||||
|
@ -307,6 +308,9 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
|
||||||
|
|
||||||
protected int consistencyCheckerTaskId = -1;
|
protected int consistencyCheckerTaskId = -1;
|
||||||
|
|
||||||
|
/** Listeners for players joining and leaving (monitor level) */
|
||||||
|
protected final List<JoinLeaveListener> joinLeaveListeners = new ArrayList<JoinLeaveListener>();
|
||||||
|
|
||||||
/** All registered components. */
|
/** All registered components. */
|
||||||
protected Set<Object> allComponents = new LinkedHashSet<Object>(50);
|
protected Set<Object> allComponents = new LinkedHashSet<Object>(50);
|
||||||
|
|
||||||
|
@ -347,6 +351,10 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
|
||||||
consistencyCheckers.add((ConsistencyChecker) obj);
|
consistencyCheckers.add((ConsistencyChecker) obj);
|
||||||
added = true;
|
added = true;
|
||||||
}
|
}
|
||||||
|
if (obj instanceof JoinLeaveListener){
|
||||||
|
joinLeaveListeners.add((JoinLeaveListener) obj);
|
||||||
|
added = true;
|
||||||
|
}
|
||||||
// Also add to DataManager, which will pick what it needs.
|
// Also add to DataManager, which will pick what it needs.
|
||||||
// TODO: This is fishy in principle, something more concise?
|
// TODO: This is fishy in principle, something more concise?
|
||||||
if (dataMan.addComponent(obj)) added = true;
|
if (dataMan.addComponent(obj)) added = true;
|
||||||
|
@ -404,6 +412,9 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
|
||||||
if (obj instanceof ConsistencyChecker){
|
if (obj instanceof ConsistencyChecker){
|
||||||
consistencyCheckers.remove(obj);
|
consistencyCheckers.remove(obj);
|
||||||
}
|
}
|
||||||
|
if (obj instanceof JoinLeaveListener){
|
||||||
|
joinLeaveListeners.remove((JoinLeaveListener) obj);
|
||||||
|
}
|
||||||
dataMan.removeComponent(obj);
|
dataMan.removeComponent(obj);
|
||||||
allComponents.remove(obj);
|
allComponents.remove(obj);
|
||||||
}
|
}
|
||||||
|
@ -798,21 +809,7 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||||
final Player player = event.getPlayer();
|
onJoin(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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) {
|
protected void onLeave(final Player player) {
|
||||||
for (final PermStateReceiver pr : permStateReceivers) {
|
for (final PermStateReceiver pr : permStateReceivers) {
|
||||||
pr.removePlayer(player.getName());
|
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) {
|
protected void updatePermStateReceivers(final Player player) {
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user