diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java index 593786f32..cf11924b4 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java @@ -1777,8 +1777,12 @@ public class NMSImpl implements NMSBridge { } public static SoundEffect getSoundEffect(NPC npc, SoundEffect snd, NPC.Metadata meta) { - return npc == null || !npc.data().has(meta) ? snd - : SoundEffect.a.get(new MinecraftKey(npc.data().get(meta, snd == null ? "" : snd.toString()))); + if (npc == null) + return snd; + String data = npc.data().get(meta); + return data == null ? snd + : SoundEffect.a.get(data.contains(":") ? new MinecraftKey(data.split(":")[0], data.split(":")[1]) + : new MinecraftKey(data)); } public static void initNetworkManager(NetworkManager network) { diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java index f519aa16a..415ca776f 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java @@ -1836,8 +1836,12 @@ public class NMSImpl implements NMSBridge { } public static SoundEffect getSoundEffect(NPC npc, SoundEffect snd, NPC.Metadata meta) { - return npc == null || !npc.data().has(meta) ? snd - : SoundEffect.a.get(new MinecraftKey(npc.data().get(meta, snd == null ? "" : snd.toString()))); + if (npc == null) + return snd; + String data = npc.data().get(meta); + return data == null ? snd + : SoundEffect.a.get(data.contains(":") ? new MinecraftKey(data.split(":")[0], data.split(":")[1]) + : new MinecraftKey(data)); } public static void initNetworkManager(NetworkManager network) { diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java index 110401c1e..3459bcffa 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java @@ -1844,8 +1844,12 @@ public class NMSImpl implements NMSBridge { } public static SoundEffect getSoundEffect(NPC npc, SoundEffect snd, NPC.Metadata meta) { - return npc == null || !npc.data().has(meta) ? snd - : SoundEffect.a.get(new MinecraftKey(npc.data().get(meta, snd == null ? "" : snd.toString()))); + if (npc == null) + return snd; + String data = npc.data().get(meta); + return data == null ? snd + : SoundEffect.a.get(data.contains(":") ? new MinecraftKey(data.split(":")[0], data.split(":")[1]) + : new MinecraftKey(data)); } public static void initNetworkManager(NetworkManager network) { diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java index dbf3f77b5..dda9952ae 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java @@ -1934,8 +1934,11 @@ public class NMSImpl implements NMSBridge { } public static SoundEffect getSoundEffect(NPC npc, SoundEffect snd, NPC.Metadata meta) { - return npc == null || !npc.data().has(meta) ? snd - : IRegistry.SOUND_EVENT.get(new MinecraftKey(npc.data().get(meta, snd == null ? "" : snd.toString()))); + if (npc == null) + return snd; + String data = npc.data().get(meta); + return data == null ? snd + : IRegistry.SOUND_EVENT.get(data.contains(":") ? MinecraftKey.a(data) : new MinecraftKey(data)); } public static void initNetworkManager(NetworkManager network) { diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java index 277843d98..decdb1257 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java @@ -2015,8 +2015,11 @@ public class NMSImpl implements NMSBridge { } public static SoundEffect getSoundEffect(NPC npc, SoundEffect snd, NPC.Metadata meta) { - return npc == null || !npc.data().has(meta) ? snd - : IRegistry.SOUND_EVENT.get(new MinecraftKey(npc.data().get(meta, snd == null ? "" : snd.toString()))); + if (npc == null) + return snd; + String data = npc.data().get(meta); + return data == null ? snd + : IRegistry.SOUND_EVENT.get(data.contains(":") ? MinecraftKey.a(data) : new MinecraftKey(data)); } public static void initNetworkManager(NetworkManager network) { diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java index 6a2227302..7f02b8fa6 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java @@ -2059,8 +2059,11 @@ public class NMSImpl implements NMSBridge { } public static SoundEffect getSoundEffect(NPC npc, SoundEffect snd, NPC.Metadata meta) { - return npc == null || !npc.data().has(meta) ? snd - : IRegistry.SOUND_EVENT.get(new MinecraftKey(npc.data().get(meta, snd == null ? "" : snd.toString()))); + if (npc == null) + return snd; + String data = npc.data().get(meta); + return data == null ? snd + : IRegistry.SOUND_EVENT.get(data.contains(":") ? MinecraftKey.a(data) : new MinecraftKey(data)); } public static void initNetworkManager(NetworkManager network) { diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java index 98c73e60e..3718c7c51 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java @@ -2052,8 +2052,11 @@ public class NMSImpl implements NMSBridge { } public static SoundEffect getSoundEffect(NPC npc, SoundEffect snd, NPC.Metadata meta) { - return npc == null || !npc.data().has(meta) ? snd - : IRegistry.SOUND_EVENT.get(new MinecraftKey(npc.data().get(meta, snd == null ? "" : snd.toString()))); + if (npc == null) + return snd; + String data = npc.data().get(meta); + return data == null ? snd + : IRegistry.SOUND_EVENT.get(data.contains(":") ? MinecraftKey.a(data) : new MinecraftKey(data)); } public static void initNetworkManager(NetworkManager network) { diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java index ba776ef5f..82b07e0d7 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java @@ -372,8 +372,8 @@ public class NMSImpl implements NMSBridge { return; try { - CHUNKMAP_UPDATE_PLAYER_STATUS.invoke( - ((ServerChunkCache) ((ServerLevel) handle.level).getChunkSource()).chunkMap, handle, !remove); + CHUNKMAP_UPDATE_PLAYER_STATUS.invoke(((ServerChunkCache) handle.level.getChunkSource()).chunkMap, handle, + !remove); } catch (Throwable e) { e.printStackTrace(); } @@ -2059,9 +2059,10 @@ public class NMSImpl implements NMSBridge { } public static SoundEvent getSoundEffect(NPC npc, SoundEvent snd, NPC.Metadata meta) { - return npc == null || !npc.data().has(meta) ? snd - : Registry.SOUND_EVENT - .get(new ResourceLocation(npc.data().get(meta, snd == null ? "" : snd.toString()))); + if (npc == null) + return snd; + String data = npc.data().get(meta); + return data == null ? snd : Registry.SOUND_EVENT.get(ResourceLocation.tryParse(data)); } public static void initNetworkManager(Connection network) { diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java index 6ce859a82..868181602 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java @@ -2068,9 +2068,10 @@ public class NMSImpl implements NMSBridge { } public static SoundEvent getSoundEffect(NPC npc, SoundEvent snd, NPC.Metadata meta) { - return npc == null || !npc.data().has(meta) ? snd - : Registry.SOUND_EVENT - .get(new ResourceLocation(npc.data().get(meta, snd == null ? "" : snd.toString()))); + if (npc == null) + return snd; + String data = npc.data().get(meta); + return data == null ? snd : Registry.SOUND_EVENT.get(ResourceLocation.tryParse(data)); } public static void initNetworkManager(Connection network) { diff --git a/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java b/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java index 9bb0a58c8..0c75f6bd2 100644 --- a/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java +++ b/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java @@ -934,22 +934,6 @@ public class NMSImpl implements NMSBridge { return handle.valid && handle.isAlive(); } - @Override - public void positionInteractionText(org.bukkit.entity.Player player, org.bukkit.entity.Entity entity, - org.bukkit.entity.Entity mount, double offset) { - offset += getRidingHeightOffset(entity, mount) + 0.5; - sendPacket(player, - new ClientboundBundlePacket(List.of( - new ClientboundSetEntityDataPacket(entity.getEntityId(), - List.of(new SynchedEntityData.DataItem<>(INTERACTION_WIDTH, 0f).value(), - new SynchedEntityData.DataItem<>(INTERACTION_HEIGHT, (float) offset).value(), - new SynchedEntityData.DataItem<>(DATA_POSE, Pose.CROAKING).value(), - new SynchedEntityData.DataItem<>(DATA_NAME_VISIBLE, true).value())), - new ClientboundSetPassengersPacket(getHandle(mount)), - new ClientboundSetEntityDataPacket(entity.getEntityId(), - List.of(new SynchedEntityData.DataItem<>(INTERACTION_HEIGHT, 999999f).value()))))); - } - @Override public void load(CommandManager manager) { registerTraitWithCommand(manager, EnderDragonTrait.class); @@ -1314,6 +1298,22 @@ public class NMSImpl implements NMSBridge { }; } + @Override + public void positionInteractionText(org.bukkit.entity.Player player, org.bukkit.entity.Entity entity, + org.bukkit.entity.Entity mount, double offset) { + offset += getRidingHeightOffset(entity, mount) + 0.5; + sendPacket(player, + new ClientboundBundlePacket(List.of( + new ClientboundSetEntityDataPacket(entity.getEntityId(), + List.of(new SynchedEntityData.DataItem<>(INTERACTION_WIDTH, 0f).value(), + new SynchedEntityData.DataItem<>(INTERACTION_HEIGHT, (float) offset).value(), + new SynchedEntityData.DataItem<>(DATA_POSE, Pose.CROAKING).value(), + new SynchedEntityData.DataItem<>(DATA_NAME_VISIBLE, true).value())), + new ClientboundSetPassengersPacket(getHandle(mount)), + new ClientboundSetEntityDataPacket(entity.getEntityId(), + List.of(new SynchedEntityData.DataItem<>(INTERACTION_HEIGHT, 999999f).value()))))); + } + @Override public void registerEntityClass(Class clazz) { if (ENTITY_REGISTRY == null) @@ -2295,9 +2295,10 @@ public class NMSImpl implements NMSBridge { } public static SoundEvent getSoundEffect(NPC npc, SoundEvent snd, NPC.Metadata meta) { - return npc == null || !npc.data().has(meta) ? snd - : BuiltInRegistries.SOUND_EVENT - .get(new ResourceLocation(npc.data().get(meta, snd == null ? "" : snd.toString()))); + if (npc == null) + return snd; + String data = npc.data().get(meta); + return data == null ? snd : BuiltInRegistries.SOUND_EVENT.get(ResourceLocation.tryParse(data)); } public static void initNetworkManager(Connection network) { diff --git a/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/NMSImpl.java b/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/NMSImpl.java index d9cb3f5e4..7f1b50989 100644 --- a/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/NMSImpl.java +++ b/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/NMSImpl.java @@ -911,22 +911,6 @@ public class NMSImpl implements NMSBridge { return handle.valid && handle.isAlive(); } - @Override - public void positionInteractionText(org.bukkit.entity.Player player, org.bukkit.entity.Entity entity, - org.bukkit.entity.Entity mount, double offset) { - offset += getRidingHeightOffset(entity, mount); - sendPacket(player, - new ClientboundBundlePacket(List.of( - new ClientboundSetEntityDataPacket(entity.getEntityId(), - List.of(new SynchedEntityData.DataItem<>(INTERACTION_WIDTH, 0f).value(), - new SynchedEntityData.DataItem<>(INTERACTION_HEIGHT, (float) offset).value(), - new SynchedEntityData.DataItem<>(DATA_POSE, Pose.CROAKING).value(), - new SynchedEntityData.DataItem<>(DATA_NAME_VISIBLE, true).value())), - new ClientboundSetPassengersPacket(getHandle(mount)), - new ClientboundSetEntityDataPacket(entity.getEntityId(), - List.of(new SynchedEntityData.DataItem<>(INTERACTION_HEIGHT, 999999f).value()))))); - } - @Override public void load(CommandManager manager) { registerTraitWithCommand(manager, EnderDragonTrait.class); @@ -1301,6 +1285,22 @@ public class NMSImpl implements NMSBridge { }; } + @Override + public void positionInteractionText(org.bukkit.entity.Player player, org.bukkit.entity.Entity entity, + org.bukkit.entity.Entity mount, double offset) { + offset += getRidingHeightOffset(entity, mount); + sendPacket(player, + new ClientboundBundlePacket(List.of( + new ClientboundSetEntityDataPacket(entity.getEntityId(), + List.of(new SynchedEntityData.DataItem<>(INTERACTION_WIDTH, 0f).value(), + new SynchedEntityData.DataItem<>(INTERACTION_HEIGHT, (float) offset).value(), + new SynchedEntityData.DataItem<>(DATA_POSE, Pose.CROAKING).value(), + new SynchedEntityData.DataItem<>(DATA_NAME_VISIBLE, true).value())), + new ClientboundSetPassengersPacket(getHandle(mount)), + new ClientboundSetEntityDataPacket(entity.getEntityId(), + List.of(new SynchedEntityData.DataItem<>(INTERACTION_HEIGHT, 999999f).value()))))); + } + @Override public void registerEntityClass(Class clazz) { if (ENTITY_REGISTRY == null) @@ -2297,9 +2297,10 @@ public class NMSImpl implements NMSBridge { } public static SoundEvent getSoundEffect(NPC npc, SoundEvent snd, NPC.Metadata meta) { - return npc == null || !npc.data().has(meta) ? snd - : BuiltInRegistries.SOUND_EVENT - .get(new ResourceLocation(npc.data().get(meta, snd == null ? "" : snd.toString()))); + if (npc == null) + return snd; + String data = npc.data().get(meta); + return data == null ? snd : BuiltInRegistries.SOUND_EVENT.get(ResourceLocation.tryParse(data)); } public static boolean isLeashed(NPC npc, Supplier isLeashed, Mob entity) { diff --git a/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/entity/EntityHumanNPC.java b/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/entity/EntityHumanNPC.java index 526940fe4..26fa4ff10 100644 --- a/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/entity/EntityHumanNPC.java +++ b/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/entity/EntityHumanNPC.java @@ -58,7 +58,7 @@ import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; public class EntityHumanNPC extends ServerPlayer implements NPCHolder, SkinnableEntity, ForwardingMobAI { - private MobAI ai; + private final MobAI ai; private int jumpTicks = 0; private final CitizensNPC npc; private boolean setBukkitEntity; @@ -73,12 +73,13 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable ai = new BasicMobAI(this); skinTracker = new SkinPacketTracker(this); try { - GAMEMODE_SETTING.invoke(gameMode, GameType.SURVIVAL, null); + GAMEMODE_SETTER.invoke(gameMode, GameType.SURVIVAL, null); } catch (Throwable e) { e.printStackTrace(); } initialise(minecraftServer, ci); } else { + ai = null; skinTracker = null; } } @@ -474,6 +475,6 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable } private static final float EPSILON = 0.003F; - private static final MethodHandle GAMEMODE_SETTING = NMS.getFirstMethodHandle(ServerPlayerGameMode.class, true, + private static final MethodHandle GAMEMODE_SETTER = NMS.getFirstMethodHandle(ServerPlayerGameMode.class, true, GameType.class, GameType.class); } diff --git a/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/NMSImpl.java b/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/NMSImpl.java index 3a7baf999..0613f800d 100644 --- a/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/NMSImpl.java +++ b/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/NMSImpl.java @@ -890,22 +890,6 @@ public class NMSImpl implements NMSBridge { return handle.valid && handle.isAlive(); } - @Override - public void positionInteractionText(org.bukkit.entity.Player player, org.bukkit.entity.Entity entity, - org.bukkit.entity.Entity mount, double offset) { - offset += getRidingHeightOffset(entity, mount); - sendPacket(player, - new ClientboundBundlePacket(List.of( - new ClientboundSetEntityDataPacket(entity.getEntityId(), - List.of(new SynchedEntityData.DataItem<>(INTERACTION_WIDTH, 0f).value(), - new SynchedEntityData.DataItem<>(INTERACTION_HEIGHT, (float) offset).value(), - new SynchedEntityData.DataItem<>(DATA_POSE, Pose.CROAKING).value(), - new SynchedEntityData.DataItem<>(DATA_NAME_VISIBLE, true).value())), - new ClientboundSetPassengersPacket(getHandle(mount)), - new ClientboundSetEntityDataPacket(entity.getEntityId(), - List.of(new SynchedEntityData.DataItem<>(INTERACTION_HEIGHT, 999999f).value()))))); - } - @Override public void load(CommandManager manager) { registerTraitWithCommand(manager, EnderDragonTrait.class); @@ -1279,6 +1263,22 @@ public class NMSImpl implements NMSBridge { }; } + @Override + public void positionInteractionText(org.bukkit.entity.Player player, org.bukkit.entity.Entity entity, + org.bukkit.entity.Entity mount, double offset) { + offset += getRidingHeightOffset(entity, mount); + sendPacket(player, + new ClientboundBundlePacket(List.of( + new ClientboundSetEntityDataPacket(entity.getEntityId(), + List.of(new SynchedEntityData.DataItem<>(INTERACTION_WIDTH, 0f).value(), + new SynchedEntityData.DataItem<>(INTERACTION_HEIGHT, (float) offset).value(), + new SynchedEntityData.DataItem<>(DATA_POSE, Pose.CROAKING).value(), + new SynchedEntityData.DataItem<>(DATA_NAME_VISIBLE, true).value())), + new ClientboundSetPassengersPacket(getHandle(mount)), + new ClientboundSetEntityDataPacket(entity.getEntityId(), + List.of(new SynchedEntityData.DataItem<>(INTERACTION_HEIGHT, 999999f).value()))))); + } + @Override public void registerEntityClass(Class clazz) { if (ENTITY_REGISTRY == null) @@ -2283,9 +2283,10 @@ public class NMSImpl implements NMSBridge { } public static SoundEvent getSoundEffect(NPC npc, SoundEvent snd, NPC.Metadata meta) { - return npc == null || !npc.data().has(meta) ? snd - : BuiltInRegistries.SOUND_EVENT.get( - ResourceLocation.withDefaultNamespace(npc.data().get(meta, snd == null ? "" : snd.toString()))); + if (npc == null) + return snd; + String data = npc.data().get(meta); + return data == null ? snd : BuiltInRegistries.SOUND_EVENT.get(ResourceLocation.tryParse(data)); } public static boolean isLeashed(NPC npc, Supplier isLeashed, Mob entity) {