Temporary fix for handling of player death in minecraft until bukkit

gets patched
This commit is contained in:
Evenprime 2011-11-28 14:12:05 +01:00
parent a3479b0f58
commit 345b835e5d
8 changed files with 58 additions and 23 deletions

View File

@ -7,7 +7,14 @@ import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
@ -19,7 +26,7 @@ import cc.co.evenprime.bukkit.nocheat.debug.ActiveCheckPrinter;
import cc.co.evenprime.bukkit.nocheat.debug.LagMeasureTask;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType;
import cc.co.evenprime.bukkit.nocheat.events.BlockBreakEventManager;
import cc.co.evenprime.bukkit.nocheat.events.BlockPlaceEventManager;
import cc.co.evenprime.bukkit.nocheat.events.ChatEventManager;
@ -127,6 +134,34 @@ public class NoCheat extends JavaPlugin {
// Then print a list of active checks per world
ActiveCheckPrinter.printActiveChecks(this, eventManagers);
if(mcVersion == MCVersion.MC100) {
// Tell the server admin that we are activating a workaround
log.logToConsole(LogLevel.LOW, "[NoCheat] Activating temporary bugfix for broken player death handling of minecraft.");
// Activate workaround, reset death ticks when a player dies
getServer().getPluginManager().registerEvent(Type.ENTITY_DEATH, new EntityListener() {
@Override
public void onEntityDeath(EntityDeathEvent event) {
if(event.getEntity() instanceof CraftPlayer) {
CraftPlayer player = (CraftPlayer) event.getEntity();
player.getHandle().deathTicks = 0;
}
}
}, Priority.Monitor, this);
// Activate workaround, reset death ticks when a player spawns
getServer().getPluginManager().registerEvent(Type.PLAYER_RESPAWN, new PlayerListener() {
@Override
public void onPlayerRespawn(PlayerRespawnEvent event) {
if(event.getPlayer() instanceof CraftPlayer) {
CraftPlayer player = (CraftPlayer) event.getPlayer();
player.getHandle().deathTicks = 0;
}
}
}, Priority.Monitor, this);
}
// Tell the server admin that we finished loading NoCheat now
log.logToConsole(LogLevel.LOW, "[NoCheat] version [" + this.getDescription().getVersion() + "] is enabled.");
}
@ -147,7 +182,7 @@ public class NoCheat extends JavaPlugin {
players.clearCriticalData(playerName);
}
public Performance getPerformance(Type type) {
public Performance getPerformance(EventType type) {
return performance.get(type);
}

View File

@ -13,7 +13,7 @@ import org.bukkit.permissions.Permission;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType;
public class CommandHandler {
@ -120,7 +120,7 @@ public class CommandHandler {
long totalTime = 0;
for(Type type : Type.values()) {
for(EventType type : EventType.values()) {
Performance p = plugin.getPerformance(type);
long total = p.getTotalTime();

View File

@ -5,22 +5,22 @@ import java.util.Map;
public class PerformanceManager {
public enum Type {
public enum EventType {
BLOCKBREAK, BLOCKDAMAGE, BLOCKPLACE, CHAT, MOVING, VELOCITY, FIGHT, TIMED
}
private final Map<Type, Performance> map;
private final Map<EventType, Performance> map;
public PerformanceManager() {
map = new HashMap<Type, Performance>();
map = new HashMap<EventType, Performance>();
for(Type type : Type.values()) {
for(EventType type : EventType.values()) {
map.put(type, new Performance(true));
}
}
public Performance get(Type type) {
public Performance get(EventType type) {
return map.get(type);
}
}

View File

@ -20,7 +20,7 @@ import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockBreak;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType;
/**
* Central location to listen to player-interact events and dispatch them to
@ -41,8 +41,8 @@ public class BlockBreakEventManager extends EventManagerImpl {
this.checks.add(new ReachCheck(plugin));
this.checks.add(new DirectionCheck(plugin));
registerListener(Event.Type.BLOCK_BREAK, Priority.Lowest, true, plugin.getPerformance(Type.BLOCKBREAK));
registerListener(Event.Type.BLOCK_DAMAGE, Priority.Monitor, true, plugin.getPerformance(Type.BLOCKDAMAGE));
registerListener(Event.Type.BLOCK_BREAK, Priority.Lowest, true, plugin.getPerformance(EventType.BLOCKBREAK));
registerListener(Event.Type.BLOCK_DAMAGE, Priority.Monitor, true, plugin.getPerformance(EventType.BLOCKDAMAGE));
registerListener(Event.Type.PLAYER_ANIMATION, Priority.Monitor, false, null);
}

View File

@ -17,7 +17,7 @@ import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockPlace;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType;
/**
* Central location to listen to Block-related events and dispatching them to
@ -36,7 +36,7 @@ public class BlockPlaceEventManager extends EventManagerImpl {
this.checks.add(new ReachCheck(plugin));
this.checks.add(new DirectionCheck(plugin));
registerListener(Event.Type.BLOCK_PLACE, Priority.Lowest, true, plugin.getPerformance(Type.BLOCKPLACE));
registerListener(Event.Type.BLOCK_PLACE, Priority.Lowest, true, plugin.getPerformance(EventType.BLOCKPLACE));
}
@Override

View File

@ -18,7 +18,7 @@ import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCChat;
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;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType;
public class ChatEventManager extends EventManagerImpl {
@ -32,8 +32,8 @@ public class ChatEventManager extends EventManagerImpl {
this.checks.add(new EmptyCheck(plugin));
this.checks.add(new SpamCheck(plugin));
registerListener(Event.Type.PLAYER_CHAT, Priority.Lowest, true, plugin.getPerformance(Type.CHAT));
registerListener(Event.Type.PLAYER_COMMAND_PREPROCESS, Priority.Lowest, true, plugin.getPerformance(Type.CHAT));
registerListener(Event.Type.PLAYER_CHAT, Priority.Lowest, true, plugin.getPerformance(EventType.CHAT));
registerListener(Event.Type.PLAYER_COMMAND_PREPROCESS, Priority.Lowest, true, plugin.getPerformance(EventType.CHAT));
}
@Override

View File

@ -21,7 +21,7 @@ import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCFight;
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;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType;
public class FightEventManager extends EventManagerImpl {
@ -35,7 +35,7 @@ public class FightEventManager extends EventManagerImpl {
this.checks.add(new SelfhitCheck(plugin));
this.checks.add(new DirectionCheck(plugin));
registerListener(Event.Type.ENTITY_DAMAGE, Priority.Lowest, true, plugin.getPerformance(Type.FIGHT));
registerListener(Event.Type.ENTITY_DAMAGE, Priority.Lowest, true, plugin.getPerformance(EventType.FIGHT));
registerListener(Event.Type.PLAYER_ANIMATION, Priority.Monitor, false, null);
}

View File

@ -26,7 +26,7 @@ import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType;
/**
* The only place that listens to and modifies player_move events if necessary
@ -48,9 +48,9 @@ public class MovingEventManager extends EventManagerImpl {
checks.add(new RunflyCheck(plugin));
checks.add(new MorePacketsCheck(plugin));
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_MOVE, Priority.Lowest, true, plugin.getPerformance(EventType.MOVING));
registerListener(Event.Type.PLAYER_VELOCITY, Priority.Monitor, true, plugin.getPerformance(EventType.VELOCITY));
registerListener(Event.Type.BLOCK_PLACE, Priority.Monitor, true, plugin.getPerformance(EventType.BLOCKPLACE));
registerListener(Event.Type.PLAYER_TELEPORT, Priority.Highest, false, null);
}