mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-07 03:02:11 +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;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.MobEffectList;
|
||||
@ -56,9 +55,7 @@ public class CreativeFly extends Check {
|
||||
* the to
|
||||
* @return the location
|
||||
*/
|
||||
public Location check(final Player player, final MovingData data, final MovingConfig cc) {
|
||||
final PlayerLocation from = data.from;
|
||||
final PlayerLocation to = data.to;
|
||||
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) {
|
||||
|
||||
// If we have no setback, define one now.
|
||||
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
|
||||
// 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()"
|
||||
// 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(),
|
||||
@ -151,15 +152,4 @@ public class CreativeFly extends Check {
|
||||
data.setBack = to.getLocation();
|
||||
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
|
||||
* @return the location
|
||||
*/
|
||||
public Location check(final Player player, final MovingData data, final MovingConfig cc) {
|
||||
final PlayerLocation from = data.from;
|
||||
final PlayerLocation to = data.to;
|
||||
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) {
|
||||
// Take time once, first:
|
||||
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.ICheckData;
|
||||
import fr.neatmonster.nocheatplus.utilities.ActionFrequency;
|
||||
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
|
||||
|
||||
/*
|
||||
* M"""""`'"""`YM oo M""""""'YMM dP
|
||||
@ -129,11 +128,10 @@ public class MovingData extends ACheckData {
|
||||
public final ActionFrequency vDistCount = new ActionFrequency(3, 333);
|
||||
|
||||
// Locations shared between all checks.
|
||||
public final PlayerLocation from = new PlayerLocation();
|
||||
public Location ground;
|
||||
public Location setBack;
|
||||
public Location teleported;
|
||||
public final PlayerLocation to = new PlayerLocation();
|
||||
|
||||
|
||||
/**
|
||||
* Clear the data of the fly checks (not more-packets).
|
||||
|
@ -1,5 +1,8 @@
|
||||
package fr.neatmonster.nocheatplus.checks.moving;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@ -32,6 +35,7 @@ import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
|
||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
|
||||
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
|
||||
|
||||
/*
|
||||
* M"""""`'"""`YM oo
|
||||
@ -58,13 +62,21 @@ import fr.neatmonster.nocheatplus.utilities.BlockProperties;
|
||||
*/
|
||||
public class MovingListener implements Listener {
|
||||
|
||||
/** The no fall check. **/
|
||||
public final static NoFall noFall = new NoFall();
|
||||
private static final class LocationData{
|
||||
public final PlayerLocation from = new PlayerLocation();
|
||||
public final PlayerLocation to = new PlayerLocation();
|
||||
public final void cleanup(){
|
||||
from.cleanup();
|
||||
to.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
/** The instance of NoCheatPlus. */
|
||||
private final NoCheatPlus plugin = (NoCheatPlus) Bukkit.getPluginManager().getPlugin(
|
||||
"NoCheatPlus");
|
||||
|
||||
/** The no fall check. **/
|
||||
public final NoFall noFall = new NoFall();
|
||||
|
||||
/** The creative fly check. */
|
||||
private final CreativeFly creativeFly = new CreativeFly();
|
||||
|
||||
@ -77,7 +89,14 @@ public class MovingListener implements Listener {
|
||||
/** The survival fly check. */
|
||||
private final SurvivalFly survivalFly = new SurvivalFly();
|
||||
|
||||
/** The Passable (simple no-clip) check.*/
|
||||
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.
|
||||
@ -295,7 +314,15 @@ public class MovingListener implements Listener {
|
||||
final Location to = event.getTo();
|
||||
if (!from.getWorld().equals(to.getWorld()) || player.isInsideVehicle())
|
||||
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 MovingConfig cc = MovingConfig.getConfig(player);
|
||||
|
||||
@ -318,14 +345,15 @@ public class MovingListener implements Listener {
|
||||
data.verticalFreedom *= 0.93D;
|
||||
|
||||
final double yOnGround = cc.yOnGround;
|
||||
data.from.set(from, player, yOnGround);
|
||||
if (data.from.isOnGround())
|
||||
data.ground = data.from.getLocation();
|
||||
data.to.set(to, player, yOnGround);
|
||||
|
||||
pFrom.set(from, player, yOnGround);
|
||||
if (pFrom.isOnGround())
|
||||
data.ground = from; // pFrom.getLocation();
|
||||
pTo.set(to, player, yOnGround);
|
||||
|
||||
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.
|
||||
if (newTo != null);
|
||||
@ -334,15 +362,15 @@ public class MovingListener implements Listener {
|
||||
if ((cc.ignoreCreative || player.getGameMode() != GameMode.CREATIVE) && (cc.ignoreAllowFlight || !player.getAllowFlight())
|
||||
&& cc.survivalFlyCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_SURVIVALFLY) && !player.hasPermission(Permissions.MOVING_SURVIVALFLY)){
|
||||
// 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 (newTo == null && cc.noFallCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_NOFALL) && !player.hasPermission(Permissions.MOVING_NOFALL))
|
||||
// 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)){
|
||||
// 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();
|
||||
}
|
||||
@ -351,7 +379,7 @@ public class MovingListener implements Listener {
|
||||
if (newTo == null
|
||||
&& 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.
|
||||
newTo = morePackets.check(player, data, cc);
|
||||
newTo = morePackets.check(player, pFrom, pTo, data, cc);
|
||||
else
|
||||
// Otherwise we need to clear his data.
|
||||
data.clearMorePacketsData();
|
||||
@ -365,8 +393,8 @@ public class MovingListener implements Listener {
|
||||
data.teleported = newTo;
|
||||
}
|
||||
// Cleanup.
|
||||
data.from.cleanup();
|
||||
data.to.cleanup();
|
||||
locationData.cleanup();
|
||||
parkedInfo.add(locationData);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,9 +86,7 @@ public class NoFall extends Check {
|
||||
* @param to
|
||||
* the to
|
||||
*/
|
||||
public void check(final Player player, final MovingData data, final MovingConfig cc) {
|
||||
final PlayerLocation from = data.from;
|
||||
final PlayerLocation to = data.to;
|
||||
public void check(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) {
|
||||
|
||||
// Reset the on ground properties only if necessary.
|
||||
if (from.getY() > to.getY()){
|
||||
|
@ -1,7 +1,6 @@
|
||||
package fr.neatmonster.nocheatplus.checks.moving;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.MobEffectList;
|
||||
@ -91,10 +90,8 @@ public class SurvivalFly extends Check {
|
||||
* the to
|
||||
* @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 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.
|
||||
final boolean sprinting = player.isSprinting() && player.getFoodLevel() > 5;
|
||||
@ -332,7 +329,11 @@ public class SurvivalFly extends Check {
|
||||
data.survivalFlyJumpPhase = 0;
|
||||
// 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.
|
||||
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
|
||||
// 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(),
|
||||
@ -380,14 +381,4 @@ public class SurvivalFly extends Check {
|
||||
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