Add command + money queues to process after items in kits (#3434)

Fixes #3431
This commit is contained in:
Josh Roy 2020-07-01 16:51:10 -04:00 committed by GitHub
parent b7f38517ef
commit b6c9bc1439
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 5 deletions

View File

@ -162,12 +162,11 @@ public class Kit {
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
final boolean currencyIsSuffix = ess.getSettings().isCurrencySymbolSuffixed();
List<ItemStack> itemList = new ArrayList<>();
List<String> commandQueue = new ArrayList<>();
List<String> moneyQueue = new ArrayList<>();
for (String kitItem : output.getLines()) {
if (!currencyIsSuffix ? kitItem.startsWith(ess.getSettings().getCurrencySymbol()) : kitItem.endsWith(ess.getSettings().getCurrencySymbol())) {
final String valueString = NumberUtil.sanitizeCurrencyString(kitItem, ess);
BigDecimal value = new BigDecimal(valueString.trim());
Trade t = new Trade(value, ess);
t.pay(user, OverflowType.DROP);
moneyQueue.add(NumberUtil.sanitizeCurrencyString(kitItem, ess));
continue;
}
@ -175,7 +174,7 @@ public class Kit {
String command = kitItem.substring(1);
String name = user.getName();
command = command.replace("{player}", name);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
commandQueue.add(command);
continue;
}
@ -229,6 +228,20 @@ public class Kit {
}
}
user.getBase().updateInventory();
// Process money & command queues
// Done after all items have been processed so commands are not run and money is not given if
// an error occurs during the item giving process
for (String valueString : moneyQueue) {
BigDecimal value = new BigDecimal(valueString.trim());
Trade t = new Trade(value, ess);
t.pay(user, OverflowType.DROP);
}
for (String cmd : commandQueue) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
}
if (spew) {
user.sendMessage(tl("kitInvFull"));
}