mirror of https://github.com/PikaMug/Quests.git
Weak loading of legacy items, see #2151
This commit is contained in:
parent
6c15c41d97
commit
977a386366
|
@ -12,6 +12,7 @@ import me.pikamug.quests.util.BukkitItemUtil;
|
||||||
import me.pikamug.quests.util.BukkitMiscUtil;
|
import me.pikamug.quests.util.BukkitMiscUtil;
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.Effect;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
|
@ -211,13 +212,28 @@ public class BukkitActionYamlStorage implements ActionStorageImpl {
|
||||||
}
|
}
|
||||||
if (data.contains(actionKey + "items")) {
|
if (data.contains(actionKey + "items")) {
|
||||||
final LinkedList<ItemStack> temp = new LinkedList<>();
|
final LinkedList<ItemStack> temp = new LinkedList<>();
|
||||||
final List<ItemStack> stackList = (List<ItemStack>) data.get(actionKey + "items");
|
final List<?> itemList = (List<?>) data.get(actionKey + "items");
|
||||||
if (BukkitConfigUtil.checkList(stackList, ItemStack.class)) {
|
if (BukkitConfigUtil.checkList(itemList, ItemStack.class)) {
|
||||||
for (final ItemStack stack : stackList) {
|
for (final Object item : itemList) {
|
||||||
|
final ItemStack stack = (ItemStack) item;
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
temp.add(stack);
|
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 {
|
} else {
|
||||||
throw new ActionFormatException("'items' is not a list of items", actionKey);
|
throw new ActionFormatException("'items' is not a list of items", actionKey);
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,7 @@ public class BukkitQuestYamlStorage implements QuestStorageImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.contains("quests." + questId + ".gui-display")) {
|
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) {
|
if (stack != null) {
|
||||||
quest.setGUIDisplay(stack);
|
quest.setGUIDisplay(stack);
|
||||||
} else {
|
} else {
|
||||||
|
@ -335,13 +335,28 @@ public class BukkitQuestYamlStorage implements QuestStorageImpl {
|
||||||
final BukkitDependencies depends = plugin.getDependencies();
|
final BukkitDependencies depends = plugin.getDependencies();
|
||||||
if (config.contains("quests." + questKey + ".rewards.items")) {
|
if (config.contains("quests." + questKey + ".rewards.items")) {
|
||||||
final LinkedList<ItemStack> temp = new LinkedList<>();
|
final LinkedList<ItemStack> temp = new LinkedList<>();
|
||||||
final List<ItemStack> stackList = (List<ItemStack>) config.get("quests." + questKey + ".rewards.items");
|
final List<?> itemList = (List<?>) config.get("quests." + questKey + ".rewards.items");
|
||||||
if (BukkitConfigUtil.checkList(stackList, ItemStack.class)) {
|
if (BukkitConfigUtil.checkList(itemList, ItemStack.class)) {
|
||||||
for (final ItemStack stack : stackList) {
|
for (final Object item : itemList) {
|
||||||
|
final ItemStack stack = (ItemStack) item;
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
temp.add(stack);
|
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 {
|
} else {
|
||||||
throw new QuestFormatException("Reward 'items' has invalid formatting", questKey);
|
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")) {
|
if (config.contains("quests." + questKey + ".requirements.items")) {
|
||||||
final List<ItemStack> temp = new LinkedList<>();
|
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");
|
+ ".requirements.items");
|
||||||
if (BukkitConfigUtil.checkList(stackList, ItemStack.class)) {
|
if (BukkitConfigUtil.checkList(itemList, ItemStack.class)) {
|
||||||
for (final ItemStack stack : stackList) {
|
for (final Object item : itemList) {
|
||||||
|
final ItemStack stack = (ItemStack) item;
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
temp.add(stack);
|
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 {
|
} else {
|
||||||
throw new QuestFormatException("Requirement 'items' has invalid formatting", questKey);
|
throw new QuestFormatException("Requirement 'items' has invalid formatting", questKey);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue