Merge pull request #40 from A248/master
Add Getters for NPC's Item, Text, and State
This commit is contained in:
@@ -101,6 +101,14 @@ public interface NPC {
|
|||||||
* @return Object instance.
|
* @return Object instance.
|
||||||
*/
|
*/
|
||||||
NPC toggleState(NPCState state);
|
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.
|
* Change the item in the inventory of the NPC.
|
||||||
@@ -112,4 +120,19 @@ public interface NPC {
|
|||||||
NPC setItem(NPCSlot slot, ItemStack item);
|
NPC setItem(NPCSlot slot, ItemStack item);
|
||||||
|
|
||||||
NPC setText(List<String> text);
|
NPC setText(List<String> text);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the text of an NPC
|
||||||
|
*
|
||||||
|
* @return List<String> text
|
||||||
|
*/
|
||||||
|
List<String> getText();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a NPC's item.
|
||||||
|
*
|
||||||
|
* @param slot The slot the item is in.
|
||||||
|
* @return ItemStack item.
|
||||||
|
*/
|
||||||
|
ItemStack getItem(NPCSlot slot);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
@Override
|
||||||
public NPC toggleState(NPCState state) {
|
public NPC toggleState(NPCState state) {
|
||||||
int inActiveStatesIndex = -1;
|
int inActiveStatesIndex = -1;
|
||||||
@@ -263,6 +275,29 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
|||||||
return this;
|
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
|
@Override
|
||||||
public NPC setItem(NPCSlot slot, ItemStack item) {
|
public NPC setItem(NPCSlot slot, ItemStack item) {
|
||||||
if (slot == null) {
|
if (slot == null) {
|
||||||
@@ -315,4 +350,9 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
|||||||
this.text = text;
|
this.text = text;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user