Weak loading of legacy items, see #2151

This commit is contained in:
PikaMug 2023-11-01 18:31:37 -04:00
parent 6c15c41d97
commit 977a386366
2 changed files with 56 additions and 10 deletions

View File

@ -12,6 +12,7 @@ import me.pikamug.quests.util.BukkitItemUtil;
import me.pikamug.quests.util.BukkitMiscUtil;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
@ -211,13 +212,28 @@ public class BukkitActionYamlStorage implements ActionStorageImpl {
}
if (data.contains(actionKey + "items")) {
final LinkedList<ItemStack> temp = new LinkedList<>();
final List<ItemStack> stackList = (List<ItemStack>) data.get(actionKey + "items");
if (BukkitConfigUtil.checkList(stackList, ItemStack.class)) {
for (final ItemStack stack : stackList) {
final List<?> itemList = (List<?>) data.get(actionKey + "items");
if (BukkitConfigUtil.checkList(itemList, ItemStack.class)) {
for (final Object item : itemList) {
final ItemStack stack = (ItemStack) item;
if (stack != null) {
temp.add(stack);
}
}
} else if (BukkitConfigUtil.checkList(itemList, String.class)) {
// Legacy
for (final Object item : itemList) {
final String stack = (String) item;
if (stack != null) {
final String itemName = stack.substring(5, stack.indexOf(':'));
final Material itemMat = Material.matchMaterial(itemName);
if (itemMat != null) {
temp.add(new ItemStack(itemMat, 1));
} else {
throw new ActionFormatException("'items' has invalid name" + itemName, actionKey);
}
}
}
} else {
throw new ActionFormatException("'items' is not a list of items", actionKey);
}

View File

@ -222,7 +222,7 @@ public class BukkitQuestYamlStorage implements QuestStorageImpl {
}
}
if (config.contains("quests." + questId + ".gui-display")) {
ItemStack stack = config.getItemStack("quests." + questId + ".gui-display");
final ItemStack stack = config.getItemStack("quests." + questId + ".gui-display");
if (stack != null) {
quest.setGUIDisplay(stack);
} else {
@ -335,13 +335,28 @@ public class BukkitQuestYamlStorage implements QuestStorageImpl {
final BukkitDependencies depends = plugin.getDependencies();
if (config.contains("quests." + questKey + ".rewards.items")) {
final LinkedList<ItemStack> temp = new LinkedList<>();
final List<ItemStack> stackList = (List<ItemStack>) config.get("quests." + questKey + ".rewards.items");
if (BukkitConfigUtil.checkList(stackList, ItemStack.class)) {
for (final ItemStack stack : stackList) {
final List<?> itemList = (List<?>) config.get("quests." + questKey + ".rewards.items");
if (BukkitConfigUtil.checkList(itemList, ItemStack.class)) {
for (final Object item : itemList) {
final ItemStack stack = (ItemStack) item;
if (stack != null) {
temp.add(stack);
}
}
} else if (BukkitConfigUtil.checkList(itemList, String.class)) {
// Legacy
for (final Object item : itemList) {
final String stack = (String) item;
if (stack != null) {
final String itemName = stack.substring(5, stack.indexOf(':'));
final Material itemMat = Material.matchMaterial(itemName);
if (itemMat != null) {
temp.add(new ItemStack(itemMat, 1));
} else {
throw new QuestFormatException("Reward 'items' has invalid name" + itemName, questKey);
}
}
}
} else {
throw new QuestFormatException("Reward 'items' has invalid formatting", questKey);
}
@ -505,14 +520,29 @@ public class BukkitQuestYamlStorage implements QuestStorageImpl {
}
if (config.contains("quests." + questKey + ".requirements.items")) {
final List<ItemStack> temp = new LinkedList<>();
final List<ItemStack> stackList = (List<ItemStack>) config.get("quests." + questKey
final List<?> itemList = (List<?>) config.get("quests." + questKey
+ ".requirements.items");
if (BukkitConfigUtil.checkList(stackList, ItemStack.class)) {
for (final ItemStack stack : stackList) {
if (BukkitConfigUtil.checkList(itemList, ItemStack.class)) {
for (final Object item : itemList) {
final ItemStack stack = (ItemStack) item;
if (stack != null) {
temp.add(stack);
}
}
} else if (BukkitConfigUtil.checkList(itemList, String.class)) {
// Legacy
for (final Object item : itemList) {
final String stack = (String) item;
if (stack != null) {
final String itemName = stack.substring(5, stack.indexOf(':'));
final Material itemMat = Material.matchMaterial(itemName);
if (itemMat != null) {
temp.add(new ItemStack(itemMat, 1));
} else {
throw new QuestFormatException("Requirement 'items' has invalid name" + itemName, questKey);
}
}
}
} else {
throw new QuestFormatException("Requirement 'items' has invalid formatting", questKey);
}