mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-02 14:29:07 +01:00
Taking into consideration changed durability on the item
This commit is contained in:
parent
33b4dfe6ce
commit
531b12a6fa
@ -736,7 +736,6 @@ public final class JobsPaymentListener implements Listener {
|
|||||||
for (ItemStack OneDye : dyeStack) {
|
for (ItemStack OneDye : dyeStack) {
|
||||||
Jobs.action(jPlayer, new ItemActionInfo(OneDye, ActionType.DYE));
|
Jobs.action(jPlayer, new ItemActionInfo(OneDye, ActionType.DYE));
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -857,6 +856,33 @@ public final class JobsPaymentListener implements Listener {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean changed(ItemStack first, ItemStack second, ItemStack result) {
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
ItemStack itemToCheck = first;
|
||||||
|
if (first == null || first.getType() != result.getType())
|
||||||
|
itemToCheck = second;
|
||||||
|
|
||||||
|
if (itemToCheck == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (itemToCheck.getType() != result.getType())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (new CMIItemStack(itemToCheck).getDurability() != new CMIItemStack(result).getDurability() || itemToCheck.getEnchantments().size() != result.getEnchantments().size())
|
||||||
|
return true;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemToCheck.getEnchantments().size() != result.getEnchantments().size())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onInventoryRepair(InventoryClickEvent event) {
|
public void onInventoryRepair(InventoryClickEvent event) {
|
||||||
// If event is nothing or place, do nothing
|
// If event is nothing or place, do nothing
|
||||||
@ -979,8 +1005,13 @@ public final class JobsPaymentListener implements Listener {
|
|||||||
if (enchantName != null)
|
if (enchantName != null)
|
||||||
Jobs.action(jPlayer, new EnchantActionInfo(enchantName, oneEnchant.getValue(), ActionType.ENCHANT));
|
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
|
} 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));
|
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.REPAIR));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
Loading…
Reference in New Issue
Block a user