mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 14:05:25 +01:00
Correct way to check for anvil enchanting
This commit is contained in:
parent
2655a1cf94
commit
37a1afecb5
@ -18,9 +18,11 @@
|
||||
|
||||
package com.gamingmesh.jobs.listeners;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -126,6 +128,7 @@ import net.Zrips.CMILib.Container.CMILocation;
|
||||
import net.Zrips.CMILib.Entities.CMIEntityType;
|
||||
import net.Zrips.CMILib.Items.CMIItemStack;
|
||||
import net.Zrips.CMILib.Items.CMIMaterial;
|
||||
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||
import net.Zrips.CMILib.Version.Version;
|
||||
|
||||
public final class JobsPaymentListener implements Listener {
|
||||
@ -990,7 +993,7 @@ public final class JobsPaymentListener implements Listener {
|
||||
ItemStack secondSlotItem = inv.getItem(1);
|
||||
|
||||
if (Jobs.getGCManager().PayForEnchantingOnAnvil && secondSlotItem != null && secondSlotItem.getType() == Material.ENCHANTED_BOOK) {
|
||||
Map<Enchantment, Integer> newEnchantments = Util.mapUnique(resultStack.getEnchantments(), firstSlot.getEnchantments());
|
||||
Map<Enchantment, Integer> newEnchantments = mapUnique(resultStack.getEnchantments(), firstSlot.getEnchantments());
|
||||
|
||||
for (Map.Entry<Enchantment, Integer> oneEnchant : newEnchantments.entrySet()) {
|
||||
Enchantment enchant = oneEnchant.getKey();
|
||||
@ -998,20 +1001,30 @@ public final class JobsPaymentListener implements Listener {
|
||||
continue;
|
||||
|
||||
String enchantName = getEnchantName(enchant);
|
||||
if (enchantName != null)
|
||||
if (enchantName != null) {
|
||||
Jobs.action(jPlayer, new EnchantActionInfo(enchantName, oneEnchant.getValue(), ActionType.ENCHANT));
|
||||
}
|
||||
}
|
||||
} else if (secondSlotItem == null || secondSlotItem.getType() != Material.ENCHANTED_BOOK) { // Enchanted books does not have durability
|
||||
|
||||
if (!changed(firstSlot, secondSlotItem, resultStack))
|
||||
return;
|
||||
|
||||
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.REPAIR));
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<Enchantment, Integer> mapUnique(Map<Enchantment, Integer> map1, Map<Enchantment, Integer> map2) {
|
||||
Map<Enchantment, Integer> map = new HashMap<Enchantment, Integer>();
|
||||
for (Entry<Enchantment, Integer> entry : map1.entrySet()) {
|
||||
if (map2.get(entry.getKey()) != null && map2.get(entry.getKey()) == entry.getValue())
|
||||
continue;
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEnchantItem(EnchantItemEvent event) {
|
||||
|
||||
if (!Jobs.getGCManager().canPerformActionInWorld(event.getEnchanter().getWorld()))
|
||||
return;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user