mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-03 06:57:58 +01:00
Better stage/action item serialization. Convert from legacy on save
This commit is contained in:
parent
c2b4ac45cb
commit
27efbdd0c3
@ -794,7 +794,7 @@ public class QuestFactory implements ConversationAbandonedListener {
|
|||||||
String failMessage = null;
|
String failMessage = null;
|
||||||
Integer moneyRew = null;
|
Integer moneyRew = null;
|
||||||
Integer questPointsRew = null;
|
Integer questPointsRew = null;
|
||||||
List<String> itemRews = null;
|
List<ItemStack> itemRews = null;
|
||||||
List<Integer> RPGItemRews = null;
|
List<Integer> RPGItemRews = null;
|
||||||
List<Integer> RPGItemAmounts = null;
|
List<Integer> RPGItemAmounts = null;
|
||||||
Integer expRew = null;
|
Integer expRew = null;
|
||||||
@ -883,10 +883,7 @@ public class QuestFactory implements ConversationAbandonedListener {
|
|||||||
questPointsRew = (Integer) cc.getSessionData(CK.REW_QUEST_POINTS);
|
questPointsRew = (Integer) cc.getSessionData(CK.REW_QUEST_POINTS);
|
||||||
}
|
}
|
||||||
if (cc.getSessionData(CK.REW_ITEMS) != null) {
|
if (cc.getSessionData(CK.REW_ITEMS) != null) {
|
||||||
itemRews = new LinkedList<String>();
|
itemRews = (List<ItemStack>) cc.getSessionData(CK.REW_ITEMS);
|
||||||
for (ItemStack is : (List<ItemStack>) cc.getSessionData(CK.REW_ITEMS)) {
|
|
||||||
itemRews.add(ItemUtil.serializeItemStack(is));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (cc.getSessionData(CK.REW_EXP) != null) {
|
if (cc.getSessionData(CK.REW_EXP) != null) {
|
||||||
expRew = (Integer) cc.getSessionData(CK.REW_EXP);
|
expRew = (Integer) cc.getSessionData(CK.REW_EXP);
|
||||||
@ -957,16 +954,10 @@ public class QuestFactory implements ConversationAbandonedListener {
|
|||||||
cs.set("finish-message", finish);
|
cs.set("finish-message", finish);
|
||||||
cs.set("event", initialEvent);
|
cs.set("event", initialEvent);
|
||||||
cs.set("region", region);
|
cs.set("region", region);
|
||||||
cs.set("gui-display", ItemUtil.serializeItemStack(guiDisplay));
|
cs.set("gui-display", guiDisplay);
|
||||||
if (moneyReq != null || questPointsReq != null || itemReqs != null && itemReqs.isEmpty() == false || permReqs != null && permReqs.isEmpty() == false || (questReqs != null && questReqs.isEmpty() == false) || (questBlocks != null && questBlocks.isEmpty() == false) || (mcMMOSkillReqs != null && mcMMOSkillReqs.isEmpty() == false) || heroesPrimaryReq != null || heroesSecondaryReq != null || customReqs != null) {
|
if (moneyReq != null || questPointsReq != null || itemReqs != null && itemReqs.isEmpty() == false || permReqs != null && permReqs.isEmpty() == false || (questReqs != null && questReqs.isEmpty() == false) || (questBlocks != null && questBlocks.isEmpty() == false) || (mcMMOSkillReqs != null && mcMMOSkillReqs.isEmpty() == false) || heroesPrimaryReq != null || heroesSecondaryReq != null || customReqs != null) {
|
||||||
ConfigurationSection reqs = cs.createSection("requirements");
|
ConfigurationSection reqs = cs.createSection("requirements");
|
||||||
List<String> items = new LinkedList<String>();
|
reqs.set("items", itemReqs);
|
||||||
if (itemReqs != null) {
|
|
||||||
for (ItemStack is : itemReqs) {
|
|
||||||
items.add(ItemUtil.serializeItemStack(is));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reqs.set("items", (items.isEmpty() == false) ? items : null);
|
|
||||||
reqs.set("remove-items", removeItemReqs);
|
reqs.set("remove-items", removeItemReqs);
|
||||||
reqs.set("money", moneyReq);
|
reqs.set("money", moneyReq);
|
||||||
reqs.set("quest-points", questPointsReq);
|
reqs.set("quest-points", questPointsReq);
|
||||||
@ -1265,20 +1256,12 @@ public class QuestFactory implements ConversationAbandonedListener {
|
|||||||
stage.set("cut-block-durability", cutDurability);
|
stage.set("cut-block-durability", cutDurability);
|
||||||
}
|
}
|
||||||
if (craftItems != null && craftItems.isEmpty() == false) {
|
if (craftItems != null && craftItems.isEmpty() == false) {
|
||||||
LinkedList<String> items = new LinkedList<String>();
|
stage.set("items-to-craft", craftItems);
|
||||||
for (ItemStack is : craftItems) {
|
|
||||||
items.add(ItemUtil.serializeItemStack(is));
|
|
||||||
}
|
|
||||||
stage.set("items-to-craft", items);
|
|
||||||
} else {
|
} else {
|
||||||
stage.set("items-to-craft", null);
|
stage.set("items-to-craft", null);
|
||||||
}
|
}
|
||||||
if (smeltItems != null && smeltItems.isEmpty() == false) {
|
if (smeltItems != null && smeltItems.isEmpty() == false) {
|
||||||
LinkedList<String> items = new LinkedList<String>();
|
stage.set("items-to-smelt", smeltItems);
|
||||||
for (ItemStack is : smeltItems) {
|
|
||||||
items.add(ItemUtil.serializeItemStack(is));
|
|
||||||
}
|
|
||||||
stage.set("items-to-smelt", items);
|
|
||||||
} else {
|
} else {
|
||||||
stage.set("items-to-smelt", null);
|
stage.set("items-to-smelt", null);
|
||||||
}
|
}
|
||||||
@ -1286,22 +1269,14 @@ public class QuestFactory implements ConversationAbandonedListener {
|
|||||||
stage.set("enchantment-item-names", enchantmentIds);
|
stage.set("enchantment-item-names", enchantmentIds);
|
||||||
stage.set("enchantment-amounts", enchantmentAmounts);
|
stage.set("enchantment-amounts", enchantmentAmounts);
|
||||||
if (brewItems != null && brewItems.isEmpty() == false) {
|
if (brewItems != null && brewItems.isEmpty() == false) {
|
||||||
LinkedList<String> items = new LinkedList<String>();
|
stage.set("items-to-brew", brewItems);
|
||||||
for (ItemStack is : brewItems) {
|
|
||||||
items.add(ItemUtil.serializeItemStack(is));
|
|
||||||
}
|
|
||||||
stage.set("items-to-brew", items);
|
|
||||||
} else {
|
} else {
|
||||||
stage.set("items-to-brew", null);
|
stage.set("items-to-brew", null);
|
||||||
}
|
}
|
||||||
stage.set("fish-to-catch", fish);
|
stage.set("fish-to-catch", fish);
|
||||||
stage.set("players-to-kill", players);
|
stage.set("players-to-kill", players);
|
||||||
if (deliveryItems != null && deliveryItems.isEmpty() == false) {
|
if (deliveryItems != null && deliveryItems.isEmpty() == false) {
|
||||||
LinkedList<String> items = new LinkedList<String>();
|
stage.set("items-to-deliver", deliveryItems);
|
||||||
for (ItemStack is : deliveryItems) {
|
|
||||||
items.add(ItemUtil.serializeItemStack(is));
|
|
||||||
}
|
|
||||||
stage.set("items-to-deliver", items);
|
|
||||||
} else {
|
} else {
|
||||||
stage.set("items-to-deliver", null);
|
stage.set("items-to-deliver", null);
|
||||||
}
|
}
|
||||||
|
@ -1525,18 +1525,22 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.contains("quests." + questKey + ".gui-display")) {
|
if (config.contains("quests." + questKey + ".gui-display")) {
|
||||||
String item = config.getString("quests." + questKey + ".gui-display");
|
ItemStack stack = config.getItemStack("quests." + questKey + ".gui-display");
|
||||||
try {
|
if (stack == null) {
|
||||||
ItemStack stack = ItemUtil.readItemStack(item);
|
// Legacy
|
||||||
if (stack != null) {
|
String item = config.getString("quests." + questKey + ".gui-display");
|
||||||
quest.guiDisplay = stack;
|
try {
|
||||||
|
stack = ItemUtil.readItemStack(item);
|
||||||
|
} catch (Exception e) {
|
||||||
|
skipQuestProcess(item + " inside items: GUI Display in Quest " + quest.getName() + "is not properly formatted!");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
}
|
||||||
this.getLogger().warning(item + " in items: GUI Display in Quest " + quest.getName() + "is not properly formatted!");
|
if (stack != null) {
|
||||||
|
quest.guiDisplay = stack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.contains("quests." + questKey + ".redo-delay")) {
|
if (config.contains("quests." + questKey + ".redo-delay")) {
|
||||||
//Legacy
|
// Legacy
|
||||||
if (config.getInt("quests." + questKey + ".redo-delay", -999) != -999) {
|
if (config.getInt("quests." + questKey + ".redo-delay", -999) != -999) {
|
||||||
quest.getPlanner().setCooldown(config.getInt("quests." + questKey + ".redo-delay") * 1000);
|
quest.getPlanner().setCooldown(config.getInt("quests." + questKey + ".redo-delay") * 1000);
|
||||||
} else {
|
} else {
|
||||||
@ -1603,25 +1607,37 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private void loadQuestRewards(FileConfiguration config, Quest quest, String questKey) throws SkipQuest {
|
private void loadQuestRewards(FileConfiguration config, Quest quest, String questKey) throws SkipQuest {
|
||||||
Rewards rews = quest.getRewards();
|
Rewards rews = quest.getRewards();
|
||||||
if (config.contains("quests." + questKey + ".rewards.items")) {
|
if (config.contains("quests." + questKey + ".rewards.items")) {
|
||||||
if (Quests.checkList(config.getList("quests." + questKey + ".rewards.items"), String.class)) {
|
LinkedList<ItemStack> temp = new LinkedList<ItemStack>(); // TODO - should maybe be = rews.getItems() ?
|
||||||
LinkedList<ItemStack> temp = new LinkedList<ItemStack>();
|
List<ItemStack> stackList = (List<ItemStack>) config.get("quests." + questKey + ".rewards.items");
|
||||||
for (String item : config.getStringList("quests." + questKey + ".rewards.items")) {
|
if (Quests.checkList(stackList, ItemStack.class)) {
|
||||||
try {
|
for (ItemStack stack : stackList) {
|
||||||
ItemStack stack = ItemUtil.readItemStack(item);
|
if (stack != null) {
|
||||||
if (stack != null) {
|
temp.add(stack);
|
||||||
temp.add(stack);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
skipQuestProcess("" + item + " in items: Reward in Quest " + quest.getName() + " is not properly formatted!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rews.setItems(temp);
|
|
||||||
} else {
|
} else {
|
||||||
skipQuestProcess("items: Reward in Quest " + quest.getName() + " is not a list of strings!");
|
// Legacy
|
||||||
|
if (Quests.checkList(stackList, String.class)) {
|
||||||
|
List<String> items = config.getStringList("quests." + questKey + ".rewards.items");
|
||||||
|
for (String item : items) {
|
||||||
|
try {
|
||||||
|
ItemStack stack = ItemUtil.readItemStack(item);
|
||||||
|
if (stack != null) {
|
||||||
|
temp.add(stack);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
skipQuestProcess("" + item + " inside items: Reward in Quest " + quest.getName() + " is not properly formatted!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
skipQuestProcess("items: Reward in Quest " + quest.getName() + " is not properly formatted!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
rews.setItems(temp);
|
||||||
}
|
}
|
||||||
if (config.contains("quests." + questKey + ".rewards.money")) {
|
if (config.contains("quests." + questKey + ".rewards.money")) {
|
||||||
if (config.getInt("quests." + questKey + ".rewards.money", -999) != -999) {
|
if (config.getInt("quests." + questKey + ".rewards.money", -999) != -999) {
|
||||||
@ -1733,6 +1749,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private void loadQuestRequirements(FileConfiguration config, ConfigurationSection questsSection, Quest quest, String questKey) throws SkipQuest {
|
private void loadQuestRequirements(FileConfiguration config, ConfigurationSection questsSection, Quest quest, String questKey) throws SkipQuest {
|
||||||
Requirements reqs = quest.getRequirements();
|
Requirements reqs = quest.getRequirements();
|
||||||
if (config.contains("quests." + questKey + ".requirements.fail-requirement-message")) {
|
if (config.contains("quests." + questKey + ".requirements.fail-requirement-message")) {
|
||||||
@ -1741,25 +1758,31 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
skipQuestProcess("Requirements for Quest " + quest.getName() + " is missing fail-requirement-message:");
|
skipQuestProcess("Requirements for Quest " + quest.getName() + " is missing fail-requirement-message:");
|
||||||
}
|
}
|
||||||
if (config.contains("quests." + questKey + ".requirements.items")) {
|
if (config.contains("quests." + questKey + ".requirements.items")) {
|
||||||
if (Quests.checkList(config.getList("quests." + questKey + ".requirements.items"), String.class)) {
|
List<ItemStack> temp = reqs.getItems(); // TODO - should maybe be = newLinkedList<ItemStack>() ?
|
||||||
List<String> itemReqs = config.getStringList("quests." + questKey + ".requirements.items");
|
List<ItemStack> stackList = (List<ItemStack>) config.get("quests." + questKey + ".requirements.items");
|
||||||
boolean failed = false;
|
if (checkList(stackList, ItemStack.class)) {
|
||||||
List<ItemStack> temp = reqs.getItems();
|
for (ItemStack stack : stackList) {
|
||||||
for (String item : itemReqs) {
|
|
||||||
ItemStack stack = ItemUtil.readItemStack(item);
|
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
temp.add(stack);
|
temp.add(stack);
|
||||||
} else {
|
|
||||||
failed = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reqs.setItems(temp);
|
|
||||||
if (failed == true) {
|
|
||||||
skipQuestProcess("items: Requirement for Quest " + quest.getName() + " is not formatted correctly!");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
skipQuestProcess("items: Requirement for Quest " + quest.getName() + " is not formatted correctly!");
|
// Legacy
|
||||||
|
List<String> items = config.getStringList("quests." + questKey + ".requirements.items");
|
||||||
|
if (checkList(items, String.class)) {
|
||||||
|
for (String item : items) {
|
||||||
|
try {
|
||||||
|
ItemStack stack = ItemUtil.readItemStack(item);
|
||||||
|
if (stack != null) {
|
||||||
|
temp.add(stack);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
skipQuestProcess("" + item + " inside items: Requirement in Quest " + quest.getName() + " is not properly formatted!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
skipQuestProcess("items: Requirement in Quest " + quest.getName() + " is not properly formatted!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (config.contains("quests." + questKey + ".requirements.remove-items")) {
|
if (config.contains("quests." + questKey + ".requirements.remove-items")) {
|
||||||
if (Quests.checkList(config.getList("quests." + questKey + ".requirements.remove-items"), Boolean.class)) {
|
if (Quests.checkList(config.getList("quests." + questKey + ".requirements.remove-items"), Boolean.class)) {
|
||||||
@ -1978,6 +2001,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
return exists;
|
return exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "unchecked", "unused" })
|
||||||
private void processStages(Quest quest, FileConfiguration config, String questKey) throws StageFailedException {
|
private void processStages(Quest quest, FileConfiguration config, String questKey) throws StageFailedException {
|
||||||
ConfigurationSection questStages = config.getConfigurationSection("quests." + questKey + ".stages.ordered");
|
ConfigurationSection questStages = config.getConfigurationSection("quests." + questKey + ".stages.ordered");
|
||||||
for (String s2 : questStages.getKeys(false)) {
|
for (String s2 : questStages.getKeys(false)) {
|
||||||
@ -2002,14 +2026,14 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
List<Location> locationsToKillWithin = new LinkedList<Location>();
|
List<Location> locationsToKillWithin = new LinkedList<Location>();
|
||||||
List<Integer> radiiToKillWithin = new LinkedList<Integer>();
|
List<Integer> radiiToKillWithin = new LinkedList<Integer>();
|
||||||
List<String> areaNames = new LinkedList<String>();
|
List<String> areaNames = new LinkedList<String>();
|
||||||
List<String> itemsToCraft = new LinkedList<String>();
|
List<ItemStack> itemsToCraft = new LinkedList<ItemStack>();
|
||||||
List<String> itemsToSmelt = new LinkedList<String>();
|
List<ItemStack> itemsToSmelt = new LinkedList<ItemStack>();
|
||||||
List<Enchantment> enchantments = new LinkedList<Enchantment>();
|
List<Enchantment> enchantments = new LinkedList<Enchantment>();
|
||||||
List<Material> itemsToEnchant = new LinkedList<Material>();
|
List<Material> itemsToEnchant = new LinkedList<Material>();
|
||||||
List<Integer> amountsToEnchant = new LinkedList<Integer>();
|
List<Integer> amountsToEnchant = new LinkedList<Integer>();
|
||||||
List<String> itemsToBrew = new LinkedList<String>();
|
List<ItemStack> itemsToBrew = new LinkedList<ItemStack>();
|
||||||
List<Integer> npcIdsToTalkTo = new LinkedList<Integer>();
|
List<Integer> npcIdsToTalkTo = new LinkedList<Integer>();
|
||||||
List<String> itemsToDeliver= new LinkedList<String>();
|
List<ItemStack> itemsToDeliver= new LinkedList<ItemStack>();
|
||||||
List<Integer> itemDeliveryTargetIds = new LinkedList<Integer>();
|
List<Integer> itemDeliveryTargetIds = new LinkedList<Integer>();
|
||||||
List<String> deliveryMessages = new LinkedList<String>();
|
List<String> deliveryMessages = new LinkedList<String>();
|
||||||
List<Integer> npcIdsToKill = new LinkedList<Integer>();
|
List<Integer> npcIdsToKill = new LinkedList<Integer>();
|
||||||
@ -2229,33 +2253,57 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
cutIndex++;
|
cutIndex++;
|
||||||
}
|
}
|
||||||
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".items-to-craft")) {
|
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".items-to-craft")) {
|
||||||
if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-craft"), String.class)) {
|
itemsToCraft = (List<ItemStack>) config.get("quests." + questKey + ".stages.ordered." + s2 + ".items-to-craft");
|
||||||
itemsToCraft = config.getStringList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-craft");
|
if (checkList(itemsToCraft, ItemStack.class)) {
|
||||||
for (String item : itemsToCraft) {
|
for (ItemStack stack : itemsToCraft) {
|
||||||
ItemStack is = ItemUtil.readItemStack("" + item);
|
if (stack != null) {
|
||||||
if (is != null) {
|
oStage.itemsToCraft.add(stack);
|
||||||
oStage.getItemsToCraft().add(is);
|
|
||||||
} else {
|
} else {
|
||||||
stageFailed("" + item + " inside items-to-craft: inside Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
stageFailed("" + stack + " inside items-to-craft: inside Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stageFailed("items-to-craft: in Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
// Legacy
|
||||||
|
List<String> items = config.getStringList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-craft");
|
||||||
|
if (checkList(items, String.class)) {
|
||||||
|
for (String item : items) {
|
||||||
|
ItemStack is = ItemUtil.readItemStack("" + item);
|
||||||
|
if (is != null) {
|
||||||
|
oStage.itemsToCraft.add(is);
|
||||||
|
} else {
|
||||||
|
stageFailed("" + item + " inside legacy items-to-craft: inside Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stageFailed("items-to-craft: in Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".items-to-smelt")) {
|
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".items-to-smelt")) {
|
||||||
if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-smelt"), String.class)) {
|
itemsToSmelt = (List<ItemStack>) config.get("quests." + questKey + ".stages.ordered." + s2 + ".items-to-smelt");
|
||||||
itemsToSmelt = config.getStringList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-smelt");
|
if (checkList(itemsToSmelt, ItemStack.class)) {
|
||||||
for (String item : itemsToSmelt) {
|
for (ItemStack stack : itemsToSmelt) {
|
||||||
ItemStack is = ItemUtil.readItemStack("" + item);
|
if (stack != null) {
|
||||||
if (is != null) {
|
oStage.itemsToSmelt.add(stack);
|
||||||
oStage.getItemsToSmelt().add(is);
|
|
||||||
} else {
|
} else {
|
||||||
stageFailed("" + item + " inside items-to-smelt: inside Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
stageFailed("" + stack + " inside items-to-smelt: inside Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stageFailed("items-to-smelt: in Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
// Legacy
|
||||||
|
List<String> items = config.getStringList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-smelt");
|
||||||
|
if (checkList(items, String.class)) {
|
||||||
|
for (String item : items) {
|
||||||
|
ItemStack is = ItemUtil.readItemStack("" + item);
|
||||||
|
if (is != null) {
|
||||||
|
oStage.itemsToSmelt.add(is);
|
||||||
|
} else {
|
||||||
|
stageFailed("" + item + " inside legacy items-to-smelt: inside Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stageFailed("items-to-smelt: in Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".enchantments")) {
|
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".enchantments")) {
|
||||||
@ -2297,18 +2345,30 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".items-to-brew")) {
|
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".items-to-brew")) {
|
||||||
if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-brew"), String.class)) {
|
itemsToBrew = (List<ItemStack>) config.get("quests." + questKey + ".stages.ordered." + s2 + ".items-to-brew");
|
||||||
itemsToBrew = config.getStringList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-brew");
|
if (checkList(itemsToBrew, ItemStack.class)) {
|
||||||
for (String item : itemsToBrew) {
|
for (ItemStack stack : itemsToBrew) {
|
||||||
ItemStack is = ItemUtil.readItemStack("" + item);
|
if (stack != null) {
|
||||||
if (is != null) {
|
oStage.itemsToBrew.add(stack);
|
||||||
oStage.getItemsToBrew().add(is);
|
|
||||||
} else {
|
} else {
|
||||||
stageFailed("" + item + " inside items-to-brew: inside Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
stageFailed("" + stack + " inside items-to-brew: inside Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stageFailed("items-to-brew: in Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
// Legacy
|
||||||
|
List<String> items = config.getStringList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-brew");
|
||||||
|
if (checkList(items, String.class)) {
|
||||||
|
for (String item : items) {
|
||||||
|
ItemStack is = ItemUtil.readItemStack("" + item);
|
||||||
|
if (is != null) {
|
||||||
|
oStage.itemsToBrew.add(is);
|
||||||
|
} else {
|
||||||
|
stageFailed("" + item + " inside legacy items-to-brew: inside Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stageFailed("items-to-brew: in Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".fish-to-catch")) {
|
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".fish-to-catch")) {
|
||||||
@ -2345,46 +2405,71 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".items-to-deliver")) {
|
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".items-to-deliver")) {
|
||||||
if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-deliver"), String.class)) {
|
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".npc-delivery-ids")) {
|
||||||
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".npc-delivery-ids")) {
|
if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".npc-delivery-ids"), Integer.class)) {
|
||||||
if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".npc-delivery-ids"), Integer.class)) {
|
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".delivery-messages")) {
|
||||||
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".delivery-messages")) {
|
itemsToDeliver = (List<ItemStack>) config.get("quests." + questKey + ".stages.ordered." + s2 + ".items-to-deliver");
|
||||||
itemsToDeliver = config.getStringList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-deliver");
|
itemDeliveryTargetIds = config.getIntegerList("quests." + questKey + ".stages.ordered." + s2 + ".npc-delivery-ids");
|
||||||
itemDeliveryTargetIds = config.getIntegerList("quests." + questKey + ".stages.ordered." + s2 + ".npc-delivery-ids");
|
deliveryMessages.addAll(config.getStringList("quests." + questKey + ".stages.ordered." + s2 + ".delivery-messages"));
|
||||||
deliveryMessages.addAll(config.getStringList("quests." + questKey + ".stages.ordered." + s2 + ".delivery-messages"));
|
int index = 0;
|
||||||
int index = 0;
|
if (checkList(itemsToDeliver, ItemStack.class)) {
|
||||||
for (String item : itemsToDeliver) {
|
for (ItemStack stack : itemsToDeliver) {
|
||||||
ItemStack is = ItemUtil.readItemStack("" + item);
|
if (stack != null) {
|
||||||
int npcId = itemDeliveryTargetIds.get(index);
|
int npcId = itemDeliveryTargetIds.get(index);
|
||||||
index++;
|
index++;
|
||||||
if (is != null) {
|
if (stack != null) {
|
||||||
if (getDependencies().getCitizens() != null) {
|
if (getDependencies().getCitizens() != null) {
|
||||||
NPC npc = CitizensAPI.getNPCRegistry().getById(npcId);
|
NPC npc = CitizensAPI.getNPCRegistry().getById(npcId);
|
||||||
if (npc != null) {
|
if (npc != null) {
|
||||||
oStage.getItemsToDeliver().add(is);
|
oStage.getItemsToDeliver().add(stack);
|
||||||
oStage.getItemDeliveryTargets().add(npcId);
|
oStage.getItemDeliveryTargets().add(npcId);
|
||||||
oStage.deliverMessages.addAll(deliveryMessages);
|
oStage.deliverMessages.addAll(deliveryMessages);
|
||||||
|
} else {
|
||||||
|
stageFailed("Citizens was not installed for ID " + npcId + " inside npc-delivery-ids: inside Stage " + s2 + " of Quest " + quest.getName());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
stageFailed("" + npcId + " inside npc-delivery-ids: inside Stage " + s2 + " of Quest " + quest.getName() + " is not a valid NPC id!");
|
stageFailed("" + npcId + " inside npc-delivery-ids: inside Stage " + s2 + " of Quest " + quest.getName() + " is not a valid NPC id!");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stageFailed("Citizens was not installed for ID " + npcId + " inside npc-delivery-ids: inside Stage " + s2 + " of Quest " + quest.getName());
|
stageFailed("" + stack + " inside items-to-deliver: inside Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
stageFailed("" + item + " inside items-to-deliver: inside Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stageFailed("Stage " + s2 + " of Quest " + quest.getName() + " is missing delivery-messages:");
|
List<String> items = config.getStringList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-deliver");
|
||||||
|
if (checkList(items, String.class)) {
|
||||||
|
// Legacy
|
||||||
|
for (String item : items) {
|
||||||
|
ItemStack is = ItemUtil.readItemStack("" + item);
|
||||||
|
int npcId = itemDeliveryTargetIds.get(index);
|
||||||
|
index++;
|
||||||
|
if (is != null) {
|
||||||
|
if (getDependencies().getCitizens() != null) {
|
||||||
|
NPC npc = CitizensAPI.getNPCRegistry().getById(npcId);
|
||||||
|
if (npc != null) {
|
||||||
|
oStage.getItemsToDeliver().add(is);
|
||||||
|
oStage.getItemDeliveryTargets().add(npcId);
|
||||||
|
oStage.deliverMessages.addAll(deliveryMessages);
|
||||||
|
} else {
|
||||||
|
stageFailed("" + npcId + " inside npc-delivery-ids: inside Stage " + s2 + " of Quest " + quest.getName() + " is not a valid NPC id!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stageFailed("Citizens was not installed for ID " + npcId + " inside npc-delivery-ids: inside Stage " + s2 + " of Quest " + quest.getName());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stageFailed("" + item + " inside items-to-deliver: inside Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stageFailed("items-to-deliver: in Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
stageFailed("npc-delivery-ids: in Stage " + s2 + " of Quest " + ChatColor.DARK_PURPLE + quest.getName() + " is not a list of NPC ids!");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stageFailed("Stage " + s2 + " of Quest " + quest.getName() + " is missing npc-delivery-ids:");
|
stageFailed("npc-delivery-ids: in Stage " + s2 + " of Quest " + ChatColor.DARK_PURPLE + quest.getName() + " is not a list of NPC ids!");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stageFailed("items-to-deliver: in Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!");
|
stageFailed("Stage " + s2 + " of Quest " + quest.getName() + " is missing npc-delivery-ids:");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".npc-ids-to-kill")) {
|
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".npc-ids-to-kill")) {
|
||||||
@ -3353,15 +3438,20 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether items in a list are instances of a class<p>
|
||||||
|
*
|
||||||
|
* Does NOT check whether list objects are null
|
||||||
|
*
|
||||||
|
* @param list The list to check objects of
|
||||||
|
* @param clazz The class to compare against
|
||||||
|
* @return false if list is null or list object does not match
|
||||||
|
*/
|
||||||
public static boolean checkList(List<?> list, Class<?> clazz) {
|
public static boolean checkList(List<?> list, Class<?> clazz) {
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (Object o : list) {
|
for (Object o : list) {
|
||||||
if (o == null) {
|
|
||||||
Bukkit.getLogger().severe("A null " + clazz.getSimpleName() + " value was detected in quests.yml, please correct the file");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (clazz.isAssignableFrom(o.getClass()) == false) {
|
if (clazz.isAssignableFrom(o.getClass()) == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -493,16 +493,28 @@ public class Action {
|
|||||||
}
|
}
|
||||||
if (data.contains(actionKey + "items")) {
|
if (data.contains(actionKey + "items")) {
|
||||||
if (Quests.checkList(data.getList(actionKey + "items"), String.class)) {
|
if (Quests.checkList(data.getList(actionKey + "items"), String.class)) {
|
||||||
List<ItemStack> eventItems = new LinkedList<ItemStack>();
|
@SuppressWarnings("unchecked")
|
||||||
for (String s : data.getStringList(actionKey + "items")) {
|
List<ItemStack> items = (List<ItemStack>) data.get(actionKey + "items");
|
||||||
try {
|
if (items != null && !items.isEmpty() && items.get(0) instanceof ItemStack) {
|
||||||
eventItems.add(ItemUtil.readItemStack(s));
|
for (ItemStack item : items) {
|
||||||
} catch (Exception e) {
|
try {
|
||||||
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] \"" + ChatColor.RED + s + ChatColor.GOLD + "\" inside " + ChatColor.GREEN + " items: " + ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not formatted properly!");
|
action.items.add(item);
|
||||||
return null;
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] \"" + ChatColor.RED + item.getType().name() + ChatColor.GOLD + "\" inside " + ChatColor.GREEN + " items: " + ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not formatted properly!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Legacy
|
||||||
|
for (String s : data.getStringList(actionKey + "items")) {
|
||||||
|
try {
|
||||||
|
action.items.add(ItemUtil.readItemStack(s));
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] \"" + ChatColor.RED + s + ChatColor.GOLD + "\" inside " + ChatColor.GREEN + " items: " + ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not formatted properly!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
action.items.addAll(eventItems);
|
|
||||||
} else {
|
} else {
|
||||||
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "items: " + ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not a list of items!");
|
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "items: " + ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not a list of items!");
|
||||||
return null;
|
return null;
|
||||||
|
@ -935,11 +935,7 @@ public class ActionFactory implements ConversationAbandonedListener {
|
|||||||
if (context.getSessionData(CK.E_ITEMS) != null) {
|
if (context.getSessionData(CK.E_ITEMS) != null) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
LinkedList<ItemStack> items = (LinkedList<ItemStack>) context.getSessionData(CK.E_ITEMS);
|
LinkedList<ItemStack> items = (LinkedList<ItemStack>) context.getSessionData(CK.E_ITEMS);
|
||||||
LinkedList<String> lines = new LinkedList<String>();
|
section.set("items", items);
|
||||||
for (ItemStack is : items) {
|
|
||||||
lines.add(ItemUtil.serializeItemStack(is));
|
|
||||||
}
|
|
||||||
section.set("items", lines);
|
|
||||||
}
|
}
|
||||||
if (context.getSessionData(CK.E_EXPLOSIONS) != null) {
|
if (context.getSessionData(CK.E_EXPLOSIONS) != null) {
|
||||||
LinkedList<String> locations = getCStringList(context, CK.E_EXPLOSIONS);
|
LinkedList<String> locations = getCStringList(context, CK.E_EXPLOSIONS);
|
||||||
|
Loading…
Reference in New Issue
Block a user