Potential fix for all those "player can no longer do X" problems

This commit is contained in:
Evenprime 2011-11-18 02:34:33 +01:00
parent 8401d26d6d
commit d502f66472
11 changed files with 33 additions and 27 deletions

View File

@ -3,7 +3,7 @@ name: NoCheat
author: Evenprime
main: cc.co.evenprime.bukkit.nocheat.NoCheat
version: 2.16b
version: 2.16c
commands:
nocheat:

View File

@ -187,8 +187,8 @@ public class NoCheat extends JavaPlugin {
}
public NoCheatPlayer getPlayer(String playerName) {
return players.getPlayer(playerName);
public NoCheatPlayer getPlayer(Player player) {
return players.getPlayer(player);
}
}

View File

@ -6,6 +6,8 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.player.NoCheatPlayerImpl;
@ -29,18 +31,19 @@ public class PlayerManager {
* Get a data object of the specified class. If none is stored yet, create
* one.
*/
public NoCheatPlayer getPlayer(String playerName) {
public NoCheatPlayer getPlayer(Player player) {
NoCheatPlayerImpl p = this.players.get(playerName);
NoCheatPlayerImpl p = this.players.get(player.getName());
if(p == null) {
// TODO: Differentiate which player"type" should be created, e.g.
// based on bukkit version
p = new NoCheatPlayerImpl(playerName, plugin, new BaseData());
this.players.put(playerName, p);
p = new NoCheatPlayerImpl(player, plugin, new BaseData());
this.players.put(player.getName(), p);
}
p.setLastUsedTime(System.currentTimeMillis());
p.refresh(player);
return p;
}

View File

@ -51,7 +51,7 @@ public class BlockBreakEventManager extends EventManager {
boolean cancelled = false;
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
final CCBlockBreak cc = player.getConfiguration().blockbreak;
if(!cc.check || player.hasPermission(Permissions.BLOCKBREAK)) {
@ -81,7 +81,7 @@ public class BlockBreakEventManager extends EventManager {
return;
// Get the player-specific stored data that applies here
final BlockBreakData data = plugin.getPlayer(event.getPlayer().getName()).getData().blockbreak;
final BlockBreakData data = plugin.getPlayer(event.getPlayer()).getData().blockbreak;
// Remember this location. We ignore block breaks in the block-break
// direction check that are insta-breaks
@ -90,7 +90,7 @@ public class BlockBreakEventManager extends EventManager {
@Override
protected void handlePlayerAnimationEvent(final PlayerAnimationEvent event, final Priority priority) {
plugin.getPlayer(event.getPlayer().getName()).getData().blockbreak.armswung = true;
plugin.getPlayer(event.getPlayer()).getData().blockbreak.armswung = true;
}
public List<String> getActiveChecks(ConfigurationCache cc) {

View File

@ -47,7 +47,7 @@ public class BlockPlaceEventManager extends EventManager {
boolean cancelled = false;
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
final CCBlockPlace cc = player.getConfiguration().blockplace;
if(!cc.check || player.hasPermission(Permissions.BLOCKPLACE)) {

View File

@ -44,7 +44,7 @@ public class ChatEventManager extends EventManager {
boolean cancelled = false;
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
final CCChat cc = player.getConfiguration().chat;
if(!cc.check || player.hasPermission(Permissions.CHAT)) {

View File

@ -45,7 +45,7 @@ public class FightEventManager extends EventManager {
// Our event listener already checked if that cast is valid
final Player damager = (Player) event.getDamager();
final NoCheatPlayer player = plugin.getPlayer(damager.getName());
final NoCheatPlayer player = plugin.getPlayer(damager);
final CCFight cc = player.getConfiguration().fight;
if(!cc.check || player.hasPermission(Permissions.FIGHT)) {
@ -73,7 +73,7 @@ public class FightEventManager extends EventManager {
@Override
protected void handlePlayerAnimationEvent(final PlayerAnimationEvent event, final Priority priority) {
plugin.getPlayer(event.getPlayer().getName()).getData().fight.armswung = true;
plugin.getPlayer(event.getPlayer()).getData().fight.armswung = true;
}
public List<String> getActiveChecks(ConfigurationCache cc) {

View File

@ -55,7 +55,7 @@ public class MovingEventManager extends EventManager {
@Override
protected void handleBlockPlaceEvent(final BlockPlaceEvent event, final Priority priority) {
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
// Get the player-specific stored data that applies here
final MovingData data = player.getData().moving;
@ -91,7 +91,7 @@ public class MovingEventManager extends EventManager {
}
// Get the world-specific configuration that applies here
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
final CCMoving cc = player.getConfiguration().moving;
if(!cc.check || player.hasPermission(Permissions.MOVING)) {
@ -147,7 +147,7 @@ public class MovingEventManager extends EventManager {
@Override
protected void handlePlayerVelocityEvent(final PlayerVelocityEvent event, final Priority priority) {
final MovingData data = plugin.getPlayer(event.getPlayer().getName()).getData().moving;
final MovingData data = plugin.getPlayer(event.getPlayer()).getData().moving;
final Vector v = event.getVelocity();

View File

@ -41,7 +41,7 @@ public class PlayerTeleportEventManager extends EventManager {
if(!event.isCancelled())
return;
NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
final MovingData data = player.getData().moving;
if(data.teleportTo.isSet() && data.teleportTo.equals(event.getTo())) {
@ -72,7 +72,7 @@ public class PlayerTeleportEventManager extends EventManager {
// Fix a common mistake that other developers make (cancelling move
// events is crazy, rather set the target location to the from location
if(plugin.getPlayer(event.getPlayer().getName()).getConfiguration().debug.overrideIdiocy) {
if(plugin.getPlayer(event.getPlayer()).getConfiguration().debug.overrideIdiocy) {
event.setCancelled(false);
event.setTo(event.getFrom().clone());
}
@ -81,7 +81,7 @@ public class PlayerTeleportEventManager extends EventManager {
@Override
protected void handlePlayerToggleSprintEvent(final PlayerToggleSprintEvent event, final Priority priority) {
if(event.isCancelled() && event.isSprinting()) {
if(plugin.getPlayer(event.getPlayer().getName()).getConfiguration().debug.overrideIdiocy)
if(plugin.getPlayer(event.getPlayer()).getConfiguration().debug.overrideIdiocy)
event.setCancelled(false);
}
}

View File

@ -8,6 +8,7 @@ import java.util.List;
import net.minecraft.server.EntityPlayer;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
@ -79,7 +80,7 @@ public class TimedEventManager extends EventManager {
if(performanceCheck)
nanoTimeStart = System.nanoTime();
handleEvent(plugin.getPlayer(p.name));
handleEvent(plugin.getPlayer((Player)p.getBukkitEntity()));
// store performance time
if(performanceCheck)

View File

@ -3,7 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.player;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
@ -15,20 +14,23 @@ import cc.co.evenprime.bukkit.nocheat.data.BaseData;
public class NoCheatPlayerImpl implements NoCheatPlayer {
private final Player player;
private Player player;
private final NoCheat plugin;
private final BaseData data;
private long lastUsedTime;
public NoCheatPlayerImpl(String playerName, NoCheat plugin, BaseData data) {
this.player = Bukkit.getServer().getPlayer(playerName);
public NoCheatPlayerImpl(Player player, NoCheat plugin, BaseData data) {
this.player = player;
this.plugin = plugin;
this.data = data;
this.lastUsedTime = System.currentTimeMillis();
}
public void refresh(Player player) {
this.player = player;
}
public boolean hasPermission(String permission) {
if(permission == null) {
System.out.println("NoCheat: Warning, asked for null permission");
@ -69,7 +71,7 @@ public class NoCheatPlayerImpl implements NoCheatPlayer {
EntityPlayer ep = ((CraftPlayer) player).getHandle();
if(ep.hasEffect(MobEffectList.FASTER_MOVEMENT)) {
// Taken directly from Minecraft code, should work
return 1.0F + 0.2F * (float)(ep.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1);
return 1.0F + 0.2F * (float) (ep.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1);
} else {
return 1.0F;
}