mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-02 14:29:07 +01:00
Added option to ignore the tools (items) when using durability losing option
+ supports enchantments
This commit is contained in:
parent
dd8a717271
commit
4d3106e585
Binary file not shown.
6
pom.xml
6
pom.xml
@ -16,16 +16,16 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.14.2-R0.1-SNAPSHOT</version>
|
||||
<version>1.14.3-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- MyPet -->
|
||||
<dependency>
|
||||
<groupId>de.Keyle.MyPet</groupId>
|
||||
<artifactId>MyPet</artifactId>
|
||||
<version>3.3</version>
|
||||
<version>3.4</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/libs/MyPet-3.3.jar</systemPath>
|
||||
<systemPath>${basedir}/libs/MyPet-3.4.jar</systemPath>
|
||||
</dependency>
|
||||
<!-- McMMO -->
|
||||
<dependency>
|
||||
|
@ -53,6 +53,7 @@ public class GeneralConfigManager {
|
||||
public boolean disablePaymentIfRiding;
|
||||
protected boolean addXpPlayer;
|
||||
public boolean payItemDurabilityLoss;
|
||||
public List<String> WhiteListedItems = new ArrayList<>();
|
||||
protected boolean hideJobsWithoutPermission;
|
||||
protected int maxJobs;
|
||||
protected boolean payNearSpawner;
|
||||
@ -557,7 +558,9 @@ public class GeneralConfigManager {
|
||||
|
||||
c.addComment("allow-pay-for-durability-loss", "Allows, when losing maximum durability of item then it does not pay the player until it is repaired.",
|
||||
"E.g. the player wants to enchant a item with enchanting table and the item has durability loss then not paying.");
|
||||
payItemDurabilityLoss = c.get("allow-pay-for-durability-loss", true);
|
||||
payItemDurabilityLoss = c.get("allow-pay-for-durability-loss.Use", true);
|
||||
WhiteListedItems = c.get("allow-pay-for-durability-loss.WhiteListedItems",
|
||||
Arrays.asList("wooden_pickaxe=DURABILITY-1", "fishing_rod"));
|
||||
|
||||
c.addComment("modify-chat", "Modifys chat to add chat titles. If you're using a chat manager, you may add the tag {jobs} to your chat format and disable this.");
|
||||
modifyChat = c.get("modify-chat.use", false);
|
||||
|
@ -307,11 +307,7 @@ public class JobsPaymentListener implements Listener {
|
||||
if (Jobs.getGCManager().disablePaymentIfRiding && player.isInsideVehicle())
|
||||
return;
|
||||
|
||||
ItemStack item = Jobs.getNms().getItemInMainHand(player);
|
||||
|
||||
// Prevent item durability loss
|
||||
if (!Jobs.getGCManager().payItemDurabilityLoss && item.getType().getMaxDurability()
|
||||
- Jobs.getNms().getDurability(item) != item.getType().getMaxDurability())
|
||||
if (!payForItemDurabilityLoss(player))
|
||||
return;
|
||||
|
||||
// pay
|
||||
@ -393,6 +389,7 @@ public class JobsPaymentListener implements Listener {
|
||||
// check if player is riding
|
||||
if (Jobs.getGCManager().disablePaymentIfRiding && player.isInsideVehicle())
|
||||
return;
|
||||
|
||||
CMIMaterial cmat = CMIMaterial.get(block);
|
||||
if (cmat.equals(CMIMaterial.FURNACE) && block.hasMetadata(furnaceOwnerMetadata))
|
||||
FurnaceBrewingHandling.removeFurnace(block);
|
||||
@ -420,16 +417,14 @@ public class JobsPaymentListener implements Listener {
|
||||
Jobs.FastPayment.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
if (!payForItemDurabilityLoss(player))
|
||||
return;
|
||||
|
||||
// restricted area multiplier
|
||||
|
||||
// Item in hand
|
||||
ItemStack item = Jobs.getNms().getItemInMainHand(player);
|
||||
if (item != null && !item.getType().equals(Material.AIR)) {
|
||||
// Prevent item durability loss
|
||||
if (!Jobs.getGCManager().payItemDurabilityLoss && item.getType().getMaxDurability()
|
||||
- Jobs.getNms().getDurability(item) != item.getType().getMaxDurability())
|
||||
return;
|
||||
|
||||
// Protection for block break with silktouch
|
||||
if (Jobs.getGCManager().useSilkTouchProtection) {
|
||||
for (Entry<Enchantment, Integer> one : item.getEnchantments().entrySet()) {
|
||||
@ -509,11 +504,7 @@ public class JobsPaymentListener implements Listener {
|
||||
if (Jobs.getGCManager().disablePaymentIfRiding && player.isInsideVehicle())
|
||||
return;
|
||||
|
||||
ItemStack item = Jobs.getNms().getItemInMainHand(player);
|
||||
|
||||
// Prevent item durability loss
|
||||
if (!Jobs.getGCManager().payItemDurabilityLoss && item.getType().getMaxDurability()
|
||||
- Jobs.getNms().getDurability(item) != item.getType().getMaxDurability())
|
||||
if (!payForItemDurabilityLoss(player))
|
||||
return;
|
||||
|
||||
if (event.getState().equals(PlayerFishEvent.State.CAUGHT_FISH) && event.getCaught() instanceof Item) {
|
||||
@ -919,11 +910,7 @@ public class JobsPaymentListener implements Listener {
|
||||
if (Jobs.getGCManager().disablePaymentIfRiding && player.isInsideVehicle())
|
||||
return;
|
||||
|
||||
ItemStack item = inv.getItem(0);
|
||||
|
||||
// Prevent item durability loss
|
||||
if (!Jobs.getGCManager().payItemDurabilityLoss && item.getType().getMaxDurability()
|
||||
- Jobs.getNms().getDurability(item) != item.getType().getMaxDurability())
|
||||
if (!payForItemDurabilityLoss(player))
|
||||
return;
|
||||
|
||||
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
|
||||
@ -1181,13 +1168,8 @@ public class JobsPaymentListener implements Listener {
|
||||
if (Jobs.getGCManager().disablePaymentIfRiding && pDamager.isInsideVehicle())
|
||||
return;
|
||||
|
||||
ItemStack item = Jobs.getNms().getItemInMainHand(pDamager);
|
||||
if (item != null && !item.getType().equals(Material.AIR)) {
|
||||
// Prevent item durability loss
|
||||
if (!Jobs.getGCManager().payItemDurabilityLoss && item.getType().getMaxDurability()
|
||||
- Jobs.getNms().getDurability(item) != item.getType().getMaxDurability())
|
||||
return;
|
||||
}
|
||||
if (!payForItemDurabilityLoss(pDamager))
|
||||
return;
|
||||
|
||||
// pay
|
||||
JobsPlayer jDamager = Jobs.getPlayerManager().getJobsPlayer(pDamager);
|
||||
@ -1776,4 +1758,49 @@ public class JobsPaymentListener implements Listener {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Prevent item durability loss
|
||||
private static boolean payForItemDurabilityLoss(Player p) {
|
||||
ItemStack hand = Jobs.getNms().getItemInMainHand(p);
|
||||
|
||||
if (!Jobs.getGCManager().payItemDurabilityLoss && hand != null && !hand.getType().equals(Material.AIR)
|
||||
&& hand.getType().getMaxDurability() - Jobs.getNms().getDurability(hand) != hand.getType().getMaxDurability()) {
|
||||
for (String whiteList : Jobs.getGCManager().WhiteListedItems) {
|
||||
String item = whiteList.contains("=") ? whiteList.split("=")[0] : whiteList;
|
||||
if (item.contains("-")) {
|
||||
item = item.split("-")[0];
|
||||
}
|
||||
|
||||
CMIMaterial mat = CMIMaterial.get(item);
|
||||
if (mat == null) {
|
||||
mat = CMIMaterial.get(item.replace(" ", "_").toUpperCase());
|
||||
}
|
||||
|
||||
if (mat == null) {
|
||||
// try integer method
|
||||
Integer matId = null;
|
||||
try {
|
||||
matId = Integer.valueOf(item);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
if (matId != null) {
|
||||
mat = CMIMaterial.get(matId);
|
||||
}
|
||||
}
|
||||
|
||||
if (whiteList.contains("=") && whiteList.split("=").length == 2) {
|
||||
if (!hand.getEnchantments().containsKey(CMIEnchantment.getEnchantment(whiteList.split("=")[1]))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (mat != null && hand.getType().equals(mat.getMaterial())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user