Fixed NoFall damaging players switching from Creative to Survival mode.

This commit is contained in:
NeatMonster 2012-08-15 16:55:39 +02:00
parent 0f0e22a993
commit 90f16a2799
4 changed files with 100 additions and 109 deletions

View File

@ -35,72 +35,67 @@ public enum CheckType {
ALL, ALL,
BLOCKBREAK(BlockBreakConfig.factory, BlockBreakData.factory), BLOCKBREAK(BlockBreakConfig.factory, BlockBreakData.factory),
BLOCKBREAK_DIRECTION(BLOCKBREAK, "direction", Permissions.BLOCKBREAK_DIRECTION), BLOCKBREAK_DIRECTION(BLOCKBREAK, Permissions.BLOCKBREAK_DIRECTION),
BLOCKBREAK_FASTBREAK(BLOCKBREAK, "fastBreak", Permissions.BLOCKBREAK_FASTBREAK), BLOCKBREAK_FASTBREAK(BLOCKBREAK, Permissions.BLOCKBREAK_FASTBREAK),
BLOCKBREAK_NOSWING(BLOCKBREAK, "noSwing", Permissions.BLOCKBREAK_NOSWING), BLOCKBREAK_NOSWING(BLOCKBREAK, Permissions.BLOCKBREAK_NOSWING),
BLOCKBREAK_REACH(BLOCKBREAK, "reach", Permissions.BLOCKBREAK_REACH), BLOCKBREAK_REACH(BLOCKBREAK, Permissions.BLOCKBREAK_REACH),
BLOCKINTERACT(BlockInteractConfig.factory, BlockInteractData.factory), BLOCKINTERACT(BlockInteractConfig.factory, BlockInteractData.factory),
BLOCKINTERACT_DIRECTION(BLOCKINTERACT, "direction", Permissions.BLOCKINTERACT_DIRECTION), BLOCKINTERACT_DIRECTION(BLOCKINTERACT, Permissions.BLOCKINTERACT_DIRECTION),
BLOCKINTERACT_REACH(BLOCKINTERACT, "reach", Permissions.BLOCKINTERACT_REACH), BLOCKINTERACT_REACH(BLOCKINTERACT, Permissions.BLOCKINTERACT_REACH),
BLOCKPLACE(BlockPlaceConfig.factory, BlockPlaceData.factory), BLOCKPLACE(BlockPlaceConfig.factory, BlockPlaceData.factory),
BLOCKPLACE_DIRECTION(BLOCKPLACE, "direction", Permissions.BLOCKPLACE_DIRECTION), BLOCKPLACE_DIRECTION(BLOCKPLACE, Permissions.BLOCKPLACE_DIRECTION),
BLOCKPLACE_FASTPLACE(BLOCKPLACE, "fastPlace", Permissions.BLOCKPLACE_FASTPLACE), BLOCKPLACE_FASTPLACE(BLOCKPLACE, Permissions.BLOCKPLACE_FASTPLACE),
BLOCKPLACE_NOSWING(BLOCKPLACE, "noSwing", Permissions.BLOCKPLACE_NOSWING), BLOCKPLACE_NOSWING(BLOCKPLACE, Permissions.BLOCKPLACE_NOSWING),
BLOCKPLACE_REACH(BLOCKPLACE, "reach", Permissions.BLOCKBREAK_REACH), BLOCKPLACE_REACH(BLOCKPLACE, Permissions.BLOCKBREAK_REACH),
BLOCKPLACE_SPEED(BLOCKPLACE, "speed", Permissions.BLOCKPLACE_SPEED), BLOCKPLACE_SPEED(BLOCKPLACE, Permissions.BLOCKPLACE_SPEED),
CHAT(ChatConfig.factory, ChatData.factory), CHAT(ChatConfig.factory, ChatData.factory),
CHAT_COLOR(CHAT, "color", Permissions.CHAT_COLOR), CHAT_COLOR(CHAT, Permissions.CHAT_COLOR),
CHAT_NOPWNAGE(CHAT, "noPwnage", Permissions.CHAT_NOPWNAGE), CHAT_NOPWNAGE(CHAT, Permissions.CHAT_NOPWNAGE),
FIGHT(FightConfig.factory, FightData.factory), FIGHT(FightConfig.factory, FightData.factory),
FIGHT_ANGLE(FIGHT, "angle", Permissions.FIGHT_ANGLE), FIGHT_ANGLE(FIGHT, Permissions.FIGHT_ANGLE),
FIGHT_CRITICAL(FIGHT, "critical", Permissions.FIGHT_CRITICAL), FIGHT_CRITICAL(FIGHT, Permissions.FIGHT_CRITICAL),
FIGHT_DIRECTION(FIGHT, "direction", Permissions.FIGHT_DIRECTION), FIGHT_DIRECTION(FIGHT, Permissions.FIGHT_DIRECTION),
FIGHT_GODMODE(FIGHT, "godMode", Permissions.FIGHT_GODMODE), FIGHT_GODMODE(FIGHT, Permissions.FIGHT_GODMODE),
FIGHT_INSTANTHEAL(FIGHT, "instantHeal", Permissions.FIGHT_INSTANTHEAL), FIGHT_INSTANTHEAL(FIGHT, Permissions.FIGHT_INSTANTHEAL),
FIGHT_KNOCKBACK(FIGHT, "knockback", Permissions.FIGHT_KNOCKBACK), FIGHT_KNOCKBACK(FIGHT, Permissions.FIGHT_KNOCKBACK),
FIGHT_NOSWING(FIGHT, "noSwing", Permissions.FIGHT_NOSWING), FIGHT_NOSWING(FIGHT, Permissions.FIGHT_NOSWING),
FIGHT_REACH(FIGHT, "reach", Permissions.FIGHT_REACH), FIGHT_REACH(FIGHT, Permissions.FIGHT_REACH),
FIGHT_SPEED(FIGHT, "speed", Permissions.FIGHT_SPEED), FIGHT_SPEED(FIGHT, Permissions.FIGHT_SPEED),
INVENTORY(InventoryConfig.factory, InventoryData.factory), INVENTORY(InventoryConfig.factory, InventoryData.factory),
INVENTORY_DROP(INVENTORY, "drop", Permissions.INVENTORY_DROP), INVENTORY_DROP(INVENTORY, Permissions.INVENTORY_DROP),
INVENTORY_INSTANTBOW(INVENTORY, "instantBow", Permissions.INVENTORY_INSTANTBOW), INVENTORY_INSTANTBOW(INVENTORY, Permissions.INVENTORY_INSTANTBOW),
INVENTORY_INSTANTEAT(INVENTORY, "instantEat", Permissions.INVENTORY_INSTANTEAT), INVENTORY_INSTANTEAT(INVENTORY, Permissions.INVENTORY_INSTANTEAT),
MOVING(MovingConfig.factory, MovingData.factory), MOVING(MovingConfig.factory, MovingData.factory),
MOVING_CREATIVEFLY(MOVING, "creativeFly", Permissions.MOVING_CREATIVEFLY), MOVING_CREATIVEFLY(MOVING, Permissions.MOVING_CREATIVEFLY),
MOVING_MOREPACKETS(MOVING, "morePackets", Permissions.MOVING_MOREPACKETS), MOVING_MOREPACKETS(MOVING, Permissions.MOVING_MOREPACKETS),
MOVING_MOREPACKETSVEHICLE(MOVING, "morePacketsVehicle", Permissions.MOVING_MOREPACKETSVEHICLE), MOVING_MOREPACKETSVEHICLE(MOVING, Permissions.MOVING_MOREPACKETSVEHICLE),
MOVING_NOFALL(MOVING, "noFall", Permissions.MOVING_NOFALL), MOVING_NOFALL(MOVING, Permissions.MOVING_NOFALL),
MOVING_SURVIVALFLY(MOVING, "survivalFly", Permissions.MOVING_SURVIVALFLY), MOVING_SURVIVALFLY(MOVING, Permissions.MOVING_SURVIVALFLY),
UNKNOWN; UNKNOWN;
/** The group. */ /** The group. */
public final CheckType group; private CheckType parent = null;
/** The configFactory. */ /** The configFactory. */
public final CheckConfigFactory configFactory; private CheckConfigFactory configFactory = null;
/** The dataFactory. */ /** The dataFactory. */
public final CheckDataFactory dataFactory; private CheckDataFactory dataFactory = null;
/** The name. */
public final String name;
/** The permission. */ /** The permission. */
public final String permission; private String permission = null;
/** /**
* Instantiates a new check type. * Instantiates a new check type.
*/ */
private CheckType() { private CheckType() {}
this(null, null, null, null, null);
}
/** /**
* Instantiates a new check type. * Instantiates a new check type.
@ -111,59 +106,38 @@ public enum CheckType {
* the dataFactory * the dataFactory
*/ */
private CheckType(final CheckConfigFactory configFactory, final CheckDataFactory dataFactory) { private CheckType(final CheckConfigFactory configFactory, final CheckDataFactory dataFactory) {
this(null, configFactory, dataFactory, null, null); this.configFactory = configFactory;
this.dataFactory = dataFactory;
} }
/** /**
* Instantiates a new check type. * Instantiates a new check type.
* *
* @param group * @param parent
* the group * the parent
* @param configFactory
* the configFactory class
* @param dataFactory
* the dataFactory class
* @param name
* the name
* @param permission * @param permission
* the permission * the permission
*/ */
private CheckType(final CheckType group, final CheckConfigFactory configFactory, private CheckType(final CheckType parent, final String permission) {
final CheckDataFactory dataFactory, final String name, final String permission) { this.parent = parent;
this.group = group; configFactory = parent.getConfigFactory();
this.configFactory = configFactory; dataFactory = parent.getDataFactory();
this.dataFactory = dataFactory;
this.name = name;
this.permission = permission; this.permission = permission;
} }
/** /**
* Instantiates a new check type. * Gets the configFactory.
* *
* @param group * @return the configFactory
* the group
* @param name
* the name
* @param permission
* the permission
*/
private CheckType(final CheckType group, final String name, final String permission) {
this(group, group.getConfigFactory(), group.getDataFactory(), name, permission);
}
/**
* Gets the configFactory class.
*
* @return the configFactory class
*/ */
public CheckConfigFactory getConfigFactory() { public CheckConfigFactory getConfigFactory() {
return configFactory; return configFactory;
} }
/** /**
* Gets the dataFactory class. * Gets the dataFactory.
* *
* @return the dataFactory class * @return the dataFactory
*/ */
public CheckDataFactory getDataFactory() { public CheckDataFactory getDataFactory() {
return dataFactory; return dataFactory;
@ -175,7 +149,16 @@ public enum CheckType {
* @return the name * @return the name
*/ */
public String getName() { public String getName() {
return name; return toString().toLowerCase().replace("_", ".");
}
/**
* Gets the parent.
*
* @return the parent
*/
public CheckType getParent() {
return parent;
} }
/** /**

View File

@ -13,11 +13,10 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerBedEnterEvent; import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent; import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
@ -135,31 +134,6 @@ public class MovingListener implements Listener {
} }
} }
/**
* We listen to EntityDamage events the reset the fall distance when a damage is dealt.
*
* @param event
* the event
*/
@EventHandler(
priority = EventPriority.MONITOR, ignoreCancelled = false)
public void onEntityDamage(final EntityDamageEvent event) {
/*
* _____ _ _ _ ____
* | ____|_ __ | |_(_) |_ _ _ | _ \ __ _ _ __ ___ __ _ __ _ ___
* | _| | '_ \| __| | __| | | | | | | |/ _` | '_ ` _ \ / _` |/ _` |/ _ \
* | |___| | | | |_| | |_| |_| | | |_| | (_| | | | | | | (_| | (_| | __/
* |_____|_| |_|\__|_|\__|\__, | |____/ \__,_|_| |_| |_|\__,_|\__, |\___|
* |___/ |___/
*/
// Workaround fix attempt for NoFall multiple damage.
if (event.getCause() == DamageCause.FALL && event.getEntity() instanceof Player) {
final MovingData data = MovingData.getData((Player) event.getEntity());
// Simple model: once damage dealt the fall distance is reset.
data.noFallFallDistance = data.noFallNewFallDistance = 0D;
}
}
/** /**
* We listen to this event to prevent player from flying by sending bed leaving packets. * We listen to this event to prevent player from flying by sending bed leaving packets.
* *
@ -226,6 +200,36 @@ public class MovingListener implements Listener {
data.teleported = null; data.teleported = null;
data.clearFlyData(); data.clearFlyData();
data.clearMorePacketsData(); data.clearMorePacketsData();
data.resetNoFallDistances();
}
/**
* When a player changes his gamemode, all information related to the moving checks becomes invalid.
*
* @param event
* the event
*/
@EventHandler(
ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerGameModeChange(final PlayerGameModeChangeEvent event) {
/*
* ____ _ ____ __ __ _
* | _ \| | __ _ _ _ ___ _ __ / ___| __ _ _ __ ___ ___| \/ | ___ __| | ___
* | |_) | |/ _` | | | |/ _ \ '__| | | _ / _` | '_ ` _ \ / _ \ |\/| |/ _ \ / _` |/ _ \
* | __/| | (_| | |_| | __/ | | |_| | (_| | | | | | | __/ | | | (_) | (_| | __/
* |_| |_|\__,_|\__, |\___|_| \____|\__,_|_| |_| |_|\___|_| |_|\___/ \__,_|\___|
* |___/
* ____ _
* / ___| |__ __ _ _ __ __ _ ___
* | | | '_ \ / _` | '_ \ / _` |/ _ \
* | |___| | | | (_| | | | | (_| | __/
* \____|_| |_|\__,_|_| |_|\__, |\___|
* |___/
*/
final MovingData data = MovingData.getData(event.getPlayer());
data.clearFlyData();
data.clearMorePacketsData();
data.resetNoFallDistances();
} }
/** /**
@ -350,9 +354,11 @@ public class MovingListener implements Listener {
// If don't have a new location and if he is handled by the no fall check, execute it. // If don't have a new location and if he is handled by the no fall check, execute it.
if (newTo == null && noFall.isEnabled(player)) if (newTo == null && noFall.isEnabled(player))
noFall.check(player, from, to); noFall.check(player, from, to);
} else } else {
// He isn't handled by any fly check, clear his data. // He isn't handled by any fly check, clear his data.
data.clearFlyData(); data.clearFlyData();
data.resetNoFallDistances();
}
if (newTo == null && morePackets.isEnabled(player)) if (newTo == null && morePackets.isEnabled(player))
// If he hasn't been stopped by any other check and is handled by the more packets check, execute it. // If he hasn't been stopped by any other check and is handled by the more packets check, execute it.
@ -390,6 +396,7 @@ public class MovingListener implements Listener {
final MovingData data = MovingData.getData(event.getPlayer()); final MovingData data = MovingData.getData(event.getPlayer());
data.clearFlyData(); data.clearFlyData();
data.clearMorePacketsData(); data.clearMorePacketsData();
data.resetNoFallDistances();
} }
/** /**
@ -412,6 +419,7 @@ public class MovingListener implements Listener {
final MovingData data = MovingData.getData(event.getPlayer()); final MovingData data = MovingData.getData(event.getPlayer());
data.clearFlyData(); data.clearFlyData();
data.clearMorePacketsData(); data.clearMorePacketsData();
data.resetNoFallDistances();
} }
/** /**
@ -449,6 +457,7 @@ public class MovingListener implements Listener {
// Always drop data from fly checks, as it always loses its validity after teleports. Always! // Always drop data from fly checks, as it always loses its validity after teleports. Always!
data.teleported = null; data.teleported = null;
data.clearFlyData(); data.clearFlyData();
data.resetNoFallDistances();
} }
/** /**

View File

@ -75,8 +75,7 @@ public class NoFall extends Check {
else if (!data.noFallWasOnGroundServer && data.noFallOnGroundServer) { else if (!data.noFallWasOnGroundServer && data.noFallOnGroundServer) {
// If the difference between the fall distance recorded by Bukkit and NoCheatPlus is too big and the fall // If the difference between the fall distance recorded by Bukkit and NoCheatPlus is too big and the fall
// distance bigger than 2. // distance bigger than 2.
if (data.noFallFallDistance - player.getFallDistance() > Math.pow(1D, -3D) if (data.noFallFallDistance - player.getFallDistance() > 0.1D && (int) data.noFallFallDistance > 2) {
&& (int) data.noFallFallDistance > 2) {
// Add the difference to the violation level. // Add the difference to the violation level.
data.noFallVL += data.noFallFallDistance - player.getFallDistance(); data.noFallVL += data.noFallFallDistance - player.getFallDistance();

View File

@ -132,12 +132,12 @@ public final class NCPHookManager {
*/ */
private static boolean addToMappingsRecursively(final CheckType checkType, final CheckType refType, private static boolean addToMappingsRecursively(final CheckType checkType, final CheckType refType,
final NCPHook hook) { final NCPHook hook) {
if (refType.group == null) if (refType.getParent() == null)
return false; return false;
else if (refType.group == checkType) { else if (refType.getParent() == checkType) {
addToMapping(refType, hook); addToMapping(refType, hook);
return true; return true;
} else if (addToMappingsRecursively(checkType, refType.group, hook)) { } else if (addToMappingsRecursively(checkType, refType.getParent(), hook)) {
addToMapping(refType, hook); addToMapping(refType, hook);
return true; return true;
} else } else
@ -271,8 +271,8 @@ public final class NCPHookManager {
final StringBuilder builder = new StringBuilder(1024); final StringBuilder builder = new StringBuilder(1024);
builder.append("[NoCheatPlus] Hook " + getHookDescription(hook) + " encountered an unexpected exception:\n"); builder.append("[NoCheatPlus] Hook " + getHookDescription(hook) + " encountered an unexpected exception:\n");
builder.append("Processing: "); builder.append("Processing: ");
if (checkType.group != null) if (checkType.getParent() != null)
builder.append("Group " + checkType.group + " "); builder.append("Prent " + checkType.getParent() + " ");
builder.append("Check " + checkType); builder.append("Check " + checkType);
builder.append(" Player " + player.getName()); builder.append(" Player " + player.getName());
builder.append("\n"); builder.append("\n");