mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-06-28 23:34:43 +02:00
Change IEntityAccessLastPositionAndLook to have get and set.
This commit is contained in:
parent
a0386c6648
commit
0726f9785e
|
@ -6,6 +6,7 @@ import org.bukkit.entity.Entity;
|
|||
|
||||
import fr.neatmonster.nocheatplus.NCPAPIProvider;
|
||||
import fr.neatmonster.nocheatplus.components.location.IEntityAccessLastPositionAndLook;
|
||||
import fr.neatmonster.nocheatplus.components.location.IGetPositionWithLook;
|
||||
import fr.neatmonster.nocheatplus.components.location.ISetPositionWithLook;
|
||||
import fr.neatmonster.nocheatplus.logging.Streams;
|
||||
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
|
||||
|
@ -42,16 +43,16 @@ public class ReflectEntityLastPositionAndLook extends ReflectGetHandleBase<Entit
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setPositionAndLook(final Entity entity, final ISetPositionWithLook location) {
|
||||
public void getPositionAndLook(final Entity entity, final ISetPositionWithLook location) {
|
||||
try {
|
||||
performSet(entity, location);
|
||||
performGet(entity, location);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().warning(Streams.STATUS, "Could not retrieve last location for Entity: " + entity.getClass().getName());
|
||||
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().warning(Streams.STATUS, "Could not retrieve last position and look for Entity: " + entity.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
private void performSet(final Entity entity, final ISetPositionWithLook location) throws IllegalArgumentException, IllegalAccessException {
|
||||
private void performGet(final Entity entity, final ISetPositionWithLook location) throws IllegalArgumentException, IllegalAccessException {
|
||||
final Object nmsObject = getHandle(entity);
|
||||
location.setX(lastX.getDouble(nmsObject));
|
||||
location.setY(lastY.getDouble(nmsObject));
|
||||
|
@ -60,6 +61,25 @@ public class ReflectEntityLastPositionAndLook extends ReflectGetHandleBase<Entit
|
|||
location.setPitch(lastPitch.getFloat(nmsObject));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPositionAndLook(Entity entity, IGetPositionWithLook location) {
|
||||
try {
|
||||
performSet(entity, location);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().warning(Streams.STATUS, "Could not set last position and look for Entity: " + entity.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
private void performSet(Entity entity, IGetPositionWithLook location) throws IllegalArgumentException, IllegalAccessException {
|
||||
final Object nmsObject = getHandle(entity);
|
||||
lastX.setDouble(nmsObject, location.getX());
|
||||
lastY.setDouble(nmsObject, location.getY());
|
||||
lastZ.setDouble(nmsObject, location.getZ());
|
||||
lastYaw.setFloat(nmsObject, location.getYaw());
|
||||
lastPitch.setFloat(nmsObject, location.getPitch());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fail() {
|
||||
throw new RuntimeException("Not available."); // To be caught internally.
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity;
|
|||
import org.bukkit.entity.Entity;
|
||||
|
||||
import fr.neatmonster.nocheatplus.components.location.IEntityAccessLastPositionAndLook;
|
||||
import fr.neatmonster.nocheatplus.components.location.IGetPositionWithLook;
|
||||
import fr.neatmonster.nocheatplus.components.location.ISetPositionWithLook;
|
||||
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
|
||||
|
||||
|
@ -19,7 +20,7 @@ public class EntityAccessLastPositionAndLook implements IEntityAccessLastPositio
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setPositionAndLook(final Entity entity, final ISetPositionWithLook location) {
|
||||
public void getPositionAndLook(final Entity entity, final ISetPositionWithLook location) {
|
||||
// TODO: Error handling / conventions.
|
||||
final net.minecraft.server.v1_9_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
location.setX(nmsEntity.lastX);
|
||||
|
@ -29,4 +30,14 @@ public class EntityAccessLastPositionAndLook implements IEntityAccessLastPositio
|
|||
location.setPitch(nmsEntity.lastPitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPositionAndLook(Entity entity, IGetPositionWithLook location) {
|
||||
final net.minecraft.server.v1_9_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
nmsEntity.lastX = location.getX();
|
||||
nmsEntity.lastY = location.getY();
|
||||
nmsEntity.lastZ = location.getZ();
|
||||
nmsEntity.lastYaw = location.getYaw();
|
||||
nmsEntity.lastPitch = location.getPitch();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity;
|
|||
import org.bukkit.entity.Entity;
|
||||
|
||||
import fr.neatmonster.nocheatplus.components.location.IEntityAccessLastPositionAndLook;
|
||||
import fr.neatmonster.nocheatplus.components.location.IGetPositionWithLook;
|
||||
import fr.neatmonster.nocheatplus.components.location.ISetPositionWithLook;
|
||||
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
|
||||
|
||||
|
@ -19,7 +20,7 @@ public class EntityAccessLastPositionAndLook implements IEntityAccessLastPositio
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setPositionAndLook(final Entity entity, final ISetPositionWithLook location) {
|
||||
public void getPositionAndLook(final Entity entity, final ISetPositionWithLook location) {
|
||||
// TODO: Error handling / conventions.
|
||||
final net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
location.setX(nmsEntity.lastX);
|
||||
|
@ -29,4 +30,14 @@ public class EntityAccessLastPositionAndLook implements IEntityAccessLastPositio
|
|||
location.setPitch(nmsEntity.lastPitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPositionAndLook(Entity entity, IGetPositionWithLook location) {
|
||||
final net.minecraft.server.v1_9_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
|
||||
nmsEntity.lastX = location.getX();
|
||||
nmsEntity.lastY = location.getY();
|
||||
nmsEntity.lastZ = location.getZ();
|
||||
nmsEntity.lastYaw = location.getYaw();
|
||||
nmsEntity.lastPitch = location.getPitch();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -296,7 +296,7 @@ public class VehicleChecks extends CheckListener {
|
|||
if (data.debug) {
|
||||
if (lastPosLook != null) {
|
||||
// Retrieve last pos.
|
||||
lastPosLook.setPositionAndLook(vehicle, usePos1);
|
||||
lastPosLook.getPositionAndLook(vehicle, usePos1);
|
||||
debug(player, "Last position is reported as: " + LocUtil.simpleFormat(usePos1));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,24 @@ import org.bukkit.entity.Entity;
|
|||
public interface IEntityAccessLastPositionAndLook {
|
||||
|
||||
/**
|
||||
* Fetch the last position with look from an entity.
|
||||
*
|
||||
* @param entity
|
||||
* @param location
|
||||
* This instance gets updated by last coordinates and looking
|
||||
* direction.
|
||||
*/
|
||||
public void setPositionAndLook(Entity entity, ISetPositionWithLook location);
|
||||
public void getPositionAndLook(Entity entity, ISetPositionWithLook location);
|
||||
|
||||
/**
|
||||
* Set the last position with look of an entity.
|
||||
*
|
||||
* @param entity
|
||||
* The entity for which to set last position and look.
|
||||
* @param location
|
||||
* The reference data to set the last position and look of the
|
||||
* entity to.
|
||||
*/
|
||||
public void setPositionAndLook(Entity entity, IGetPositionWithLook location);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user