2017-12-30 08:36:36 +01:00
|
|
|
package net.citizensnpcs.util;
|
|
|
|
|
2019-04-25 09:43:44 +02:00
|
|
|
import java.lang.invoke.MethodHandle;
|
|
|
|
import java.lang.invoke.MethodHandles;
|
2017-12-30 08:36:36 +01:00
|
|
|
import java.lang.reflect.Field;
|
2018-10-25 10:48:15 +02:00
|
|
|
import java.lang.reflect.Method;
|
2017-12-30 08:36:36 +01:00
|
|
|
import java.lang.reflect.Modifier;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.List;
|
2023-02-13 13:32:20 +01:00
|
|
|
import java.util.function.Consumer;
|
|
|
|
import java.util.function.Supplier;
|
2023-03-14 20:37:05 +01:00
|
|
|
import java.util.stream.Collectors;
|
2017-12-30 08:36:36 +01:00
|
|
|
|
2023-02-13 13:32:20 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2017-12-30 08:36:36 +01:00
|
|
|
import org.bukkit.Location;
|
2021-11-21 15:12:17 +01:00
|
|
|
import org.bukkit.Material;
|
2023-06-12 15:20:51 +02:00
|
|
|
import org.bukkit.attribute.Attribute;
|
|
|
|
import org.bukkit.attribute.AttributeInstance;
|
2017-12-30 08:36:36 +01:00
|
|
|
import org.bukkit.block.Block;
|
2023-01-05 13:05:15 +01:00
|
|
|
import org.bukkit.command.BlockCommandSender;
|
2020-06-27 09:41:47 +02:00
|
|
|
import org.bukkit.entity.Enderman;
|
2017-12-30 08:36:36 +01:00
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.FishHook;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
2019-04-24 15:01:22 +02:00
|
|
|
import org.bukkit.entity.Ocelot;
|
2017-12-30 08:36:36 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.entity.Tameable;
|
|
|
|
import org.bukkit.entity.Wither;
|
|
|
|
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
2022-06-12 13:49:21 +02:00
|
|
|
import org.bukkit.inventory.Inventory;
|
2022-06-11 19:37:38 +02:00
|
|
|
import org.bukkit.inventory.InventoryView;
|
2022-12-03 11:21:46 +01:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2017-12-30 08:36:36 +01:00
|
|
|
import org.bukkit.inventory.meta.SkullMeta;
|
2020-03-03 16:31:04 +01:00
|
|
|
import org.bukkit.scoreboard.Team;
|
2017-12-30 08:36:36 +01:00
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
2023-03-14 20:37:05 +01:00
|
|
|
import com.google.common.collect.Lists;
|
2017-12-30 08:36:36 +01:00
|
|
|
import com.mojang.authlib.GameProfile;
|
|
|
|
import com.mojang.authlib.GameProfileRepository;
|
|
|
|
|
2023-03-12 15:29:41 +01:00
|
|
|
import net.citizensnpcs.Settings.Setting;
|
2017-12-30 08:36:36 +01:00
|
|
|
import net.citizensnpcs.api.ai.NavigatorParameters;
|
2022-12-18 17:36:53 +01:00
|
|
|
import net.citizensnpcs.api.astar.pathfinder.SwimmingExaminer;
|
2017-12-30 08:36:36 +01:00
|
|
|
import net.citizensnpcs.api.command.CommandManager;
|
|
|
|
import net.citizensnpcs.api.command.exception.CommandException;
|
2023-02-13 13:32:20 +01:00
|
|
|
import net.citizensnpcs.api.event.NPCKnockbackEvent;
|
2022-12-03 11:21:46 +01:00
|
|
|
import net.citizensnpcs.api.jnbt.CompoundTag;
|
2017-12-30 08:36:36 +01:00
|
|
|
import net.citizensnpcs.api.npc.BlockBreaker;
|
|
|
|
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
|
|
|
|
import net.citizensnpcs.api.npc.NPC;
|
|
|
|
import net.citizensnpcs.api.npc.NPCRegistry;
|
2020-06-30 14:39:40 +02:00
|
|
|
import net.citizensnpcs.api.util.BoundingBox;
|
2023-01-03 13:55:27 +01:00
|
|
|
import net.citizensnpcs.api.util.EntityDim;
|
2017-12-30 08:36:36 +01:00
|
|
|
import net.citizensnpcs.api.util.Messaging;
|
|
|
|
import net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator;
|
|
|
|
import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator;
|
2023-04-16 19:47:32 +02:00
|
|
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
2017-12-30 08:36:36 +01:00
|
|
|
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
2023-04-16 19:47:32 +02:00
|
|
|
import net.citizensnpcs.trait.PacketNPC;
|
2022-12-18 06:25:08 +01:00
|
|
|
import net.citizensnpcs.trait.versioned.CamelTrait.CamelPose;
|
2023-03-14 20:37:05 +01:00
|
|
|
import net.citizensnpcs.trait.versioned.SnifferTrait.SnifferState;
|
2023-04-03 16:40:04 +02:00
|
|
|
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
|
2017-12-30 08:36:36 +01:00
|
|
|
|
|
|
|
public class NMS {
|
|
|
|
private NMS() {
|
|
|
|
// util class
|
|
|
|
}
|
|
|
|
|
2022-12-18 17:36:53 +01:00
|
|
|
public static void activate(Entity entity) {
|
|
|
|
BRIDGE.activate(entity);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static boolean addEntityToWorld(org.bukkit.entity.Entity entity, SpawnReason custom) {
|
|
|
|
return BRIDGE.addEntityToWorld(entity, custom);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void addOrRemoveFromPlayerList(org.bukkit.entity.Entity entity, boolean remove) {
|
|
|
|
BRIDGE.addOrRemoveFromPlayerList(entity, remove);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void attack(LivingEntity attacker, LivingEntity bukkitTarget) {
|
|
|
|
BRIDGE.attack(attacker, bukkitTarget);
|
|
|
|
}
|
|
|
|
|
2023-03-28 18:30:56 +02:00
|
|
|
public static float[][] calculateDragonPositions(float yrot, double[][] latency) {
|
|
|
|
float[][] positions = new float[8][];
|
|
|
|
float f7 = (float) (latency[1][1] - latency[2][1]) * 10.0F * 0.017453292F;
|
|
|
|
float f8 = (float) Math.cos(f7);
|
|
|
|
float f9 = (float) Math.sin(f7);
|
|
|
|
float f6 = yrot * 0.017453292F;
|
|
|
|
float f11 = (float) Math.sin(f6);
|
|
|
|
float f12 = (float) Math.cos(f6);
|
|
|
|
positions[2] = new float[] { f11 * 0.5F, 0.0F, -f12 * 0.5F };
|
|
|
|
positions[6] = new float[] { f12 * 4.5F, 2F, f11 * 4.5F };
|
|
|
|
positions[7] = new float[] { f12 * -4.5F, 2f, f11 * -4.5F };
|
|
|
|
float f15 = (float) (latency[1][1] - latency[0][1]);
|
|
|
|
positions[0] = new float[] { f11 * 6.5F * f8, f15 + f9 * 6.5F, -f12 * 6.5F * f8 };
|
|
|
|
positions[1] = new float[] { f11 * 5.5F * f8, f15 + f9 * 5.5F, -f12 * 5.5F * f8 };
|
|
|
|
for (int k = 3; k < 6; ++k) {
|
|
|
|
float f16 = f6 + Util.clamp((float) (latency[k][0] - latency[1][0])) * 0.017453292F;
|
|
|
|
float f3 = (float) Math.sin(f16);
|
|
|
|
float f4 = (float) Math.cos(f16);
|
|
|
|
float f17 = (k - 2) * 2.0F;
|
|
|
|
positions[k] = new float[] { -(f11 * 1.5F + f3 * f17) * f8,
|
|
|
|
(float) (latency[k][1] - latency[1][1] - (f17 + 1.5F) * f9 + 1.5), (f12 * 1.5F + f4 * f17) * f8 };
|
|
|
|
}
|
|
|
|
return positions;
|
|
|
|
}
|
|
|
|
|
2023-02-13 13:32:20 +01:00
|
|
|
public static void callKnockbackEvent(NPC npc, float strength, double dx, double dz,
|
|
|
|
Consumer<NPCKnockbackEvent> cb) {
|
2023-06-12 15:20:51 +02:00
|
|
|
if (SUPPORT_KNOCKBACK_RESISTANCE && npc.getEntity() instanceof LivingEntity) {
|
|
|
|
try {
|
|
|
|
AttributeInstance attribute = ((LivingEntity) npc.getEntity())
|
|
|
|
.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE);
|
|
|
|
if (attribute != null) {
|
|
|
|
strength *= 1 - attribute.getValue();
|
|
|
|
}
|
|
|
|
} catch (Throwable t) {
|
|
|
|
SUPPORT_KNOCKBACK_RESISTANCE = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Vector vector = npc.getEntity().getVelocity();
|
|
|
|
Vector impulse = new Vector(dx, 0, dz).normalize().multiply(strength);
|
|
|
|
Vector delta = new Vector(vector.getX() / 2 - impulse.getX() - vector.getX(),
|
|
|
|
-vector.getY()
|
|
|
|
+ (npc.getEntity().isOnGround() ? Math.min(0.4, vector.getY() / 2 + strength) : vector.getY()),
|
|
|
|
vector.getZ() / 2 - impulse.getZ() - vector.getZ());
|
|
|
|
NPCKnockbackEvent event = new NPCKnockbackEvent(npc, strength, delta, null);
|
2023-02-13 13:32:20 +01:00
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
cb.accept(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-02 14:40:19 +01:00
|
|
|
public static void cancelMoveDestination(Entity entity) {
|
|
|
|
BRIDGE.cancelMoveDestination(entity);
|
2022-12-03 11:21:46 +01:00
|
|
|
}/*
|
2017-12-30 08:36:36 +01:00
|
|
|
* Yggdrasil's default implementation of this method silently fails instead of throwing
|
|
|
|
* an Exception like it should.
|
|
|
|
*/
|
2022-12-03 11:21:46 +01:00
|
|
|
|
2023-04-03 16:40:04 +02:00
|
|
|
public static Iterable<Object> createBundlePacket(List<Object> packets) {
|
|
|
|
return BRIDGE.createBundlePacket(packets);
|
|
|
|
}
|
|
|
|
|
2023-03-07 16:58:03 +01:00
|
|
|
public static EntityPacketTracker createPacketTracker(Entity entity) {
|
2023-04-03 16:40:04 +02:00
|
|
|
return createPacketTracker(entity, new PacketAggregator());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static EntityPacketTracker createPacketTracker(Entity entity, PacketAggregator agg) {
|
|
|
|
return BRIDGE.createPacketTracker(entity, agg);
|
2023-03-07 16:58:03 +01:00
|
|
|
}
|
|
|
|
|
2019-04-25 09:43:44 +02:00
|
|
|
public static GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) throws Throwable {
|
2017-12-30 08:36:36 +01:00
|
|
|
return BRIDGE.fillProfileProperties(profile, requireSecure);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static BlockBreaker getBlockBreaker(Entity entity, Block targetBlock, BlockBreakerConfiguration config) {
|
|
|
|
return BRIDGE.getBlockBreaker(entity, targetBlock, config);
|
|
|
|
}
|
|
|
|
|
2019-12-11 17:13:54 +01:00
|
|
|
public static Object getBossBar(Entity entity) {
|
|
|
|
return BRIDGE.getBossBar(entity);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static BoundingBox getBoundingBox(org.bukkit.entity.Entity handle) {
|
|
|
|
return BRIDGE.getBoundingBox(handle);
|
|
|
|
}
|
|
|
|
|
2020-06-30 14:39:40 +02:00
|
|
|
public static BoundingBox getCollisionBox(Block block) {
|
2021-11-21 15:12:17 +01:00
|
|
|
if (block.getType() == Material.AIR) {
|
2021-11-27 05:19:19 +01:00
|
|
|
return BoundingBox.EMPTY;
|
2021-11-21 15:12:17 +01:00
|
|
|
}
|
2020-06-30 14:39:40 +02:00
|
|
|
return BRIDGE.getCollisionBox(block).add(block.getX(), block.getY(), block.getZ());
|
|
|
|
}
|
|
|
|
|
2022-02-19 09:36:31 +01:00
|
|
|
public static Location getDestination(Entity entity) {
|
|
|
|
return BRIDGE.getDestination(entity);
|
|
|
|
}
|
|
|
|
|
2023-03-12 15:29:41 +01:00
|
|
|
public static int getFallDistance(NPC npc, int def) {
|
|
|
|
return npc == null ? def
|
|
|
|
: npc.data().get(NPC.Metadata.PATHFINDER_FALL_DISTANCE,
|
|
|
|
Setting.PATHFINDER_FALL_DISTANCE.asInt() != -1 ? Setting.PATHFINDER_FALL_DISTANCE.asInt()
|
|
|
|
: def);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static Field getField(Class<?> clazz, String field) {
|
2018-09-26 12:57:34 +02:00
|
|
|
return getField(clazz, field, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Field getField(Class<?> clazz, String field, boolean log) {
|
2017-12-30 08:36:36 +01:00
|
|
|
if (clazz == null)
|
|
|
|
return null;
|
|
|
|
Field f = null;
|
|
|
|
try {
|
|
|
|
f = clazz.getDeclaredField(field);
|
|
|
|
f.setAccessible(true);
|
2019-05-21 13:26:33 +02:00
|
|
|
return f;
|
2017-12-30 08:36:36 +01:00
|
|
|
} catch (Exception e) {
|
2018-09-26 12:57:34 +02:00
|
|
|
if (log) {
|
|
|
|
Messaging.logTr(Messages.ERROR_GETTING_FIELD, field, e.getLocalizedMessage());
|
2023-05-01 18:10:07 +02:00
|
|
|
if (Messaging.isDebugging()) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2018-09-26 12:57:34 +02:00
|
|
|
}
|
2019-05-21 13:26:33 +02:00
|
|
|
return null;
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 20:37:05 +01:00
|
|
|
private static List<Field> getFieldsMatchingType(Class<?> clazz, Class<?> type, boolean allowStatic) {
|
|
|
|
List<Field> found = Lists.newArrayList();
|
|
|
|
for (Field field : clazz.getDeclaredFields()) {
|
|
|
|
if (allowStatic ^ Modifier.isStatic(field.getModifiers()))
|
|
|
|
continue;
|
|
|
|
if (field.getType() == type) {
|
|
|
|
found.add(field);
|
|
|
|
field.setAccessible(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<MethodHandle> getFieldsOfType(Class<?> clazz, Class<?> type) {
|
|
|
|
List<Field> found = getFieldsMatchingType(clazz, type, false);
|
|
|
|
if (found.isEmpty())
|
|
|
|
return null;
|
|
|
|
return found.stream().map(f -> {
|
|
|
|
try {
|
|
|
|
return LOOKUP.unreflectGetter(f);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}).filter(f -> f != null).collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
|
2019-05-16 11:50:59 +02:00
|
|
|
public static MethodHandle getFinalSetter(Class<?> clazz, String field) {
|
|
|
|
return getFinalSetter(clazz, field, true);
|
2018-09-26 12:57:34 +02:00
|
|
|
}
|
|
|
|
|
2023-03-26 20:52:56 +02:00
|
|
|
public static MethodHandle getFinalSetter(Class<?> clazz, String field, boolean log) {
|
|
|
|
return getFinalSetter(NMS.getField(clazz, field, log), log);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static MethodHandle getFinalSetter(Field field, boolean log) {
|
|
|
|
if (field == null)
|
|
|
|
return null;
|
2019-05-16 11:50:59 +02:00
|
|
|
if (MODIFIERS_FIELD == null) {
|
|
|
|
if (UNSAFE == null) {
|
|
|
|
try {
|
|
|
|
UNSAFE = NMS.getField(Class.forName("sun.misc.Unsafe"), "theUnsafe").get(null);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
if (log) {
|
2023-03-26 20:52:56 +02:00
|
|
|
Messaging.logTr(Messages.ERROR_GETTING_FIELD, field.getName(), e.getLocalizedMessage());
|
2019-05-16 11:50:59 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2022-06-08 08:07:33 +02:00
|
|
|
UNSAFE_STATIC_FIELD_OFFSET = getMethodHandle(UNSAFE.getClass(), "staticFieldOffset", true, Field.class)
|
2019-05-16 11:50:59 +02:00
|
|
|
.bindTo(UNSAFE);
|
2022-06-08 08:07:33 +02:00
|
|
|
UNSAFE_FIELD_OFFSET = getMethodHandle(UNSAFE.getClass(), "objectFieldOffset", true, Field.class)
|
2019-05-16 11:50:59 +02:00
|
|
|
.bindTo(UNSAFE);
|
2022-06-08 08:07:33 +02:00
|
|
|
UNSAFE_PUT_OBJECT = getMethodHandle(UNSAFE.getClass(), "putObject", true, Object.class, long.class,
|
|
|
|
Object.class).bindTo(UNSAFE);
|
2023-03-26 20:52:56 +02:00
|
|
|
UNSAFE_PUT_INT = getMethodHandle(UNSAFE.getClass(), "putInt", true, Object.class, long.class, int.class)
|
|
|
|
.bindTo(UNSAFE);
|
|
|
|
UNSAFE_PUT_FLOAT = getMethodHandle(UNSAFE.getClass(), "putFloat", true, Object.class, long.class,
|
|
|
|
float.class).bindTo(UNSAFE);
|
|
|
|
UNSAFE_PUT_DOUBLE = getMethodHandle(UNSAFE.getClass(), "putDouble", true, Object.class, long.class,
|
|
|
|
double.class).bindTo(UNSAFE);
|
|
|
|
UNSAFE_PUT_BOOLEAN = getMethodHandle(UNSAFE.getClass(), "putBoolean", true, Object.class, long.class,
|
|
|
|
boolean.class).bindTo(UNSAFE);
|
|
|
|
UNSAFE_PUT_LONG = getMethodHandle(UNSAFE.getClass(), "putLong", true, Object.class, long.class,
|
|
|
|
long.class).bindTo(UNSAFE);
|
2019-05-16 11:50:59 +02:00
|
|
|
}
|
|
|
|
try {
|
2022-06-08 08:07:33 +02:00
|
|
|
boolean isStatic = Modifier.isStatic(field.getModifiers());
|
|
|
|
long offset = (long) (isStatic ? UNSAFE_STATIC_FIELD_OFFSET.invoke(field)
|
|
|
|
: UNSAFE_FIELD_OFFSET.invoke(field));
|
2023-03-26 20:52:56 +02:00
|
|
|
MethodHandle mh = field.getType() == int.class ? UNSAFE_PUT_INT
|
|
|
|
: field.getType() == boolean.class ? UNSAFE_PUT_BOOLEAN
|
|
|
|
: field.getType() == double.class ? UNSAFE_PUT_DOUBLE
|
|
|
|
: field.getType() == float.class ? UNSAFE_PUT_FLOAT
|
|
|
|
: field.getType() == long.class ? UNSAFE_PUT_LONG : UNSAFE_PUT_OBJECT;
|
|
|
|
return isStatic ? MethodHandles.insertArguments(mh, 0, field.getDeclaringClass(), offset)
|
|
|
|
: MethodHandles.insertArguments(mh, 1, offset);
|
2019-05-16 11:50:59 +02:00
|
|
|
} catch (Throwable t) {
|
|
|
|
t.printStackTrace();
|
|
|
|
if (log) {
|
2023-03-26 20:52:56 +02:00
|
|
|
Messaging.logTr(Messages.ERROR_GETTING_FIELD, field.getName(), t.getLocalizedMessage());
|
2019-05-16 11:50:59 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2017-12-30 08:36:36 +01:00
|
|
|
try {
|
2022-06-08 08:07:33 +02:00
|
|
|
MODIFIERS_FIELD.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
2017-12-30 08:36:36 +01:00
|
|
|
} catch (Exception e) {
|
2018-09-26 12:57:34 +02:00
|
|
|
if (log) {
|
2023-03-26 20:52:56 +02:00
|
|
|
Messaging.logTr(Messages.ERROR_GETTING_FIELD, field.getName(), e.getLocalizedMessage());
|
2023-05-01 18:10:07 +02:00
|
|
|
if (Messaging.isDebugging()) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2018-09-26 12:57:34 +02:00
|
|
|
}
|
2017-12-30 08:36:36 +01:00
|
|
|
return null;
|
|
|
|
}
|
2019-04-25 09:43:44 +02:00
|
|
|
try {
|
2022-06-08 08:07:33 +02:00
|
|
|
return LOOKUP.unreflectSetter(field);
|
2019-04-25 09:43:44 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
if (log) {
|
2023-03-26 20:52:56 +02:00
|
|
|
Messaging.logTr(Messages.ERROR_GETTING_FIELD, field.getName(), e.getLocalizedMessage());
|
2023-05-01 18:10:07 +02:00
|
|
|
if (Messaging.isDebugging()) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2019-04-25 09:43:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-03-07 16:58:03 +01:00
|
|
|
public static MethodHandle getFirstFinalSetter(Class<?> clazz, Class<?> type) {
|
|
|
|
try {
|
2023-03-14 20:37:05 +01:00
|
|
|
List<Field> found = getFieldsMatchingType(clazz, type, false);
|
|
|
|
if (found.isEmpty())
|
2023-03-07 16:58:03 +01:00
|
|
|
return null;
|
2023-03-26 20:52:56 +02:00
|
|
|
return getFinalSetter(found.get(0), true);
|
2023-03-07 16:58:03 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
Messaging.logTr(Messages.ERROR_GETTING_FIELD, type, e.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-06-13 07:41:36 +02:00
|
|
|
public static MethodHandle getFirstGetter(Class<?> clazz, Class<?> type) {
|
|
|
|
try {
|
2023-03-14 20:37:05 +01:00
|
|
|
List<Field> found = getFieldsMatchingType(clazz, type, false);
|
|
|
|
if (found.isEmpty())
|
2021-06-13 07:41:36 +02:00
|
|
|
return null;
|
2023-03-14 20:37:05 +01:00
|
|
|
return LOOKUP.unreflectGetter(found.get(0));
|
2021-06-13 07:41:36 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
Messaging.logTr(Messages.ERROR_GETTING_FIELD, type, e.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-06-12 21:20:18 +02:00
|
|
|
public static MethodHandle getFirstMethodHandle(Class<?> clazz, boolean log, Class<?>... params) {
|
2022-01-16 07:05:23 +01:00
|
|
|
return getFirstMethodHandleWithReturnType(clazz, log, null, params);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static MethodHandle getFirstMethodHandleWithReturnType(Class<?> clazz, boolean log, Class<?> returnType,
|
|
|
|
Class<?>... params) {
|
2021-06-12 21:20:18 +02:00
|
|
|
if (clazz == null)
|
|
|
|
return null;
|
|
|
|
try {
|
|
|
|
Method first = null;
|
|
|
|
for (Method method : clazz.getDeclaredMethods()) {
|
2022-01-16 07:05:23 +01:00
|
|
|
if (returnType != null && !returnType.equals(method.getReturnType()))
|
|
|
|
continue;
|
2021-06-12 21:20:18 +02:00
|
|
|
Class<?>[] paramTypes = method.getParameterTypes();
|
|
|
|
if (paramTypes.length == params.length) {
|
|
|
|
first = method;
|
|
|
|
for (int i = 0; i < paramTypes.length; i++) {
|
|
|
|
if (paramTypes[i] != params[i]) {
|
|
|
|
first = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (first != null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (first == null)
|
|
|
|
return null;
|
|
|
|
first.setAccessible(true);
|
|
|
|
return LOOKUP.unreflect(first);
|
|
|
|
} catch (Exception e) {
|
|
|
|
if (log) {
|
|
|
|
Messaging.logTr(Messages.ERROR_GETTING_METHOD, e.getLocalizedMessage());
|
2023-05-01 18:10:07 +02:00
|
|
|
if (Messaging.isDebugging()) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2021-06-12 21:20:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-06-13 07:41:36 +02:00
|
|
|
public static MethodHandle getFirstSetter(Class<?> clazz, Class<?> type) {
|
|
|
|
try {
|
2023-03-14 20:37:05 +01:00
|
|
|
List<Field> found = getFieldsMatchingType(clazz, type, false);
|
|
|
|
if (found.isEmpty())
|
2021-06-13 07:41:36 +02:00
|
|
|
return null;
|
2023-03-14 20:37:05 +01:00
|
|
|
return LOOKUP.unreflectSetter(found.get(0));
|
2021-06-13 07:41:36 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
Messaging.logTr(Messages.ERROR_GETTING_FIELD, type, e.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-07-09 18:47:05 +02:00
|
|
|
public static MethodHandle getFirstStaticGetter(Class<?> clazz, Class<?> type) {
|
|
|
|
try {
|
2023-03-14 20:37:05 +01:00
|
|
|
List<Field> found = getFieldsMatchingType(clazz, type, true);
|
|
|
|
if (found.isEmpty())
|
2021-07-09 18:47:05 +02:00
|
|
|
return null;
|
2023-03-14 20:37:05 +01:00
|
|
|
return LOOKUP.unreflectGetter(found.get(0));
|
2021-07-09 18:47:05 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
Messaging.logTr(Messages.ERROR_GETTING_FIELD, type, e.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static GameProfileRepository getGameProfileRepository() {
|
|
|
|
return BRIDGE.getGameProfileRepository();
|
|
|
|
}
|
|
|
|
|
2019-04-25 09:43:44 +02:00
|
|
|
public static MethodHandle getGetter(Class<?> clazz, String name) {
|
|
|
|
return getGetter(clazz, name, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static MethodHandle getGetter(Class<?> clazz, String name, boolean log) {
|
|
|
|
try {
|
|
|
|
return LOOKUP.unreflectGetter(getField(clazz, name, log));
|
|
|
|
} catch (Exception e) {
|
|
|
|
if (log) {
|
|
|
|
Messaging.logTr(Messages.ERROR_GETTING_FIELD, name, e.getLocalizedMessage());
|
2023-05-01 18:10:07 +02:00
|
|
|
if (Messaging.isDebugging()) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2019-04-25 09:43:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static float getHeadYaw(org.bukkit.entity.Entity entity) {
|
|
|
|
return BRIDGE.getHeadYaw(entity);
|
|
|
|
}
|
|
|
|
|
2020-07-06 02:42:46 +02:00
|
|
|
public static double getHeight(Entity entity) {
|
|
|
|
return BRIDGE.getHeight(entity);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static float getHorizontalMovement(org.bukkit.entity.Entity bukkitEntity) {
|
|
|
|
return BRIDGE.getHorizontalMovement(bukkitEntity);
|
|
|
|
}
|
|
|
|
|
2018-10-25 10:48:15 +02:00
|
|
|
public static Method getMethod(Class<?> clazz, String method, boolean log, Class<?>... params) {
|
|
|
|
if (clazz == null)
|
|
|
|
return null;
|
|
|
|
Method f = null;
|
|
|
|
try {
|
|
|
|
f = clazz.getDeclaredMethod(method, params);
|
|
|
|
f.setAccessible(true);
|
|
|
|
} catch (Exception e) {
|
|
|
|
if (log) {
|
|
|
|
Messaging.logTr(Messages.ERROR_GETTING_METHOD, method, e.getLocalizedMessage());
|
2023-05-01 18:10:07 +02:00
|
|
|
if (Messaging.isDebugging()) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2018-10-25 10:48:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2019-04-25 09:43:44 +02:00
|
|
|
public static MethodHandle getMethodHandle(Class<?> clazz, String method, boolean log, Class<?>... params) {
|
|
|
|
if (clazz == null)
|
|
|
|
return null;
|
|
|
|
try {
|
|
|
|
return LOOKUP.unreflect(getMethod(clazz, method, log, params));
|
|
|
|
} catch (Exception e) {
|
|
|
|
if (log) {
|
|
|
|
Messaging.logTr(Messages.ERROR_GETTING_METHOD, method, e.getLocalizedMessage());
|
2023-05-01 18:10:07 +02:00
|
|
|
if (Messaging.isDebugging()) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2019-04-25 09:43:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-12-03 11:21:46 +01:00
|
|
|
public static CompoundTag getNBT(ItemStack item) {
|
|
|
|
return BRIDGE.getNBT(item);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static NPC getNPC(Entity entity) {
|
|
|
|
return BRIDGE.getNPC(entity);
|
|
|
|
}
|
|
|
|
|
2023-04-16 19:47:32 +02:00
|
|
|
public static EntityPacketTracker getPacketTracker(Entity entity) {
|
|
|
|
if (entity == null)
|
|
|
|
return null;
|
|
|
|
if (entity instanceof NPCHolder) {
|
|
|
|
NPC npc = ((NPCHolder) entity).getNPC();
|
|
|
|
if (npc.hasTrait(PacketNPC.class))
|
|
|
|
return npc.getOrAddTrait(PacketNPC.class).getPacketTracker();
|
|
|
|
}
|
|
|
|
if (!entity.isValid())
|
|
|
|
return null;
|
|
|
|
return BRIDGE.getPacketTracker(entity);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity entity) {
|
|
|
|
return BRIDGE.getPassengers(entity);
|
|
|
|
}
|
|
|
|
|
2022-12-24 18:37:54 +01:00
|
|
|
public static GameProfile getProfile(Player player) {
|
|
|
|
return BRIDGE.getProfile(player);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static GameProfile getProfile(SkullMeta meta) {
|
|
|
|
return BRIDGE.getProfile(meta);
|
|
|
|
}
|
|
|
|
|
2019-04-25 09:43:44 +02:00
|
|
|
public static MethodHandle getSetter(Class<?> clazz, String name) {
|
|
|
|
return getSetter(clazz, name, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static MethodHandle getSetter(Class<?> clazz, String name, boolean log) {
|
|
|
|
try {
|
|
|
|
return LOOKUP.unreflectSetter(getField(clazz, name, log));
|
|
|
|
} catch (Exception e) {
|
|
|
|
if (log) {
|
|
|
|
Messaging.logTr(Messages.ERROR_GETTING_FIELD, name, e.getLocalizedMessage());
|
2023-05-01 18:10:07 +02:00
|
|
|
if (Messaging.isDebugging()) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2019-04-25 09:43:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static String getSound(String flag) throws CommandException {
|
|
|
|
return BRIDGE.getSound(flag);
|
|
|
|
}
|
|
|
|
|
2023-01-05 13:05:15 +01:00
|
|
|
public static Entity getSource(BlockCommandSender sender) {
|
|
|
|
return BRIDGE.getSource(sender);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static float getSpeedFor(NPC npc) {
|
|
|
|
return BRIDGE.getSpeedFor(npc);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static float getStepHeight(org.bukkit.entity.Entity entity) {
|
|
|
|
return BRIDGE.getStepHeight(entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static MCNavigator getTargetNavigator(Entity entity, Iterable<Vector> dest, NavigatorParameters params) {
|
|
|
|
return BRIDGE.getTargetNavigator(entity, dest, params);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static MCNavigator getTargetNavigator(Entity entity, Location dest, NavigatorParameters params) {
|
|
|
|
return BRIDGE.getTargetNavigator(entity, dest, params);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static TargetNavigator getTargetNavigator(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity target,
|
|
|
|
NavigatorParameters parameters) {
|
|
|
|
return BRIDGE.getTargetNavigator(entity, target, parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static org.bukkit.entity.Entity getVehicle(org.bukkit.entity.Entity entity) {
|
|
|
|
return BRIDGE.getVehicle(entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static float getVerticalMovement(org.bukkit.entity.Entity bukkitEntity) {
|
|
|
|
return BRIDGE.getVerticalMovement(bukkitEntity);
|
|
|
|
}
|
|
|
|
|
2020-07-06 02:42:46 +02:00
|
|
|
public static double getWidth(Entity entity) {
|
|
|
|
return BRIDGE.getWidth(entity);
|
|
|
|
}
|
|
|
|
|
2020-04-30 13:11:56 +02:00
|
|
|
public static float getYaw(Entity entity) {
|
|
|
|
return BRIDGE.getYaw(entity);
|
|
|
|
}
|
|
|
|
|
2021-04-14 09:03:39 +02:00
|
|
|
public static void giveReflectiveAccess(Class<?> from, Class<?> to) {
|
2021-04-08 12:47:38 +02:00
|
|
|
try {
|
|
|
|
if (GET_MODULE == null) {
|
|
|
|
Class<?> module = Class.forName("java.lang.Module");
|
|
|
|
GET_MODULE = Class.class.getMethod("getModule");
|
|
|
|
ADD_OPENS = module.getMethod("addOpens", String.class, module);
|
|
|
|
}
|
2021-04-14 09:03:39 +02:00
|
|
|
ADD_OPENS.invoke(GET_MODULE.invoke(from), from.getPackage().getName(), GET_MODULE.invoke(to));
|
2021-04-08 12:47:38 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-13 13:32:20 +01:00
|
|
|
public static boolean isLeashed(NPC npc, Supplier<Boolean> isLeashed, Runnable unleash) {
|
|
|
|
if (npc == null)
|
|
|
|
return isLeashed.get();
|
|
|
|
boolean protectedDefault = npc.isProtected();
|
|
|
|
if (!protectedDefault || !npc.data().get(NPC.Metadata.LEASH_PROTECTED, protectedDefault))
|
|
|
|
return isLeashed.get();
|
|
|
|
if (isLeashed.get()) {
|
|
|
|
unleash.run();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static boolean isOnGround(org.bukkit.entity.Entity entity) {
|
|
|
|
return BRIDGE.isOnGround(entity);
|
|
|
|
}
|
|
|
|
|
2021-04-30 04:31:25 +02:00
|
|
|
public static boolean isSolid(Block in) {
|
|
|
|
return BRIDGE.isSolid(in);
|
|
|
|
}
|
|
|
|
|
2019-10-03 07:14:20 +02:00
|
|
|
public static boolean isValid(Entity entity) {
|
|
|
|
return BRIDGE.isValid(entity);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static void load(CommandManager commands) {
|
|
|
|
BRIDGE.load(commands);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void loadBridge(String rev) throws Exception {
|
2021-06-12 21:20:18 +02:00
|
|
|
Class<?> entity = null;
|
|
|
|
try {
|
|
|
|
entity = Class.forName("net.minecraft.server.v" + rev + ".Entity");
|
|
|
|
} catch (ClassNotFoundException ex) {
|
|
|
|
entity = Class.forName("net.minecraft.world.entity.Entity");
|
|
|
|
}
|
2021-04-14 09:03:39 +02:00
|
|
|
giveReflectiveAccess(entity, NMS.class);
|
2017-12-30 08:36:36 +01:00
|
|
|
BRIDGE = (NMSBridge) Class.forName("net.citizensnpcs.nms.v" + rev + ".util.NMSImpl").getConstructor()
|
|
|
|
.newInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void look(Entity entity, float yaw, float pitch) {
|
|
|
|
BRIDGE.look(entity, yaw, pitch);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, boolean immediate) {
|
|
|
|
BRIDGE.look(entity, to, headOnly, immediate);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void look(org.bukkit.entity.Entity bhandle, org.bukkit.entity.Entity btarget) {
|
|
|
|
BRIDGE.look(bhandle, btarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void mount(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity passenger) {
|
|
|
|
BRIDGE.mount(entity, passenger);
|
|
|
|
}
|
|
|
|
|
2022-12-29 16:26:02 +01:00
|
|
|
public static void onPlayerInfoAdd(Player player, Object source) {
|
|
|
|
BRIDGE.onPlayerInfoAdd(player, source);
|
|
|
|
}
|
|
|
|
|
2022-06-12 13:49:21 +02:00
|
|
|
public static InventoryView openAnvilInventory(Player player, Inventory inventory, String title) {
|
|
|
|
return BRIDGE.openAnvilInventory(player, inventory, title);
|
|
|
|
}
|
|
|
|
|
2018-02-03 01:56:09 +01:00
|
|
|
public static void openHorseScreen(Tameable horse, Player equipper) {
|
2017-12-30 08:36:36 +01:00
|
|
|
BRIDGE.openHorseScreen(horse, equipper);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void playAnimation(PlayerAnimation animation, Player player, int radius) {
|
|
|
|
BRIDGE.playAnimation(animation, player, radius);
|
|
|
|
}
|
|
|
|
|
2023-01-01 08:26:35 +01:00
|
|
|
public static Runnable playerTicker(Player entity) {
|
2023-01-05 15:51:42 +01:00
|
|
|
Runnable tick = BRIDGE.playerTicker(entity);
|
|
|
|
return () -> {
|
|
|
|
if (entity.isValid()) {
|
|
|
|
tick.run();
|
|
|
|
}
|
|
|
|
};
|
2020-04-29 14:56:39 +02:00
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static void registerEntityClass(Class<?> clazz) {
|
|
|
|
BRIDGE.registerEntityClass(clazz);
|
|
|
|
}
|
|
|
|
|
2019-02-05 11:12:02 +01:00
|
|
|
public static void remove(Entity entity) {
|
|
|
|
BRIDGE.remove(entity);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static void removeFromServerPlayerList(Player player) {
|
|
|
|
BRIDGE.removeFromServerPlayerList(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void removeFromWorld(org.bukkit.entity.Entity entity) {
|
|
|
|
BRIDGE.removeFromWorld(entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void removeHookIfNecessary(NPCRegistry npcRegistry, FishHook entity) {
|
|
|
|
BRIDGE.removeHookIfNecessary(npcRegistry, entity);
|
|
|
|
}
|
|
|
|
|
2023-03-07 16:58:03 +01:00
|
|
|
public static void replaceTracker(Entity entity) {
|
|
|
|
BRIDGE.replaceTrackerEntry(entity);
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
|
|
|
|
2023-04-29 18:18:24 +02:00
|
|
|
public static void sendPositionUpdate(Entity from, boolean position, Float bodyYaw, Float pitch, Float headYaw) {
|
|
|
|
BRIDGE.sendPositionUpdate(from, position, bodyYaw, pitch, headYaw);
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
|
|
|
|
2022-12-08 16:21:09 +01:00
|
|
|
public static boolean sendTabListAdd(Player recipient, Player listPlayer) {
|
|
|
|
return BRIDGE.sendTabListAdd(recipient, listPlayer);
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void sendTabListRemove(Player recipient, Collection<? extends SkinnableEntity> skinnableNPCs) {
|
|
|
|
BRIDGE.sendTabListRemove(recipient, skinnableNPCs);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void sendTabListRemove(Player recipient, Player listPlayer) {
|
|
|
|
BRIDGE.sendTabListRemove(recipient, listPlayer);
|
|
|
|
}
|
|
|
|
|
2020-04-30 19:39:07 +02:00
|
|
|
public static void sendTeamPacket(Player recipient, Team team, int mode) {
|
|
|
|
BRIDGE.sendTeamPacket(recipient, team, mode);
|
2020-04-30 14:51:10 +02:00
|
|
|
}
|
|
|
|
|
2023-01-16 16:54:21 +01:00
|
|
|
public static void setAggressive(Entity entity, boolean aggro) {
|
|
|
|
BRIDGE.setAggressive(entity, aggro);
|
|
|
|
}
|
|
|
|
|
2022-07-28 00:36:51 +02:00
|
|
|
public static void setAllayDancing(Entity entity, boolean dancing) {
|
|
|
|
BRIDGE.setAllayDancing(entity, dancing);
|
|
|
|
}
|
|
|
|
|
2020-03-21 11:30:52 +01:00
|
|
|
public static void setBodyYaw(Entity entity, float yaw) {
|
|
|
|
BRIDGE.setBodyYaw(entity, yaw);
|
|
|
|
}
|
|
|
|
|
2023-01-03 13:55:27 +01:00
|
|
|
public static void setBoundingBox(Entity entity, BoundingBox box) {
|
|
|
|
BRIDGE.setBoundingBox(entity, box);
|
|
|
|
}
|
|
|
|
|
2022-12-18 06:25:08 +01:00
|
|
|
public static void setCamelPose(Entity entity, CamelPose pose) {
|
|
|
|
BRIDGE.setCamelPose(entity, pose);
|
|
|
|
}
|
|
|
|
|
2022-12-22 16:17:28 +01:00
|
|
|
public static void setCustomName(Entity entity, Object component, String string) {
|
|
|
|
BRIDGE.setCustomName(entity, component, string);
|
2022-11-29 23:13:55 +01:00
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) {
|
|
|
|
BRIDGE.setDestination(entity, x, y, z, speed);
|
|
|
|
}
|
|
|
|
|
2023-01-03 13:55:27 +01:00
|
|
|
public static void setDimensions(Entity entity, EntityDim desired) {
|
|
|
|
BRIDGE.setDimensions(entity, desired);
|
|
|
|
}
|
|
|
|
|
2020-06-27 09:41:47 +02:00
|
|
|
public static void setEndermanAngry(Enderman enderman, boolean angry) {
|
|
|
|
BRIDGE.setEndermanAngry(enderman, angry);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static void setHeadYaw(org.bukkit.entity.Entity entity, float yaw) {
|
|
|
|
BRIDGE.setHeadYaw(entity, yaw);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setKnockbackResistance(org.bukkit.entity.LivingEntity entity, double d) {
|
|
|
|
BRIDGE.setKnockbackResistance(entity, d);
|
|
|
|
}
|
|
|
|
|
2023-02-21 15:56:50 +01:00
|
|
|
public static void setLocationDirectly(Entity entity, Location location) {
|
|
|
|
BRIDGE.setLocationDirectly(entity, location);
|
|
|
|
}
|
|
|
|
|
2019-12-11 17:13:54 +01:00
|
|
|
public static void setLyingDown(Entity cat, boolean lying) {
|
|
|
|
BRIDGE.setLyingDown(cat, lying);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static void setNavigationTarget(org.bukkit.entity.Entity handle, org.bukkit.entity.Entity target,
|
|
|
|
float speed) {
|
|
|
|
BRIDGE.setNavigationTarget(handle, target, speed);
|
|
|
|
}
|
|
|
|
|
2022-05-26 09:58:54 +02:00
|
|
|
public static void setNoGravity(Entity entity, boolean nogravity) {
|
|
|
|
BRIDGE.setNoGravity(entity, nogravity);
|
2020-03-02 07:51:54 +01:00
|
|
|
}
|
|
|
|
|
2020-02-21 13:28:57 +01:00
|
|
|
public static void setPandaSitting(Entity entity, boolean sitting) {
|
|
|
|
BRIDGE.setPandaSitting(entity, sitting);
|
|
|
|
}
|
|
|
|
|
2018-04-08 18:17:17 +02:00
|
|
|
public static void setPeekShulker(org.bukkit.entity.Entity entity, int peek) {
|
2018-04-08 18:26:16 +02:00
|
|
|
if (!entity.getType().name().equals("SHULKER")) {
|
2018-04-08 18:17:17 +02:00
|
|
|
throw new IllegalArgumentException("entity must be a shulker");
|
|
|
|
}
|
|
|
|
BRIDGE.setPeekShulker(entity, peek);
|
|
|
|
}
|
|
|
|
|
2022-07-07 17:34:15 +02:00
|
|
|
public static void setPiglinDancing(Entity entity, boolean dancing) {
|
|
|
|
BRIDGE.setPiglinDancing(entity, dancing);
|
|
|
|
}
|
|
|
|
|
2022-04-24 13:22:55 +02:00
|
|
|
public static void setPitch(Entity entity, float pitch) {
|
|
|
|
BRIDGE.setPitch(entity, pitch);
|
|
|
|
}
|
|
|
|
|
2020-12-17 06:13:23 +01:00
|
|
|
public static void setPolarBearRearing(Entity entity, boolean rearing) {
|
|
|
|
BRIDGE.setPolarBearRearing(entity, rearing);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static void setProfile(SkullMeta meta, GameProfile profile) {
|
|
|
|
BRIDGE.setProfile(meta, profile);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setShouldJump(org.bukkit.entity.Entity entity) {
|
|
|
|
BRIDGE.setShouldJump(entity);
|
|
|
|
}
|
|
|
|
|
2019-04-24 15:01:22 +02:00
|
|
|
public static void setSitting(Ocelot ocelot, boolean sitting) {
|
|
|
|
BRIDGE.setSitting(ocelot, sitting);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static void setSitting(Tameable tameable, boolean sitting) {
|
|
|
|
BRIDGE.setSitting(tameable, sitting);
|
|
|
|
}
|
|
|
|
|
2021-09-20 14:59:54 +02:00
|
|
|
public static void setSneaking(Entity entity, boolean sneaking) {
|
|
|
|
BRIDGE.setSneaking(entity, sneaking);
|
|
|
|
}
|
|
|
|
|
2023-03-14 20:37:05 +01:00
|
|
|
public static void setSnifferState(Entity entity, SnifferState state) {
|
|
|
|
BRIDGE.setSnifferState(entity, state);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static void setStepHeight(org.bukkit.entity.Entity entity, float height) {
|
|
|
|
BRIDGE.setStepHeight(entity, height);
|
|
|
|
}
|
|
|
|
|
2020-03-03 16:31:04 +01:00
|
|
|
public static void setTeamNameTagVisible(Team team, boolean visible) {
|
|
|
|
BRIDGE.setTeamNameTagVisible(team, visible);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static void setVerticalMovement(org.bukkit.entity.Entity bukkitEntity, double d) {
|
|
|
|
BRIDGE.setVerticalMovement(bukkitEntity, d);
|
|
|
|
}
|
|
|
|
|
2022-09-08 07:28:14 +02:00
|
|
|
public static void setWitherInvulnerable(Wither wither, boolean charged) {
|
2017-12-30 08:36:36 +01:00
|
|
|
BRIDGE.setWitherCharged(wither, charged);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean shouldJump(org.bukkit.entity.Entity entity) {
|
|
|
|
return BRIDGE.shouldJump(entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void shutdown() {
|
2022-04-19 12:16:48 +02:00
|
|
|
if (BRIDGE != null) {
|
|
|
|
BRIDGE.shutdown();
|
|
|
|
BRIDGE = null;
|
|
|
|
}
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
|
|
|
|
2022-10-25 11:07:11 +02:00
|
|
|
public static void sleep(Player entity, boolean sleep) {
|
|
|
|
BRIDGE.sleep(entity, sleep);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static void trySwim(org.bukkit.entity.Entity entity) {
|
2022-12-18 17:36:53 +01:00
|
|
|
trySwim(entity, SwimmingExaminer.isWaterMob(entity) ? 0.02F : 0.04F);
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void trySwim(org.bukkit.entity.Entity entity, float power) {
|
|
|
|
BRIDGE.trySwim(entity, power);
|
|
|
|
}
|
|
|
|
|
2022-06-11 19:37:38 +02:00
|
|
|
public static void updateInventoryTitle(Player player, InventoryView view, String newTitle) {
|
|
|
|
BRIDGE.updateInventoryTitle(player, view, newTitle);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public static void updateNavigationWorld(org.bukkit.entity.Entity entity, org.bukkit.World world) {
|
|
|
|
BRIDGE.updateNavigationWorld(entity, world);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void updatePathfindingRange(NPC npc, float pathfindingRange) {
|
|
|
|
BRIDGE.updatePathfindingRange(npc, pathfindingRange);
|
|
|
|
}
|
|
|
|
|
2021-04-08 12:47:38 +02:00
|
|
|
private static Method ADD_OPENS;
|
2017-12-30 08:36:36 +01:00
|
|
|
private static NMSBridge BRIDGE;
|
2021-04-08 12:47:38 +02:00
|
|
|
private static Method GET_MODULE;
|
2019-04-25 09:43:44 +02:00
|
|
|
private static MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
|
2021-04-14 09:03:39 +02:00
|
|
|
private static Field MODIFIERS_FIELD;
|
2023-06-12 15:20:51 +02:00
|
|
|
private static boolean SUPPORT_KNOCKBACK_RESISTANCE = true;
|
2019-05-16 11:50:59 +02:00
|
|
|
private static Object UNSAFE;
|
|
|
|
private static MethodHandle UNSAFE_FIELD_OFFSET;
|
2023-03-26 20:52:56 +02:00
|
|
|
private static MethodHandle UNSAFE_PUT_BOOLEAN;
|
|
|
|
private static MethodHandle UNSAFE_PUT_DOUBLE;
|
|
|
|
private static MethodHandle UNSAFE_PUT_FLOAT;
|
|
|
|
private static MethodHandle UNSAFE_PUT_INT;
|
|
|
|
private static MethodHandle UNSAFE_PUT_LONG;
|
2019-05-16 11:50:59 +02:00
|
|
|
private static MethodHandle UNSAFE_PUT_OBJECT;
|
|
|
|
private static MethodHandle UNSAFE_STATIC_FIELD_OFFSET;
|
2021-04-14 09:03:39 +02:00
|
|
|
|
|
|
|
static {
|
|
|
|
giveReflectiveAccess(Field.class, NMS.class);
|
|
|
|
MODIFIERS_FIELD = NMS.getField(Field.class, "modifiers", false);
|
|
|
|
}
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|