No longer check arrows and other projectiles, even if aimed at other

players - More verbose data for "playerinfo" command - fix
potential dupe bug
This commit is contained in:
Evenprime 2011-12-04 17:40:40 +01:00
parent 8dbfc3893c
commit 2f5a726494
13 changed files with 128 additions and 34 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cc.co.evenprime.bukkit</groupId>
<artifactId>NoCheat</artifactId>
<version>2.20</version>
<version>2.20a</version>
<packaging>jar</packaging>
<name>NoCheat</name>
<properties>

View File

@ -41,6 +41,8 @@ public class FlyingCheck extends MovingCheck {
final double zDistance = to.z - from.z;
final double horizontalDistance = Math.sqrt((xDistance * xDistance + zDistance * zDistance));
double resultHoriz = 0;
double resultVert = 0;
double result = 0;
PreciseLocation newToLocation = null;
@ -50,32 +52,42 @@ public class FlyingCheck extends MovingCheck {
speedLimitHorizontal *= player.getSpeedAmplifier();
result += Math.max(0.0D, horizontalDistance - data.horizFreedom - speedLimitHorizontal);
resultHoriz = Math.max(0.0D, horizontalDistance - data.horizFreedom - speedLimitHorizontal);
boolean sprinting = player.isSprinting();
data.bunnyhopdelay--;
// Did he go too far?
if(result > 0 && sprinting) {
if(resultHoriz > 0 && sprinting) {
// Try to treat it as a the "bunnyhop" problem
if(data.bunnyhopdelay <= 0 && result < 0.4D) {
if(data.bunnyhopdelay <= 0 && resultHoriz < 0.4D) {
data.bunnyhopdelay = 3;
result = 0;
resultHoriz = 0;
}
}
resultHoriz *= 100;
// super simple, just check distance compared to max distance
result += Math.max(0.0D, yDistance - data.vertFreedom - ccmoving.flyingSpeedLimitVertical);
result = result * 100;
resultVert = Math.max(0.0D, yDistance - data.vertFreedom - ccmoving.flyingSpeedLimitVertical) * 100;
result = resultHoriz + resultVert;
if(result > 0) {
// Increment violation counter
data.runflyVL += result;
data.runflyTotalVL += result;
data.runflyFailed++;
if(resultHoriz > 0) {
data.runflyRunningTotalVL += resultHoriz;
data.runflyRunningFailed++;
}
if(resultVert > 0) {
data.runflyFlyingTotalVL += resultVert;
data.runflyFlyingFailed++;
}
boolean cancel = executeActions(player, ccmoving.flyingActions.getActions(data.runflyVL));

View File

@ -77,8 +77,20 @@ public class RunningCheck extends MovingCheck {
// Increment violation counter
data.runflyVL += result;
data.runflyTotalVL += result;
data.runflyFailed++;
if(data.checknamesuffix.equals("sneaking")) {
data.runflySneakingTotalVL += result;
data.runflySneakingFailed++;
} else if(data.checknamesuffix.equals("swimming")) {
data.runflySwimmingTotalVL += result;
data.runflySwimmingFailed++;
} else if(data.checknamesuffix.equals("vertical")) {
data.runflyFlyingTotalVL += result;
data.runflyFlyingFailed++;
} else {
data.runflyRunningTotalVL += result;
data.runflyRunningFailed++;
}
boolean cancel = executeActions(player, cc.actions.getActions(data.runflyVL));

View File

@ -30,11 +30,14 @@ public abstract class Configuration {
private final static OptionNode DEBUG = new OptionNode("debug", ROOT, DataType.PARENT);
public final static OptionNode DEBUG_SHOWACTIVECHECKS = new OptionNode("showactivechecks", DEBUG, DataType.BOOLEAN);
public static final OptionNode DEBUG_COMPATIBILITY = new OptionNode("compatibility", DEBUG, DataType.BOOLEAN);
public final static OptionNode DEBUG_COMPATIBILITY = new OptionNode("compatibility", DEBUG, DataType.BOOLEAN);
private final static OptionNode EMERGENCYFIX = new OptionNode("emergencyfix", ROOT, DataType.PARENT);
public final static OptionNode EMERGENCYFIX_ENFORCEPLAYERDEATH = new OptionNode("enforceplayerdeath", EMERGENCYFIX, DataType.BOOLEAN);
public final static OptionNode INVENTORY = new OptionNode("inventory", ROOT, DataType.PARENT);
public final static OptionNode INVENTORY_CLOSEOBEFORETELEPORTS = new OptionNode("closebeforeteleports", INVENTORY, DataType.BOOLEAN);
private final static OptionNode MOVING = new OptionNode("moving", ROOT, DataType.PARENT);
public final static OptionNode MOVING_CHECK = new OptionNode("check", MOVING, DataType.BOOLEAN);
public final static OptionNode MOVING_IDENTIFYCREATIVEMODE = new OptionNode("identifycreativemode", MOVING, DataType.BOOLEAN);
@ -87,10 +90,10 @@ public abstract class Configuration {
public final static OptionNode BLOCKPLACE_REACH_ACTIONS = new OptionNode("actions", BLOCKPLACE_REACH, DataType.ACTIONLIST);
private final static OptionNode BLOCKPLACE_DIRECTION = new OptionNode("direction", BLOCKPLACE, DataType.PARENT);
public static final OptionNode BLOCKPLACE_DIRECTION_CHECK = new OptionNode("check", BLOCKPLACE_DIRECTION, DataType.BOOLEAN); ;
public static final OptionNode BLOCKPLACE_DIRECTION_PENALTYTIME = new OptionNode("penaltytime", BLOCKPLACE_DIRECTION, DataType.INTEGER);
public final static OptionNode BLOCKPLACE_DIRECTION_CHECK = new OptionNode("check", BLOCKPLACE_DIRECTION, DataType.BOOLEAN); ;
public final static OptionNode BLOCKPLACE_DIRECTION_PENALTYTIME = new OptionNode("penaltytime", BLOCKPLACE_DIRECTION, DataType.INTEGER);
public final static OptionNode BLOCKPLACE_DIRECTION_PRECISION = new OptionNode("precision", BLOCKPLACE_DIRECTION, DataType.INTEGER);
public static final OptionNode BLOCKPLACE_DIRECTION_ACTIONS = new OptionNode("actions", BLOCKPLACE_DIRECTION, DataType.ACTIONLIST);
public final static OptionNode BLOCKPLACE_DIRECTION_ACTIONS = new OptionNode("actions", BLOCKPLACE_DIRECTION, DataType.ACTIONLIST);
private final static OptionNode CHAT = new OptionNode("chat", ROOT, DataType.PARENT);
public final static OptionNode CHAT_CHECK = new OptionNode("check", CHAT, DataType.BOOLEAN);
@ -103,8 +106,8 @@ public abstract class Configuration {
public final static OptionNode CHAT_SPAM_ACTIONS = new OptionNode("actions", CHAT_SPAM, DataType.ACTIONLIST);
private final static OptionNode CHAT_EMPTY = new OptionNode("empty", CHAT, DataType.PARENT);
public static final OptionNode CHAT_EMPTY_CHECK = new OptionNode("check", CHAT_EMPTY, DataType.BOOLEAN);
public static final OptionNode CHAT_EMPTY_ACTIONS = new OptionNode("actions", CHAT_EMPTY, DataType.ACTIONLIST);
public final static OptionNode CHAT_EMPTY_CHECK = new OptionNode("check", CHAT_EMPTY, DataType.BOOLEAN);
public final static OptionNode CHAT_EMPTY_ACTIONS = new OptionNode("actions", CHAT_EMPTY, DataType.ACTIONLIST);
private final static OptionNode FIGHT = new OptionNode("fight", ROOT, DataType.PARENT);
public final static OptionNode FIGHT_CHECK = new OptionNode("check", FIGHT, DataType.BOOLEAN);
@ -116,12 +119,12 @@ public abstract class Configuration {
public final static OptionNode FIGHT_DIRECTION_ACTIONS = new OptionNode("actions", FIGHT_DIRECTION, DataType.ACTIONLIST);
private final static OptionNode FIGHT_SELFHIT = new OptionNode("selfhit", FIGHT, DataType.PARENT);
public static final OptionNode FIGHT_SELFHIT_CHECK = new OptionNode("check", FIGHT_SELFHIT, DataType.BOOLEAN);
public final static OptionNode FIGHT_SELFHIT_CHECK = new OptionNode("check", FIGHT_SELFHIT, DataType.BOOLEAN);
public final static OptionNode FIGHT_SELFHIT_ACTIONS = new OptionNode("actions", FIGHT_SELFHIT, DataType.ACTIONLIST);
private final static OptionNode FIGHT_NOSWING = new OptionNode("noswing", FIGHT, DataType.PARENT);
public static final OptionNode FIGHT_NOSWING_CHECK = new OptionNode("check", FIGHT_NOSWING, DataType.BOOLEAN);
public static final OptionNode FIGHT_NOSWING_ACTIONS = new OptionNode("actions", FIGHT_NOSWING, DataType.ACTIONLIST);
public final static OptionNode FIGHT_NOSWING_CHECK = new OptionNode("check", FIGHT_NOSWING, DataType.BOOLEAN);
public final static OptionNode FIGHT_NOSWING_ACTIONS = new OptionNode("actions", FIGHT_NOSWING, DataType.ACTIONLIST);
private final Map<OptionNode, Object> values;
private final Configuration defaults;

View File

@ -40,6 +40,11 @@ public class DefaultConfiguration extends Configuration {
setValue(EMERGENCYFIX_ENFORCEPLAYERDEATH, true);
}
/*** INVENTORY ***/
{
setValue(INVENTORY_CLOSEOBEFORETELEPORTS, true);
}
/*** MOVING ***/
{
setValue(MOVING_CHECK, true);

View File

@ -29,6 +29,8 @@ public class Explainations {
set(Configuration.EMERGENCYFIX_ENFORCEPLAYERDEATH, "Fix a bug that prevents people from really dying, causing them to not drop XP,\n and still being able to fight, place/destroy blocks etc. in an invulnerable state.");
set(Configuration.INVENTORY_CLOSEOBEFORETELEPORTS, "Close inventory screens of players before they get teleported, preventing creation of real or fake duplicates.");
set(Configuration.MOVING_CHECK, "If true, do various checks on PlayerMove events.");
set(Configuration.MOVING_IDENTIFYCREATIVEMODE, "If true, NoCheat will automatically identify if players are in creative mode and will allow them to fly, avoid fall damage etc.");

View File

@ -0,0 +1,14 @@
package cc.co.evenprime.bukkit.nocheat.config.cache;
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
public class CCInventory {
public final boolean closebeforeteleports;
public CCInventory(Configuration data) {
closebeforeteleports = data.getBoolean(Configuration.INVENTORY_CLOSEOBEFORETELEPORTS);
}
}

View File

@ -19,12 +19,11 @@ public class ConfigurationCache {
public final CCDebug debug;
public final CCFight fight;
public final boolean emergencyfix;
public final CCInventory inventory;
/**
* Instantiate a config cache and populate it with the data of a
* Config tree (and its parent tree)
*
* @param data
*/
public ConfigurationCache(Configuration data, Logger worldSpecificFileLogger) {
@ -35,6 +34,7 @@ public class ConfigurationCache {
logging = new CCLogging(data, worldSpecificFileLogger);
debug = new CCDebug(data);
fight = new CCFight(data);
inventory = new CCInventory(data);
emergencyfix = data.getBoolean(Configuration.EMERGENCYFIX_ENFORCEPLAYERDEATH);
}

View File

@ -21,12 +21,13 @@ public class FightData extends Data {
public Entity damagee;
public boolean armswung = true;
public boolean skipNext = false;
@Override
public void collectData(Map<String, Object> map) {
map.put("fight.direction.vl", (int)directionTotalVL);
map.put("fight.selfhit.vl", (int)selfhitTotalVL);
map.put("fight.noswing.vl", (int)noswingTotalVL);
map.put("fight.direction.vl", (int) directionTotalVL);
map.put("fight.selfhit.vl", (int) selfhitTotalVL);
map.put("fight.noswing.vl", (int) noswingTotalVL);
map.put("fight.direction.failed", directionFailed);
map.put("fight.selfhit.failed", selfhitFailed);
map.put("fight.noswing.failed", noswingFailed);

View File

@ -8,8 +8,18 @@ import java.util.Map;
public class MovingData extends Data {
public double runflyVL;
public double runflyTotalVL;
public int runflyFailed;
public double runflyRunningTotalVL;
public int runflyRunningFailed;
public double runflyFlyingTotalVL;
public int runflyFlyingFailed;
public double runflySneakingTotalVL;
public int runflySneakingFailed;
public double runflySwimmingTotalVL;
public int runflySwimmingFailed;
public double nofallVL;
public double nofallTotalVL;
@ -71,10 +81,17 @@ public class MovingData extends Data {
@Override
public void collectData(Map<String, Object> map) {
map.put("moving.runfly.vl", (int) runflyTotalVL);
map.put("moving.running.vl", (int) runflyRunningTotalVL);
map.put("moving.flying.vl", (int) runflyFlyingTotalVL);
map.put("moving.sneaking.vl", (int) runflySneakingTotalVL);
map.put("moving.swimming.vl", (int) runflySwimmingTotalVL);
map.put("moving.nofall.vl", (int) nofallTotalVL);
map.put("moving.morepackets.vl", (int) morePacketsTotalVL);
map.put("moving.runfly.failed", runflyFailed);
map.put("moving.running.failed", runflyRunningFailed);
map.put("moving.flying.failed", runflyFlyingFailed);
map.put("moving.sneaking.failed", runflySneakingFailed);
map.put("moving.swimming.failed", runflySwimmingFailed);
map.put("moving.nofall.failed", nofallFailed);
map.put("moving.morepackets.failed", morePacketsFailed);
}

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
@ -14,7 +15,6 @@ import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerChatEvent;
@ -271,10 +271,11 @@ public abstract class EventManagerImpl implements EventManager {
final EntityDamageByEntityEvent event2 = (EntityDamageByEntityEvent) event;
// Only if player really attacked other player
if(!(event2.getDamager() instanceof Player) || !event2.getCause().equals(DamageCause.ENTITY_ATTACK))
// Only handle if attack done by a player directly or inderictly with a projectile
if(!(event2.getDamager() instanceof Player) && !((event2.getDamager() instanceof Projectile) && ((Projectile)event2.getDamager()).getShooter() instanceof Player)) {
return;
}
/** Only now measure time and dispatch event */
if(measureTime != null && measureTime.isEnabled()) {
final long startTime = System.nanoTime();

View File

@ -6,6 +6,7 @@ import java.util.List;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -42,7 +43,23 @@ public class FightEventManager extends EventManagerImpl {
@Override
protected void handleEntityDamageByEntityEvent(final EntityDamageByEntityEvent event, final Priority priority) {
// Our event listener already checked if that cast is valid
// Two possibilities: The player attacked directly, or by projectile
// We already made sure in the calling method that it is one of those
// two
if(event.getDamager() instanceof Projectile) {
final Player damager = (Player) ((Projectile) event.getDamager()).getShooter();
final NoCheatPlayer player = plugin.getPlayer(damager);
final FightData data = player.getData().fight;
// Skip the next damage event, because it is with high probability
// the same as this one
data.skipNext = true;
return;
}
// Other possibility, the player is the damager directly
final Player damager = (Player) event.getDamager();
final NoCheatPlayer player = plugin.getPlayer(damager);
@ -54,6 +71,12 @@ public class FightEventManager extends EventManagerImpl {
final FightData data = player.getData().fight;
if(data.skipNext) {
data.skipNext = false;
return;
}
// We are still interested in this event type
boolean cancelled = false;
data.damagee = ((CraftEntity) event.getEntity()).getHandle();

View File

@ -1,5 +1,6 @@
package cc.co.evenprime.bukkit.nocheat.events;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
@ -69,6 +70,9 @@ public class WorkaroundsEventManager extends EventManagerImpl {
}
private void handleTeleportation(final Player player) {
if(plugin.getPlayer(player).getConfiguration().inventory.closebeforeteleports && player instanceof CraftPlayer) {
((CraftPlayer) player).getHandle().closeInventory();
}
plugin.clearCriticalData(player.getName());
}
}