Some bugfixes to the new ability tool tracking

This commit is contained in:
nossr50 2020-08-18 19:47:15 -07:00
parent a7ded7e982
commit 557cfe3944
7 changed files with 44 additions and 26 deletions

View File

@ -1,6 +1,7 @@
Version 2.1.143 Version 2.1.143
mcMMO now tracks super ability boosted items through item metadata 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 mcMMO no longer relies on lore to tell if an item has been modified by a super ability
Slight buff to Rupture
NOTES: NOTES:
The item tracking on 1.14+ is persistent (up until now its been temporary) The item tracking on 1.14+ is persistent (up until now its been temporary)

View File

@ -188,6 +188,9 @@ public class BleedTimerTask extends BukkitRunnable {
if(toolTier < 4) if(toolTier < 4)
ticks = Math.max(1, (ticks / 3)); ticks = Math.max(1, (ticks / 3));
ticks+=1;
BleedContainer newBleedContainer = new BleedContainer(entity, ticks, bleedRank, toolTier, attacker); BleedContainer newBleedContainer = new BleedContainer(entity, ticks, bleedRank, toolTier, attacker);
bleedList.put(entity, newBleedContainer); bleedList.put(entity, newBleedContainer);
} }

View File

@ -523,6 +523,11 @@ public final class ItemUtils {
public static void addDigSpeedToItem(ItemStack itemStack, int existingEnchantLevel) { public static void addDigSpeedToItem(ItemStack itemStack, int existingEnchantLevel) {
ItemMeta itemMeta = itemStack.getItemMeta(); ItemMeta itemMeta = itemStack.getItemMeta();
if(itemMeta == null)
return;
itemMeta.addEnchant(Enchantment.DIG_SPEED, existingEnchantLevel + AdvancedConfig.getInstance().getEnchantBuff(), true); itemMeta.addEnchant(Enchantment.DIG_SPEED, existingEnchantLevel + AdvancedConfig.getInstance().getEnchantBuff(), true);
itemStack.setItemMeta(itemMeta);
} }
} }

View File

@ -20,9 +20,9 @@ public abstract class AbstractPersistentDataLayer extends AbstractCompatibilityL
public abstract void setSuperAbilityBoostedItem(ItemStack itemStack, int originalDigSpeed); 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); public abstract void removeBonusDigSpeedOnSuperAbilityTool(ItemStack itemStack);

View File

@ -73,8 +73,13 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
@Override @Override
public void setSuperAbilityBoostedItem(ItemStack itemStack, int originalDigSpeed) { 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(); ItemMeta itemMeta = itemStack.getItemMeta();
PersistentDataContainer dataContainer = ((PersistentDataHolder) itemMeta).getPersistentDataContainer(); PersistentDataContainer dataContainer = itemMeta.getPersistentDataContainer();
dataContainer.set(superAbilityBoosted, PersistentDataType.INTEGER, originalDigSpeed); dataContainer.set(superAbilityBoosted, PersistentDataType.INTEGER, originalDigSpeed);
@ -82,9 +87,13 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
} }
@Override @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 //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 //If this value isn't null, then the tool can be considered dig speed boosted
Integer boostValue = dataContainer.get(superAbilityBoosted, PersistentDataType.INTEGER); Integer boostValue = dataContainer.get(superAbilityBoosted, PersistentDataType.INTEGER);
@ -93,9 +102,14 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
} }
@Override @Override
public int getSuperAbilityToolOriginalDigSpeed(@NotNull ItemMeta itemMeta) { public int getSuperAbilityToolOriginalDigSpeed(@NotNull ItemStack itemStack) {
//Get container from entity //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) { if(dataContainer.get(superAbilityBoosted, PersistentDataType.INTEGER) == null) {
mcMMO.p.getLogger().severe("Value should never be null for a boosted item"); mcMMO.p.getLogger().severe("Value should never be null for a boosted item");
@ -109,11 +123,10 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
@Override @Override
public void removeBonusDigSpeedOnSuperAbilityTool(@NotNull ItemStack itemStack) { public void removeBonusDigSpeedOnSuperAbilityTool(@NotNull ItemStack itemStack) {
int originalSpeed = getSuperAbilityToolOriginalDigSpeed(itemStack);
ItemMeta itemMeta = itemStack.getItemMeta(); ItemMeta itemMeta = itemStack.getItemMeta();
//TODO: can be optimized //TODO: can be optimized
int originalSpeed = getSuperAbilityToolOriginalDigSpeed(itemMeta);
if(itemMeta.hasEnchant(Enchantment.DIG_SPEED)) { if(itemMeta.hasEnchant(Enchantment.DIG_SPEED)) {
itemMeta.removeEnchant(Enchantment.DIG_SPEED); itemMeta.removeEnchant(Enchantment.DIG_SPEED);
} }
@ -122,7 +135,7 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
itemMeta.addEnchant(Enchantment.DIG_SPEED, originalSpeed, true); itemMeta.addEnchant(Enchantment.DIG_SPEED, originalSpeed, true);
} }
PersistentDataContainer dataContainer = ((PersistentDataHolder) itemMeta).getPersistentDataContainer(); PersistentDataContainer dataContainer = itemMeta.getPersistentDataContainer();
dataContainer.remove(superAbilityBoosted); //Remove persistent data dataContainer.remove(superAbilityBoosted); //Remove persistent data
//TODO: needed? //TODO: needed?

View File

@ -1,6 +1,5 @@
package com.gmail.nossr50.util.compat.layers.persistentdata; 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.SuperAbilityToolMeta;
import com.gmail.nossr50.datatypes.meta.UUIDMeta; import com.gmail.nossr50.datatypes.meta.UUIDMeta;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
@ -39,7 +38,7 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
} }
@Override @Override
public void setFurnaceOwner(Furnace furnace, UUID uuid) { public void setFurnaceOwner(@NotNull Furnace furnace, UUID uuid) {
Metadatable metadatable = (Metadatable) furnace; Metadatable metadatable = (Metadatable) furnace;
if(metadatable.getMetadata(FURNACE_OWNER_METADATA_KEY).size() > 0) { if(metadatable.getMetadata(FURNACE_OWNER_METADATA_KEY).size() > 0) {
@ -50,24 +49,24 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
} }
@Override @Override
public void setSuperAbilityBoostedItem(ItemStack itemStack, int originalDigSpeed) { public void setSuperAbilityBoostedItem(@NotNull ItemStack itemStack, int originalDigSpeed) {
ItemMeta itemMeta = itemStack.getItemMeta(); Metadatable metadatable = getMetadatable(itemStack);
Metadatable metadatable = (Metadatable) itemMeta;
metadatable.setMetadata(ABILITY_TOOL_METADATA_KEY, new SuperAbilityToolMeta(originalDigSpeed, mcMMO.p)); metadatable.setMetadata(ABILITY_TOOL_METADATA_KEY, new SuperAbilityToolMeta(originalDigSpeed, mcMMO.p));
}
//TODO: needed? private Metadatable getMetadatable(@NotNull ItemStack itemStack) {
itemStack.setItemMeta(itemMeta); return (Metadatable) itemStack;
} }
@Override @Override
public boolean isSuperAbilityBoosted(@NotNull ItemMeta itemMeta) { public boolean isSuperAbilityBoosted(@NotNull ItemStack itemStack) {
Metadatable metadatable = (Metadatable) itemMeta; Metadatable metadatable = getMetadatable(itemStack);
return metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).size() > 0; return metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).size() > 0;
} }
@Override @Override
public int getSuperAbilityToolOriginalDigSpeed(@NotNull ItemMeta itemMeta) { public int getSuperAbilityToolOriginalDigSpeed(@NotNull ItemStack itemStack) {
Metadatable metadatable = (Metadatable) itemMeta; Metadatable metadatable = getMetadatable(itemStack);
if(metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).size() > 0) { if(metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).size() > 0) {
SuperAbilityToolMeta toolMeta = (SuperAbilityToolMeta) metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).get(0); SuperAbilityToolMeta toolMeta = (SuperAbilityToolMeta) metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).get(0);
@ -80,13 +79,13 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
@Override @Override
public void removeBonusDigSpeedOnSuperAbilityTool(@NotNull ItemStack itemStack) { public void removeBonusDigSpeedOnSuperAbilityTool(@NotNull ItemStack itemStack) {
int originalSpeed = getSuperAbilityToolOriginalDigSpeed(itemStack);
ItemMeta itemMeta = itemStack.getItemMeta(); ItemMeta itemMeta = itemStack.getItemMeta();
if(itemMeta.hasEnchant(Enchantment.DIG_SPEED)) { if(itemMeta.hasEnchant(Enchantment.DIG_SPEED)) {
itemMeta.removeEnchant(Enchantment.DIG_SPEED); itemMeta.removeEnchant(Enchantment.DIG_SPEED);
} }
int originalSpeed = getSuperAbilityToolOriginalDigSpeed(itemMeta);
if(originalSpeed > 0) { if(originalSpeed > 0) {
itemMeta.addEnchant(Enchantment.DIG_SPEED, originalSpeed, true); itemMeta.addEnchant(Enchantment.DIG_SPEED, originalSpeed, true);

View File

@ -24,13 +24,10 @@ import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.*; import org.bukkit.inventory.*;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
public class SkillUtils { public class SkillUtils {
@ -210,7 +207,7 @@ public class SkillUtils {
//1.14+ will have persistent metadata for this itemStack //1.14+ will have persistent metadata for this itemStack
AbstractPersistentDataLayer compatLayer = mcMMO.getCompatibilityManager().getPersistentDataLayer(); AbstractPersistentDataLayer compatLayer = mcMMO.getCompatibilityManager().getPersistentDataLayer();
if(compatLayer.isSuperAbilityBoosted(itemStack.getItemMeta())) if(compatLayer.isSuperAbilityBoosted(itemStack))
compatLayer.removeBonusDigSpeedOnSuperAbilityTool(itemStack); compatLayer.removeBonusDigSpeedOnSuperAbilityTool(itemStack);
} }