Change IEntityAccessLastPositionAndLook to have get and set.

This commit is contained in:
asofold 2016-05-16 14:02:17 +02:00
parent a0386c6648
commit 0726f9785e
5 changed files with 62 additions and 8 deletions

View File

@ -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.

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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));
}
}

View File

@ -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);
}