diff --git a/src/cc/co/evenprime/bukkit/nocheat/EventManager.java b/src/cc/co/evenprime/bukkit/nocheat/EventManager.java new file mode 100644 index 00000000..710ac2ef --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/EventManager.java @@ -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 getActiveChecks(ConfigurationCache cc); +} diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java index e65173ac..9e08c9f9 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java @@ -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 eventManagers; + private List 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(8); // Big enough + eventManagers = new ArrayList(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); diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileConfiguration.java b/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileConfiguration.java index 39215589..158cdd3c 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileConfiguration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileConfiguration.java @@ -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; diff --git a/src/cc/co/evenprime/bukkit/nocheat/debug/ActiveCheckPrinter.java b/src/cc/co/evenprime/bukkit/nocheat/debug/ActiveCheckPrinter.java index 1292fa8b..04b08dfa 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/debug/ActiveCheckPrinter.java +++ b/src/cc/co/evenprime/bukkit/nocheat/debug/ActiveCheckPrinter.java @@ -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 eventManagers) { + public static void printActiveChecks(NoCheat plugin, List eventManagers) { boolean introPrinted = false; String intro = "[NoCheat] Active Checks: "; diff --git a/src/cc/co/evenprime/bukkit/nocheat/events/BlockBreakEventManager.java b/src/cc/co/evenprime/bukkit/nocheat/events/BlockBreakEventManager.java index e55edc3c..6b655b49 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/events/BlockBreakEventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/events/BlockBreakEventManager.java @@ -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 checks; diff --git a/src/cc/co/evenprime/bukkit/nocheat/events/BlockPlaceEventManager.java b/src/cc/co/evenprime/bukkit/nocheat/events/BlockPlaceEventManager.java index 22658f9d..b3cb78ac 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/events/BlockPlaceEventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/events/BlockPlaceEventManager.java @@ -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 checks; diff --git a/src/cc/co/evenprime/bukkit/nocheat/events/ChatEventManager.java b/src/cc/co/evenprime/bukkit/nocheat/events/ChatEventManager.java index 24a5230e..e84104d7 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/events/ChatEventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/events/ChatEventManager.java @@ -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 checks; diff --git a/src/cc/co/evenprime/bukkit/nocheat/events/EventManager.java b/src/cc/co/evenprime/bukkit/nocheat/events/EventManagerImpl.java similarity index 88% rename from src/cc/co/evenprime/bukkit/nocheat/events/EventManager.java rename to src/cc/co/evenprime/bukkit/nocheat/events/EventManagerImpl.java index 1b4a3152..acf04e59 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/events/EventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/events/EventManagerImpl.java @@ -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 getActiveChecks(ConfigurationCache cc) { return Collections.emptyList(); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/events/FightEventManager.java b/src/cc/co/evenprime/bukkit/nocheat/events/FightEventManager.java index 9f54aa5e..70f9f163 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/events/FightEventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/events/FightEventManager.java @@ -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 checks; diff --git a/src/cc/co/evenprime/bukkit/nocheat/events/MovingEventManager.java b/src/cc/co/evenprime/bukkit/nocheat/events/MovingEventManager.java index fb86ae0f..1f263576 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/events/MovingEventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/events/MovingEventManager.java @@ -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 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) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/events/TimedEventManager.java b/src/cc/co/evenprime/bukkit/nocheat/events/TimedEventManager.java index 13483fe0..508cc985 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/events/TimedEventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/events/TimedEventManager.java @@ -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 checks; private final Performance timedPerformance; - public final int taskId; + public int taskId = -1; public TimedEventManager(final NoCheat plugin) { super(plugin); checks = new ArrayList(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() { diff --git a/src/cc/co/evenprime/bukkit/nocheat/events/PlayerTeleportEventManager.java b/src/cc/co/evenprime/bukkit/nocheat/events/WorkaroundsEventManager.java similarity index 71% rename from src/cc/co/evenprime/bukkit/nocheat/events/PlayerTeleportEventManager.java rename to src/cc/co/evenprime/bukkit/nocheat/events/WorkaroundsEventManager.java index f77ab2cd..072f7431 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/events/PlayerTeleportEventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/events/WorkaroundsEventManager.java @@ -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 diff --git a/src/cc/co/evenprime/bukkit/nocheat/player/NoCheatPlayerImpl.java b/src/cc/co/evenprime/bukkit/nocheat/player/NoCheatPlayerImpl.java index 88453ff6..5cc1bdda 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/player/NoCheatPlayerImpl.java +++ b/src/cc/co/evenprime/bukkit/nocheat/player/NoCheatPlayerImpl.java @@ -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