From 8a65d4a5a03941fca7fd0d817c9c8dee130c245b Mon Sep 17 00:00:00 2001 From: fullwall Date: Wed, 30 Nov 2022 06:13:55 +0800 Subject: [PATCH] Add way to set custom name directly --- .../net/citizensnpcs/ProtocolLibListener.java | 6 ++--- .../citizensnpcs/commands/NPCCommands.java | 10 ++++--- .../net/citizensnpcs/npc/CitizensNPC.java | 26 ++++++++++++++----- .../npc/CitizensTraitFactory.java | 4 +-- ...hRotationTrait.java => RotationTrait.java} | 8 +++--- .../net/citizensnpcs/trait/ShopTrait.java | 8 ++++++ .../main/java/net/citizensnpcs/util/NMS.java | 4 +++ .../java/net/citizensnpcs/util/NMSBridge.java | 2 ++ .../nms/v1_10_R1/util/NMSImpl.java | 12 ++++++--- .../nms/v1_11_R1/util/NMSImpl.java | 12 ++++++--- .../nms/v1_12_R1/util/NMSImpl.java | 12 ++++++--- .../nms/v1_13_R2/util/NMSImpl.java | 12 ++++++--- .../nms/v1_14_R1/util/NMSImpl.java | 12 ++++++--- .../nms/v1_15_R1/util/NMSImpl.java | 12 ++++++--- .../nms/v1_16_R3/util/NMSImpl.java | 12 ++++++--- .../nms/v1_17_R1/util/NMSImpl.java | 12 ++++++--- .../nms/v1_18_R2/util/NMSImpl.java | 12 ++++++--- .../nms/v1_19_R1/util/NMSImpl.java | 13 +++++++--- .../nms/v1_8_R3/util/NMSImpl.java | 12 ++++++--- 19 files changed, 149 insertions(+), 52 deletions(-) rename main/src/main/java/net/citizensnpcs/trait/{SmoothRotationTrait.java => RotationTrait.java} (98%) diff --git a/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java b/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java index 6a1d732e28..de9692dd37 100644 --- a/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java +++ b/main/src/main/java/net/citizensnpcs/ProtocolLibListener.java @@ -17,8 +17,8 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.trait.SmoothRotationTrait; -import net.citizensnpcs.trait.SmoothRotationTrait.LocalRotationSession; +import net.citizensnpcs.trait.RotationTrait; +import net.citizensnpcs.trait.RotationTrait.LocalRotationSession; public class ProtocolLibListener { private final Class flagsClass; @@ -42,7 +42,7 @@ public void onPacketSending(PacketEvent event) { return; NPC npc = ((NPCHolder) entity).getNPC(); - SmoothRotationTrait trait = npc.getTraitNullable(SmoothRotationTrait.class); + RotationTrait trait = npc.getTraitNullable(RotationTrait.class); if (trait == null) return; diff --git a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java index f5c607ef6a..14cb81169d 100644 --- a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -133,7 +133,7 @@ import net.citizensnpcs.trait.SkinLayers.Layer; import net.citizensnpcs.trait.SkinTrait; import net.citizensnpcs.trait.SlimeSize; -import net.citizensnpcs.trait.SmoothRotationTrait; +import net.citizensnpcs.trait.RotationTrait; import net.citizensnpcs.trait.VillagerProfession; import net.citizensnpcs.trait.WitherTrait; import net.citizensnpcs.trait.WolfModifiers; @@ -2135,7 +2135,7 @@ public void rotate(CommandContext args, CommandSender sender, NPC npc, @Flag("bo yaw = NMS.getHeadYaw(npc.getEntity()); } } - npc.getOrAddTrait(SmoothRotationTrait.class).rotateToHave(yaw, pitch); + npc.getOrAddTrait(RotationTrait.class).rotateToHave(yaw, pitch); return; } if (yaw != null) { @@ -2294,14 +2294,14 @@ public void sheep(CommandContext args, CommandSender sender, NPC npc, @Flag("col @Command( aliases = { "npc" }, - usage = "shop (edit|show) (name)", + usage = "shop (edit|show|delete) (name)", desc = "NPC shop edit/show", modifiers = { "shop" }, min = 1, max = 3, permission = "citizens.npc.shop") public void shop(CommandContext args, Player sender, NPC npc, - @Arg(value = 1, completions = { "edit", "show" }) String action) throws CommandException { + @Arg(value = 1, completions = { "edit", "show", "delete" }) String action) throws CommandException { ShopTrait trait = npc.getOrAddTrait(ShopTrait.class); NPCShop shop = trait.getDefaultShop(); if (args.argsLength() > 1) { @@ -2317,6 +2317,8 @@ public void shop(CommandContext args, Player sender, NPC npc, shop.displayEditor(trait, sender); } else if (action.equalsIgnoreCase("show")) { shop.display(sender); + } else if (action.equalsIgnoreCase("delete")) { + trait.deleteShop(args.getString(2)); } else { throw new CommandUsageException(); } diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index d55009b1e0..736ec12c3f 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -7,6 +7,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Nameable; import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -59,6 +60,7 @@ public class CitizensNPC extends AbstractNPC { private ChunkCoord cachedCoord; private EntityController entityController; + private Object minecraftComponentCache; private final CitizensNavigator navigator = new CitizensNavigator(this); private int updateCounter = 0; @@ -241,6 +243,7 @@ public void setMoveDestination(Location destination) { @Override public void setName(String name) { + minecraftComponentCache = Messaging.minecraftComponentFromRawMessage(name); super.setName(name); if (requiresNameHologram() && !hasTrait(HologramTrait.class)) { @@ -384,7 +387,7 @@ public void accept(Runnable cancel) { updateFlyableState(); updateCustomNameVisibility(); - updateCustomName(); + updateScoreboard(); Messaging.debug("Spawned", CitizensNPC.this, "SpawnReason." + reason); cancel.run(); @@ -465,7 +468,7 @@ public void update() { } } if (isLiving) { - updateCustomName(); + updateScoreboard(); } updateCounter = 0; } @@ -505,9 +508,14 @@ public void update() { } } - private void updateCustomName() { - if (data().has(NPC.Metadata.SCOREBOARD_FAKE_TEAM_NAME)) { - getOrAddTrait(ScoreboardTrait.class).update(); + @Override + public void updateCustomName() { + if (!(getEntity() instanceof Nameable)) + return; + if (minecraftComponentCache != null) { + NMS.setCustomName(getEntity(), minecraftComponentCache); + } else { + super.updateCustomName(); } } @@ -517,7 +525,7 @@ private void updateCustomNameVisibility() { nameplateVisible = "false"; } if (nameplateVisible.equals("true") || nameplateVisible.equals("hover")) { - getEntity().setCustomName(getFullName()); + updateCustomName(); } getEntity().setCustomNameVisible(Boolean.parseBoolean(nameplateVisible)); } @@ -536,6 +544,12 @@ private void updateFlyableState() { } } + private void updateScoreboard() { + if (data().has(NPC.Metadata.SCOREBOARD_FAKE_TEAM_NAME)) { + getOrAddTrait(ScoreboardTrait.class).update(); + } + } + private void updateUsingItemState(Player player) { boolean useItem = data().get(NPC.Metadata.USING_HELD_ITEM, false), offhand = data().get(NPC.Metadata.USING_OFFHAND_ITEM, false); diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java b/main/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java index e10b997d94..2f6c1635ab 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java @@ -52,7 +52,7 @@ import net.citizensnpcs.trait.SkinTrait; import net.citizensnpcs.trait.SleepTrait; import net.citizensnpcs.trait.SlimeSize; -import net.citizensnpcs.trait.SmoothRotationTrait; +import net.citizensnpcs.trait.RotationTrait; import net.citizensnpcs.trait.SneakTrait; import net.citizensnpcs.trait.VillagerProfession; import net.citizensnpcs.trait.WitherTrait; @@ -91,7 +91,7 @@ public CitizensTraitFactory() { registerTrait(TraitInfo.create(Poses.class)); registerTrait(TraitInfo.create(Powered.class)); registerTrait(TraitInfo.create(RabbitType.class)); - registerTrait(TraitInfo.create(SmoothRotationTrait.class)); + registerTrait(TraitInfo.create(RotationTrait.class)); registerTrait(TraitInfo.create(Saddle.class)); registerTrait(TraitInfo.create(ScoreboardTrait.class)); registerTrait(TraitInfo.create(ScriptTrait.class)); diff --git a/main/src/main/java/net/citizensnpcs/trait/SmoothRotationTrait.java b/main/src/main/java/net/citizensnpcs/trait/RotationTrait.java similarity index 98% rename from main/src/main/java/net/citizensnpcs/trait/SmoothRotationTrait.java rename to main/src/main/java/net/citizensnpcs/trait/RotationTrait.java index 430913a6f2..af11a7c4b2 100644 --- a/main/src/main/java/net/citizensnpcs/trait/SmoothRotationTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/RotationTrait.java @@ -19,15 +19,15 @@ import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; -@TraitName("smoothrotationtrait") -public class SmoothRotationTrait extends Trait { +@TraitName("rotationtrait") +public class RotationTrait extends Trait { @Persist(reify = true) private final RotationParams globalParameters = new RotationParams(); private final RotationSession globalSession = new RotationSession(globalParameters); private final List localSessions = Lists.newArrayList(); - public SmoothRotationTrait() { - super("smoothrotationtrait"); + public RotationTrait() { + super("rotationtrait"); } public void clearLocalSessions() { diff --git a/main/src/main/java/net/citizensnpcs/trait/ShopTrait.java b/main/src/main/java/net/citizensnpcs/trait/ShopTrait.java index a21d25afb6..bb08ee1b05 100644 --- a/main/src/main/java/net/citizensnpcs/trait/ShopTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/ShopTrait.java @@ -64,6 +64,14 @@ public ShopTrait() { super("shop"); } + public void deleteShop(String name) { + if (StoredShops.GLOBAL_SHOPS.containsKey(name)) { + StoredShops.GLOBAL_SHOPS.remove(name); + } else { + StoredShops.NPC_SHOPS.remove(name); + } + } + public NPCShop getDefaultShop() { return StoredShops.NPC_SHOPS.computeIfAbsent(npc.getUniqueId().toString(), NPCShop::new); } diff --git a/main/src/main/java/net/citizensnpcs/util/NMS.java b/main/src/main/java/net/citizensnpcs/util/NMS.java index a174f8b9e4..c856ef9874 100644 --- a/main/src/main/java/net/citizensnpcs/util/NMS.java +++ b/main/src/main/java/net/citizensnpcs/util/NMS.java @@ -527,6 +527,10 @@ public static void setBodyYaw(Entity entity, float yaw) { BRIDGE.setBodyYaw(entity, yaw); } + public static void setCustomName(Entity entity, Object component) { + BRIDGE.setCustomName(entity, component); + } + public static void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) { BRIDGE.setDestination(entity, x, y, z, speed); } diff --git a/main/src/main/java/net/citizensnpcs/util/NMSBridge.java b/main/src/main/java/net/citizensnpcs/util/NMSBridge.java index a5547cc10e..9df8912f43 100644 --- a/main/src/main/java/net/citizensnpcs/util/NMSBridge.java +++ b/main/src/main/java/net/citizensnpcs/util/NMSBridge.java @@ -145,6 +145,8 @@ public interface NMSBridge { public void setBodyYaw(Entity entity, float yaw); + public void setCustomName(Entity entity, Object component); + public void setDestination(Entity entity, double x, double y, double z, float speed); public void setEndermanAngry(Enderman enderman, boolean angry); 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 d322a86825..31470af4a0 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 @@ -149,7 +149,7 @@ import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.skin.SkinnableEntity; -import net.citizensnpcs.trait.SmoothRotationTrait; +import net.citizensnpcs.trait.RotationTrait; import net.citizensnpcs.trait.versioned.BossBarTrait; import net.citizensnpcs.trait.versioned.PolarBearTrait; import net.citizensnpcs.trait.versioned.ShulkerTrait; @@ -197,6 +197,7 @@ import net.minecraft.server.v1_10_R1.EntityTypes; import net.minecraft.server.v1_10_R1.EntityWither; import net.minecraft.server.v1_10_R1.GenericAttributes; +import net.minecraft.server.v1_10_R1.IChatBaseComponent; import net.minecraft.server.v1_10_R1.IInventory; import net.minecraft.server.v1_10_R1.MathHelper; import net.minecraft.server.v1_10_R1.MinecraftKey; @@ -764,7 +765,7 @@ public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, ((EntityInsentient) handle).aQ += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -788,7 +789,7 @@ public void look(org.bukkit.entity.Entity from, org.bukkit.entity.Entity to) { ((EntityLiving) handle).aQ += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -1024,6 +1025,11 @@ public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).yaw = yaw; } + @Override + public void setCustomName(org.bukkit.entity.Entity entity, Object component) { + getHandle(entity).setCustomName(((IChatBaseComponent) component).getText()); + } + @Override public void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) { Entity handle = NMSImpl.getHandle(entity); 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 795d2415e6..6590032b46 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 @@ -163,7 +163,7 @@ import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.skin.SkinnableEntity; -import net.citizensnpcs.trait.SmoothRotationTrait; +import net.citizensnpcs.trait.RotationTrait; import net.citizensnpcs.trait.versioned.BossBarTrait; import net.citizensnpcs.trait.versioned.LlamaTrait; import net.citizensnpcs.trait.versioned.PolarBearTrait; @@ -215,6 +215,7 @@ import net.minecraft.server.v1_11_R1.EntityWither; import net.minecraft.server.v1_11_R1.EnumMoveType; import net.minecraft.server.v1_11_R1.GenericAttributes; +import net.minecraft.server.v1_11_R1.IChatBaseComponent; import net.minecraft.server.v1_11_R1.IInventory; import net.minecraft.server.v1_11_R1.MathHelper; import net.minecraft.server.v1_11_R1.MinecraftKey; @@ -819,7 +820,7 @@ public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, ((EntityLiving) handle).aP += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -843,7 +844,7 @@ public void look(org.bukkit.entity.Entity from, org.bukkit.entity.Entity to) { ((EntityLiving) handle).aP += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -1080,6 +1081,11 @@ public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).yaw = yaw; } + @Override + public void setCustomName(org.bukkit.entity.Entity entity, Object component) { + getHandle(entity).setCustomName(((IChatBaseComponent) component).getText()); + } + @Override public void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) { Entity handle = NMSImpl.getHandle(entity); 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 b0337bb15d..edf4485463 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 @@ -165,7 +165,7 @@ import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.skin.SkinnableEntity; -import net.citizensnpcs.trait.SmoothRotationTrait; +import net.citizensnpcs.trait.RotationTrait; import net.citizensnpcs.trait.versioned.BossBarTrait; import net.citizensnpcs.trait.versioned.LlamaTrait; import net.citizensnpcs.trait.versioned.ParrotTrait; @@ -219,6 +219,7 @@ import net.minecraft.server.v1_12_R1.EntityWither; import net.minecraft.server.v1_12_R1.EnumMoveType; import net.minecraft.server.v1_12_R1.GenericAttributes; +import net.minecraft.server.v1_12_R1.IChatBaseComponent; import net.minecraft.server.v1_12_R1.IInventory; import net.minecraft.server.v1_12_R1.MathHelper; import net.minecraft.server.v1_12_R1.MinecraftKey; @@ -826,7 +827,7 @@ public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, ((EntityLiving) handle).aP += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -851,7 +852,7 @@ public void look(org.bukkit.entity.Entity from, org.bukkit.entity.Entity to) { ((EntityLiving) handle).aP += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -1090,6 +1091,11 @@ public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).yaw = yaw; } + @Override + public void setCustomName(org.bukkit.entity.Entity entity, Object component) { + getHandle(entity).setCustomName(((IChatBaseComponent) component).getText()); + } + @Override public void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) { Entity handle = NMSImpl.getHandle(entity); 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 fbca669419..1f429981e5 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 @@ -176,7 +176,7 @@ import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.skin.SkinnableEntity; -import net.citizensnpcs.trait.SmoothRotationTrait; +import net.citizensnpcs.trait.RotationTrait; import net.citizensnpcs.trait.versioned.BossBarTrait; import net.citizensnpcs.trait.versioned.LlamaTrait; import net.citizensnpcs.trait.versioned.ParrotTrait; @@ -236,6 +236,7 @@ import net.minecraft.server.v1_13_R2.EnumMoveType; import net.minecraft.server.v1_13_R2.GenericAttributes; import net.minecraft.server.v1_13_R2.IBlockData; +import net.minecraft.server.v1_13_R2.IChatBaseComponent; import net.minecraft.server.v1_13_R2.IInventory; import net.minecraft.server.v1_13_R2.IRegistry; import net.minecraft.server.v1_13_R2.MathHelper; @@ -862,7 +863,7 @@ public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, ((EntityLiving) handle).aS += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -886,7 +887,7 @@ public void look(org.bukkit.entity.Entity from, org.bukkit.entity.Entity to) { ((EntityLiving) handle).aS += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -1126,6 +1127,11 @@ public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).yaw = yaw; } + @Override + public void setCustomName(org.bukkit.entity.Entity entity, Object component) { + getHandle(entity).setCustomName((IChatBaseComponent) component); + } + @Override public void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) { Entity handle = NMSImpl.getHandle(entity); 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 77fb13aa34..46be637768 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 @@ -184,7 +184,7 @@ import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.skin.SkinnableEntity; -import net.citizensnpcs.trait.SmoothRotationTrait; +import net.citizensnpcs.trait.RotationTrait; import net.citizensnpcs.trait.versioned.BossBarTrait; import net.citizensnpcs.trait.versioned.CatTrait; import net.citizensnpcs.trait.versioned.FoxTrait; @@ -256,6 +256,7 @@ import net.minecraft.server.v1_14_R1.EnumMoveType; import net.minecraft.server.v1_14_R1.GenericAttributes; import net.minecraft.server.v1_14_R1.IBlockData; +import net.minecraft.server.v1_14_R1.IChatBaseComponent; import net.minecraft.server.v1_14_R1.IInventory; import net.minecraft.server.v1_14_R1.IRegistry; import net.minecraft.server.v1_14_R1.MathHelper; @@ -929,7 +930,7 @@ public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, ((EntityLiving) handle).aM += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -953,7 +954,7 @@ public void look(org.bukkit.entity.Entity from, org.bukkit.entity.Entity to) { ((EntityLiving) handle).aM += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -1183,6 +1184,11 @@ public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).yaw = yaw; } + @Override + public void setCustomName(org.bukkit.entity.Entity entity, Object component) { + getHandle(entity).setCustomName((IChatBaseComponent) component); + } + @Override public void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) { Entity handle = NMSImpl.getHandle(entity); 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 5cbe21c80c..bf843548f0 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 @@ -185,7 +185,7 @@ import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.skin.SkinnableEntity; -import net.citizensnpcs.trait.SmoothRotationTrait; +import net.citizensnpcs.trait.RotationTrait; import net.citizensnpcs.trait.versioned.BeeTrait; import net.citizensnpcs.trait.versioned.BossBarTrait; import net.citizensnpcs.trait.versioned.CatTrait; @@ -260,6 +260,7 @@ import net.minecraft.server.v1_15_R1.EnumMoveType; import net.minecraft.server.v1_15_R1.GenericAttributes; import net.minecraft.server.v1_15_R1.IBlockData; +import net.minecraft.server.v1_15_R1.IChatBaseComponent; import net.minecraft.server.v1_15_R1.IInventory; import net.minecraft.server.v1_15_R1.IRegistry; import net.minecraft.server.v1_15_R1.MathHelper; @@ -941,7 +942,7 @@ public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, ((EntityLiving) handle).aK += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -965,7 +966,7 @@ public void look(org.bukkit.entity.Entity from, org.bukkit.entity.Entity to) { ((EntityLiving) handle).aK += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -1195,6 +1196,11 @@ public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).yaw = yaw; } + @Override + public void setCustomName(org.bukkit.entity.Entity entity, Object component) { + getHandle(entity).setCustomName((IChatBaseComponent) component); + } + @Override public void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) { Entity handle = NMSImpl.getHandle(entity); 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 16a873e27a..520eea6216 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 @@ -191,7 +191,7 @@ import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.skin.SkinnableEntity; -import net.citizensnpcs.trait.SmoothRotationTrait; +import net.citizensnpcs.trait.RotationTrait; import net.citizensnpcs.trait.versioned.BeeTrait; import net.citizensnpcs.trait.versioned.BossBarTrait; import net.citizensnpcs.trait.versioned.CatTrait; @@ -269,6 +269,7 @@ import net.minecraft.server.v1_16_R3.Fluid; import net.minecraft.server.v1_16_R3.GenericAttributes; import net.minecraft.server.v1_16_R3.IBlockData; +import net.minecraft.server.v1_16_R3.IChatBaseComponent; import net.minecraft.server.v1_16_R3.IInventory; import net.minecraft.server.v1_16_R3.IRegistry; import net.minecraft.server.v1_16_R3.MathHelper; @@ -965,7 +966,7 @@ public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, ((EntityLiving) handle).aC += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -989,7 +990,7 @@ public void look(org.bukkit.entity.Entity from, org.bukkit.entity.Entity to) { ((EntityLiving) handle).aC += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -1225,6 +1226,11 @@ public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).yaw = yaw; } + @Override + public void setCustomName(org.bukkit.entity.Entity entity, Object component) { + getHandle(entity).setCustomName((IChatBaseComponent) component); + } + @Override public void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) { Entity handle = NMSImpl.getHandle(entity); 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 085ec17a9b..dc5e8c6788 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 @@ -193,7 +193,7 @@ import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.skin.SkinnableEntity; -import net.citizensnpcs.trait.SmoothRotationTrait; +import net.citizensnpcs.trait.RotationTrait; import net.citizensnpcs.trait.versioned.AxolotlTrait; import net.citizensnpcs.trait.versioned.BeeTrait; import net.citizensnpcs.trait.versioned.BossBarTrait; @@ -223,6 +223,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; import net.minecraft.network.Connection; +import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket; @@ -970,7 +971,7 @@ public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, ((LivingEntity) handle).yHeadRot += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -994,7 +995,7 @@ public void look(org.bukkit.entity.Entity from, org.bukkit.entity.Entity to) { ((LivingEntity) handle).yHeadRot += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -1221,6 +1222,11 @@ public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).setYRot(yaw); } + @Override + public void setCustomName(org.bukkit.entity.Entity entity, Object component) { + getHandle(entity).setCustomName((Component) component); + } + @Override public void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) { Entity handle = NMSImpl.getHandle(entity); 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 fe04b5839c..bd81db161e 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 @@ -195,7 +195,7 @@ import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.skin.SkinnableEntity; -import net.citizensnpcs.trait.SmoothRotationTrait; +import net.citizensnpcs.trait.RotationTrait; import net.citizensnpcs.trait.versioned.AxolotlTrait; import net.citizensnpcs.trait.versioned.BeeTrait; import net.citizensnpcs.trait.versioned.BossBarTrait; @@ -225,6 +225,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; import net.minecraft.network.Connection; +import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket; @@ -976,7 +977,7 @@ public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, ((LivingEntity) handle).yHeadRot += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -1001,7 +1002,7 @@ public void look(org.bukkit.entity.Entity from, org.bukkit.entity.Entity to) { ((LivingEntity) handle).yHeadRot += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -1228,6 +1229,11 @@ public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).setYRot(yaw); } + @Override + public void setCustomName(org.bukkit.entity.Entity entity, Object component) { + getHandle(entity).setCustomName((Component) component); + } + @Override public void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) { Entity handle = NMSImpl.getHandle(entity); diff --git a/v1_19_R1/src/main/java/net/citizensnpcs/nms/v1_19_R1/util/NMSImpl.java b/v1_19_R1/src/main/java/net/citizensnpcs/nms/v1_19_R1/util/NMSImpl.java index 05d435e60e..0542d4c263 100644 --- a/v1_19_R1/src/main/java/net/citizensnpcs/nms/v1_19_R1/util/NMSImpl.java +++ b/v1_19_R1/src/main/java/net/citizensnpcs/nms/v1_19_R1/util/NMSImpl.java @@ -200,7 +200,7 @@ import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.skin.SkinnableEntity; -import net.citizensnpcs.trait.SmoothRotationTrait; +import net.citizensnpcs.trait.RotationTrait; import net.citizensnpcs.trait.versioned.AllayTrait; import net.citizensnpcs.trait.versioned.AxolotlTrait; import net.citizensnpcs.trait.versioned.BeeTrait; @@ -234,6 +234,7 @@ import net.minecraft.core.PositionImpl; import net.minecraft.core.Registry; import net.minecraft.network.Connection; +import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.contents.LiteralContents; import net.minecraft.network.protocol.Packet; @@ -324,6 +325,7 @@ public NMSImpl() { @Override public boolean addEntityToWorld(org.bukkit.entity.Entity entity, SpawnReason custom) { int viewDistance = -1; + ChunkMap chunkMap = null; try { if (entity instanceof Player) { @@ -996,7 +998,7 @@ public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, ((LivingEntity) handle).yHeadRot += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -1021,7 +1023,7 @@ public void look(org.bukkit.entity.Entity from, org.bukkit.entity.Entity to) { ((LivingEntity) handle).yHeadRot += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -1248,6 +1250,11 @@ public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).setYRot(yaw); } + @Override + public void setCustomName(org.bukkit.entity.Entity entity, Object component) { + getHandle(entity).setCustomName((Component) component); + } + @Override public void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) { Entity handle = NMSImpl.getHandle(entity); diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java index c6a21d798e..3f8db8aefc 100644 --- a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java @@ -138,7 +138,7 @@ import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.skin.SkinnableEntity; -import net.citizensnpcs.trait.SmoothRotationTrait; +import net.citizensnpcs.trait.RotationTrait; import net.citizensnpcs.util.EmptyChannel; import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.NMS; @@ -175,6 +175,7 @@ import net.minecraft.server.v1_8_R3.EntityTypes; import net.minecraft.server.v1_8_R3.EntityWither; import net.minecraft.server.v1_8_R3.GenericAttributes; +import net.minecraft.server.v1_8_R3.IChatBaseComponent; import net.minecraft.server.v1_8_R3.IInventory; import net.minecraft.server.v1_8_R3.MathHelper; import net.minecraft.server.v1_8_R3.Navigation; @@ -711,7 +712,7 @@ public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, ((EntityInsentient) handle).aK += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -734,7 +735,7 @@ public void look(org.bukkit.entity.Entity from, org.bukkit.entity.Entity to) { ((EntityLiving) handle).aK += 360F; } } else if (handle instanceof EntityHumanNPC) { - ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to); + ((EntityHumanNPC) handle).getNPC().getOrAddTrait(RotationTrait.class).rotateToFace(to); } } @@ -965,6 +966,11 @@ public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) { getHandle(entity).yaw = yaw; } + @Override + public void setCustomName(org.bukkit.entity.Entity entity, Object component) { + getHandle(entity).setCustomName(((IChatBaseComponent) component).getText()); + } + @Override public void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) { Entity handle = NMSImpl.getHandle(entity);