Make NCP listeners identifiable by implementing ComponentWithName

(adding NCPListener, CheckListener).
This commit is contained in:
asofold 2012-11-12 09:04:43 +01:00
parent 448ae2249b
commit 040947b6d3
13 changed files with 107 additions and 21 deletions

View File

@ -40,6 +40,7 @@ import fr.neatmonster.nocheatplus.command.CommandHandler;
import fr.neatmonster.nocheatplus.command.INotifyReload;
import fr.neatmonster.nocheatplus.components.ComponentWithName;
import fr.neatmonster.nocheatplus.components.INeedConfig;
import fr.neatmonster.nocheatplus.components.NCPListener;
import fr.neatmonster.nocheatplus.components.NameSetPermState;
import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI;
import fr.neatmonster.nocheatplus.components.PermStateReceiver;
@ -606,7 +607,7 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
* @return
*/
private Listener getCoreListener() {
return new Listener() {
return new NCPListener() {
@SuppressWarnings("unused")
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(final PlayerLoginEvent event) {

View File

@ -0,0 +1,29 @@
package fr.neatmonster.nocheatplus.checks;
import fr.neatmonster.nocheatplus.components.NCPListener;
/**
* This class provides naming etc for registration with ListenerManager.
* For listeners registered by NoCheatPlus only.
* @author mc_dev
*
*/
public class CheckListener extends NCPListener{
/** Check group / type which this listener is for. */
protected final CheckType checkType;
public CheckListener(){
this(null);
}
public CheckListener(CheckType checkType){
this.checkType = checkType;
}
@Override
public String getComponentName() {
final String part = super.getComponentName();
return checkType == null ? part : part + "_" + checkType.name();
}
}

View File

@ -6,13 +6,14 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.inventory.Items;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
@ -40,7 +41,7 @@ import fr.neatmonster.nocheatplus.utilities.TickTask;
*
* @see BlockBreakEvent
*/
public class BlockBreakListener implements Listener {
public class BlockBreakListener extends CheckListener {
/** The direction check. */
private final Direction direction = new Direction();
@ -62,6 +63,10 @@ public class BlockBreakListener implements Listener {
private boolean isInstaBreak = false;
public BlockBreakListener(){
super(CheckType.BLOCKBREAK);
}
/**
* We listen to BlockBreak events for obvious reasons.
*

View File

@ -4,10 +4,12 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* M#"""""""'M dP dP M""M dP dP
* ## mmmm. `M 88 88 M M 88 88
@ -30,7 +32,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
*
* @see BlockInteractEvent
*/
public class BlockInteractListener implements Listener {
public class BlockInteractListener extends CheckListener {
/** The direction check. */
private final Direction direction = new Direction();
@ -38,6 +40,10 @@ public class BlockInteractListener implements Listener {
/** The reach check. */
private final Reach reach = new Reach();
public BlockInteractListener(){
super(CheckType.BLOCKINTERACT);
}
/**
* We listen to PlayerInteractEvent events for obvious reasons.
*

View File

@ -7,7 +7,6 @@ import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
@ -15,6 +14,8 @@ import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.combined.Combined;
import fr.neatmonster.nocheatplus.checks.combined.Improbable;
import fr.neatmonster.nocheatplus.permissions.Permissions;
@ -42,7 +43,7 @@ import fr.neatmonster.nocheatplus.utilities.BlockProperties;
*
* @see BlockPlaceEvent
*/
public class BlockPlaceListener implements Listener {
public class BlockPlaceListener extends CheckListener {
/** The direction check. */
private final Direction direction = new Direction();
@ -59,6 +60,10 @@ public class BlockPlaceListener implements Listener {
/** The speed check. */
private final Speed speed = new Speed();
public BlockPlaceListener(){
super(CheckType.BLOCKPLACE);
}
/**
* We listen to BlockPlace events for obvious reasons.
*

View File

@ -4,7 +4,6 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
@ -12,6 +11,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.command.CommandUtil;
import fr.neatmonster.nocheatplus.command.INotifyReload;
@ -36,7 +36,7 @@ import fr.neatmonster.nocheatplus.utilities.ds.prefixtree.SimpleCharPrefixTree;
*
* @see ChatEvent
*/
public class ChatListener implements Listener, INotifyReload {
public class ChatListener extends CheckListener implements INotifyReload {
// Checks.
@ -66,8 +66,8 @@ public class ChatListener implements Listener, INotifyReload {
/** Commands to be handled as chat. */
private final SimpleCharPrefixTree chatCommands = new SimpleCharPrefixTree();
public ChatListener(){
super(CheckType.CHAT);
ConfigFile config = ConfigManager.getConfigFile();
initFilters(config);
// (text inits in constructor.)

View File

@ -7,13 +7,14 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.event.player.PlayerToggleSprintEvent;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.TickTask;
/**
@ -21,11 +22,12 @@ import fr.neatmonster.nocheatplus.utilities.TickTask;
* @author mc_dev
*
*/
public class CombinedListener implements Listener {
public class CombinedListener extends CheckListener {
protected final Improbable improbable;
public CombinedListener(){
super(CheckType.COMBINED);
this.improbable = new Improbable();
}

View File

@ -5,7 +5,6 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@ -14,6 +13,8 @@ import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerToggleSprintEvent;
import org.bukkit.inventory.ItemStack;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.combined.Combined;
import fr.neatmonster.nocheatplus.checks.combined.Improbable;
import fr.neatmonster.nocheatplus.checks.inventory.Items;
@ -35,7 +36,7 @@ import fr.neatmonster.nocheatplus.utilities.TickTask;
*
* @see FightEvent
*/
public class FightListener implements Listener {
public class FightListener extends CheckListener {
/** The angle check. */
private final Angle angle = new Angle();
@ -64,6 +65,10 @@ public class FightListener implements Listener {
/** The speed check. */
private final Speed speed = new Speed();
public FightListener(){
super(CheckType.FIGHT);
}
/**
* A player attacked something with DamageCause ENTITY_ATTACK. That's most likely what we want to really check.
*

View File

@ -7,7 +7,6 @@ import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
@ -19,6 +18,8 @@ import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.combined.Combined;
import fr.neatmonster.nocheatplus.checks.combined.Improbable;
@ -45,7 +46,7 @@ import fr.neatmonster.nocheatplus.checks.combined.Improbable;
*
* @see InventoryEvent
*/
public class InventoryListener implements Listener {
public class InventoryListener extends CheckListener {
/** The drop check. */
private final Drop drop = new Drop();
@ -61,6 +62,10 @@ public class InventoryListener implements Listener {
protected final Items items = new Items();
public InventoryListener(){
super(CheckType.INVENTORY);
}
/**
* We listen to EntityShootBow events for the InstantBow check.
*

View File

@ -15,7 +15,6 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@ -36,6 +35,7 @@ import org.bukkit.event.vehicle.VehicleMoveEvent;
import org.bukkit.util.Vector;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.combined.Combined;
import fr.neatmonster.nocheatplus.checks.combined.CombinedData;
@ -70,7 +70,7 @@ import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
*
* @see MovingEvent
*/
public class MovingListener implements Listener {
public class MovingListener extends CheckListener{
private static final class MoveInfo{
public final PlayerLocation from = new PlayerLocation();
@ -117,6 +117,10 @@ public class MovingListener implements Listener {
*/
private final List<MoveInfo> parkedInfo = new ArrayList<MoveInfo>(10);
public MovingListener() {
super(CheckType.MOVING);
}
/**
* A workaround for players placing blocks below them getting pushed off the block by NoCheatPlus.
*

View File

@ -0,0 +1,17 @@
package fr.neatmonster.nocheatplus.components;
import org.bukkit.event.Listener;
/**
* Registers with default name "NoCheatPlus_Listener".
* @author mc_dev
*
*/
public abstract class NCPListener implements Listener, ComponentWithName {
@Override
public String getComponentName() {
return "NoCheatPlus_Listener";
}
}

View File

@ -15,6 +15,7 @@ import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.components.NCPListener;
/*
* M"""""""`YM MM'""""'YMM MM"""""""`YM MM""""""""`M dP oo
@ -119,7 +120,7 @@ public class NCPExemptionManager {
* @return the listener
*/
public static Listener getListener() {
return new Listener() {
return new NCPListener() {
@SuppressWarnings("unused")
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(final PlayerJoinEvent event) {

View File

@ -32,6 +32,7 @@ import fr.neatmonster.nocheatplus.checks.inventory.InventoryConfig;
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
import fr.neatmonster.nocheatplus.command.INotifyReload;
import fr.neatmonster.nocheatplus.components.ComponentRegistry;
import fr.neatmonster.nocheatplus.components.ComponentWithName;
import fr.neatmonster.nocheatplus.components.IHaveCheckType;
import fr.neatmonster.nocheatplus.components.INeedConfig;
import fr.neatmonster.nocheatplus.components.IRemoveData;
@ -48,7 +49,7 @@ import fr.neatmonster.nocheatplus.hooks.APIUtils;
* @author mc_dev
*
*/
public class DataManager implements Listener, INotifyReload, INeedConfig, ComponentRegistry{
public class DataManager implements Listener, INotifyReload, INeedConfig, ComponentRegistry, ComponentWithName{
protected static DataManager instance = null;
@ -328,4 +329,9 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, Compon
lastLogout.clear();
executionHistories.clear();
}
@Override
public String getComponentName() {
return "NoCheatPlus_DataManager";
}
}