mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-12-30 20:37:52 +01:00
A bit of refactoring, maybe fixed the "can't edit config file" bug,
handle MC 1.0 versions better.
This commit is contained in:
parent
79d545f5e3
commit
0459235c43
10
src/cc/co/evenprime/bukkit/nocheat/EventManager.java
Normal file
10
src/cc/co/evenprime/bukkit/nocheat/EventManager.java
Normal file
@ -0,0 +1,10 @@
|
||||
package cc.co.evenprime.bukkit.nocheat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
|
||||
public interface EventManager {
|
||||
|
||||
public List<String> getActiveChecks(ConfigurationCache cc);
|
||||
}
|
@ -3,6 +3,7 @@ package cc.co.evenprime.bukkit.nocheat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -23,10 +24,10 @@ import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.BlockPlaceEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.BlockBreakEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.FightEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.EventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.ChatEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.MovingEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.PlayerTeleportEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.WorkaroundsEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.TimedEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
|
||||
import cc.co.evenprime.bukkit.nocheat.log.LogManager;
|
||||
@ -40,16 +41,16 @@ import cc.co.evenprime.bukkit.nocheat.log.LogManager;
|
||||
*/
|
||||
public class NoCheat extends JavaPlugin {
|
||||
|
||||
private ConfigurationManager conf;
|
||||
private LogManager log;
|
||||
private PlayerManager players;
|
||||
private PerformanceManager performance;
|
||||
private ConfigurationManager conf;
|
||||
private LogManager log;
|
||||
private PlayerManager players;
|
||||
private PerformanceManager performance;
|
||||
|
||||
private List<EventManager> eventManagers;
|
||||
private List<EventManagerImpl> eventManagers;
|
||||
|
||||
private LagMeasureTask lagMeasureTask;
|
||||
private LagMeasureTask lagMeasureTask;
|
||||
|
||||
private int taskId = -1;
|
||||
private int taskId = -1;
|
||||
|
||||
public NoCheat() {
|
||||
|
||||
@ -96,14 +97,16 @@ public class NoCheat extends JavaPlugin {
|
||||
// Then set up the performance counters
|
||||
this.performance = new PerformanceManager();
|
||||
|
||||
eventManagers = new ArrayList<EventManager>(8); // Big enough
|
||||
eventManagers = new ArrayList<EventManagerImpl>(8); // Big enough
|
||||
// Then set up the event listeners
|
||||
eventManagers.add(new MovingEventManager(this));
|
||||
eventManagers.add(new PlayerTeleportEventManager(this));
|
||||
eventManagers.add(new WorkaroundsEventManager(this));
|
||||
eventManagers.add(new ChatEventManager(this));
|
||||
eventManagers.add(new BlockBreakEventManager(this));
|
||||
eventManagers.add(new BlockPlaceEventManager(this));
|
||||
eventManagers.add(new FightEventManager(this));
|
||||
|
||||
System.out.println(Bukkit.getVersion());
|
||||
TimedEventManager m = new TimedEventManager(this);
|
||||
taskId = m.taskId; // There's a bukkit task, remember its id
|
||||
eventManagers.add(m);
|
||||
|
@ -26,7 +26,7 @@ public class FlatFileConfiguration extends Configuration {
|
||||
|
||||
public void load(ActionMapper action) throws IOException {
|
||||
|
||||
BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
|
||||
BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
|
||||
|
||||
String line = null;
|
||||
|
||||
|
@ -4,14 +4,15 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.EventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.EventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl;
|
||||
import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
|
||||
|
||||
public class ActiveCheckPrinter {
|
||||
|
||||
public static void printActiveChecks(NoCheat plugin, List<EventManager> eventManagers) {
|
||||
public static void printActiveChecks(NoCheat plugin, List<EventManagerImpl> eventManagers) {
|
||||
|
||||
boolean introPrinted = false;
|
||||
String intro = "[NoCheat] Active Checks: ";
|
||||
|
@ -27,7 +27,7 @@ import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
||||
* relevant checks
|
||||
*
|
||||
*/
|
||||
public class BlockBreakEventManager extends EventManager {
|
||||
public class BlockBreakEventManager extends EventManagerImpl {
|
||||
|
||||
private final List<BlockBreakCheck> checks;
|
||||
|
||||
|
@ -24,7 +24,7 @@ import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
||||
* checks
|
||||
*
|
||||
*/
|
||||
public class BlockPlaceEventManager extends EventManager {
|
||||
public class BlockPlaceEventManager extends EventManagerImpl {
|
||||
|
||||
private final List<BlockPlaceCheck> checks;
|
||||
|
||||
|
@ -19,7 +19,7 @@ import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ChatData;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
||||
|
||||
public class ChatEventManager extends EventManager {
|
||||
public class ChatEventManager extends EventManagerImpl {
|
||||
|
||||
private final List<ChatCheck> checks;
|
||||
|
||||
|
@ -27,6 +27,7 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSprintEvent;
|
||||
import org.bukkit.event.player.PlayerVelocityEvent;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.EventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
|
||||
@ -38,18 +39,18 @@ import cc.co.evenprime.bukkit.nocheat.debug.Performance;
|
||||
* time it takes to handle the event.
|
||||
*
|
||||
*/
|
||||
public abstract class EventManager {
|
||||
public abstract class EventManagerImpl implements EventManager {
|
||||
|
||||
protected final NoCheat plugin;
|
||||
|
||||
private static class BlockL extends BlockListener {
|
||||
|
||||
private final EventManager m;
|
||||
private final Priority priority;
|
||||
private final boolean ignoreCancelledEvents;
|
||||
private final Performance measureTime;
|
||||
private final EventManagerImpl m;
|
||||
private final Priority priority;
|
||||
private final boolean ignoreCancelledEvents;
|
||||
private final Performance measureTime;
|
||||
|
||||
public BlockL(EventManager m, Priority priority, boolean ignoreCancelled, Performance measureTime) {
|
||||
public BlockL(EventManagerImpl m, Priority priority, boolean ignoreCancelled, Performance measureTime) {
|
||||
this.m = m;
|
||||
this.priority = priority;
|
||||
this.ignoreCancelledEvents = ignoreCancelled;
|
||||
@ -101,12 +102,12 @@ public abstract class EventManager {
|
||||
|
||||
private static class PlayerL extends PlayerListener {
|
||||
|
||||
private final EventManager m;
|
||||
private final Priority priority;
|
||||
private final boolean ignoreCancelledEvents;
|
||||
private final Performance measureTime;
|
||||
private final EventManagerImpl m;
|
||||
private final Priority priority;
|
||||
private final boolean ignoreCancelledEvents;
|
||||
private final Performance measureTime;
|
||||
|
||||
public PlayerL(EventManager m, Priority priority, boolean ignoreCancelled, Performance measureTime) {
|
||||
public PlayerL(EventManagerImpl m, Priority priority, boolean ignoreCancelled, Performance measureTime) {
|
||||
this.m = m;
|
||||
this.priority = priority;
|
||||
this.ignoreCancelledEvents = ignoreCancelled;
|
||||
@ -243,12 +244,12 @@ public abstract class EventManager {
|
||||
|
||||
private static class EntityL extends EntityListener {
|
||||
|
||||
private final EventManager m;
|
||||
private final Priority priority;
|
||||
private final boolean ignoreCancelledEvents;
|
||||
private final Performance measureTime;
|
||||
private final EventManagerImpl m;
|
||||
private final Priority priority;
|
||||
private final boolean ignoreCancelledEvents;
|
||||
private final Performance measureTime;
|
||||
|
||||
public EntityL(EventManager m, Priority priority, boolean ignoreCancelled, Performance measureTime) {
|
||||
public EntityL(EventManagerImpl m, Priority priority, boolean ignoreCancelled, Performance measureTime) {
|
||||
this.m = m;
|
||||
this.priority = priority;
|
||||
this.ignoreCancelledEvents = ignoreCancelled;
|
||||
@ -285,7 +286,7 @@ public abstract class EventManager {
|
||||
}
|
||||
}
|
||||
|
||||
public EventManager(NoCheat plugin) {
|
||||
public EventManagerImpl(NoCheat plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@ -314,6 +315,14 @@ public abstract class EventManager {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* cc.co.evenprime.bukkit.nocheat.events.EventManager#getActiveChecks(cc
|
||||
* .co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache)
|
||||
*/
|
||||
@Override
|
||||
public List<String> getActiveChecks(ConfigurationCache cc) {
|
||||
return Collections.emptyList();
|
||||
}
|
@ -23,7 +23,7 @@ import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.FightData;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
||||
|
||||
public class FightEventManager extends EventManager {
|
||||
public class FightEventManager extends EventManagerImpl {
|
||||
|
||||
private final List<FightCheck> checks;
|
||||
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerVelocityEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@ -34,7 +35,7 @@ import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
||||
* evaluate the check results and decide what to
|
||||
*
|
||||
*/
|
||||
public class MovingEventManager extends EventManager {
|
||||
public class MovingEventManager extends EventManagerImpl {
|
||||
|
||||
private final List<MovingCheck> checks;
|
||||
|
||||
@ -50,6 +51,7 @@ public class MovingEventManager extends EventManager {
|
||||
registerListener(Event.Type.PLAYER_MOVE, Priority.Lowest, true, plugin.getPerformance(Type.MOVING));
|
||||
registerListener(Event.Type.PLAYER_VELOCITY, Priority.Monitor, true, plugin.getPerformance(Type.VELOCITY));
|
||||
registerListener(Event.Type.BLOCK_PLACE, Priority.Monitor, true, plugin.getPerformance(Type.BLOCKPLACE));
|
||||
registerListener(Event.Type.PLAYER_TELEPORT, Priority.Highest, false, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -82,6 +84,23 @@ public class MovingEventManager extends EventManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerTeleportEvent(final PlayerTeleportEvent event, final Priority priority) {
|
||||
|
||||
// No typo here, I really want to only handle cancelled events
|
||||
if(!event.isCancelled())
|
||||
return;
|
||||
|
||||
NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
final MovingData data = player.getData().moving;
|
||||
|
||||
if(data.teleportTo.isSet() && data.teleportTo.equals(event.getTo())) {
|
||||
event.setCancelled(false);
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerMoveEvent(final PlayerMoveEvent event, final Priority priority) {
|
||||
|
||||
|
@ -21,21 +21,33 @@ import cc.co.evenprime.bukkit.nocheat.data.TimedData;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
||||
|
||||
public class TimedEventManager extends EventManager {
|
||||
public class TimedEventManager extends EventManagerImpl {
|
||||
|
||||
private final List<TimedCheck> checks;
|
||||
private final Performance timedPerformance;
|
||||
public final int taskId;
|
||||
public int taskId = -1;
|
||||
|
||||
public TimedEventManager(final NoCheat plugin) {
|
||||
|
||||
super(plugin);
|
||||
|
||||
checks = new ArrayList<TimedCheck>(1);
|
||||
checks.add(new GodmodeCheck(plugin));
|
||||
|
||||
this.timedPerformance = plugin.getPerformance(Type.TIMED);
|
||||
|
||||
try {
|
||||
// Get an error thrown if "b" doesn't exist
|
||||
EntityPlayer.class.getMethod("b", Boolean.class);
|
||||
|
||||
checks.add(new GodmodeCheck(plugin));
|
||||
|
||||
} catch(NoSuchMethodException e1) {
|
||||
System.out.println("[NoCheat]: Couldn't find needed method for \"timed.godmode\" check, disabling it. You probably run an incompatible craftbukkit version.");
|
||||
System.out.println("[NoCheat]: This problem may be fixed in a newer version of NoCheat (when available).");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// "register a listener" for passed time
|
||||
this.taskId = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
|
||||
|
@ -10,46 +10,28 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSprintEvent;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
|
||||
|
||||
/**
|
||||
* Only place that listens to Player-teleport related events and dispatches them
|
||||
* to relevant checks
|
||||
*
|
||||
*/
|
||||
public class PlayerTeleportEventManager extends EventManager {
|
||||
public class WorkaroundsEventManager extends EventManagerImpl {
|
||||
|
||||
public PlayerTeleportEventManager(NoCheat plugin) {
|
||||
public WorkaroundsEventManager(NoCheat plugin) {
|
||||
|
||||
super(plugin);
|
||||
|
||||
registerListener(Event.Type.PLAYER_MOVE, Priority.Highest, false, null);
|
||||
registerListener(Event.Type.PLAYER_TOGGLE_SPRINT, Priority.Highest, false, null);
|
||||
registerListener(Event.Type.PLAYER_TELEPORT, Priority.Monitor, true, null);
|
||||
registerListener(Event.Type.PLAYER_TELEPORT, Priority.Highest, false, null);
|
||||
registerListener(Event.Type.PLAYER_PORTAL, Priority.Monitor, true, null);
|
||||
registerListener(Event.Type.PLAYER_RESPAWN, Priority.Monitor, true, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerTeleportEvent(final PlayerTeleportEvent event, final Priority priority) {
|
||||
if(priority.equals(Priority.Monitor)) {
|
||||
handleTeleportation(event.getPlayer());
|
||||
} else {
|
||||
// No typo here, I really want to only handle cancelled events
|
||||
if(!event.isCancelled())
|
||||
return;
|
||||
|
||||
NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
final MovingData data = player.getData().moving;
|
||||
|
||||
if(data.teleportTo.isSet() && data.teleportTo.equals(event.getTo())) {
|
||||
if(player.getConfiguration().debug.overrideIdiocy) {
|
||||
event.setCancelled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
handleTeleportation(event.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
@ -61,6 +61,7 @@ public class NoCheatPlayerImpl implements NoCheatPlayer {
|
||||
|
||||
public void increaseAge(int ticks) {
|
||||
EntityPlayer p = ((CraftPlayer) player).getHandle();
|
||||
|
||||
for(int i = 0; i < ticks; i++) {
|
||||
// TODO: This is highly fragile and breaks every update!!
|
||||
p.b(true); // Catch up with the server, one tick at a time
|
||||
|
Loading…
Reference in New Issue
Block a user