This commit is contained in:
Jitse Boonstra 2019-11-04 10:13:19 +01:00
commit 81b2bc3569
3 changed files with 64 additions and 1 deletions

View File

@ -40,7 +40,7 @@
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.33.Final</version>
<version>4.1.42.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>

View File

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

View File

@ -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<String> getText() {
return text;
}
}