mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-20 06:21:23 +01:00
PlayerLocation: consistency + cleanup.
This commit is contained in:
parent
5d337b2b25
commit
9e6325eb9f
@ -71,6 +71,7 @@ public class Critical extends Check {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location.cleanup(); // Slightly better for gc.
|
||||||
|
|
||||||
return cancel;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
@ -392,6 +392,9 @@ public class MovingListener implements Listener {
|
|||||||
// Remember where we send the player to.
|
// Remember where we send the player to.
|
||||||
data.teleported = newTo;
|
data.teleported = newTo;
|
||||||
}
|
}
|
||||||
|
// Cleanup.
|
||||||
|
data.from.cleanup();
|
||||||
|
data.to.cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -272,6 +272,7 @@ public class SurvivalFly extends Check {
|
|||||||
// System.out.println("hDist: " + hDistance + " / " + hAllowedDistance + " , vDist: " + (to.getY() - from.getY()) + " ("+player.getVelocity().getY()+")" + " / " + vAllowedDistance + " / from passable: " + BlockProperties.isPassable(from));
|
// System.out.println("hDist: " + hDistance + " / " + hAllowedDistance + " , vDist: " + (to.getY() - from.getY()) + " ("+player.getVelocity().getY()+")" + " / " + vAllowedDistance + " / from passable: " + BlockProperties.isPassable(from));
|
||||||
// System.out.println(from.getY() +"(" + player.getLocation().getY() + ") -> " + to.getY()) ;
|
// System.out.println(from.getY() +"(" + player.getLocation().getY() + ") -> " + to.getY()) ;
|
||||||
if (result > 0D) {
|
if (result > 0D) {
|
||||||
|
// System.out.println(BlockProperties.isStairs(from.getTypeIdBelow()) + " / " + BlockProperties.isStairs(to.getTypeIdBelow()));
|
||||||
// Increment violation counter.
|
// Increment violation counter.
|
||||||
data.survivalFlyVL += result;
|
data.survivalFlyVL += result;
|
||||||
|
|
||||||
|
@ -234,6 +234,8 @@ public class BlockProperties {
|
|||||||
Material.CROPS,
|
Material.CROPS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static final PlayerLocation pLoc = new PlayerLocation();
|
||||||
|
|
||||||
protected static final long[] blockFlags = new long[maxBlocks];
|
protected static final long[] blockFlags = new long[maxBlocks];
|
||||||
|
|
||||||
/** Flag position for stairs. */
|
/** Flag position for stairs. */
|
||||||
@ -748,10 +750,11 @@ public class BlockProperties {
|
|||||||
*/
|
*/
|
||||||
public static boolean isOnGround(Player player, Location location) {
|
public static boolean isOnGround(Player player, Location location) {
|
||||||
// return blockId != 0 && net.minecraft.server.Block.byId[blockId].//.c();// d();
|
// return blockId != 0 && net.minecraft.server.Block.byId[blockId].//.c();// d();
|
||||||
final PlayerLocation loc = new PlayerLocation();
|
|
||||||
// Bit fat workaround, maybe put the object through from check listener ?
|
// Bit fat workaround, maybe put the object through from check listener ?
|
||||||
loc.set(location, player, 0.3);
|
pLoc.set(location, player, 0.3);
|
||||||
return loc.isOnGround();
|
final boolean onGround = pLoc.isOnGround();
|
||||||
|
pLoc.cleanup();
|
||||||
|
return onGround;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,6 +7,7 @@ import net.minecraft.server.WorldServer;
|
|||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.craftbukkit.CraftWorld;
|
import org.bukkit.craftbukkit.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -40,9 +41,6 @@ public class PlayerLocation {
|
|||||||
/** Type id of the block below. */
|
/** Type id of the block below. */
|
||||||
private Integer typeIdBelow;
|
private Integer typeIdBelow;
|
||||||
|
|
||||||
/** The original location. */
|
|
||||||
private Location location;
|
|
||||||
|
|
||||||
/** Is the player above stairs? */
|
/** Is the player above stairs? */
|
||||||
private Boolean aboveStairs;
|
private Boolean aboveStairs;
|
||||||
|
|
||||||
@ -73,11 +71,19 @@ public class PlayerLocation {
|
|||||||
/** The entity player. */
|
/** The entity player. */
|
||||||
private EntityPlayer entity;
|
private EntityPlayer entity;
|
||||||
|
|
||||||
/** The x, y and z coordinates. */
|
/** The block coordinates. */
|
||||||
private int x, y, z;
|
private int blockX, blockY, blockZ;
|
||||||
|
|
||||||
/** The world. */
|
/** The exact coordinates. */
|
||||||
private WorldServer world;
|
private double x,y,z;
|
||||||
|
|
||||||
|
private float yaw, pitch;
|
||||||
|
|
||||||
|
/** Bukkit world. */
|
||||||
|
private World world;
|
||||||
|
|
||||||
|
/** The worldServer. */
|
||||||
|
private WorldServer worldServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the location.
|
* Gets the location.
|
||||||
@ -85,34 +91,34 @@ public class PlayerLocation {
|
|||||||
* @return the location
|
* @return the location
|
||||||
*/
|
*/
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
return location;
|
return new Location(world, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the pitch.
|
* Gets the blockX.
|
||||||
*
|
*
|
||||||
* @return the pitch
|
* @return the blockX
|
||||||
*/
|
|
||||||
public float getPitch() {
|
|
||||||
return location.getPitch();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the x.
|
|
||||||
*
|
|
||||||
* @return the x
|
|
||||||
*/
|
*/
|
||||||
public double getX() {
|
public double getX() {
|
||||||
return location.getX();
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the y.
|
* Gets the boundY.
|
||||||
*
|
*
|
||||||
* @return the y
|
* @return the boundY
|
||||||
*/
|
*/
|
||||||
public double getY() {
|
public double getY() {
|
||||||
return location.getY();
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the blockZ.
|
||||||
|
*
|
||||||
|
* @return the blockZ
|
||||||
|
*/
|
||||||
|
public double getZ() {
|
||||||
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,16 +127,28 @@ public class PlayerLocation {
|
|||||||
* @return the yaw
|
* @return the yaw
|
||||||
*/
|
*/
|
||||||
public float getYaw() {
|
public float getYaw() {
|
||||||
return location.getYaw();
|
return yaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the z.
|
* Gets the pitch.
|
||||||
*
|
*
|
||||||
* @return the z
|
* @return the pitch
|
||||||
*/
|
*/
|
||||||
public double getZ() {
|
public float getPitch() {
|
||||||
return location.getZ();
|
return pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBlockX(){
|
||||||
|
return blockX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBlockY(){
|
||||||
|
return blockY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBlockZ(){
|
||||||
|
return blockZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -153,7 +171,7 @@ public class PlayerLocation {
|
|||||||
if (inLava == null) {
|
if (inLava == null) {
|
||||||
AxisAlignedBB boundingBoxLava = boundingBox.clone();
|
AxisAlignedBB boundingBoxLava = boundingBox.clone();
|
||||||
boundingBoxLava = boundingBoxLava.grow(-0.10000000149011612D, -0.40000000596046448D, -0.10000000149011612D);
|
boundingBoxLava = boundingBoxLava.grow(-0.10000000149011612D, -0.40000000596046448D, -0.10000000149011612D);
|
||||||
inLava = world.a(boundingBoxLava, net.minecraft.server.Material.LAVA);
|
inLava = worldServer.a(boundingBoxLava, net.minecraft.server.Material.LAVA);
|
||||||
}
|
}
|
||||||
return inLava;
|
return inLava;
|
||||||
}
|
}
|
||||||
@ -177,7 +195,7 @@ public class PlayerLocation {
|
|||||||
AxisAlignedBB boundingBoxWater = boundingBox.clone();
|
AxisAlignedBB boundingBoxWater = boundingBox.clone();
|
||||||
boundingBoxWater = boundingBoxWater.grow(0.0D, -0.40000000596046448D, 0.0D);
|
boundingBoxWater = boundingBoxWater.grow(0.0D, -0.40000000596046448D, 0.0D);
|
||||||
boundingBoxWater = boundingBoxWater.shrink(0.001D, 0.001D, 0.001D);
|
boundingBoxWater = boundingBoxWater.shrink(0.001D, 0.001D, 0.001D);
|
||||||
inWater = world.a(boundingBoxWater, net.minecraft.server.Material.WATER, entity);
|
inWater = worldServer.a(boundingBoxWater, net.minecraft.server.Material.WATER, entity);
|
||||||
}
|
}
|
||||||
return inWater;
|
return inWater;
|
||||||
}
|
}
|
||||||
@ -195,7 +213,7 @@ public class PlayerLocation {
|
|||||||
.floor(boundingBox.e - 0.001D); blockY++)
|
.floor(boundingBox.e - 0.001D); blockY++)
|
||||||
for (int blockZ = (int) Math.floor(boundingBox.c + 0.001D); blockZ <= (int) Math
|
for (int blockZ = (int) Math.floor(boundingBox.c + 0.001D); blockZ <= (int) Math
|
||||||
.floor(boundingBox.f - 0.001D); blockZ++)
|
.floor(boundingBox.f - 0.001D); blockZ++)
|
||||||
if (world.getTypeId(blockX, blockY, blockZ) == Material.WEB.getId())
|
if (worldServer.getTypeId(blockX, blockY, blockZ) == Material.WEB.getId())
|
||||||
inWeb = true;
|
inWeb = true;
|
||||||
if (inWeb == null)
|
if (inWeb == null)
|
||||||
inWeb = false;
|
inWeb = false;
|
||||||
@ -212,8 +230,15 @@ public class PlayerLocation {
|
|||||||
if (onGround == null) {
|
if (onGround == null) {
|
||||||
AxisAlignedBB boundingBoxGround = boundingBox.clone();
|
AxisAlignedBB boundingBoxGround = boundingBox.clone();
|
||||||
boundingBoxGround = boundingBoxGround.d(0D, -getyOnGround(), 0D);
|
boundingBoxGround = boundingBoxGround.d(0D, -getyOnGround(), 0D);
|
||||||
onGround = world.getCubes(entity, boundingBoxGround).size() > 0;
|
onGround = worldServer.getCubes(entity, boundingBoxGround).size() > 0;
|
||||||
}
|
}
|
||||||
|
// if (!onGround){
|
||||||
|
// double y = this.getY() - this.blockY;
|
||||||
|
// // TODO: maybe make an auxiliary method in BlockProperties (can stand on ? id, boundY)
|
||||||
|
// if (y < 0) y += 1D;
|
||||||
|
// final int id = getTypeId();
|
||||||
|
// if (y >= 0.5 && BlockProperties.isStairs(id)) onGround = true;
|
||||||
|
// }
|
||||||
return onGround;
|
return onGround;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +250,7 @@ public class PlayerLocation {
|
|||||||
public boolean isOnIce() {
|
public boolean isOnIce() {
|
||||||
if (onIce == null)
|
if (onIce == null)
|
||||||
if (entity.getBukkitEntity().isSneaking() || entity.getBukkitEntity().isBlocking())
|
if (entity.getBukkitEntity().isSneaking() || entity.getBukkitEntity().isBlocking())
|
||||||
onIce = world.getTypeId(x, (int) Math.floor(boundingBox.b - 0.1D), z) == Material.ICE.getId();
|
onIce = worldServer.getTypeId(blockX, (int) Math.floor(boundingBox.b - 0.1D), blockZ) == Material.ICE.getId();
|
||||||
else
|
else
|
||||||
onIce = getTypeIdBelow() == Material.ICE.getId();
|
onIce = getTypeIdBelow() == Material.ICE.getId();
|
||||||
return onIce;
|
return onIce;
|
||||||
@ -265,15 +290,20 @@ public class PlayerLocation {
|
|||||||
* the player
|
* the player
|
||||||
*/
|
*/
|
||||||
public void set(final Location location, final Player player, final double yFreedom) {
|
public void set(final Location location, final Player player, final double yFreedom) {
|
||||||
this.location = location;
|
|
||||||
|
|
||||||
entity = ((CraftPlayer) player).getHandle();
|
entity = ((CraftPlayer) player).getHandle();
|
||||||
boundingBox = entity.boundingBox.clone().d(location.getX() - entity.locX, location.getY() - entity.locY,
|
boundingBox = entity.boundingBox.clone().d(location.getX() - entity.locX, location.getY() - entity.locY,
|
||||||
location.getZ() - entity.locZ);
|
location.getZ() - entity.locZ);
|
||||||
x = (int) Math.floor(location.getX());
|
blockX = location.getBlockX();
|
||||||
y = (int) Math.floor(boundingBox.b);
|
blockY = location.getBlockY();
|
||||||
z = (int) Math.floor(location.getZ());
|
blockZ = location.getBlockZ();
|
||||||
world = ((CraftWorld) location.getWorld()).getHandle();
|
x = location.getX();
|
||||||
|
y = location.getY();
|
||||||
|
z = location.getZ();
|
||||||
|
yaw = location.getYaw();
|
||||||
|
pitch = location.getPitch();
|
||||||
|
world = location.getWorld();
|
||||||
|
worldServer = ((CraftWorld) world).getHandle();
|
||||||
|
|
||||||
typeId = typeIdBelow = null;
|
typeId = typeIdBelow = null;
|
||||||
aboveStairs = inLava = inWater = inWeb = onGround = onIce = onLadder = null;
|
aboveStairs = inLava = inWater = inWeb = onGround = onIce = onLadder = null;
|
||||||
@ -291,19 +321,19 @@ public class PlayerLocation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Integer getTypeId() {
|
public Integer getTypeId() {
|
||||||
if (typeId == null) typeId = world.getTypeId(x, y, z);
|
if (typeId == null) typeId = worldServer.getTypeId(blockX, blockY, blockZ);
|
||||||
return typeId;
|
return typeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Integer getTypeIdBelow() {
|
public Integer getTypeIdBelow() {
|
||||||
if (typeIdBelow == null) typeIdBelow = world.getTypeId(x, y - 1, z);
|
if (typeIdBelow == null) typeIdBelow = worldServer.getTypeId(blockX, blockY - 1, blockZ);
|
||||||
return typeIdBelow;
|
return typeIdBelow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isSameBlock(final PlayerLocation other) {
|
public final boolean isSameBlock(final PlayerLocation other) {
|
||||||
// Maybe make block coordinate fields later.
|
// Maybe make block coordinate fields later.
|
||||||
return Location.locToBlock(x) == Location.locToBlock(other.getX()) && Location.locToBlock(y) == Location.locToBlock(other.getY()) && Location.locToBlock(z) == Location.locToBlock(other.getZ());
|
return blockX == other.getBlockX() && blockZ == other.getBlockZ() && blockY == other.getBlockY();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -311,7 +341,16 @@ public class PlayerLocation {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public final IBlockAccess getBlockAccess() {
|
public final IBlockAccess getBlockAccess() {
|
||||||
return world;
|
return worldServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set some references to null.
|
||||||
|
*/
|
||||||
|
public void cleanup(){
|
||||||
|
world = null;
|
||||||
|
worldServer = null;
|
||||||
|
boundingBox = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user