Skip to content

Commit

Permalink
Set item in hand less aggressively
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Mar 9, 2022
1 parent 562b964 commit baee9f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void onSpawn() {

@Override
public void run() {
if (!npc.isSpawned())
if (!npc.isSpawned() || !(npc.getEntity() instanceof LivingEntity))
return;
if (npc.getEntity() instanceof Enderman) {
Enderman enderman = (Enderman) npc.getEntity();
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/net/citizensnpcs/api/trait/trait/Inventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.minecart.StorageMinecart;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -61,7 +62,9 @@ public void inventoryCloseEvent(InventoryCloseEvent event) {
for (int i = 0; i < contents.length; i++) {
this.contents[i] = contents[i];
if (i == 0) {
npc.getOrAddTrait(Equipment.class).setItemInHand(contents[i]);
if (npc.getEntity() instanceof LivingEntity) {
npc.getOrAddTrait(Equipment.class).setItemInHand(contents[i]);
}
}
}
if (npc.getEntity() instanceof InventoryHolder) {
Expand Down Expand Up @@ -163,7 +166,7 @@ private void saveContents(Entity entity) {
} else if (entity instanceof InventoryHolder) {
contents = ((InventoryHolder) entity).getInventory().getContents();
}
if (entity instanceof Player) {
if (entity instanceof LivingEntity) {
npc.getOrAddTrait(Equipment.class).setItemInHand(contents[0]);
}
}
Expand Down Expand Up @@ -232,7 +235,7 @@ public void setItem(int slot, ItemStack item) {
} else {
throw new IndexOutOfBoundsException();
}
if (slot == 0) {
if (slot == 0 && npc.getEntity() instanceof LivingEntity) {
npc.getOrAddTrait(Equipment.class).setItemInHand(item);
}
}
Expand Down

0 comments on commit baee9f0

Please sign in to comment.