1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 05:55:27 +01:00

Fixed NPE, when break a block and checks air in hand instead of item, #427

- Lets try to ignore recently updated deprecated methods
This commit is contained in:
montlikadani 2019-05-20 16:38:16 +02:00
parent 59f013ba36
commit 75b1ab8e0a
3 changed files with 35 additions and 21 deletions

View File

@ -531,9 +531,9 @@ public class GeneralConfigManager {
c.addComment("add-xp-player", "Adds the Jobs xp received to the player's Minecraft XP bar");
addXpPlayer = c.get("add-xp-player", false);
c.addComment("enable-pay-when-item-durability-loss", "Allows, when losing maximum durability of item then it does not pay the player until it is repaired.",
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("enable-pay-when-item-durability-loss", true);
payItemDurabilityLoss = c.get("allow-pay-for-durability-loss", true);
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);

View File

@ -72,6 +72,7 @@ import org.bukkit.plugin.PluginManager;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial;
import com.gamingmesh.jobs.CMILib.VersionChecker.Version;
import com.gamingmesh.jobs.Gui.GuiInfoList;
import com.gamingmesh.jobs.api.JobsAreaSelectionEvent;
import com.gamingmesh.jobs.api.JobsChunkChangeEvent;
@ -878,6 +879,7 @@ public class JobsListener implements Listener {
ArmorTypes type = ArmorTypes.matchType(item);
if (ArmorTypes.matchType(item) == null)
return;
Location loc = event.getBlock().getLocation();
for (Player p : loc.getWorld().getPlayers()) {
Location ploc = p.getLocation();
@ -890,9 +892,19 @@ public class JobsListener implements Listener {
if (!(event.getBlock().getState() instanceof Dispenser))
continue;
Dispenser dispenser = (Dispenser) event.getBlock().getState();
org.bukkit.material.Dispenser dis = (org.bukkit.material.Dispenser) dispenser.getData();
BlockFace directionFacing = dis.getFacing();
Dispenser dispenser = null;
BlockFace directionFacing = null;
if (Version.isCurrentEqualOrLower(Version.v1_13_R2)) {
dispenser = (Dispenser) event.getBlock().getState();
org.bukkit.material.Dispenser dis = (org.bukkit.material.Dispenser) dispenser.getData();
directionFacing = dis.getFacing();
} else {
dispenser = (Dispenser) event.getBlock().getState();
org.bukkit.block.data.type.Dispenser dis = (org.bukkit.block.data.type.Dispenser) dispenser.getBlockData();
directionFacing = dis.getFacing();
}
if (directionFacing == BlockFace.EAST &&
ploc.getBlockX() != loc.getBlockX() &&
ploc.getX() <= loc.getX() + 2.3 &&

View File

@ -399,18 +399,19 @@ public class JobsPaymentListener implements Listener {
// 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;
// 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 && item != null) {
for (Entry<Enchantment, Integer> one : item.getEnchantments().entrySet()) {
if (one.getKey().getName().equalsIgnoreCase("SILK_TOUCH")) {
if (Jobs.getBpManager().isInBp(block))
return;
// Protection for block break with silktouch
if (Jobs.getGCManager().useSilkTouchProtection) {
for (Entry<Enchantment, Integer> one : item.getEnchantments().entrySet()) {
if (one.getKey().getName().equalsIgnoreCase("SILK_TOUCH")) {
if (Jobs.getBpManager().isInBp(block))
return;
}
}
}
}
@ -1115,11 +1116,12 @@ public class JobsPaymentListener implements Listener {
return;
ItemStack item = Jobs.getNms().getItemInMainHand(pDamager);
// Prevent item durability loss
if (!Jobs.getGCManager().payItemDurabilityLoss && item.getType().getMaxDurability()
- Jobs.getNms().getDurability(item) != item.getType().getMaxDurability())
return;
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;
}
// pay
JobsPlayer jDamager = Jobs.getPlayerManager().getJobsPlayer(pDamager);