Entity IDs should not be changing

Removing an entity from a client doesn't work if the ID has changed.
This commit is contained in:
Eric 2019-05-01 12:53:38 +02:00
parent e47fc9765d
commit 63e1b263c2
2 changed files with 5 additions and 6 deletions

View File

@ -17,24 +17,24 @@ public class ArmorStandWrapper {
private final Class<?> dataWatcherClass = Utils.getNMSClass("DataWatcher");
private final UUID uuid = UUID.randomUUID();
private final int entityId;
private ShopChest plugin;
private Object entity;
private Location location;
private String customName;
private int entityId = -1;
public ArmorStandWrapper(ShopChest plugin, Location location, String customName, boolean interactable) {
this.plugin = plugin;
this.location = location;
this.customName = customName;
this.entityId = Utils.getFreeEntityId();
}
public void setVisible(Player player, boolean visible) {
try {
if (visible) {
Object dataWatcher = Utils.createDataWatcher(customName, null);
entityId = Utils.getFreeEntityId();
Utils.sendPacket(plugin, Utils.createPacketSpawnEntity(plugin, entityId, uuid, location, EntityType.ARMOR_STAND), player);
Utils.sendPacket(plugin, packetPlayOutEntityMetadataClass.getConstructor(int.class, dataWatcherClass, boolean.class)
.newInstance(entityId, dataWatcher, true), player);

View File

@ -22,8 +22,7 @@ public class ShopItem {
private final ItemStack itemStack;
private final Location location;
private final UUID uuid = UUID.randomUUID();
private int entityId = -1;
private final int entityId;
private final Class<?> packetPlayOutEntityDestroyClass = Utils.getNMSClass("PacketPlayOutEntityDestroy");
private final Class<?> packetPlayOutEntityVelocityClass = Utils.getNMSClass("PacketPlayOutEntityVelocity");
@ -37,6 +36,7 @@ public class ShopItem {
this.plugin = plugin;
this.itemStack = itemStack;
this.location = location;
this.entityId = Utils.getFreeEntityId();
Class<?> entityClass = Utils.getNMSClass("Entity");
@ -91,7 +91,6 @@ public class ShopItem {
try {
Object nmsItemStack = craftItemStackClass.getMethod("asNMSCopy", ItemStack.class).invoke(null, itemStack);
Object dataWatcher = Utils.createDataWatcher(null, nmsItemStack);
entityId = Utils.getFreeEntityId();
Utils.sendPacket(plugin, Utils.createPacketSpawnEntity(plugin, entityId, uuid, location, EntityType.DROPPED_ITEM), p);
Utils.sendPacket(plugin, packetPlayOutEntityMetadataClass.getConstructor(int.class, dataWatcherClass, boolean.class).newInstance(entityId, dataWatcher, true), p);
if (Utils.getMajorVersion() < 14) {