From d7144e445e166ae94cd8a592a0c37616229fdd96 Mon Sep 17 00:00:00 2001 From: A248 Date: Thu, 31 Oct 2019 19:50:46 -0400 Subject: [PATCH 1/4] Update NPC.java with getText() and getItem() Adds these methods to the NPC interface. --- api/src/main/java/net/jitse/npclib/api/NPC.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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..7fa369f 100644 --- a/api/src/main/java/net/jitse/npclib/api/NPC.java +++ b/api/src/main/java/net/jitse/npclib/api/NPC.java @@ -112,4 +112,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); } From b97361516cd8c7b79e55423bdfc2e129aa2057ea Mon Sep 17 00:00:00 2001 From: A248 Date: Thu, 31 Oct 2019 19:57:04 -0400 Subject: [PATCH 2/4] Make NPCBase.java compliant with updated NPC.java Makes NPCBase compliant with net.jitse.npclib.api.NPC. Implements NPC#getText() to return List and NPC#getSlot(NPCSlot slot) to return ItemStack. --- .../net/jitse/npclib/internal/NPCBase.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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..0abfc05 100644 --- a/api/src/main/java/net/jitse/npclib/internal/NPCBase.java +++ b/api/src/main/java/net/jitse/npclib/internal/NPCBase.java @@ -263,6 +263,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 +338,9 @@ public abstract class NPCBase implements NPC, NPCPacketHandler { this.text = text; return this; } + + @Override + public List getText() { + return text; + } } From 73df32172e5f88db05d0aab847296c8e37106daa Mon Sep 17 00:00:00 2001 From: A248 Date: Thu, 31 Oct 2019 20:10:20 -0400 Subject: [PATCH 3/4] Add getState(NPCState) Adds NPC#getState(NPCState) to return a boolean indicating whether the NPC in question has a specific state. --- api/src/main/java/net/jitse/npclib/api/NPC.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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 7fa369f..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. From 47d3417606034468d797d26829436debaccc5416 Mon Sep 17 00:00:00 2001 From: A248 Date: Thu, 31 Oct 2019 20:14:46 -0400 Subject: [PATCH 4/4] Updated NPCBase to with NPC#getState(NPCState) Implemented net.jitse.npclib.api.NPC#getState(NPCState) to return a boolean indicating whether a state is toggled or not. --- .../main/java/net/jitse/npclib/internal/NPCBase.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 0abfc05..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;