1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-25 20:16:13 +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

@ -22,26 +22,26 @@ import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.BaseActionInfo;
public class EnchantActionInfo extends BaseActionInfo {
private String name;
private int level;
private String name;
private int level;
public EnchantActionInfo(String name, int level, ActionType type) {
super(type);
this.name = name;
this.level = level;
}
public EnchantActionInfo(String name, int level, ActionType type) {
super(type);
this.name = name;
this.level = level;
}
@Override
public String getName() {
return name;
}
@Override
public String getName() {
return name;
}
@Override
public String getNameWithSub() {
return name + ":" + level;
}
@Override
public String getNameWithSub() {
return name + ":" + level;
}
public int getLevel() {
return level;
}
public int getLevel() {
return level;
}
}

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,9 +340,9 @@ 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++) {
Jobs.action(jDamager, new CustomKillInfo(sheep.getColor().name(), ActionType.SHEAR));
}
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)) {
for (uk.antiperson.stackmob.entity.StackEntity stacked : HookManager.getStackMobHandler().getStackEntities()) {
if (stacked.getEntity().getType() == sheep.getType()) {
@ -588,7 +591,7 @@ public final class JobsPaymentListener implements Listener {
if (Jobs.getGCManager().payForStackedEntities) {
if (JobsHook.WildStacker.isEnabled()) {
for (int i = 0; i < HookManager.getWildStackerHandler().getEntityAmount(animal) - 1; i++) {
Jobs.action(jDamager, new EntityActionInfo(animal, ActionType.TAME));
Jobs.action(jDamager, new EntityActionInfo(animal, ActionType.TAME));
}
} else if (JobsHook.StackMob.isEnabled() && HookManager.getStackMobHandler().isStacked(animal)) {
for (uk.antiperson.stackmob.entity.StackEntity stacked : HookManager.getStackMobHandler().getStackEntities()) {
@ -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;
@ -1330,7 +1343,7 @@ public final class JobsPaymentListener implements Listener {
if (Jobs.getGCManager().payForStackedEntities) {
if (JobsHook.WildStacker.isEnabled()) {
for (int i = 0; i < HookManager.getWildStackerHandler().getEntityAmount(lVictim) - 1; i++) {
Jobs.action(jDamager, new EntityActionInfo(lVictim, ActionType.KILL), e.getDamager(), lVictim);
Jobs.action(jDamager, new EntityActionInfo(lVictim, ActionType.KILL), e.getDamager(), lVictim);
}
} else if (JobsHook.StackMob.isEnabled() && HookManager.getStackMobHandler().isStacked(lVictim)) {
for (uk.antiperson.stackmob.entity.StackEntity stacked : HookManager.getStackMobHandler().getStackEntities()) {