-
-
Save electronicboy/031df94bb2ba120ceebb8c7f8a3f8425 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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