mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-31 03:41:22 +01:00
Change PlayerLocation use (reduces memory footprint).
This commit is contained in:
parent
167d442501
commit
24eede78fe
@ -1,7 +1,6 @@
|
|||||||
package fr.neatmonster.nocheatplus.checks.moving;
|
package fr.neatmonster.nocheatplus.checks.moving;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityPlayer;
|
import net.minecraft.server.EntityPlayer;
|
||||||
import net.minecraft.server.MobEffectList;
|
import net.minecraft.server.MobEffectList;
|
||||||
@ -56,9 +55,7 @@ public class CreativeFly extends Check {
|
|||||||
* the to
|
* the to
|
||||||
* @return the location
|
* @return the location
|
||||||
*/
|
*/
|
||||||
public Location check(final Player player, final MovingData data, final MovingConfig cc) {
|
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) {
|
||||||
final PlayerLocation from = data.from;
|
|
||||||
final PlayerLocation to = data.to;
|
|
||||||
|
|
||||||
// If we have no setback, define one now.
|
// If we have no setback, define one now.
|
||||||
if (data.setBack == null)
|
if (data.setBack == null)
|
||||||
@ -134,7 +131,11 @@ public class CreativeFly extends Check {
|
|||||||
|
|
||||||
// Execute whatever actions are associated with this check and the violation level and find out if we
|
// Execute whatever actions are associated with this check and the violation level and find out if we
|
||||||
// should cancel the event.
|
// should cancel the event.
|
||||||
if (executeActions(player, data.creativeFlyVL, result, cc.creativeFlyActions))
|
final ViolationData vd = new ViolationData(this, player, data.creativeFlyVL, result, cc.creativeFlyActions);
|
||||||
|
vd.setParameter(ParameterName.LOCATION_FROM, String.format(Locale.US, "%.2f, %.2f, %.2f", from.getX(), from.getY(), from.getZ()));
|
||||||
|
vd.setParameter(ParameterName.LOCATION_TO, String.format(Locale.US, "%.2f, %.2f, %.2f", to.getX(), to.getY(), to.getZ()));
|
||||||
|
vd.setParameter(ParameterName.DISTANCE, String.format(Locale.US, "%.2f", to.getLocation().distance(from.getLocation())));
|
||||||
|
if (executeActions(vd))
|
||||||
// Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()"
|
// Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()"
|
||||||
// to allow the player to look somewhere else despite getting pulled back by NoCheatPlus.
|
// to allow the player to look somewhere else despite getting pulled back by NoCheatPlus.
|
||||||
return new Location(player.getWorld(), data.setBack.getX(), data.setBack.getY(),
|
return new Location(player.getWorld(), data.setBack.getX(), data.setBack.getY(),
|
||||||
@ -151,15 +152,4 @@ public class CreativeFly extends Check {
|
|||||||
data.setBack = to.getLocation();
|
data.setBack = to.getLocation();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Map<ParameterName, String> getParameterMap(final ViolationData violationData) {
|
|
||||||
final MovingData data = MovingData.getData(violationData.player);
|
|
||||||
final Map<ParameterName, String> parameters = super.getParameterMap(violationData);
|
|
||||||
parameters.put(ParameterName.LOCATION_FROM, String.format(Locale.US, "%.2f, %.2f, %.2f", data.from.getX(), data.from.getY(), data.from.getZ()));
|
|
||||||
parameters.put(ParameterName.LOCATION_TO, String.format(Locale.US, "%.2f, %.2f, %.2f", data.to.getX(), data.to.getY(), data.to.getZ()));
|
|
||||||
parameters.put(ParameterName.DISTANCE, String.format(Locale.US, "%.2f", data.to.getLocation().subtract(data.from.getLocation()).length()));
|
|
||||||
return parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,7 @@ public class MorePackets extends Check {
|
|||||||
* the to
|
* the to
|
||||||
* @return the location
|
* @return the location
|
||||||
*/
|
*/
|
||||||
public Location check(final Player player, final MovingData data, final MovingConfig cc) {
|
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) {
|
||||||
final PlayerLocation from = data.from;
|
|
||||||
final PlayerLocation to = data.to;
|
|
||||||
// Take time once, first:
|
// Take time once, first:
|
||||||
final long time = System.currentTimeMillis();
|
final long time = System.currentTimeMillis();
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ import fr.neatmonster.nocheatplus.checks.access.ACheckData;
|
|||||||
import fr.neatmonster.nocheatplus.checks.access.CheckDataFactory;
|
import fr.neatmonster.nocheatplus.checks.access.CheckDataFactory;
|
||||||
import fr.neatmonster.nocheatplus.checks.access.ICheckData;
|
import fr.neatmonster.nocheatplus.checks.access.ICheckData;
|
||||||
import fr.neatmonster.nocheatplus.utilities.ActionFrequency;
|
import fr.neatmonster.nocheatplus.utilities.ActionFrequency;
|
||||||
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* M"""""`'"""`YM oo M""""""'YMM dP
|
* M"""""`'"""`YM oo M""""""'YMM dP
|
||||||
@ -129,11 +128,10 @@ public class MovingData extends ACheckData {
|
|||||||
public final ActionFrequency vDistCount = new ActionFrequency(3, 333);
|
public final ActionFrequency vDistCount = new ActionFrequency(3, 333);
|
||||||
|
|
||||||
// Locations shared between all checks.
|
// Locations shared between all checks.
|
||||||
public final PlayerLocation from = new PlayerLocation();
|
|
||||||
public Location ground;
|
public Location ground;
|
||||||
public Location setBack;
|
public Location setBack;
|
||||||
public Location teleported;
|
public Location teleported;
|
||||||
public final PlayerLocation to = new PlayerLocation();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the data of the fly checks (not more-packets).
|
* Clear the data of the fly checks (not more-packets).
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package fr.neatmonster.nocheatplus.checks.moving;
|
package fr.neatmonster.nocheatplus.checks.moving;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -32,6 +35,7 @@ import fr.neatmonster.nocheatplus.checks.CheckType;
|
|||||||
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
|
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
|
||||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||||
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
|
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
|
||||||
|
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* M"""""`'"""`YM oo
|
* M"""""`'"""`YM oo
|
||||||
@ -58,12 +62,20 @@ import fr.neatmonster.nocheatplus.utilities.BlockProperties;
|
|||||||
*/
|
*/
|
||||||
public class MovingListener implements Listener {
|
public class MovingListener implements Listener {
|
||||||
|
|
||||||
/** The no fall check. **/
|
private static final class LocationData{
|
||||||
public final static NoFall noFall = new NoFall();
|
public final PlayerLocation from = new PlayerLocation();
|
||||||
|
public final PlayerLocation to = new PlayerLocation();
|
||||||
|
public final void cleanup(){
|
||||||
|
from.cleanup();
|
||||||
|
to.cleanup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** The instance of NoCheatPlus. */
|
/** The instance of NoCheatPlus. */
|
||||||
private final NoCheatPlus plugin = (NoCheatPlus) Bukkit.getPluginManager().getPlugin(
|
private final NoCheatPlus plugin = (NoCheatPlus) Bukkit.getPluginManager().getPlugin(
|
||||||
"NoCheatPlus");
|
"NoCheatPlus");
|
||||||
|
/** The no fall check. **/
|
||||||
|
public final NoFall noFall = new NoFall();
|
||||||
|
|
||||||
/** The creative fly check. */
|
/** The creative fly check. */
|
||||||
private final CreativeFly creativeFly = new CreativeFly();
|
private final CreativeFly creativeFly = new CreativeFly();
|
||||||
@ -77,8 +89,15 @@ public class MovingListener implements Listener {
|
|||||||
/** The survival fly check. */
|
/** The survival fly check. */
|
||||||
private final SurvivalFly survivalFly = new SurvivalFly();
|
private final SurvivalFly survivalFly = new SurvivalFly();
|
||||||
|
|
||||||
|
/** The Passable (simple no-clip) check.*/
|
||||||
private final Passable passable = new Passable();
|
private final Passable passable = new Passable();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unused instances.<br>
|
||||||
|
* TODO: Not sure this is needed by contract, might be better due to cascading events in case of actions.
|
||||||
|
*/
|
||||||
|
private final List<LocationData> parkedInfo = new ArrayList<LocationData>(10);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A workaround for players placing blocks below them getting pushed off the block by NoCheatPlus.
|
* A workaround for players placing blocks below them getting pushed off the block by NoCheatPlus.
|
||||||
*
|
*
|
||||||
@ -296,6 +315,14 @@ public class MovingListener implements Listener {
|
|||||||
if (!from.getWorld().equals(to.getWorld()) || player.isInsideVehicle())
|
if (!from.getWorld().equals(to.getWorld()) || player.isInsideVehicle())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Use existent locations if possible.
|
||||||
|
final LocationData locationData;
|
||||||
|
final PlayerLocation pFrom, pTo;
|
||||||
|
if (parkedInfo.isEmpty()) locationData = new LocationData();
|
||||||
|
|
||||||
|
else locationData = parkedInfo.remove(parkedInfo.size() - 1);
|
||||||
|
pFrom = locationData.from;
|
||||||
|
pTo = locationData.to;
|
||||||
final MovingData data = MovingData.getData(player);
|
final MovingData data = MovingData.getData(player);
|
||||||
final MovingConfig cc = MovingConfig.getConfig(player);
|
final MovingConfig cc = MovingConfig.getConfig(player);
|
||||||
|
|
||||||
@ -318,14 +345,15 @@ public class MovingListener implements Listener {
|
|||||||
data.verticalFreedom *= 0.93D;
|
data.verticalFreedom *= 0.93D;
|
||||||
|
|
||||||
final double yOnGround = cc.yOnGround;
|
final double yOnGround = cc.yOnGround;
|
||||||
data.from.set(from, player, yOnGround);
|
|
||||||
if (data.from.isOnGround())
|
pFrom.set(from, player, yOnGround);
|
||||||
data.ground = data.from.getLocation();
|
if (pFrom.isOnGround())
|
||||||
data.to.set(to, player, yOnGround);
|
data.ground = from; // pFrom.getLocation();
|
||||||
|
pTo.set(to, player, yOnGround);
|
||||||
|
|
||||||
Location newTo = null;
|
Location newTo = null;
|
||||||
|
|
||||||
if (passable.isEnabled(player)) newTo = passable.check(player, data.from, data.to, data, cc);
|
if (passable.isEnabled(player)) newTo = passable.check(player, pFrom, pTo, data, cc);
|
||||||
|
|
||||||
// Optimized checking, giving creativefly permission precedence over survivalfly.
|
// Optimized checking, giving creativefly permission precedence over survivalfly.
|
||||||
if (newTo != null);
|
if (newTo != null);
|
||||||
@ -334,15 +362,15 @@ public class MovingListener implements Listener {
|
|||||||
if ((cc.ignoreCreative || player.getGameMode() != GameMode.CREATIVE) && (cc.ignoreAllowFlight || !player.getAllowFlight())
|
if ((cc.ignoreCreative || player.getGameMode() != GameMode.CREATIVE) && (cc.ignoreAllowFlight || !player.getAllowFlight())
|
||||||
&& cc.survivalFlyCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_SURVIVALFLY) && !player.hasPermission(Permissions.MOVING_SURVIVALFLY)){
|
&& cc.survivalFlyCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_SURVIVALFLY) && !player.hasPermission(Permissions.MOVING_SURVIVALFLY)){
|
||||||
// If he is handled by the survival fly check, execute it.
|
// If he is handled by the survival fly check, execute it.
|
||||||
newTo = survivalFly.check(player, data, cc);
|
newTo = survivalFly.check(player, pFrom, pTo, data, cc);
|
||||||
// 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 && cc.noFallCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_NOFALL) && !player.hasPermission(Permissions.MOVING_NOFALL))
|
if (newTo == null && cc.noFallCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_NOFALL) && !player.hasPermission(Permissions.MOVING_NOFALL))
|
||||||
// NOTE: noFall might set yOnGround for the positions.
|
// NOTE: noFall might set yOnGround for the positions.
|
||||||
noFall.check(player, data, cc);
|
noFall.check(player, pFrom, pTo, data, cc);
|
||||||
}
|
}
|
||||||
else if (cc.creativeFlyCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_CREATIVEFLY)){
|
else if (cc.creativeFlyCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_CREATIVEFLY)){
|
||||||
// If the player is handled by the creative fly check, execute it.
|
// If the player is handled by the creative fly check, execute it.
|
||||||
newTo = creativeFly.check(player, data, cc);
|
newTo = creativeFly.check(player, pFrom, pTo, data, cc);
|
||||||
}
|
}
|
||||||
else data.clearFlyData();
|
else data.clearFlyData();
|
||||||
}
|
}
|
||||||
@ -351,7 +379,7 @@ public class MovingListener implements Listener {
|
|||||||
if (newTo == null
|
if (newTo == null
|
||||||
&& cc.morePacketsCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_MOREPACKETS) && !player.hasPermission(Permissions.MOVING_MOREPACKETS))
|
&& cc.morePacketsCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_MOREPACKETS) && !player.hasPermission(Permissions.MOVING_MOREPACKETS))
|
||||||
// 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.
|
||||||
newTo = morePackets.check(player, data, cc);
|
newTo = morePackets.check(player, pFrom, pTo, data, cc);
|
||||||
else
|
else
|
||||||
// Otherwise we need to clear his data.
|
// Otherwise we need to clear his data.
|
||||||
data.clearMorePacketsData();
|
data.clearMorePacketsData();
|
||||||
@ -365,8 +393,8 @@ public class MovingListener implements Listener {
|
|||||||
data.teleported = newTo;
|
data.teleported = newTo;
|
||||||
}
|
}
|
||||||
// Cleanup.
|
// Cleanup.
|
||||||
data.from.cleanup();
|
locationData.cleanup();
|
||||||
data.to.cleanup();
|
parkedInfo.add(locationData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,9 +86,7 @@ public class NoFall extends Check {
|
|||||||
* @param to
|
* @param to
|
||||||
* the to
|
* the to
|
||||||
*/
|
*/
|
||||||
public void check(final Player player, final MovingData data, final MovingConfig cc) {
|
public void check(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) {
|
||||||
final PlayerLocation from = data.from;
|
|
||||||
final PlayerLocation to = data.to;
|
|
||||||
|
|
||||||
// Reset the on ground properties only if necessary.
|
// Reset the on ground properties only if necessary.
|
||||||
if (from.getY() > to.getY()){
|
if (from.getY() > to.getY()){
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package fr.neatmonster.nocheatplus.checks.moving;
|
package fr.neatmonster.nocheatplus.checks.moving;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import net.minecraft.server.EntityPlayer;
|
import net.minecraft.server.EntityPlayer;
|
||||||
import net.minecraft.server.MobEffectList;
|
import net.minecraft.server.MobEffectList;
|
||||||
@ -91,10 +90,8 @@ public class SurvivalFly extends Check {
|
|||||||
* the to
|
* the to
|
||||||
* @return the location
|
* @return the location
|
||||||
*/
|
*/
|
||||||
public Location check(final Player player, final MovingData data, final MovingConfig cc) {
|
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) {
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
final PlayerLocation from = data.from;
|
|
||||||
final PlayerLocation to = data.to;
|
|
||||||
|
|
||||||
// A player is considered sprinting if the flag is set and if he has enough food level.
|
// A player is considered sprinting if the flag is set and if he has enough food level.
|
||||||
final boolean sprinting = player.isSprinting() && player.getFoodLevel() > 5;
|
final boolean sprinting = player.isSprinting() && player.getFoodLevel() > 5;
|
||||||
@ -332,7 +329,11 @@ public class SurvivalFly extends Check {
|
|||||||
data.survivalFlyJumpPhase = 0;
|
data.survivalFlyJumpPhase = 0;
|
||||||
// If the other plugins haven't decided to cancel the execution of the actions, then do it. If one of the
|
// If the other plugins haven't decided to cancel the execution of the actions, then do it. If one of the
|
||||||
// actions was a cancel, cancel it.
|
// actions was a cancel, cancel it.
|
||||||
if (executeActions(player, data.survivalFlyVL, result, MovingConfig.getConfig(player).survivalFlyActions)){
|
final ViolationData vd = new ViolationData(this, player, data.survivalFlyVL, result, cc.survivalFlyActions);
|
||||||
|
vd.setParameter(ParameterName.LOCATION_FROM, String.format(Locale.US, "%.2f, %.2f, %.2f", from.getX(), from.getY(), from.getZ()));
|
||||||
|
vd.setParameter(ParameterName.LOCATION_TO, String.format(Locale.US, "%.2f, %.2f, %.2f", to.getX(), to.getY(), to.getZ()));
|
||||||
|
vd.setParameter(ParameterName.DISTANCE, String.format(Locale.US, "%.2f", to.getLocation().distance(from.getLocation())));
|
||||||
|
if (executeActions(vd)){
|
||||||
// Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()" to
|
// Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()" to
|
||||||
// allow the player to look somewhere else despite getting pulled back by NoCheatPlus.
|
// allow the player to look somewhere else despite getting pulled back by NoCheatPlus.
|
||||||
return new Location(player.getWorld(), data.setBack.getX(), data.setBack.getY(), data.setBack.getZ(),
|
return new Location(player.getWorld(), data.setBack.getX(), data.setBack.getY(), data.setBack.getZ(),
|
||||||
@ -380,14 +381,4 @@ public class SurvivalFly extends Check {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Map<ParameterName, String> getParameterMap(final ViolationData violationData) {
|
|
||||||
final MovingData data = MovingData.getData(violationData.player);
|
|
||||||
final Map<ParameterName, String> parameters = super.getParameterMap(violationData);
|
|
||||||
parameters.put(ParameterName.LOCATION_FROM, String.format(Locale.US, "%.2f, %.2f, %.2f", data.from.getX(), data.from.getY(), data.from.getZ()));
|
|
||||||
parameters.put(ParameterName.LOCATION_TO, String.format(Locale.US, "%.2f, %.2f, %.2f", data.to.getX(), data.to.getY(), data.to.getZ()));
|
|
||||||
parameters.put(ParameterName.DISTANCE, String.format(Locale.US, "%.2f", data.to.getLocation().subtract(data.from.getLocation()).length()));
|
|
||||||
return parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user