Skip to content

Commit

Permalink
Allow auto equip in nbt serialized kits (EssentialsX#4491)
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com>
  • Loading branch information
pop4959 and JRoy authored Aug 28, 2021
1 parent 4811eb1 commit e4c179f
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions Essentials/src/main/java/com/earth2me/essentials/Kit.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,31 +188,33 @@ public boolean expandItems(final User user, final List<String> items) throws Exc
continue;
}

final ItemStack stack;

if (kitItem.startsWith("@")) {
if (ess.getSerializationProvider() == null) {
ess.getLogger().log(Level.WARNING, tl("kitError3", kitName, user.getName()));
continue;
}
itemList.add(ess.getSerializationProvider().deserializeItem(Base64Coder.decodeLines(kitItem.substring(1))));
continue;
}
stack = ess.getSerializationProvider().deserializeItem(Base64Coder.decodeLines(kitItem.substring(1)));
} else {
final String[] parts = kitItem.split(" +");
final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);

final String[] parts = kitItem.split(" +");
final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);
if (parseStack.getType() == Material.AIR) {
continue;
}

if (parseStack.getType() == Material.AIR) {
continue;
}
final MetaItemStack metaStack = new MetaItemStack(parseStack);

final MetaItemStack metaStack = new MetaItemStack(parseStack);
if (parts.length > 2) {
// We pass a null sender here because kits should not do perm checks
metaStack.parseStringMeta(null, allowUnsafe, parts, 2, ess);
}

if (parts.length > 2) {
// We pass a null sender here because kits should not do perm checks
metaStack.parseStringMeta(null, allowUnsafe, parts, 2, ess);
stack = metaStack.getItemStack();
}

if (autoEquip) {
final ItemStack stack = metaStack.getItemStack();
final Material material = stack.getType();
final PlayerInventory inventory = user.getBase().getInventory();
if (MaterialUtil.isHelmet(material) && isEmptyStack(inventory.getHelmet())) {
Expand All @@ -230,7 +232,7 @@ public boolean expandItems(final User user, final List<String> items) throws Exc
}
}

itemList.add(metaStack.getItemStack());
itemList.add(stack);
}

final Map<Integer, ItemStack> overfilled;
Expand Down

0 comments on commit e4c179f

Please sign in to comment.