mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-03 04:55:28 +02:00
1.13.2 related bugfixes for the new item tracking
This commit is contained in:
@@ -1,29 +1,39 @@
|
||||
package com.gmail.nossr50.util.compat.layers.persistentdata;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.compat.layers.AbstractCompatibilityLayer;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Furnace;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class AbstractPersistentDataLayer extends AbstractCompatibilityLayer {
|
||||
|
||||
public final NamespacedKey superAbilityBoosted;
|
||||
public final String SUPER_ABILITY_BOOSTED = "super_ability_boosted";
|
||||
|
||||
public AbstractPersistentDataLayer() {
|
||||
superAbilityBoosted = getNamespacedKey(SUPER_ABILITY_BOOSTED);
|
||||
initializeLayer();
|
||||
}
|
||||
|
||||
public abstract @Nullable UUID getFurnaceOwner(Furnace furnace);
|
||||
public @NotNull NamespacedKey getNamespacedKey(@NotNull String key) {
|
||||
return new NamespacedKey(mcMMO.p, key);
|
||||
}
|
||||
|
||||
public abstract void setFurnaceOwner(Furnace furnace, UUID uuid);
|
||||
public abstract @Nullable UUID getFurnaceOwner(@NotNull Furnace furnace);
|
||||
|
||||
public abstract void setSuperAbilityBoostedItem(ItemStack itemStack, int originalDigSpeed);
|
||||
public abstract void setFurnaceOwner(@NotNull Furnace furnace, @NotNull UUID uuid);
|
||||
|
||||
public abstract boolean isSuperAbilityBoosted(ItemStack itemStack);
|
||||
public abstract void setSuperAbilityBoostedItem(@NotNull ItemStack itemStack, int originalDigSpeed);
|
||||
|
||||
public abstract int getSuperAbilityToolOriginalDigSpeed(ItemStack itemStack);
|
||||
public abstract boolean isSuperAbilityBoosted(@NotNull ItemStack itemStack);
|
||||
|
||||
public abstract void removeBonusDigSpeedOnSuperAbilityTool(ItemStack itemStack);
|
||||
public abstract int getSuperAbilityToolOriginalDigSpeed(@NotNull ItemStack itemStack);
|
||||
|
||||
public abstract void removeBonusDigSpeedOnSuperAbilityTool(@NotNull ItemStack itemStack);
|
||||
|
||||
}
|
||||
|
@@ -21,12 +21,9 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
|
||||
*/
|
||||
public static final String FURNACE_UUID_MOST_SIG = "furnace_uuid_most_sig";
|
||||
public static final String FURNACE_UUID_LEAST_SIG = "furnace_uuid_least_sig";
|
||||
public static final String SUPER_ABILITY_BOOSTED = "super_ability_boosted";
|
||||
|
||||
private NamespacedKey furnaceOwner_MostSig_Key;
|
||||
private NamespacedKey furnaceOwner_LeastSig_Key;
|
||||
private NamespacedKey superAbilityBoosted;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean initializeLayer() {
|
||||
@@ -37,16 +34,10 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
|
||||
private void initNamespacedKeys() {
|
||||
furnaceOwner_MostSig_Key = getNamespacedKey(FURNACE_UUID_MOST_SIG);
|
||||
furnaceOwner_LeastSig_Key = getNamespacedKey(FURNACE_UUID_LEAST_SIG);
|
||||
superAbilityBoosted = getNamespacedKey(SUPER_ABILITY_BOOSTED);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NamespacedKey getNamespacedKey(String key) {
|
||||
return new NamespacedKey(mcMMO.p, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable UUID getFurnaceOwner(Furnace furnace) {
|
||||
public @Nullable UUID getFurnaceOwner(@NotNull Furnace furnace) {
|
||||
//Get container from entity
|
||||
PersistentDataContainer dataContainer = ((PersistentDataHolder) furnace).getPersistentDataContainer();
|
||||
|
||||
@@ -62,7 +53,7 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFurnaceOwner(Furnace furnace, UUID uuid) {
|
||||
public void setFurnaceOwner(@NotNull Furnace furnace, @NotNull UUID uuid) {
|
||||
PersistentDataContainer dataContainer = ((PersistentDataHolder) furnace).getPersistentDataContainer();
|
||||
|
||||
dataContainer.set(furnaceOwner_MostSig_Key, PersistentDataType.LONG, uuid.getMostSignificantBits());
|
||||
@@ -72,7 +63,7 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSuperAbilityBoostedItem(ItemStack itemStack, int originalDigSpeed) {
|
||||
public void setSuperAbilityBoostedItem(@NotNull 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;
|
||||
@@ -87,7 +78,7 @@ public class SpigotPersistentDataLayer extends AbstractPersistentDataLayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuperAbilityBoosted(ItemStack itemStack) {
|
||||
public boolean isSuperAbilityBoosted(@NotNull ItemStack itemStack) {
|
||||
if(itemStack.getItemMeta() == null)
|
||||
return false;
|
||||
|
||||
|
@@ -5,8 +5,11 @@ import com.gmail.nossr50.datatypes.meta.UUIDMeta;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.bukkit.block.Furnace;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.tags.CustomItemTagContainer;
|
||||
import org.bukkit.inventory.meta.tags.ItemTagType;
|
||||
import org.bukkit.metadata.Metadatable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -26,7 +29,7 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getFurnaceOwner(Furnace furnace) {
|
||||
public UUID getFurnaceOwner(@NotNull Furnace furnace) {
|
||||
Metadatable metadatable = (Metadatable) furnace;
|
||||
|
||||
if(metadatable.getMetadata(FURNACE_OWNER_METADATA_KEY).size() > 0) {
|
||||
@@ -38,7 +41,7 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFurnaceOwner(@NotNull Furnace furnace, UUID uuid) {
|
||||
public void setFurnaceOwner(@NotNull Furnace furnace, @NotNull UUID uuid) {
|
||||
Metadatable metadatable = (Metadatable) furnace;
|
||||
|
||||
if(metadatable.getMetadata(FURNACE_OWNER_METADATA_KEY).size() > 0) {
|
||||
@@ -52,6 +55,17 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
|
||||
public void setSuperAbilityBoostedItem(@NotNull ItemStack itemStack, int originalDigSpeed) {
|
||||
Metadatable metadatable = getMetadatable(itemStack);
|
||||
metadatable.setMetadata(ABILITY_TOOL_METADATA_KEY, new SuperAbilityToolMeta(originalDigSpeed, mcMMO.p));
|
||||
|
||||
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if(itemMeta == null) {
|
||||
mcMMO.p.getLogger().severe("Item meta should never be null for a super boosted item!");
|
||||
return;
|
||||
}
|
||||
|
||||
itemMeta.getCustomTagContainer().setCustomTag(superAbilityBoosted, ItemTagType.INTEGER, originalDigSpeed);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
|
||||
private Metadatable getMetadatable(@NotNull ItemStack itemStack) {
|
||||
@@ -60,19 +74,27 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
|
||||
|
||||
@Override
|
||||
public boolean isSuperAbilityBoosted(@NotNull ItemStack itemStack) {
|
||||
Metadatable metadatable = getMetadatable(itemStack);
|
||||
return metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).size() > 0;
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if(itemMeta == null)
|
||||
return false;
|
||||
|
||||
CustomItemTagContainer tagContainer = itemMeta.getCustomTagContainer();
|
||||
return tagContainer.hasCustomTag(superAbilityBoosted, ItemTagType.INTEGER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSuperAbilityToolOriginalDigSpeed(@NotNull ItemStack itemStack) {
|
||||
Metadatable metadatable = getMetadatable(itemStack);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if(metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).size() > 0) {
|
||||
SuperAbilityToolMeta toolMeta = (SuperAbilityToolMeta) metadatable.getMetadata(ABILITY_TOOL_METADATA_KEY).get(0);
|
||||
return toolMeta.asInt();
|
||||
if(itemMeta == null)
|
||||
return 0;
|
||||
|
||||
CustomItemTagContainer tagContainer = itemMeta.getCustomTagContainer();
|
||||
|
||||
if(tagContainer.hasCustomTag(superAbilityBoosted , ItemTagType.INTEGER)) {
|
||||
return tagContainer.getCustomTag(superAbilityBoosted, ItemTagType.INTEGER);
|
||||
} else {
|
||||
// mcMMO.p.getLogger().info("Original dig enchant speed could not be found on item! Most likely it was lost from a server restart.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -82,6 +104,9 @@ public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
|
||||
int originalSpeed = getSuperAbilityToolOriginalDigSpeed(itemStack);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if(itemMeta == null)
|
||||
return;
|
||||
|
||||
if(itemMeta.hasEnchant(Enchantment.DIG_SPEED)) {
|
||||
itemMeta.removeEnchant(Enchantment.DIG_SPEED);
|
||||
}
|
||||
|
Reference in New Issue
Block a user