Skip to content

Commit

Permalink
PICKUP_ITEMS now defaults to false rather than isProtected
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Feb 26, 2023
1 parent 960e103 commit 8235ed1
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 32 deletions.
11 changes: 11 additions & 0 deletions main/src/main/java/net/citizensnpcs/Citizens.java
Expand Up @@ -8,6 +8,7 @@
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;
Expand Down Expand Up @@ -58,6 +59,7 @@
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;
Expand All @@ -75,6 +77,8 @@
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;
Expand Down Expand Up @@ -432,6 +436,13 @@ public void onEnable() {
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();
Expand Down
4 changes: 2 additions & 2 deletions 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);
}
3 changes: 1 addition & 2 deletions main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java
Expand Up @@ -533,8 +533,7 @@ public void update() {
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;
}
Expand Down
Expand Up @@ -8,9 +8,6 @@
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
Expand Down
4 changes: 4 additions & 0 deletions main/src/main/java/net/citizensnpcs/trait/CommandTrait.java
Expand Up @@ -316,6 +316,10 @@ private void runCommand(final Player player, NPCCommand command) {
}
}

public String fillPlaceholder(CommandSender sender, String input) {
return null;
}

public double getCost() {
return cost;
}
Expand Down
15 changes: 5 additions & 10 deletions main/src/main/java/net/citizensnpcs/trait/HologramTrait.java
Expand Up @@ -25,7 +25,6 @@
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;
Expand Down Expand Up @@ -310,18 +309,14 @@ public void run() {

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);
}
}

Expand Down Expand Up @@ -399,7 +394,7 @@ public HologramLine(String text, boolean persist) {
}

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()) {
Expand Down
Expand Up @@ -2,10 +2,10 @@

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<Waypoint> next;
private final WaypointProvider provider;
Expand Down
@@ -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();

Expand Down
Expand Up @@ -308,7 +308,7 @@ public void k_() {
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);
Expand Down
Expand Up @@ -366,7 +366,7 @@ public void playerTick() {
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);
Expand Down
Expand Up @@ -394,7 +394,7 @@ public void playerTick() {
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);
Expand Down
Expand Up @@ -373,7 +373,7 @@ public void playerTick() {
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);
Expand Down
Expand Up @@ -378,7 +378,7 @@ public void playerTick() {
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);
Expand Down
Expand Up @@ -422,7 +422,7 @@ public void tick() {
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);
Expand Down
Expand Up @@ -452,7 +452,7 @@ public void tick() {
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);
Expand Down
Expand Up @@ -194,7 +194,7 @@ public void doTick() {
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);
Expand Down
Expand Up @@ -195,7 +195,7 @@ public void doTick() {
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);
Expand Down
Expand Up @@ -200,7 +200,7 @@ public void doTick() {
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);
Expand Down
Expand Up @@ -306,7 +306,7 @@ public void l() {
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);
Expand Down

0 comments on commit 8235ed1

Please sign in to comment.