From 69beb8efe202eb623f58271a0cd997ca25fcc78d Mon Sep 17 00:00:00 2001 From: stijnb1234 Date: Mon, 16 Mar 2020 10:27:26 +0100 Subject: [PATCH] Added packet teleportation methods (optional) --- .../V10Lift/API/Runnables/MoveLift.java | 24 ++++++++++++++++++- src/main/resources/config.yml | 3 ++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java index 37a85df..1831093 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java @@ -17,11 +17,25 @@ import org.bukkit.entity.Entity; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import java.lang.reflect.Method; import java.util.*; +import java.util.function.Supplier; /** The MoveLift runnable, used for moving a lift. */ public class MoveLift implements Runnable { + /* Packet teleportation method */ + private final Method[] methods = ((Supplier) () -> { + 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 int ft; @@ -227,7 +241,15 @@ public class MoveLift implements Runnable { if (by && loc.getBlockX() == lib.getX() && loc.getBlockZ() == lib.getZ()) { 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); + } } } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f919a69..fa3ddc9 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -12,4 +12,5 @@ MasterRepairAmount: 10 DefaultSpeed: 16 DefaultRealistic: true DoorCloseTime: 100 -CheckUpdates: true \ No newline at end of file +CheckUpdates: true +PacketTeleport: false \ No newline at end of file