Skip to content

Instantly share code, notes, and snippets.

@electronicboy
Created March 18, 2024 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electronicboy/031df94bb2ba120ceebb8c7f8a3f8425 to your computer and use it in GitHub Desktop.
Save electronicboy/031df94bb2ba120ceebb8c7f8a3f8425 to your computer and use it in GitHub Desktop.
public static List<ItemStack> parseEssKitToItems(Kit kit, User user) throws Exception {
final Essentials ess = Essentials.getInstance();
final List<String> items = kit.getItems(user);
List<ItemStack> ret = new ArrayList<>();
IText input = new SimpleTextInput(items);
IText output = new KeywordReplacer(input, user.getSource(), ess);
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
for (String kitItem : output.getLines()) {
// Trade
if (kitItem.startsWith(ess.getSettings().getCurrencySymbol())) {
BigDecimal value = new BigDecimal(kitItem.substring(ess.getSettings().getCurrencySymbol().length()).trim());
Trade t = new Trade(value, ess);
t.pay(user, Trade.OverflowType.DROP);
continue;
}
// Parts
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;
}
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);
}
ret.add(metaStack.getItemStack());
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment