1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-26 04:25:15 +01:00

Correct way to check for anvil enchanting

This commit is contained in:
Zrips 2022-02-11 11:57:36 +02:00
parent 2655a1cf94
commit 37a1afecb5
2 changed files with 40 additions and 27 deletions

View File

@ -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 {
@ -337,7 +340,7 @@ public final class JobsPaymentListener implements Listener {
if (Jobs.getGCManager().payForStackedEntities) {
if (JobsHook.WildStacker.isEnabled() && !StackSplit.SHEEP_SHEAR.isEnabled()) {
for(int i = 0; i < HookManager.getWildStackerHandler().getEntityAmount(sheep) - 1; i++) {
for (int i = 0; i < HookManager.getWildStackerHandler().getEntityAmount(sheep) - 1; i++) {
Jobs.action(jDamager, new CustomKillInfo(sheep.getColor().name(), ActionType.SHEAR));
}
} else if (JobsHook.StackMob.isEnabled() && HookManager.getStackMobHandler().isStacked(sheep)) {
@ -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;