Added packet teleportation methods (optional)
This commit is contained in:
parent
b1c0f69cb5
commit
69beb8efe2
2 changed files with 25 additions and 2 deletions
|
@ -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,10 +241,18 @@ 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);
|
||||||
|
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);
|
ent.teleport(loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
veiter = lift.getToMove().iterator();
|
veiter = lift.getToMove().iterator();
|
||||||
while (veiter.hasNext()) {
|
while (veiter.hasNext()) {
|
||||||
v10ent = veiter.next();
|
v10ent = veiter.next();
|
||||||
|
|
|
@ -13,3 +13,4 @@ DefaultSpeed: 16
|
||||||
DefaultRealistic: true
|
DefaultRealistic: true
|
||||||
DoorCloseTime: 100
|
DoorCloseTime: 100
|
||||||
CheckUpdates: true
|
CheckUpdates: true
|
||||||
|
PacketTeleport: false
|
Loading…
Reference in a new issue