Added legacy conversion
This commit is contained in:
@@ -95,6 +95,8 @@ public class TalismanChecks {
|
||||
return null;
|
||||
}
|
||||
|
||||
TalismanUtils.convertFromLegacy(item);
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
|
||||
@@ -2,12 +2,19 @@ package com.willfp.talismans.talismans.util;
|
||||
|
||||
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.talismans.TalismansPlugin;
|
||||
import com.willfp.talismans.talismans.Talisman;
|
||||
import com.willfp.talismans.talismans.TalismanLevel;
|
||||
import com.willfp.talismans.talismans.Talismans;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -73,4 +80,49 @@ public class TalismanUtils {
|
||||
public static void clearTalismanMaterials() {
|
||||
TALISMAN_MATERIALS.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update legacy talisman to 3.0.0 talisman.
|
||||
*
|
||||
* @param itemStack The Talisman ItemStack.
|
||||
*/
|
||||
public static void convertFromLegacy(@NotNull final ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
|
||||
NamespacedKey talismanKey = container.getKeys().stream().filter(namespacedKey -> namespacedKey.getNamespace().equals("talismans")).findFirst().orElse(null);
|
||||
if (talismanKey == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String key = talismanKey.getKey();
|
||||
|
||||
int level = 0;
|
||||
|
||||
if (key.endsWith("_talisman")) {
|
||||
level = 1;
|
||||
} else if (key.endsWith("_ring")) {
|
||||
level = 2;
|
||||
} else if (key.endsWith("_relic")) {
|
||||
level = 3;
|
||||
} else if (key.endsWith("_fossil")) {
|
||||
level = 4;
|
||||
}
|
||||
|
||||
if (level == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
String newKey = key.replace("_talisman", "")
|
||||
.replace("_ring", "")
|
||||
.replace("_relic", "")
|
||||
.replace("_fossil", "");
|
||||
|
||||
NamespacedKey newTalismanKey = TalismansPlugin.getInstance().getNamespacedKeyFactory().create(newKey);
|
||||
|
||||
container.set(newTalismanKey, PersistentDataType.INTEGER, level);
|
||||
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user