diff --git a/Changelog.txt b/Changelog.txt index 139db837b..cfedff549 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,6 +1,7 @@ Version 2.1.143 mcMMO now tracks super ability boosted items through item metadata mcMMO no longer relies on lore to tell if an item has been modified by a super ability + Slight buff to Rupture NOTES: The item tracking on 1.14+ is persistent (up until now its been temporary) diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java b/src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java index de303c957..228ae7f18 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java @@ -188,6 +188,9 @@ public class BleedTimerTask extends BukkitRunnable { if(toolTier < 4) ticks = Math.max(1, (ticks / 3)); + ticks+=1; + + BleedContainer newBleedContainer = new BleedContainer(entity, ticks, bleedRank, toolTier, attacker); bleedList.put(entity, newBleedContainer); } diff --git a/src/main/java/com/gmail/nossr50/util/ItemUtils.java b/src/main/java/com/gmail/nossr50/util/ItemUtils.java index 39720b038..3a9c126ab 100644 --- a/src/main/java/com/gmail/nossr50/util/ItemUtils.java +++ b/src/main/java/com/gmail/nossr50/util/ItemUtils.java @@ -523,6 +523,11 @@ public final class ItemUtils { public static void addDigSpeedToItem(ItemStack itemStack, int existingEnchantLevel) { ItemMeta itemMeta = itemStack.getItemMeta(); + + if(itemMeta == null) + return; + itemMeta.addEnchant(Enchantment.DIG_SPEED, existingEnchantLevel + AdvancedConfig.getInstance().getEnchantBuff(), true); + itemStack.setItemMeta(itemMeta); } } diff --git a/src/main/java/com/gmail/nossr50/util/compat/layers/persistentdata/AbstractPersistentDataLayer.java b/src/main/java/com/gmail/nossr50/util/compat/layers/persistentdata/AbstractPersistentDataLayer.java index 815c6c5b1..cbea2f1aa 100644 --- a/src/main/java/com/gmail/nossr50/util/compat/layers/persistentdata/AbstractPersistentDataLayer.java +++ b/src/main/java/com/gmail/nossr50/util/compat/layers/persistentdata/AbstractPersistentDataLayer.java @@ -20,9 +20,9 @@ public abstract class AbstractPersistentDataLayer extends AbstractCompatibilityL public abstract void setSuperAbilityBoostedItem(ItemStack itemStack, int originalDigSpeed); - public abstract boolean isSuperAbilityBoosted(ItemMeta itemMeta); + public abstract boolean isSuperAbilityBoosted(ItemStack itemStack); - public abstract int getSuperAbilityToolOriginalDigSpeed(ItemMeta itemMeta); + public abstract int getSuperAbilityToolOriginalDigSpeed(ItemStack itemStack); public abstract void removeBonusDigSpeedOnSuperAbilityTool(ItemStack itemStack); diff --git a/src/main/java/com/gmail/nossr50/util/compat/layers/persistentdata/SpigotPersistentDataLayer.java b/src/main/java/com/gmail/nossr50/util/compat/layers/persistentdata/SpigotPersistentDataLayer.java index 760b074ad..d6e096e70 100644 --- a/src/main/java/com/gmail/nossr50/util/compat/layers/persistentdata/SpigotPersistentDataLayer.java +++ b/src/main/java/com/gmail/nossr50/util/compat/layers/persistentdata/SpigotPersistentDataLayer.java @@ -73,8 +73,13 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer { @Override public void setSuperAbilityBoostedItem(ItemStack itemStack, int originalDigSpeed) { + if(itemStack.getItemMeta() == null) { + mcMMO.p.getLogger().severe("Can not assign persistent data to an item with null item metadata"); + return; + } + ItemMeta itemMeta = itemStack.getItemMeta(); - PersistentDataContainer dataContainer = ((PersistentDataHolder) itemMeta).getPersistentDataContainer(); + PersistentDataContainer dataContainer = itemMeta.getPersistentDataContainer(); dataContainer.set(superAbilityBoosted, PersistentDataType.INTEGER, originalDigSpeed); @@ -82,9 +87,13 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer { } @Override - public boolean isSuperAbilityBoosted(@NotNull ItemMeta itemMeta) { + public boolean isSuperAbilityBoosted(ItemStack itemStack) { + if(itemStack.getItemMeta() == null) + return false; + + ItemMeta itemMeta = itemStack.getItemMeta(); //Get container from entity - PersistentDataContainer dataContainer = ((PersistentDataHolder) itemMeta).getPersistentDataContainer(); + PersistentDataContainer dataContainer = itemMeta.getPersistentDataContainer(); //If this value isn't null, then the tool can be considered dig speed boosted Integer boostValue = dataContainer.get(superAbilityBoosted, PersistentDataType.INTEGER); @@ -93,9 +102,14 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer { } @Override - public int getSuperAbilityToolOriginalDigSpeed(@NotNull ItemMeta itemMeta) { + public int getSuperAbilityToolOriginalDigSpeed(@NotNull ItemStack itemStack) { //Get container from entity - PersistentDataContainer dataContainer = ((PersistentDataHolder) itemMeta).getPersistentDataContainer(); + ItemMeta itemMeta = itemStack.getItemMeta(); + + if(itemMeta == null) + return 0; + + PersistentDataContainer dataContainer = itemMeta.getPersistentDataContainer(); if(dataContainer.get(superAbilityBoosted, PersistentDataType.INTEGER) == null) { mcMMO.p.getLogger().severe("Value should never be null for a boosted item"); @@ -109,11 +123,10 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer { @Override public void removeBonusDigSpeedOnSuperAbilityTool(@NotNull ItemStack itemStack) { + int originalSpeed = getSuperAbilityToolOriginalDigSpeed(itemStack); ItemMeta itemMeta = itemStack.getItemMeta(); //TODO: can be optimized - int originalSpeed = getSuperAbilityToolOriginalDigSpeed(itemMeta); - if(itemMeta.hasEnchant(Enchantment.DIG_SPEED)) { itemMeta.removeEnchant(Enchantment.DIG_SPEED); } @@ -122,7 +135,7 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer { itemMeta.addEnchant(Enchantment.DIG_SPEED, originalSpeed, true); } - PersistentDataContainer dataContainer = ((PersistentDataHolder) itemMeta).getPersistentDataContainer(); + PersistentDataContainer dataContainer = itemMeta.getPersistentDataContainer(); dataContainer.remove(superAbilityBoosted); //Remove persistent data //TODO: needed? diff --git a/src/main/java/com/gmail/nossr50/util/compat/layers/persistentdata/SpigotTemporaryDataLayer.java b/src/main/java/com/gmail/nossr50/util/compat/layers/persistentdata/SpigotTemporaryDataLayer.java index 13e845d4e..1d52cb997 100644 --- a/src/main/java/com/gmail/nossr50/util/compat/layers/persistentdata/SpigotTemporaryDataLayer.java +++ b/src/main/java/com/gmail/nossr50/util/compat/layers/persistentdata/SpigotTemporaryDataLayer.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.util.compat.layers.persistentdata; -import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.datatypes.meta.SuperAbilityToolMeta; import com.gmail.nossr50.datatypes.meta.UUIDMeta; import com.gmail.nossr50.mcMMO; @@ -39,7 +38,7 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer { } @Override - public void setFurnaceOwner(Furnace furnace, UUID uuid) { + public void setFurnaceOwner(@NotNull Furnace furnace, UUID uuid) { Metadatable metadatable = (Metadatable) furnace; if(metadatable.getMetadata(FURNACE_OWNER_METADATA_KEY).size() > 0) { @@ -50,24 +49,24 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer { } @Override - public void setSuperAbilityBoostedItem(ItemStack itemStack, int originalDigSpeed) { - ItemMeta itemMeta = itemStack.getItemMeta(); - Metadatable metadatable = (Metadatable) itemMeta; + public void setSuperAbilityBoostedItem(@NotNull ItemStack itemStack, int originalDigSpeed) { + Metadatable metadatable = getMetadatable(itemStack); metadatable.setMetadata(ABILITY_TOOL_METADATA_KEY, new SuperAbilityToolMeta(originalDigSpeed, mcMMO.p)); + } - //TODO: needed? - itemStack.setItemMeta(itemMeta); + private Metadatable getMetadatable(@NotNull ItemStack itemStack) { + return (Metadatable) itemStack; } @Override - public boolean isSuperAbilityBoosted(@NotNull ItemMeta itemMeta) { - Metadatable metadatable = (Metadatable) itemMeta; + public boolean isSuperAbilityBoosted(@NotNull ItemStack itemStack) { + Metadatable metadatable = getMetadatable(itemStack); return metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).size() > 0; } @Override - public int getSuperAbilityToolOriginalDigSpeed(@NotNull ItemMeta itemMeta) { - Metadatable metadatable = (Metadatable) itemMeta; + public int getSuperAbilityToolOriginalDigSpeed(@NotNull ItemStack itemStack) { + Metadatable metadatable = getMetadatable(itemStack); if(metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).size() > 0) { SuperAbilityToolMeta toolMeta = (SuperAbilityToolMeta) metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).get(0); @@ -80,13 +79,13 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer { @Override public void removeBonusDigSpeedOnSuperAbilityTool(@NotNull ItemStack itemStack) { + int originalSpeed = getSuperAbilityToolOriginalDigSpeed(itemStack); ItemMeta itemMeta = itemStack.getItemMeta(); if(itemMeta.hasEnchant(Enchantment.DIG_SPEED)) { itemMeta.removeEnchant(Enchantment.DIG_SPEED); } - int originalSpeed = getSuperAbilityToolOriginalDigSpeed(itemMeta); if(originalSpeed > 0) { itemMeta.addEnchant(Enchantment.DIG_SPEED, originalSpeed, true); diff --git a/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java b/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java index 65f724f5d..4a09a1d4a 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java @@ -24,13 +24,10 @@ import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.*; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import java.util.ArrayList; import java.util.Iterator; -import java.util.List; public class SkillUtils { @@ -210,7 +207,7 @@ public class SkillUtils { //1.14+ will have persistent metadata for this itemStack AbstractPersistentDataLayer compatLayer = mcMMO.getCompatibilityManager().getPersistentDataLayer(); - if(compatLayer.isSuperAbilityBoosted(itemStack.getItemMeta())) + if(compatLayer.isSuperAbilityBoosted(itemStack)) compatLayer.removeBonusDigSpeedOnSuperAbilityTool(itemStack); }