From 8235ed160f3c9401ef07cd510228c2ee33af5284 Mon Sep 17 00:00:00 2001 From: fullwall Date: Sun, 26 Feb 2023 15:51:59 +0800 Subject: [PATCH] PICKUP_ITEMS now defaults to false rather than isProtected --- main/src/main/java/net/citizensnpcs/Citizens.java | 11 +++++++++++ .../java/net/citizensnpcs/editor/Equipper.java | 4 ++-- .../java/net/citizensnpcs/npc/CitizensNPC.java | 3 +-- .../net/citizensnpcs/trait/ArmorStandTrait.java | 3 --- .../java/net/citizensnpcs/trait/CommandTrait.java | 4 ++++ .../net/citizensnpcs/trait/HologramTrait.java | 15 +++++---------- .../waypoint/LinearWaypointsCompleteEvent.java | 4 ++-- .../trait/waypoint/triggers/WaypointTrigger.java | 4 ++-- .../nms/v1_10_R1/entity/EntityHumanNPC.java | 2 +- .../nms/v1_11_R1/entity/EntityHumanNPC.java | 2 +- .../nms/v1_12_R1/entity/EntityHumanNPC.java | 2 +- .../nms/v1_13_R2/entity/EntityHumanNPC.java | 2 +- .../nms/v1_14_R1/entity/EntityHumanNPC.java | 2 +- .../nms/v1_15_R1/entity/EntityHumanNPC.java | 2 +- .../nms/v1_16_R3/entity/EntityHumanNPC.java | 2 +- .../nms/v1_17_R1/entity/EntityHumanNPC.java | 2 +- .../nms/v1_18_R2/entity/EntityHumanNPC.java | 2 +- .../nms/v1_19_R2/entity/EntityHumanNPC.java | 2 +- .../nms/v1_8_R3/entity/EntityHumanNPC.java | 2 +- 19 files changed, 38 insertions(+), 32 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/Citizens.java b/main/src/main/java/net/citizensnpcs/Citizens.java index 9771a1c88..6c38ff0ce 100644 --- a/main/src/main/java/net/citizensnpcs/Citizens.java +++ b/main/src/main/java/net/citizensnpcs/Citizens.java @@ -8,6 +8,7 @@ import java.util.Locale; import java.util.Map; import java.util.UUID; import java.util.concurrent.Callable; +import java.util.regex.Pattern; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; @@ -58,6 +59,7 @@ import net.citizensnpcs.api.trait.TraitFactory; import net.citizensnpcs.api.trait.TraitInfo; import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.api.util.NBTStorage; +import net.citizensnpcs.api.util.Placeholders; import net.citizensnpcs.api.util.Storage; import net.citizensnpcs.api.util.Translator; import net.citizensnpcs.api.util.YamlStorage; @@ -75,6 +77,8 @@ import net.citizensnpcs.npc.Template; import net.citizensnpcs.npc.ai.speech.CitizensSpeechFactory; import net.citizensnpcs.npc.profile.ProfileFetcher; import net.citizensnpcs.npc.skin.Skin; +import net.citizensnpcs.trait.ClickRedirectTrait; +import net.citizensnpcs.trait.CommandTrait; import net.citizensnpcs.trait.ShopTrait; import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.NMS; @@ -432,6 +436,13 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { selector = new NPCSelector(this); Bukkit.getPluginManager().registerEvents(new EventListen(storedRegistries), this); + Bukkit.getPluginManager().registerEvents(new Placeholders(), this); + Placeholders.registerNPCPlaceholder(Pattern.compile("command_[a-zA-Z_0-9]+"), (npc, sender, input) -> { + npc = npc.hasTrait(ClickRedirectTrait.class) ? npc.getTraitNullable(ClickRedirectTrait.class).getNPC() + : npc; + CommandTrait trait = npc.getTraitNullable(CommandTrait.class); + return trait == null ? "" : trait.fillPlaceholder(sender, input); + }); Plugin papi = Bukkit.getPluginManager().getPlugin("PlaceholderAPI"); if (papi != null && papi.isEnabled()) { new CitizensPlaceholders(selector).register(); diff --git a/main/src/main/java/net/citizensnpcs/editor/Equipper.java b/main/src/main/java/net/citizensnpcs/editor/Equipper.java index 490eaec27..162ee685b 100644 --- a/main/src/main/java/net/citizensnpcs/editor/Equipper.java +++ b/main/src/main/java/net/citizensnpcs/editor/Equipper.java @@ -1,9 +1,9 @@ package net.citizensnpcs.editor; -import net.citizensnpcs.api.npc.NPC; - import org.bukkit.entity.Player; +import net.citizensnpcs.api.npc.NPC; + public interface Equipper { public void equip(Player equipper, NPC toEquip); } \ No newline at end of file diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index 605b37654..1b18feb89 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -533,8 +533,7 @@ public class CitizensNPC extends AbstractNPC { NMS.setKnockbackResistance((LivingEntity) getEntity(), isProtected() ? 1D : 0D); if (SUPPORT_PICKUP_ITEMS) { try { - ((LivingEntity) getEntity()) - .setCanPickupItems(data().get(NPC.Metadata.PICKUP_ITEMS, !isProtected())); + ((LivingEntity) getEntity()).setCanPickupItems(data().get(NPC.Metadata.PICKUP_ITEMS, false)); } catch (Throwable t) { SUPPORT_PICKUP_ITEMS = false; } diff --git a/main/src/main/java/net/citizensnpcs/trait/ArmorStandTrait.java b/main/src/main/java/net/citizensnpcs/trait/ArmorStandTrait.java index c2e55293a..53b0c4d7b 100644 --- a/main/src/main/java/net/citizensnpcs/trait/ArmorStandTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/ArmorStandTrait.java @@ -8,9 +8,6 @@ import net.citizensnpcs.api.persistence.Persist; import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.TraitName; -/** - * Persists data related to {@link ArmorStand} NPCs. - */ @TraitName("armorstandtrait") public class ArmorStandTrait extends Trait { @Persist diff --git a/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java b/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java index 93b8669e6..e776dcbcd 100644 --- a/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java @@ -316,6 +316,10 @@ public class CommandTrait extends Trait { } } + public String fillPlaceholder(CommandSender sender, String input) { + return null; + } + public double getCost() { return cost; } diff --git a/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java b/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java index 512cf556a..b1ac2b678 100644 --- a/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java @@ -25,7 +25,6 @@ import net.citizensnpcs.api.persistence.Persist; import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.TraitName; import net.citizensnpcs.api.util.DataKey; -import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.api.util.Placeholders; import net.citizensnpcs.api.util.SpigotUtil; import net.citizensnpcs.util.NMS; @@ -310,18 +309,14 @@ public class HologramTrait extends Trait { String text = line.text; if (ITEM_MATCHER.matcher(text).matches()) { - text = null; + hologramNPC.data().set(NPC.Metadata.NAMEPLATE_VISIBLE, false); + continue; } if (!updateName) continue; - if (text != null && !ChatColor.stripColor(Messaging.parseComponents(text)).isEmpty()) { - hologramNPC.setName(Placeholders.replace(text, null, npc)); - hologramNPC.data().set(NPC.Metadata.NAMEPLATE_VISIBLE, true); - } else { - hologramNPC.setName(""); - hologramNPC.data().set(NPC.Metadata.NAMEPLATE_VISIBLE, "hover"); - } + hologramNPC.setName(Placeholders.replace(text, null, npc)); + hologramNPC.data().set(NPC.Metadata.NAMEPLATE_VISIBLE, npc.getRawName().length() > 0); } } @@ -399,7 +394,7 @@ public class HologramTrait extends Trait { } public HologramLine(String text, boolean persist, int ticks) { - this.text = text; + this.text = text == null ? "" : text; this.persist = persist; this.ticks = ticks; if (ITEM_MATCHER.matcher(text).matches()) { diff --git a/main/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointsCompleteEvent.java b/main/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointsCompleteEvent.java index 3d455140f..b9497da31 100644 --- a/main/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointsCompleteEvent.java +++ b/main/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointsCompleteEvent.java @@ -2,10 +2,10 @@ package net.citizensnpcs.trait.waypoint; import java.util.Iterator; -import net.citizensnpcs.api.event.CitizensEvent; - import org.bukkit.event.HandlerList; +import net.citizensnpcs.api.event.CitizensEvent; + public class LinearWaypointsCompleteEvent extends CitizensEvent { private Iterator next; private final WaypointProvider provider; diff --git a/main/src/main/java/net/citizensnpcs/trait/waypoint/triggers/WaypointTrigger.java b/main/src/main/java/net/citizensnpcs/trait/waypoint/triggers/WaypointTrigger.java index ea50d7430..8b3b1a68c 100644 --- a/main/src/main/java/net/citizensnpcs/trait/waypoint/triggers/WaypointTrigger.java +++ b/main/src/main/java/net/citizensnpcs/trait/waypoint/triggers/WaypointTrigger.java @@ -1,9 +1,9 @@ package net.citizensnpcs.trait.waypoint.triggers; -import net.citizensnpcs.api.npc.NPC; - import org.bukkit.Location; +import net.citizensnpcs.api.npc.NPC; + public interface WaypointTrigger { String description(); diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/EntityHumanNPC.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/EntityHumanNPC.java index 94ef66881..27cadc13c 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/EntityHumanNPC.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/EntityHumanNPC.java @@ -308,7 +308,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { cs(); } - if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { + if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) { AxisAlignedBB axisalignedbb; if (this.isPassenger() && !this.getVehicle().dead) { axisalignedbb = this.getBoundingBox().a(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0); diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/EntityHumanNPC.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/EntityHumanNPC.java index 76f400d43..252e632b1 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/EntityHumanNPC.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/EntityHumanNPC.java @@ -366,7 +366,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { ct(); } - if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { + if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) { AxisAlignedBB axisalignedbb; if (this.isPassenger() && !this.getVehicle().dead) { axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0); diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/EntityHumanNPC.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/EntityHumanNPC.java index 39e6ab73d..7e4c9d751 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/EntityHumanNPC.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/EntityHumanNPC.java @@ -394,7 +394,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { cB(); } - if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { + if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) { AxisAlignedBB axisalignedbb; if (this.isPassenger() && !this.getVehicle().dead) { axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0); diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/EntityHumanNPC.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/EntityHumanNPC.java index ed87284b3..6fc13fab5 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/EntityHumanNPC.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/EntityHumanNPC.java @@ -373,7 +373,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { cN(); } - if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { + if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) { AxisAlignedBB axisalignedbb; if (this.isPassenger() && !this.getVehicle().dead) { axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0); diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/EntityHumanNPC.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/EntityHumanNPC.java index 69aee589a..6c7106cf6 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/EntityHumanNPC.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/EntityHumanNPC.java @@ -378,7 +378,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { collideNearby(); } - if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { + if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) { AxisAlignedBB axisalignedbb; if (this.isPassenger() && !this.getVehicle().dead) { axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0); diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/EntityHumanNPC.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/EntityHumanNPC.java index 446b6855f..b3e0e4ba1 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/EntityHumanNPC.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/EntityHumanNPC.java @@ -422,7 +422,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable boolean navigating = npc.getNavigator().isNavigating(); updatePackets(navigating); npc.update(); - if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { + if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) { AxisAlignedBB axisalignedbb; if (this.isPassenger() && !this.getVehicle().dead) { axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0); diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/EntityHumanNPC.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/EntityHumanNPC.java index 243328573..ed489242c 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/EntityHumanNPC.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/EntityHumanNPC.java @@ -452,7 +452,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable boolean navigating = npc.getNavigator().isNavigating(); updatePackets(navigating); npc.update(); - if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { + if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) { AxisAlignedBB axisalignedbb; if (this.isPassenger() && !this.getVehicle().dead) { axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0); diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/EntityHumanNPC.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/EntityHumanNPC.java index 5adce7577..cc48acb09 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/EntityHumanNPC.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/EntityHumanNPC.java @@ -194,7 +194,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { pushEntities(); } - if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { + if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) { AABB axisalignedbb; if (this.isPassenger() && !this.getVehicle().isRemoved()) { axisalignedbb = this.getBoundingBox().minmax(this.getVehicle().getBoundingBox()).inflate(1.0, 0.0, 1.0); diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/entity/EntityHumanNPC.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/entity/EntityHumanNPC.java index 7fa727ffb..c1b4a7ba6 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/entity/EntityHumanNPC.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/entity/EntityHumanNPC.java @@ -195,7 +195,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { pushEntities(); } - if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { + if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) { AABB axisalignedbb; if (this.isPassenger() && !this.getVehicle().isRemoved()) { axisalignedbb = this.getBoundingBox().minmax(this.getVehicle().getBoundingBox()).inflate(1.0, 0.0, 1.0); diff --git a/v1_19_R2/src/main/java/net/citizensnpcs/nms/v1_19_R2/entity/EntityHumanNPC.java b/v1_19_R2/src/main/java/net/citizensnpcs/nms/v1_19_R2/entity/EntityHumanNPC.java index 74545fd54..62e844d7f 100644 --- a/v1_19_R2/src/main/java/net/citizensnpcs/nms/v1_19_R2/entity/EntityHumanNPC.java +++ b/v1_19_R2/src/main/java/net/citizensnpcs/nms/v1_19_R2/entity/EntityHumanNPC.java @@ -200,7 +200,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { pushEntities(); } - if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { + if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) { AABB axisalignedbb; if (this.isPassenger() && !this.getVehicle().isRemoved()) { axisalignedbb = this.getBoundingBox().minmax(this.getVehicle().getBoundingBox()).inflate(1.0, 0.0, 1.0); diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EntityHumanNPC.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EntityHumanNPC.java index d7733ebb6..90f9cae39 100644 --- a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EntityHumanNPC.java +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EntityHumanNPC.java @@ -306,7 +306,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { bL(); } - if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { + if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) { AxisAlignedBB axisalignedbb = null; if (this.vehicle != null && !this.vehicle.dead) { axisalignedbb = this.getBoundingBox().a(this.vehicle.getBoundingBox()).grow(1.0, 0.0, 1.0);