PICKUP_ITEMS now defaults to false rather than isProtected

This commit is contained in:
fullwall 2023-02-26 15:51:59 +08:00
parent 960e1036b4
commit 8235ed160f
19 changed files with 38 additions and 32 deletions

View File

@ -8,6 +8,7 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.regex.Pattern;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@ -58,6 +59,7 @@ import net.citizensnpcs.api.trait.TraitFactory;
import net.citizensnpcs.api.trait.TraitInfo; import net.citizensnpcs.api.trait.TraitInfo;
import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.api.util.NBTStorage; import net.citizensnpcs.api.util.NBTStorage;
import net.citizensnpcs.api.util.Placeholders;
import net.citizensnpcs.api.util.Storage; import net.citizensnpcs.api.util.Storage;
import net.citizensnpcs.api.util.Translator; import net.citizensnpcs.api.util.Translator;
import net.citizensnpcs.api.util.YamlStorage; 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.ai.speech.CitizensSpeechFactory;
import net.citizensnpcs.npc.profile.ProfileFetcher; import net.citizensnpcs.npc.profile.ProfileFetcher;
import net.citizensnpcs.npc.skin.Skin; import net.citizensnpcs.npc.skin.Skin;
import net.citizensnpcs.trait.ClickRedirectTrait;
import net.citizensnpcs.trait.CommandTrait;
import net.citizensnpcs.trait.ShopTrait; import net.citizensnpcs.trait.ShopTrait;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
@ -432,6 +436,13 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
selector = new NPCSelector(this); selector = new NPCSelector(this);
Bukkit.getPluginManager().registerEvents(new EventListen(storedRegistries), 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"); Plugin papi = Bukkit.getPluginManager().getPlugin("PlaceholderAPI");
if (papi != null && papi.isEnabled()) { if (papi != null && papi.isEnabled()) {
new CitizensPlaceholders(selector).register(); new CitizensPlaceholders(selector).register();

View File

@ -1,9 +1,9 @@
package net.citizensnpcs.editor; package net.citizensnpcs.editor;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import net.citizensnpcs.api.npc.NPC;
public interface Equipper { public interface Equipper {
public void equip(Player equipper, NPC toEquip); public void equip(Player equipper, NPC toEquip);
} }

View File

@ -533,8 +533,7 @@ public class CitizensNPC extends AbstractNPC {
NMS.setKnockbackResistance((LivingEntity) getEntity(), isProtected() ? 1D : 0D); NMS.setKnockbackResistance((LivingEntity) getEntity(), isProtected() ? 1D : 0D);
if (SUPPORT_PICKUP_ITEMS) { if (SUPPORT_PICKUP_ITEMS) {
try { try {
((LivingEntity) getEntity()) ((LivingEntity) getEntity()).setCanPickupItems(data().get(NPC.Metadata.PICKUP_ITEMS, false));
.setCanPickupItems(data().get(NPC.Metadata.PICKUP_ITEMS, !isProtected()));
} catch (Throwable t) { } catch (Throwable t) {
SUPPORT_PICKUP_ITEMS = false; SUPPORT_PICKUP_ITEMS = false;
} }

View File

@ -8,9 +8,6 @@ import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName; import net.citizensnpcs.api.trait.TraitName;
/**
* Persists data related to {@link ArmorStand} NPCs.
*/
@TraitName("armorstandtrait") @TraitName("armorstandtrait")
public class ArmorStandTrait extends Trait { public class ArmorStandTrait extends Trait {
@Persist @Persist

View File

@ -316,6 +316,10 @@ public class CommandTrait extends Trait {
} }
} }
public String fillPlaceholder(CommandSender sender, String input) {
return null;
}
public double getCost() { public double getCost() {
return cost; return cost;
} }

View File

@ -25,7 +25,6 @@ import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName; import net.citizensnpcs.api.trait.TraitName;
import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.api.util.Placeholders; import net.citizensnpcs.api.util.Placeholders;
import net.citizensnpcs.api.util.SpigotUtil; import net.citizensnpcs.api.util.SpigotUtil;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
@ -310,18 +309,14 @@ public class HologramTrait extends Trait {
String text = line.text; String text = line.text;
if (ITEM_MATCHER.matcher(text).matches()) { if (ITEM_MATCHER.matcher(text).matches()) {
text = null; hologramNPC.data().set(NPC.Metadata.NAMEPLATE_VISIBLE, false);
continue;
} }
if (!updateName) if (!updateName)
continue; continue;
if (text != null && !ChatColor.stripColor(Messaging.parseComponents(text)).isEmpty()) { hologramNPC.setName(Placeholders.replace(text, null, npc));
hologramNPC.setName(Placeholders.replace(text, null, npc)); hologramNPC.data().set(NPC.Metadata.NAMEPLATE_VISIBLE, npc.getRawName().length() > 0);
hologramNPC.data().set(NPC.Metadata.NAMEPLATE_VISIBLE, true);
} else {
hologramNPC.setName("");
hologramNPC.data().set(NPC.Metadata.NAMEPLATE_VISIBLE, "hover");
}
} }
} }
@ -399,7 +394,7 @@ public class HologramTrait extends Trait {
} }
public HologramLine(String text, boolean persist, int ticks) { public HologramLine(String text, boolean persist, int ticks) {
this.text = text; this.text = text == null ? "" : text;
this.persist = persist; this.persist = persist;
this.ticks = ticks; this.ticks = ticks;
if (ITEM_MATCHER.matcher(text).matches()) { if (ITEM_MATCHER.matcher(text).matches()) {

View File

@ -2,10 +2,10 @@ package net.citizensnpcs.trait.waypoint;
import java.util.Iterator; import java.util.Iterator;
import net.citizensnpcs.api.event.CitizensEvent;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import net.citizensnpcs.api.event.CitizensEvent;
public class LinearWaypointsCompleteEvent extends CitizensEvent { public class LinearWaypointsCompleteEvent extends CitizensEvent {
private Iterator<Waypoint> next; private Iterator<Waypoint> next;
private final WaypointProvider provider; private final WaypointProvider provider;

View File

@ -1,9 +1,9 @@
package net.citizensnpcs.trait.waypoint.triggers; package net.citizensnpcs.trait.waypoint.triggers;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Location; import org.bukkit.Location;
import net.citizensnpcs.api.npc.NPC;
public interface WaypointTrigger { public interface WaypointTrigger {
String description(); String description();

View File

@ -308,7 +308,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
cs(); cs();
} }
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
AxisAlignedBB axisalignedbb; AxisAlignedBB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().dead) { if (this.isPassenger() && !this.getVehicle().dead) {
axisalignedbb = this.getBoundingBox().a(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0); axisalignedbb = this.getBoundingBox().a(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0);

View File

@ -366,7 +366,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
ct(); ct();
} }
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
AxisAlignedBB axisalignedbb; AxisAlignedBB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().dead) { if (this.isPassenger() && !this.getVehicle().dead) {
axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0); axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0);

View File

@ -394,7 +394,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
cB(); cB();
} }
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
AxisAlignedBB axisalignedbb; AxisAlignedBB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().dead) { if (this.isPassenger() && !this.getVehicle().dead) {
axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0); axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0);

View File

@ -373,7 +373,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
cN(); cN();
} }
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
AxisAlignedBB axisalignedbb; AxisAlignedBB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().dead) { if (this.isPassenger() && !this.getVehicle().dead) {
axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0); axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0);

View File

@ -378,7 +378,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
collideNearby(); collideNearby();
} }
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
AxisAlignedBB axisalignedbb; AxisAlignedBB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().dead) { if (this.isPassenger() && !this.getVehicle().dead) {
axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0); axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0);

View File

@ -422,7 +422,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
boolean navigating = npc.getNavigator().isNavigating(); boolean navigating = npc.getNavigator().isNavigating();
updatePackets(navigating); updatePackets(navigating);
npc.update(); npc.update();
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
AxisAlignedBB axisalignedbb; AxisAlignedBB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().dead) { if (this.isPassenger() && !this.getVehicle().dead) {
axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0); axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0);

View File

@ -452,7 +452,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
boolean navigating = npc.getNavigator().isNavigating(); boolean navigating = npc.getNavigator().isNavigating();
updatePackets(navigating); updatePackets(navigating);
npc.update(); npc.update();
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
AxisAlignedBB axisalignedbb; AxisAlignedBB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().dead) { if (this.isPassenger() && !this.getVehicle().dead) {
axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0); axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0);

View File

@ -194,7 +194,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
pushEntities(); pushEntities();
} }
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
AABB axisalignedbb; AABB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().isRemoved()) { if (this.isPassenger() && !this.getVehicle().isRemoved()) {
axisalignedbb = this.getBoundingBox().minmax(this.getVehicle().getBoundingBox()).inflate(1.0, 0.0, 1.0); axisalignedbb = this.getBoundingBox().minmax(this.getVehicle().getBoundingBox()).inflate(1.0, 0.0, 1.0);

View File

@ -195,7 +195,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
pushEntities(); pushEntities();
} }
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
AABB axisalignedbb; AABB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().isRemoved()) { if (this.isPassenger() && !this.getVehicle().isRemoved()) {
axisalignedbb = this.getBoundingBox().minmax(this.getVehicle().getBoundingBox()).inflate(1.0, 0.0, 1.0); axisalignedbb = this.getBoundingBox().minmax(this.getVehicle().getBoundingBox()).inflate(1.0, 0.0, 1.0);

View File

@ -200,7 +200,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
pushEntities(); pushEntities();
} }
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
AABB axisalignedbb; AABB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().isRemoved()) { if (this.isPassenger() && !this.getVehicle().isRemoved()) {
axisalignedbb = this.getBoundingBox().minmax(this.getVehicle().getBoundingBox()).inflate(1.0, 0.0, 1.0); axisalignedbb = this.getBoundingBox().minmax(this.getVehicle().getBoundingBox()).inflate(1.0, 0.0, 1.0);

View File

@ -306,7 +306,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.COLLIDABLE, !npc.isProtected())) {
bL(); bL();
} }
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, !npc.isProtected())) { if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
AxisAlignedBB axisalignedbb = null; AxisAlignedBB axisalignedbb = null;
if (this.vehicle != null && !this.vehicle.dead) { if (this.vehicle != null && !this.vehicle.dead) {
axisalignedbb = this.getBoundingBox().a(this.vehicle.getBoundingBox()).grow(1.0, 0.0, 1.0); axisalignedbb = this.getBoundingBox().a(this.vehicle.getBoundingBox()).grow(1.0, 0.0, 1.0);