Skip to content

Commit

Permalink
NBTApi - changes
Browse files Browse the repository at this point in the history
- Add null checkers for entities and items
- Ref #33
- Ref #21
  • Loading branch information
ShaneBeee committed Jul 7, 2020
1 parent 43c1320 commit 4acb766
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/tk/shanebee/bee/api/NBTApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,34 @@ public void addNBT(ItemStack itemStack, String value) {

public String getNBT(ItemType itemType) {
ItemStack itemStack = itemType.getRandom();
if (itemStack == null) return null;
if (itemStack == null || itemStack.getType() == Material.AIR) return null;

NBTItem item = new NBTItem(itemType.getRandom());
return item.toString();
}

public String getNBT(ItemStack itemStack) {
if (itemStack == null || itemStack.getType() == Material.AIR) return null;
NBTItem item = new NBTItem(itemStack);
return item.toString();
}

// ENTITY NBT
public void setNBT(Entity entity, String newValue) {
if (entity == null || entity.isDead()) return;
if (!validateNBT(newValue)) return;
addNBT(entity, newValue);
}

public void addNBT(Entity entity, String newValue) {
if (entity == null || entity.isDead()) return;
if (!validateNBT(newValue)) return;
NBTEntity nbtEntity = new NBTEntity(entity);
nbtEntity.mergeCompound(new NBTContainer(newValue));
}

public String getNBT(Entity entity) {
if (entity == null || entity.isDead()) return null;
NBTEntity nbtEntity = new NBTEntity(entity);
return nbtEntity.toString();
}
Expand Down

0 comments on commit 4acb766

Please sign in to comment.