1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-30 21:07:48 +01:00

Only pay for new enchantments when enchanting items with books on an anvil

This commit is contained in:
BeepoWuff 2021-09-21 01:05:13 +10:00
parent bf58cf0766
commit a224545d79
No known key found for this signature in database
GPG Key ID: 4C176134BCA5058C
2 changed files with 13 additions and 1 deletions

View File

@ -964,7 +964,9 @@ public final class JobsPaymentListener implements Listener {
ItemStack secondSlotItem = inv.getItem(1);
if (Jobs.getGCManager().PayForEnchantingOnAnvil && secondSlotItem != null && secondSlotItem.getType() == Material.ENCHANTED_BOOK) {
for (Map.Entry<Enchantment, Integer> oneEnchant : resultStack.getEnchantments().entrySet()) {
Map<Enchantment, Integer> newEnchantments = Util.mapUnique(resultStack.getEnchantments(), firstSlot.getEnchantments());
for (Map.Entry<Enchantment, Integer> oneEnchant : newEnchantments.entrySet()) {
Enchantment enchant = oneEnchant.getKey();
if (enchant == null)
continue;

View File

@ -395,4 +395,14 @@ public final class Util {
return listOfCommands;
}
public static <K, V> Map<K, V> mapUnique(Map<K, V> left, Map<K, V> right) {
Map<K, V> difference = new HashMap<>();
difference.putAll(left);
difference.putAll(right);
difference.entrySet().removeAll(right.entrySet());
return difference;
}
}