mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 22:56:45 +01:00
Some bugfixes to the new ability tool tracking
This commit is contained in:
parent
a7ded7e982
commit
557cfe3944
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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?
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user