Better handling of failed Action loading

This commit is contained in:
PikaMug 2020-04-15 04:43:37 -04:00
parent 0d7e282807
commit 6ea64136ec
3 changed files with 406 additions and 455 deletions

View File

@ -45,6 +45,7 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@ -69,6 +70,8 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import com.codisimus.plugins.phatloots.PhatLootsAPI;
import com.gmail.nossr50.datatypes.skills.SkillType;
@ -77,6 +80,7 @@ import com.herocraftonline.heroes.characters.classes.HeroClass;
import me.blackvein.quests.actions.Action;
import me.blackvein.quests.actions.ActionFactory;
import me.blackvein.quests.convo.quests.prompts.QuestOfferPrompt;
import me.blackvein.quests.exceptions.ActionFormatException;
import me.blackvein.quests.exceptions.QuestFormatException;
import me.blackvein.quests.exceptions.StageFormatException;
import me.blackvein.quests.listeners.CmdExecutor;
@ -1376,16 +1380,18 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
throw new QuestFormatException("ask-message is missing", questKey);
}
if (config.contains("quests." + questKey + ".action")) {
Action act = Action.loadAction(config.getString("quests." + questKey + ".action"), this);
Action act = loadAction(config.getString("quests." + questKey + ".action"));
if (act != null) {
quest.initialAction = act;
} else {
throw new QuestFormatException("action failed to load", questKey);
}
} else if (config.contains("quests." + questKey + ".event")) {
Action evt = Action.loadAction(config.getString("quests." + questKey + ".event"), this);
if (evt != null) {
quest.initialAction = evt;
Action action = null;
action = loadAction(config.getString("quests." + questKey + ".event"));
if (action != null) {
quest.initialAction = action;
} else {
throw new QuestFormatException("action failed to load", questKey);
}
@ -1414,11 +1420,14 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
if (failedToLoad == true) {
getLogger().log(Level.SEVERE, "Failed to load Quest \"" + questKey + "\". Skipping.");
}
} catch (QuestFormatException ex) {
ex.printStackTrace();
} catch (QuestFormatException e) {
e.printStackTrace();
continue;
} catch (StageFormatException ex) {
ex.printStackTrace();
} catch (StageFormatException e) {
e.printStackTrace();
continue;
} catch (ActionFormatException e) {
e.printStackTrace();
continue;
}
}
@ -1840,7 +1849,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
}
@SuppressWarnings({ "unchecked", "unused" })
private void loadQuestStages(Quest quest, FileConfiguration config, String questKey) throws StageFormatException {
private void loadQuestStages(Quest quest, FileConfiguration config, String questKey)
throws StageFormatException, ActionFormatException {
ConfigurationSection questStages = config.getConfigurationSection("quests." + questKey + ".stages.ordered");
for (String stage : questStages.getKeys(false)) {
int stageNum = 0;
@ -2676,37 +2686,37 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
}
}
if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".start-event")) {
Action evt = Action.loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum
+ ".start-event"), this);
if (evt != null) {
oStage.startAction = evt;
Action action = loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum
+ ".start-event"));
if (action != null) {
oStage.startAction = action;
} else {
throw new StageFormatException("start-event failed to load", quest, stageNum);
}
}
if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".finish-event")) {
Action evt = Action.loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum
+ ".finish-event"), this);
if (evt != null) {
oStage.finishAction = evt;
Action action = loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum
+ ".finish-event"));
if (action != null) {
oStage.finishAction = action;
} else {
throw new StageFormatException("finish-event failed to load", quest, stageNum);
}
}
if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".death-event")) {
Action evt = Action.loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum
+ ".death-event"), this);
if (evt != null) {
oStage.deathAction = evt;
Action action = loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum
+ ".death-event"));
if (action != null) {
oStage.deathAction = action;
} else {
throw new StageFormatException("death-event failed to load", quest, stageNum);
}
}
if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".disconnect-event")) {
Action evt = Action.loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum
+ ".disconnect-event"), this);
if (evt != null) {
oStage.disconnectAction = evt;
Action action = loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum
+ ".disconnect-event"));
if (action != null) {
oStage.disconnectAction = action;
} else {
throw new StageFormatException("disconnect-event failed to load", quest, stageNum);
}
@ -2721,9 +2731,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
+ ".stages.ordered." + stageNum + ".chat-event-triggers");
boolean loadEventFailed = false;
for (int i = 0; i < chatEvents.size(); i++) {
Action evt = Action.loadAction(chatEvents.get(i), this);
if (evt != null) {
oStage.chatActions.put(chatEventTriggers.get(i), evt);
Action action = loadAction(chatEvents.get(i));
if (action != null) {
oStage.chatActions.put(chatEventTriggers.get(i), action);
} else {
loadEventFailed = true;
throw new StageFormatException("chat-events failed to load " + chatEvents.get(i), quest, stageNum);
@ -2752,9 +2762,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
+ ".stages.ordered." + stageNum + ".command-event-triggers");
boolean loadEventFailed = false;
for (int i = 0; i < commandEvents.size(); i++) {
Action evt = Action.loadAction(commandEvents.get(i), this);
if (evt != null) {
oStage.commandActions.put(commandEventTriggers.get(i), evt);
Action action = loadAction(commandEvents.get(i));
if (action != null) {
oStage.commandActions.put(commandEventTriggers.get(i), action);
} else {
loadEventFailed = true;
throw new StageFormatException("command-events failed to load " + commandEvents.get(i), quest, stageNum);
@ -2801,6 +2811,318 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
}
}
protected Action loadAction(String name) throws ActionFormatException {
if (name == null) {
return null;
}
File legacy = new File(getDataFolder(), "events.yml");
File actions = new File(getDataFolder(), "actions.yml");
FileConfiguration data = new YamlConfiguration();
try {
if (actions.isFile()) {
data.load(actions);
} else {
data.load(legacy);
}
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
String legacyName = "events." + name;
String actionKey = "actions." + name + ".";
if (data.contains(legacyName)) {
actionKey = legacyName + ".";
}
Action action = new Action(this);
action.setName(name);
if (data.contains(actionKey + "message")) {
action.setMessage(ConfigUtil.parseString(data.getString(actionKey + "message")));
}
if (data.contains(actionKey + "open-book")) {
action.setBook(data.getString(actionKey + "open-book"));
}
if (data.contains(actionKey + "clear-inventory")) {
if (data.isBoolean(actionKey + "clear-inventory")) {
action.setClearInv(data.getBoolean(actionKey + "clear-inventory"));
} else {
throw new ActionFormatException("clear-inventory is not a true/false value", actionKey);
}
}
if (data.contains(actionKey + "fail-quest")) {
if (data.isBoolean(actionKey + "fail-quest")) {
action.setFailQuest(data.getBoolean(actionKey + "fail-quest"));
} else {
throw new ActionFormatException("fail-quest is not a true/false value", actionKey);
}
}
if (data.contains(actionKey + "explosions")) {
if (ConfigUtil.checkList(data.getList(actionKey + "explosions"), String.class)) {
LinkedList<Location> explosions = new LinkedList<Location>();
for (String s : data.getStringList(actionKey + "explosions")) {
Location loc = ConfigUtil.getLocation(s);
if (loc == null) {
throw new ActionFormatException("explosions is not in proper \"WorldName x y z\" format", actionKey);
}
explosions.add(loc);
}
action.setExplosions(explosions);
} else {
throw new ActionFormatException("explosions is not a list of locations", actionKey);
}
}
if (data.contains(actionKey + "effects")) {
if (ConfigUtil.checkList(data.getList(actionKey + "effects"), String.class)) {
if (data.contains(actionKey + "effect-locations")) {
if (ConfigUtil.checkList(data.getList(actionKey + "effect-locations"), String.class)) {
List<String> effectList = data.getStringList(actionKey + "effects");
List<String> effectLocs = data.getStringList(actionKey + "effect-locations");
Map<Location, Effect> effects = new HashMap<Location, Effect>();
for (String s : effectList) {
Effect effect = null;
try {
effect = Effect.valueOf(s.toUpperCase());
} catch (IllegalArgumentException e) {
throw new ActionFormatException("effect-locations is not a valid effect name",
actionKey);
}
Location l = ConfigUtil.getLocation(effectLocs.get(effectList.indexOf(s)));
if (l == null) {
throw new ActionFormatException("effect-locations is not in proper \"WorldName x y z\""
+ "format", actionKey);
}
effects.put(l, effect);
}
action.setEffects(effects);
} else {
throw new ActionFormatException("effect-locations is not a list of locations", actionKey);
}
} else {
throw new ActionFormatException("effect-locations is missing", actionKey);
}
} else {
throw new ActionFormatException("effects is not a list of effects", actionKey);
}
}
if (data.contains(actionKey + "items")) {
LinkedList<ItemStack> temp = new LinkedList<ItemStack>();
@SuppressWarnings("unchecked")
List<ItemStack> stackList = (List<ItemStack>) data.get(actionKey + "items");
if (ConfigUtil.checkList(stackList, ItemStack.class)) {
for (ItemStack stack : stackList) {
if (stack != null) {
temp.add(stack);
}
}
} else {
// Legacy
if (ConfigUtil.checkList(stackList, String.class)) {
List<String> items = data.getStringList(actionKey + "items");
for (String item : items) {
try {
ItemStack stack = ItemUtil.readItemStack(item);
if (stack != null) {
temp.add(stack);
}
} catch (Exception e) {
throw new ActionFormatException("items is not formatted properly", actionKey);
}
}
} else {
throw new ActionFormatException("items is not a list of items", actionKey);
}
}
action.setItems(temp);
}
if (data.contains(actionKey + "storm-world")) {
World stormWorld = getServer().getWorld(data.getString(actionKey + "storm-world"));
if (stormWorld == null) {
throw new ActionFormatException("storm-world is not a valid world name", actionKey);
}
if (data.contains(actionKey + "storm-duration")) {
if (data.getInt(actionKey + "storm-duration", -999) != -999) {
action.setStormDuration(data.getInt(actionKey + "storm-duration") * 1000);
} else {
throw new ActionFormatException("storm-duration is not a number", actionKey);
}
action.setStormWorld(stormWorld);
} else {
throw new ActionFormatException("storm-duration is missing", actionKey);
}
}
if (data.contains(actionKey + "thunder-world")) {
World thunderWorld = getServer().getWorld(data.getString(actionKey + "thunder-world"));
if (thunderWorld == null) {
throw new ActionFormatException("thunder-world is not a valid world name", actionKey);
}
if (data.contains(actionKey + "thunder-duration")) {
if (data.getInt(actionKey + "thunder-duration", -999) != -999) {
action.setThunderDuration(data.getInt(actionKey + "thunder-duration"));
} else {
throw new ActionFormatException("thunder-duration is not a number", actionKey);
}
action.setThunderWorld(thunderWorld);
} else {
throw new ActionFormatException("thunder-duration is missing", actionKey);
}
}
if (data.contains(actionKey + "mob-spawns")) {
ConfigurationSection section = data.getConfigurationSection(actionKey + "mob-spawns");
LinkedList<QuestMob> mobSpawns = new LinkedList<QuestMob>();
for (String s : section.getKeys(false)) {
String mobName = section.getString(s + ".name");
Location spawnLocation = ConfigUtil.getLocation(section.getString(s + ".spawn-location"));
EntityType type = MiscUtil.getProperMobType(section.getString(s + ".mob-type"));
Integer mobAmount = section.getInt(s + ".spawn-amounts");
if (spawnLocation == null) {
throw new ActionFormatException("mob-spawn-locations is not in proper \"WorldName x y z\" format",
actionKey);
}
if (type == null) {
throw new ActionFormatException("mob-spawn-types is not a list of mob types", actionKey);
}
ItemStack[] inventory = new ItemStack[5];
Float[] dropChances = new Float[5];
inventory[0] = ItemUtil.readItemStack(section.getString(s + ".held-item"));
dropChances[0] = (float) section.getDouble(s + ".held-item-drop-chance");
inventory[1] = ItemUtil.readItemStack(section.getString(s + ".boots"));
dropChances[1] = (float) section.getDouble(s + ".boots-drop-chance");
inventory[2] = ItemUtil.readItemStack(section.getString(s + ".leggings"));
dropChances[2] = (float) section.getDouble(s + ".leggings-drop-chance");
inventory[3] = ItemUtil.readItemStack(section.getString(s + ".chest-plate"));
dropChances[3] = (float) section.getDouble(s + ".chest-plate-drop-chance");
inventory[4] = ItemUtil.readItemStack(section.getString(s + ".helmet"));
dropChances[4] = (float) section.getDouble(s + ".helmet-drop-chance");
QuestMob questMob = new QuestMob(type, spawnLocation, mobAmount);
questMob.setInventory(inventory);
questMob.setDropChances(dropChances);
questMob.setName(mobName);
mobSpawns.add(questMob);
}
action.setMobSpawns(mobSpawns);
}
if (data.contains(actionKey + "lightning-strikes")) {
if (ConfigUtil.checkList(data.getList(actionKey + "lightning-strikes"), String.class)) {
LinkedList<Location> lightningStrikes = new LinkedList<Location>();
for (String s : data.getStringList(actionKey + "lightning-strikes")) {
Location loc = ConfigUtil.getLocation(s);
if (loc == null) {
throw new ActionFormatException("lightning-strikes is not in proper \"WorldName x y z\" format",
actionKey);
}
lightningStrikes.add(loc);
}
action.setLightningStrikes(lightningStrikes);
} else {
throw new ActionFormatException("lightning-strikes is not a list of locations", actionKey);
}
}
if (data.contains(actionKey + "commands")) {
if (ConfigUtil.checkList(data.getList(actionKey + "commands"), String.class)) {
LinkedList<String> commands = new LinkedList<String>();
for (String s : data.getStringList(actionKey + "commands")) {
if (s.startsWith("/")) {
s = s.replaceFirst("/", "");
}
commands.add(s);
}
action.setCommands(commands);
} else {
throw new ActionFormatException("commands is not a list of commands", actionKey);
}
}
if (data.contains(actionKey + "potion-effect-types")) {
if (ConfigUtil.checkList(data.getList(actionKey + "potion-effect-types"), String.class)) {
if (data.contains(actionKey + "potion-effect-durations")) {
if (ConfigUtil.checkList(data.getList(actionKey + "potion-effect-durations"), Integer.class)) {
if (data.contains(actionKey + "potion-effect-amplifiers")) {
if (ConfigUtil.checkList(data.getList(actionKey + "potion-effect-amplifiers"),
Integer.class)) {
List<String> types = data.getStringList(actionKey + "potion-effect-types");
List<Integer> durations = data.getIntegerList(actionKey + "potion-effect-durations");
List<Integer> amplifiers = data.getIntegerList(actionKey + "potion-effect-amplifiers");
LinkedList<PotionEffect> potionEffects = new LinkedList<PotionEffect>();
for (String s : types) {
PotionEffectType type = PotionEffectType.getByName(s);
if (type == null) {
throw new ActionFormatException("potion-effect-types is not a list of potion "
+ "effect types", actionKey);
}
PotionEffect effect = new PotionEffect(type, durations
.get(types.indexOf(s)), amplifiers.get(types.indexOf(s)));
potionEffects.add(effect);
}
action.setPotionEffects(potionEffects);
} else {
throw new ActionFormatException("potion-effect-amplifiers is not a list of numbers",
actionKey);
}
} else {
throw new ActionFormatException("potion-effect-amplifiers is missing", actionKey);
}
} else {
throw new ActionFormatException("potion-effect-durations is not a list of numbers", actionKey);
}
} else {
throw new ActionFormatException("potion-effect-durations is missing", actionKey);
}
} else {
throw new ActionFormatException("potion-effect-types is not a list of potion effects", actionKey);
}
}
if (data.contains(actionKey + "hunger")) {
if (data.getInt(actionKey + "hunger", -999) != -999) {
action.setHunger(data.getInt(actionKey + "hunger"));
} else {
throw new ActionFormatException("hunger is not a number", actionKey);
}
}
if (data.contains(actionKey + "saturation")) {
if (data.getInt(actionKey + "saturation", -999) != -999) {
action.setSaturation(data.getInt(actionKey + "saturation"));
} else {
throw new ActionFormatException("saturation is not a number", actionKey);
}
}
if (data.contains(actionKey + "health")) {
if (data.getInt(actionKey + "health", -999) != -999) {
action.setHealth(data.getInt(actionKey + "health"));
} else {
throw new ActionFormatException("health is not a number", actionKey);
}
}
if (data.contains(actionKey + "teleport-location")) {
if (data.isString(actionKey + "teleport-location")) {
Location teleport = ConfigUtil.getLocation(data.getString(actionKey + "teleport-location"));
if (teleport == null) {
throw new ActionFormatException("teleport-location is not in proper \"WorldName x y z\" format",
actionKey);
}
action.setTeleport(teleport);
} else {
throw new ActionFormatException("teleport-location is not a location", actionKey);
}
}
if (data.contains(actionKey + "timer")) {
if (data.isInt(actionKey + "timer")) {
action.setTimer(data.getInt(actionKey + "timer"));
} else {
throw new ActionFormatException("timer is not a number", actionKey);
}
}
if (data.contains(actionKey + "cancel-timer")) {
if (data.isBoolean(actionKey + "cancel-timer")) {
action.setCancelTimer(data.getBoolean(actionKey + "cancel-timer"));
} else {
throw new ActionFormatException("cancel-timer is not a true/false value", actionKey);
}
}
if (data.contains(actionKey + "denizen-script")) {
action.setDenizenScript(data.getString(actionKey + "denizen-script"));
}
return action;
}
private void loadCustomSections(Quest quest, FileConfiguration config, String questKey)
throws StageFormatException, QuestFormatException {
ConfigurationSection questStages = config.getConfigurationSection("quests." + questKey + ".stages.ordered");
@ -2985,9 +3307,14 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
}
if (sec != null) {
for (String s : sec.getKeys(false)) {
Action event = Action.loadAction(s, this);
if (event != null) {
actions.add(event);
Action action = null;
try {
action= loadAction(s);
} catch (ActionFormatException e) {
e.printStackTrace();
}
if (action != null) {
actions.add(action);
} else {
getLogger().log(Level.SEVERE, "Failed to load Action \"" + s + "\". Skipping.");
}

View File

@ -12,26 +12,17 @@
package me.blackvein.quests.actions;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import me.blackvein.quests.Quest;
import me.blackvein.quests.QuestMob;
@ -40,9 +31,7 @@ import me.blackvein.quests.Quests;
import me.blackvein.quests.tasks.ActionTimer;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.InventoryUtil;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
public class Action {
@ -413,414 +402,5 @@ public class Action {
plugin.getDenizenTrigger().runDenizenScript(denizenScript, quester);
}
}
public static Action loadAction(String name, Quests plugin) {
if (name == null || plugin == null) {
return null;
}
File legacy = new File(plugin.getDataFolder(), "events.yml");
File actions = new File(plugin.getDataFolder(), "actions.yml");
FileConfiguration data = new YamlConfiguration();
try {
if (actions.isFile()) {
data.load(actions);
} else {
data.load(legacy);
}
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
String legacyName = "events." + name;
String actionKey = "actions." + name + ".";
if (data.contains(legacyName)) {
actionKey = legacyName + ".";
}
Action action = new Action(plugin);
action.name = name;
if (data.contains(actionKey + "message")) {
action.message = ConfigUtil.parseString(data.getString(actionKey + "message"));
}
if (data.contains(actionKey + "open-book")) {
action.book = data.getString(actionKey + "open-book");
}
if (data.contains(actionKey + "clear-inventory")) {
if (data.isBoolean(actionKey + "clear-inventory")) {
action.clearInv = data.getBoolean(actionKey + "clear-inventory");
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "clear-inventory: "
+ ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not a true/false value!");
return null;
}
}
if (data.contains(actionKey + "fail-quest")) {
if (data.isBoolean(actionKey + "fail-quest")) {
action.failQuest = data.getBoolean(actionKey + "fail-quest");
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "fail-quest: "
+ ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not a true/false value!");
return null;
}
}
if (data.contains(actionKey + "explosions")) {
if (ConfigUtil.checkList(data.getList(actionKey + "explosions"), String.class)) {
for (String s : data.getStringList(actionKey + "explosions")) {
Location loc = ConfigUtil.getLocation(s);
if (loc == null) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + loc + ChatColor.GOLD
+ " inside " + ChatColor.GREEN + "explosions: " + ChatColor.GOLD + "inside Action "
+ ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not in proper location format!");
plugin.getLogger().severe(ChatColor.GOLD
+ "[Quests] Proper location format is: \"WorldName x y z\"");
return null;
}
action.explosions.add(loc);
}
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "explosions: "
+ ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not a list of locations!");
return null;
}
}
if (data.contains(actionKey + "effects")) {
if (ConfigUtil.checkList(data.getList(actionKey + "effects"), String.class)) {
if (data.contains(actionKey + "effect-locations")) {
if (ConfigUtil.checkList(data.getList(actionKey + "effect-locations"), String.class)) {
List<String> effectList = data.getStringList(actionKey + "effects");
List<String> effectLocs = data.getStringList(actionKey + "effect-locations");
for (String s : effectList) {
Effect effect = null;
try {
effect = Effect.valueOf(s.toUpperCase());
} catch (IllegalArgumentException e) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + s
+ ChatColor.GOLD + " inside " + ChatColor.GREEN + "effects: " + ChatColor.GOLD
+ "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not a valid effect name!");
return null;
}
Location l = ConfigUtil.getLocation(effectLocs.get(effectList.indexOf(s)));
if (l == null) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED
+ effectLocs.get(effectList.indexOf(s)) + ChatColor.GOLD + " inside "
+ ChatColor.GREEN + "effect-locations: " + ChatColor.GOLD + "inside Action "
+ ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not in proper location format!");
plugin.getLogger().severe(ChatColor.GOLD
+ "[Quests] Proper location format is: \"WorldName x y z\"");
return null;
}
action.effects.put(l, effect);
}
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "effect-locations: "
+ ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not a list of locations!");
return null;
}
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] Action " + ChatColor.DARK_PURPLE + name
+ ChatColor.GOLD + " is missing " + ChatColor.RED + "effect-locations:");
return null;
}
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "effects: " + ChatColor.GOLD
+ "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not a list of effects!");
return null;
}
}
if (data.contains(actionKey + "items")) {
LinkedList<ItemStack> temp = new LinkedList<ItemStack>(); // TODO - should maybe be = action.getItems() ?
@SuppressWarnings("unchecked")
List<ItemStack> stackList = (List<ItemStack>) data.get(actionKey + "items");
if (ConfigUtil.checkList(stackList, ItemStack.class)) {
for (ItemStack stack : stackList) {
if (stack != null) {
temp.add(stack);
}
}
} else {
// Legacy
if (ConfigUtil.checkList(stackList, String.class)) {
List<String> items = data.getStringList(actionKey + "items");
for (String item : items) {
try {
ItemStack stack = ItemUtil.readItemStack(item);
if (stack != null) {
temp.add(stack);
}
} catch (Exception e) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] \"" + ChatColor.RED + item
+ ChatColor.GOLD + "\" inside " + ChatColor.GREEN + " items: " + ChatColor.GOLD
+ "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not formatted properly!");
return null;
}
}
} 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!");
return null;
}
}
action.setItems(temp);
}
if (data.contains(actionKey + "storm-world")) {
World w = plugin.getServer().getWorld(data.getString(actionKey + "storm-world"));
if (w == null) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "storm-world: "
+ ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not a valid World name!");
return null;
}
if (data.contains(actionKey + "storm-duration")) {
if (data.getInt(actionKey + "storm-duration", -999) != -999) {
action.stormDuration = data.getInt(actionKey + "storm-duration") * 1000;
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "storm-duration: "
+ ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not a number!");
return null;
}
action.stormWorld = w;
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] Action " + ChatColor.DARK_PURPLE + name
+ ChatColor.GOLD + " is missing " + ChatColor.RED + "storm-duration:");
return null;
}
}
if (data.contains(actionKey + "thunder-world")) {
World w = plugin.getServer().getWorld(data.getString(actionKey + "thunder-world"));
if (w == null) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "thunder-world: "
+ ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not a valid World name!");
return null;
}
if (data.contains(actionKey + "thunder-duration")) {
if (data.getInt(actionKey + "thunder-duration", -999) != -999) {
action.thunderDuration = data.getInt(actionKey + "thunder-duration");
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "thunder-duration: "
+ ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not a number!");
return null;
}
action.thunderWorld = w;
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] Action " + ChatColor.DARK_PURPLE + name
+ ChatColor.GOLD + " is missing " + ChatColor.RED + "thunder-duration:");
return null;
}
}
if (data.contains(actionKey + "mob-spawns")) {
ConfigurationSection section = data.getConfigurationSection(actionKey + "mob-spawns");
// is a mob, the keys are just a number or something.
for (String s : section.getKeys(false)) {
String mobName = section.getString(s + ".name");
Location spawnLocation = ConfigUtil.getLocation(section.getString(s + ".spawn-location"));
EntityType type = MiscUtil.getProperMobType(section.getString(s + ".mob-type"));
Integer mobAmount = section.getInt(s + ".spawn-amounts");
if (spawnLocation == null) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + s + ChatColor.GOLD
+ " inside " + ChatColor.GREEN + " mob-spawn-locations: " + ChatColor.GOLD
+ "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not in proper location format!");
plugin.getLogger().severe(ChatColor.GOLD
+ "[Quests] Proper location format is: \"WorldName x y z\"");
return null;
}
if (type == null) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED
+ section.getString(s + ".mob-type") + ChatColor.GOLD + " inside " + ChatColor.GREEN
+ " mob-spawn-types: " + ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name
+ ChatColor.GOLD + " is not a valid mob name!");
return null;
}
ItemStack[] inventory = new ItemStack[5];
Float[] dropChances = new Float[5];
inventory[0] = ItemUtil.readItemStack(section.getString(s + ".held-item"));
dropChances[0] = (float) section.getDouble(s + ".held-item-drop-chance");
inventory[1] = ItemUtil.readItemStack(section.getString(s + ".boots"));
dropChances[1] = (float) section.getDouble(s + ".boots-drop-chance");
inventory[2] = ItemUtil.readItemStack(section.getString(s + ".leggings"));
dropChances[2] = (float) section.getDouble(s + ".leggings-drop-chance");
inventory[3] = ItemUtil.readItemStack(section.getString(s + ".chest-plate"));
dropChances[3] = (float) section.getDouble(s + ".chest-plate-drop-chance");
inventory[4] = ItemUtil.readItemStack(section.getString(s + ".helmet"));
dropChances[4] = (float) section.getDouble(s + ".helmet-drop-chance");
QuestMob questMob = new QuestMob(type, spawnLocation, mobAmount);
questMob.setInventory(inventory);
questMob.setDropChances(dropChances);
questMob.setName(mobName);
action.mobSpawns.add(questMob);
}
}
if (data.contains(actionKey + "lightning-strikes")) {
if (ConfigUtil.checkList(data.getList(actionKey + "lightning-strikes"), String.class)) {
for (String s : data.getStringList(actionKey + "lightning-strikes")) {
Location loc = ConfigUtil.getLocation(s);
if (loc == null) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + s + ChatColor.GOLD
+ " inside " + ChatColor.GREEN + " lightning-strikes: " + ChatColor.GOLD
+ "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not in proper location format!");
plugin.getLogger().severe(ChatColor.GOLD
+ "[Quests] Proper location format is: \"WorldName x y z\"");
return null;
}
action.lightningStrikes.add(loc);
}
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "lightning-strikes: "
+ ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not a list of locations!");
return null;
}
}
if (data.contains(actionKey + "commands")) {
if (ConfigUtil.checkList(data.getList(actionKey + "commands"), String.class)) {
for (String s : data.getStringList(actionKey + "commands")) {
if (s.startsWith("/")) {
s = s.replaceFirst("/", "");
}
action.commands.add(s);
}
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "commands: " + ChatColor.GOLD
+ "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not a list of commands!");
return null;
}
}
if (data.contains(actionKey + "potion-effect-types")) {
if (ConfigUtil.checkList(data.getList(actionKey + "potion-effect-types"), String.class)) {
if (data.contains(actionKey + "potion-effect-durations")) {
if (ConfigUtil.checkList(data.getList(actionKey + "potion-effect-durations"), Integer.class)) {
if (data.contains(actionKey + "potion-effect-amplifiers")) {
if (ConfigUtil.checkList(data.getList(actionKey + "potion-effect-amplifiers"),
Integer.class)) {
List<String> types = data.getStringList(actionKey + "potion-effect-types");
List<Integer> durations = data.getIntegerList(actionKey + "potion-effect-durations");
List<Integer> amplifiers = data.getIntegerList(actionKey + "potion-effect-amplifiers");
for (String s : types) {
PotionEffectType type = PotionEffectType.getByName(s);
if (type == null) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + s
+ ChatColor.GOLD + " inside " + ChatColor.GREEN + " lightning-strikes: "
+ ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name
+ ChatColor.GOLD + " is not a valid potion effect name!");
return null;
}
PotionEffect effect = new PotionEffect(type, durations
.get(types.indexOf(s)), amplifiers.get(types.indexOf(s)));
action.potionEffects.add(effect);
}
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED
+ "potion-effect-amplifiers: " + ChatColor.GOLD + "inside Action "
+ ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not a list of numbers!");
return null;
}
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] Action " + ChatColor.DARK_PURPLE + name
+ ChatColor.GOLD + " is missing " + ChatColor.RED + "potion-effect-amplifiers:");
return null;
}
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED
+ "potion-effect-durations: " + ChatColor.GOLD + "inside Action "
+ ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not a list of numbers!");
return null;
}
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] Action " + ChatColor.DARK_PURPLE + name
+ ChatColor.GOLD + " is missing " + ChatColor.RED + "potion-effect-durations:");
return null;
}
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "potion-effect-types: "
+ ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not a list of potion effects!");
return null;
}
}
if (data.contains(actionKey + "hunger")) {
if (data.getInt(actionKey + "hunger", -999) != -999) {
action.hunger = data.getInt(actionKey + "hunger");
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "hunger: " + ChatColor.GOLD
+ "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not a number!");
return null;
}
}
if (data.contains(actionKey + "saturation")) {
if (data.getInt(actionKey + "saturation", -999) != -999) {
action.saturation = data.getInt(actionKey + "saturation");
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "saturation: "
+ ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not a number!");
return null;
}
}
if (data.contains(actionKey + "health")) {
if (data.getInt(actionKey + "health", -999) != -999) {
action.health = data.getInt(actionKey + "health");
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "health: " + ChatColor.GOLD
+ "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not a number!");
return null;
}
}
if (data.contains(actionKey + "teleport-location")) {
if (data.isString(actionKey + "teleport-location")) {
Location l = ConfigUtil.getLocation(data.getString(actionKey + "teleport-location"));
if (l == null) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + data.getString(actionKey
+ "teleport-location") + ChatColor.GOLD + "for " + ChatColor.GREEN + " teleport-location: "
+ ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not in proper location format!");
plugin.getLogger().severe(ChatColor.GOLD
+ "[Quests] Proper location format is: \"WorldName x y z\"");
return null;
}
action.teleport = l;
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "teleport-location: "
+ ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not a location!");
return null;
}
}
if (data.contains(actionKey + "timer")) {
if (data.isInt(actionKey + "timer")) {
action.timer = data.getInt(actionKey + "timer");
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "timer: " + ChatColor.GOLD
+ "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not a number!");
return null;
}
}
if (data.contains(actionKey + "cancel-timer")) {
if (data.isBoolean(actionKey + "cancel-timer")) {
action.cancelTimer = data.getBoolean(actionKey + "cancel-timer");
} else {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "cancel-timer: "
+ ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD
+ " is not a boolean!");
return null;
}
}
if (data.contains(actionKey + "denizen-script")) {
action.denizenScript = data.getString(actionKey + "denizen-script");
}
return action;
}
}

View File

@ -0,0 +1,44 @@
/*******************************************************************************************************
* Continued by PikaMug (formerly HappyPikachu) with permission from _Blackvein_. All rights reserved.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************************************/
package me.blackvein.quests.exceptions;
public class ActionFormatException extends Exception {
private static final long serialVersionUID = 6165516939621807530L;
private final String message;
private final String actionId;
public ActionFormatException(String message, String actionId) {
super(message + ", see action of ID " + actionId);
this.message = message + ", see action of ID " + actionId;
this.actionId = actionId;
}
/**
* Get the message associated with this exception.
*
* @return The message.
*/
public String getMessage() {
return message;
}
/**
* Get the action ID associated with this exception.
*
* @return The action that an invalid value was set within.
*/
public String getActionId() {
return actionId;
}
}