Added packet teleportation methods (optional)

This commit is contained in:
stijnb1234 2020-03-16 10:27:26 +01:00
parent b1c0f69cb5
commit 69beb8efe2
2 changed files with 25 additions and 2 deletions

View file

@ -17,11 +17,25 @@ import org.bukkit.entity.Entity;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Method;
import java.util.*; import java.util.*;
import java.util.function.Supplier;
/** The MoveLift runnable, used for moving a lift. */ /** The MoveLift runnable, used for moving a lift. */
public class MoveLift implements Runnable { public class MoveLift implements Runnable {
/* Packet teleportation method */
private final Method[] methods = ((Supplier<Method[]>) () -> {
try {
Method getHandle = Class.forName(Bukkit.getServer().getClass().getPackage().getName() + ".entity.CraftEntity").getDeclaredMethod("getHandle");
return new Method[] {
getHandle, getHandle.getReturnType().getDeclaredMethod("setPositionRotation", double.class, double.class, double.class, float.class, float.class)
};
} catch (Exception ex) {
return null;
}
}).get();
private final String liftName; private final String liftName;
private final int ft; private final int ft;
@ -227,7 +241,15 @@ public class MoveLift implements Runnable {
if (by && loc.getBlockX() == lib.getX() && loc.getBlockZ() == lib.getZ()) { if (by && loc.getBlockX() == lib.getX() && loc.getBlockZ() == lib.getZ()) {
loc.setY(loc.getY() + 1); loc.setY(loc.getY() + 1);
ent.teleport(loc); if (V10LiftPlugin.getSConfig().getFile().getBoolean("PacketTeleport")) {
try {
methods[1].invoke(methods[0].invoke(ent), loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
} catch (Exception ex) {
Bukkit.getLogger().severe("[V10Lift] PacketTeleportation is enabled, but couldn't get the method.");
}
} else {
ent.teleport(loc);
}
} }
} }
} }

View file

@ -12,4 +12,5 @@ MasterRepairAmount: 10
DefaultSpeed: 16 DefaultSpeed: 16
DefaultRealistic: true DefaultRealistic: true
DoorCloseTime: 100 DoorCloseTime: 100
CheckUpdates: true CheckUpdates: true
PacketTeleport: false