This commit is contained in:
nossr50
2020-08-18 21:11:15 -07:00
parent 1feee7f312
commit 500ab628dd
6 changed files with 60 additions and 30 deletions

View File

@ -15,7 +15,6 @@ import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public final class ItemUtils {
@ -486,22 +485,22 @@ public final class ItemUtils {
return itemMeta.hasDisplayName() && itemMeta.getDisplayName().equals(ChatColor.GOLD + LocaleLoader.getString("Item.ChimaeraWing.Name"));
}
public static void addAbilityLore(@NotNull ItemStack itemStack) {
ItemMeta itemMeta = itemStack.getItemMeta();
List<String> itemLore = new ArrayList<>();
if(itemMeta == null)
return;
if (itemMeta.hasLore()) {
itemLore = itemMeta.getLore();
}
itemLore.add("mcMMO Ability Tool");
itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta);
}
// public static void addAbilityLore(@NotNull ItemStack itemStack) {
// ItemMeta itemMeta = itemStack.getItemMeta();
// List<String> itemLore = new ArrayList<>();
//
// if(itemMeta == null)
// return;
//
// if (itemMeta.hasLore()) {
// itemLore = itemMeta.getLore();
// }
//
// itemLore.add("mcMMO Ability Tool");
//
// itemMeta.setLore(itemLore);
// itemStack.setItemMeta(itemMeta);
// }
public static void removeAbilityLore(@NotNull ItemStack itemStack) {
ItemMeta itemMeta = itemStack.getItemMeta();

View File

@ -5,13 +5,16 @@ 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.List;
import java.util.UUID;
public abstract class AbstractPersistentDataLayer extends AbstractCompatibilityLayer {
public static final String LEGACY_ABILITY_TOOL_LORE = "mcMMO Ability Tool";
public final NamespacedKey superAbilityBoosted;
public final String SUPER_ABILITY_BOOSTED = "super_ability_boosted";
@ -36,4 +39,18 @@ public abstract class AbstractPersistentDataLayer extends AbstractCompatibilityL
public abstract void removeBonusDigSpeedOnSuperAbilityTool(@NotNull ItemStack itemStack);
public boolean isLegacyAbilityTool(ItemStack itemStack) {
ItemMeta itemMeta = itemStack.getItemMeta();
if(itemMeta == null)
return false;
List<String> lore = itemMeta.getLore();
if(lore == null || lore.isEmpty())
return false;
return lore.contains(LEGACY_ABILITY_TOOL_LORE);
}
}

View File

@ -19,7 +19,6 @@ import java.util.UUID;
public class SpigotTemporaryDataLayer extends AbstractPersistentDataLayer {
private final String FURNACE_OWNER_METADATA_KEY = "mcMMO_furnace_owner";
private final String ABILITY_TOOL_METADATA_KEY = "mcMMO_super_ability_tool";
@Override
public boolean initializeLayer() {

View File

@ -27,6 +27,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
@ -145,11 +146,13 @@ public class SkillUtils {
int originalDigSpeed = heldItem.getEnchantmentLevel(Enchantment.DIG_SPEED);
//Add lore, add dig speed
ItemUtils.addAbilityLore(heldItem); //lore can be a secondary failsafe for 1.13 and below
//Add dig speed
//Lore no longer gets added, no point to it afaik
//ItemUtils.addAbilityLore(heldItem); //lore can be a secondary failsafe for 1.13 and below
ItemUtils.addDigSpeedToItem(heldItem, heldItem.getEnchantmentLevel(Enchantment.DIG_SPEED));
//1.14+ will have persistent metadata for this item
//1.13.2+ will have persistent metadata for this item
AbstractPersistentDataLayer compatLayer = mcMMO.getCompatibilityManager().getPersistentDataLayer();
compatLayer.setSuperAbilityBoostedItem(heldItem, originalDigSpeed);
}
@ -211,14 +214,25 @@ public class SkillUtils {
if(!ItemUtils.canBeSuperAbilityDigBoosted(itemStack))
return;
//Take the lore off
ItemUtils.removeAbilityLore(itemStack);
//1.14+ will have persistent metadata for this itemStack
//1.13.2+ will have persistent metadata for this itemStack
AbstractPersistentDataLayer compatLayer = mcMMO.getCompatibilityManager().getPersistentDataLayer();
if(compatLayer.isSuperAbilityBoosted(itemStack))
if(compatLayer.isLegacyAbilityTool(itemStack)) {
ItemMeta itemMeta = itemStack.getItemMeta();
//TODO: can be optimized
if(itemMeta.hasEnchant(Enchantment.DIG_SPEED)) {
itemMeta.removeEnchant(Enchantment.DIG_SPEED);
}
itemStack.setItemMeta(itemMeta);
ItemUtils.removeAbilityLore(itemStack);
}
if(compatLayer.isSuperAbilityBoosted(itemStack)) {
compatLayer.removeBonusDigSpeedOnSuperAbilityTool(itemStack);
}
}
public static void handleDurabilityChange(ItemStack itemStack, int durabilityModifier) {