diff --git a/api/pom.xml b/api/pom.xml index 9356c3f..d1810a2 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -40,7 +40,7 @@ io.netty netty-all - 4.1.33.Final + 4.1.42.Final provided diff --git a/api/src/main/java/net/jitse/npclib/api/NPC.java b/api/src/main/java/net/jitse/npclib/api/NPC.java index 4c8b71a..4caae2b 100644 --- a/api/src/main/java/net/jitse/npclib/api/NPC.java +++ b/api/src/main/java/net/jitse/npclib/api/NPC.java @@ -101,6 +101,14 @@ public interface NPC { * @return Object instance. */ NPC toggleState(NPCState state); + + /** + * Get state of NPC. + * + * @param state The state requested. + * @return boolean on/off status. + */ + boolean getState(NPCState state); /** * Change the item in the inventory of the NPC. @@ -112,4 +120,19 @@ public interface NPC { NPC setItem(NPCSlot slot, ItemStack item); NPC setText(List text); + + /** + * Get the text of an NPC + * + * @return List text + */ + List getText(); + + /** + * Get a NPC's item. + * + * @param slot The slot the item is in. + * @return ItemStack item. + */ + ItemStack getItem(NPCSlot slot); } diff --git a/api/src/main/java/net/jitse/npclib/internal/NPCBase.java b/api/src/main/java/net/jitse/npclib/internal/NPCBase.java index ec86888..90cec56 100644 --- a/api/src/main/java/net/jitse/npclib/internal/NPCBase.java +++ b/api/src/main/java/net/jitse/npclib/internal/NPCBase.java @@ -220,6 +220,18 @@ public abstract class NPCBase implements NPC, NPCPacketHandler { } } + @Override + public boolean getState(NPCState state) { + if (activeStates.length != 0) { + for (int i = 0; i < activeStates.length; i++) { + if (activeStates[i] == state) { + return true; + } + } + } + return false; + } + @Override public NPC toggleState(NPCState state) { int inActiveStatesIndex = -1; @@ -263,6 +275,29 @@ public abstract class NPCBase implements NPC, NPCPacketHandler { return this; } + @Override + public ItemStack getItem(NPCSlot slot) { + if (slot == null) { + throw new NullPointerException("Slot cannot be null"); + } + switch (slot) { + case HELMET: + return this.helmet; + case CHESTPLATE: + return this.chestplate; + case LEGGINGS: + return this.leggings; + case BOOTS: + return this.boots; + case MAINHAND: + return this.inHand; + case OFFHAND: + return this.offHand; + default: + throw new IllegalArgumentException("Entered an invalid inventory slot"); + } + } + @Override public NPC setItem(NPCSlot slot, ItemStack item) { if (slot == null) { @@ -315,4 +350,9 @@ public abstract class NPCBase implements NPC, NPCPacketHandler { this.text = text; return this; } + + @Override + public List getText() { + return text; + } }