diff --git a/main/src/main/java/me/blackvein/quests/QuestFactory.java b/main/src/main/java/me/blackvein/quests/QuestFactory.java index 3cf8e5121..99157f04a 100644 --- a/main/src/main/java/me/blackvein/quests/QuestFactory.java +++ b/main/src/main/java/me/blackvein/quests/QuestFactory.java @@ -705,15 +705,6 @@ public class QuestFactory implements ConversationAbandonedListener { ConfigurationSection newSection = questSection.createSection("custom" + customNum); saveQuest(context, newSection); data.save(new File(plugin.getDataFolder(), "quests.yml")); - if (context.getSessionData(CK.Q_START_NPC) != null && context.getSessionData(CK.Q_GUIDISPLAY) != null) { - int i = (Integer) context.getSessionData(CK.Q_START_NPC); - if (!plugin.getQuestNpcGuis().contains(i)) { - LinkedList temp = plugin.getQuestNpcGuis(); - temp.add(i); - plugin.setQuestNpcGuis(temp); - } - plugin.updateData(); - } context.getForWhom().sendRawMessage(ChatColor.GREEN + Lang.get("questEditorSaved").replaceAll("", "/questadmin " + Lang.get("COMMAND_QUESTADMIN_RELOAD"))); } catch (IOException e) { diff --git a/main/src/main/java/me/blackvein/quests/Quests.java b/main/src/main/java/me/blackvein/quests/Quests.java index a5475202e..eb340707a 100644 --- a/main/src/main/java/me/blackvein/quests/Quests.java +++ b/main/src/main/java/me/blackvein/quests/Quests.java @@ -45,7 +45,6 @@ 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; @@ -71,8 +70,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; 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.player.McMMOPlayer; @@ -110,7 +107,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener private LinkedList quests = new LinkedList(); private LinkedList events = new LinkedList(); private LinkedList questNpcs = new LinkedList(); - private LinkedList questNpcGuis = new LinkedList(); private CommandExecutor cmdExecutor; private ConversationFactory conversationFactory; private ConversationFactory npcConversationFactory; @@ -172,28 +168,24 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener // 6 - Save resources from jar saveResourceAs("quests.yml", "quests.yml", false); saveResourceAs("actions.yml", "actions.yml", false); - saveResourceAs("data.yml", "data.yml", false); - // 7 - Load player data - loadData(); - - // 8 - Save config with any new options + // 7 - Save config with any new options getConfig().options().copyDefaults(true); saveConfig(); - // 9 - Setup commands + // 8 - Setup commands getCommand("quests").setExecutor(cmdExecutor); getCommand("questadmin").setExecutor(cmdExecutor); getCommand("quest").setExecutor(cmdExecutor); - // 10 - Setup conversation factory after timeout has loaded + // 9 - Setup conversation factory after timeout has loaded this.conversationFactory = new ConversationFactory(this).withModality(false).withPrefix(new QuestsPrefix()) .withFirstPrompt(new QuestPrompt()).withTimeout(settings.getAcceptTimeout()) .thatExcludesNonPlayersWithMessage("Console may not perform this conversation!").addConversationAbandonedListener(this); this.npcConversationFactory = new ConversationFactory(this).withModality(false).withFirstPrompt(new QuestAcceptPrompt(this)) .withTimeout(settings.getAcceptTimeout()).withLocalEcho(false).addConversationAbandonedListener(this); - // 11 - Register listeners + // 10 - Register listeners getServer().getPluginManager().registerEvents(playerListener, this); if (depends.getCitizens() != null) { getServer().getPluginManager().registerEvents(npcListener, this); @@ -208,18 +200,17 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener getServer().getPluginManager().registerEvents(partiesListener, this); } - // 12 - Delay loading of Quests, Actions and modules + // 11 - Delay loading of Quests, Actions and modules delayLoadQuestInfo(5L); } @Override public void onDisable() { - getLogger().info("Saving Quester data."); + getLogger().info("Saving Quester data..."); for (Player p : getServer().getOnlinePlayers()) { Quester quester = getQuester(p.getUniqueId()); quester.saveData(); } - updateData(); } public String getDetectedBukkitVersion() { @@ -315,14 +306,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener this.questNpcs = questNpcs; } - public LinkedList getQuestNpcGuis() { - return questNpcGuis; - } - - public void setQuestNpcGuis(LinkedList questNpcGuis) { - this.questNpcGuis = questNpcGuis; - } - public ConversationFactory getConversationFactory() { return conversationFactory; } @@ -507,24 +490,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } }, ticks); } - - /** - * Load player and NPC GUI data from file - */ - public void loadData() { - YamlConfiguration config = new YamlConfiguration(); - File dataFile = new File(this.getDataFolder(), "data.yml"); - try { - config.load(dataFile); - } catch (Exception e) { - e.printStackTrace(); - } - if (config.contains("npc-gui")) { - List ids = config.getIntegerList("npc-gui"); - questNpcGuis.clear(); - questNpcGuis.addAll(ids); - } - } /** * Load modules from file @@ -1374,7 +1339,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener events.clear(); loadQuests(); - loadData(); loadActions(); // Reload config from disc in-case a setting was changed reloadConfig(); @@ -3172,34 +3136,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener return info; } - public static Effect getEffect(String eff) { - if (eff.equalsIgnoreCase("BLAZE_SHOOT")) { - return Effect.BLAZE_SHOOT; - } else if (eff.equalsIgnoreCase("BOW_FIRE")) { - return Effect.BOW_FIRE; - } else if (eff.equalsIgnoreCase("CLICK1")) { - return Effect.CLICK1; - } else if (eff.equalsIgnoreCase("CLICK2")) { - return Effect.CLICK2; - } else if (eff.equalsIgnoreCase("DOOR_TOGGLE")) { - return Effect.DOOR_TOGGLE; - } else if (eff.equalsIgnoreCase("EXTINGUISH")) { - return Effect.EXTINGUISH; - } else if (eff.equalsIgnoreCase("GHAST_SHOOT")) { - return Effect.GHAST_SHOOT; - } else if (eff.equalsIgnoreCase("GHAST_SHRIEK")) { - return Effect.GHAST_SHRIEK; - } else if (eff.equalsIgnoreCase("ZOMBIE_CHEW_IRON_DOOR")) { - return Effect.ZOMBIE_CHEW_IRON_DOOR; - } else if (eff.equalsIgnoreCase("ZOMBIE_CHEW_WOODEN_DOOR")) { - return Effect.ZOMBIE_CHEW_WOODEN_DOOR; - } else if (eff.equalsIgnoreCase("ZOMBIE_DESTROY_DOOR")) { - return Effect.ZOMBIE_DESTROY_DOOR; - } else { - return null; - } - } - public static EntityType getMobType(String mob) { return MiscUtil.getProperMobType(mob); } @@ -3252,60 +3188,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } return message; } - - public static PotionEffect getPotionEffect(String type, int duration, int amplifier) { - PotionEffectType potionType; - if (type.equalsIgnoreCase("ABSORPTION")) { - potionType = PotionEffectType.ABSORPTION; - } else if (type.equalsIgnoreCase("BLINDNESS")) { - potionType = PotionEffectType.BLINDNESS; - } else if (type.equalsIgnoreCase("CONFUSION")) { - potionType = PotionEffectType.CONFUSION; - } else if (type.equalsIgnoreCase("DAMAGE_RESISTANCE")) { - potionType = PotionEffectType.DAMAGE_RESISTANCE; - } else if (type.equalsIgnoreCase("FAST_DIGGING")) { - potionType = PotionEffectType.FAST_DIGGING; - } else if (type.equalsIgnoreCase("FIRE_RESISTANCE")) { - potionType = PotionEffectType.FIRE_RESISTANCE; - } else if (type.equalsIgnoreCase("HARM")) { - potionType = PotionEffectType.HARM; - } else if (type.equalsIgnoreCase("HEAL")) { - potionType = PotionEffectType.HEAL; - } else if (type.equalsIgnoreCase("HEALTH_BOOST")) { - potionType = PotionEffectType.HEALTH_BOOST; - } else if (type.equalsIgnoreCase("HUNGER")) { - potionType = PotionEffectType.HUNGER; - } else if (type.equalsIgnoreCase("INCREASE_DAMAGE")) { - potionType = PotionEffectType.INCREASE_DAMAGE; - } else if (type.equalsIgnoreCase("INVISIBILITY")) { - potionType = PotionEffectType.INVISIBILITY; - } else if (type.equalsIgnoreCase("JUMP")) { - potionType = PotionEffectType.JUMP; - } else if (type.equalsIgnoreCase("NIGHT_VISION")) { - potionType = PotionEffectType.NIGHT_VISION; - } else if (type.equalsIgnoreCase("POISON")) { - potionType = PotionEffectType.POISON; - } else if (type.equalsIgnoreCase("REGENERATION")) { - potionType = PotionEffectType.REGENERATION; - } else if (type.equalsIgnoreCase("SATURATION")) { - potionType = PotionEffectType.SATURATION; - } else if (type.equalsIgnoreCase("SLOW")) { - potionType = PotionEffectType.SLOW; - } else if (type.equalsIgnoreCase("SLOW_DIGGING")) { - potionType = PotionEffectType.SLOW_DIGGING; - } else if (type.equalsIgnoreCase("SPEED")) { - potionType = PotionEffectType.SPEED; - } else if (type.equalsIgnoreCase("WATER_BREATHING")) { - potionType = PotionEffectType.WATER_BREATHING; - } else if (type.equalsIgnoreCase("WEAKNESS")) { - potionType = PotionEffectType.WEAKNESS; - } else if (type.equalsIgnoreCase("WITHER")) { - potionType = PotionEffectType.WITHER; - } else { - return null; - } - return new PotionEffect(potionType, duration, amplifier); - } public static SkillType getMcMMOSkill(String s) { return SkillType.getSkill(s); @@ -3615,18 +3497,4 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener Hero hero = getHero(uuid); return hero.getSecondClass().getName().equalsIgnoreCase(secondaryClass); } - - public void updateData() { - YamlConfiguration config = new YamlConfiguration(); - File dataFile = new File(this.getDataFolder(), "data.yml"); - try { - config.load(dataFile); - config.set("npc-gui", questNpcGuis); - config.save(dataFile); - } catch (Exception e) { - getLogger().severe("Unable to update data.yml file"); - e.printStackTrace(); - } - } - } \ No newline at end of file diff --git a/main/src/main/java/me/blackvein/quests/actions/Action.java b/main/src/main/java/me/blackvein/quests/actions/Action.java index 9d11c7a50..81476afc8 100644 --- a/main/src/main/java/me/blackvein/quests/actions/Action.java +++ b/main/src/main/java/me/blackvein/quests/actions/Action.java @@ -31,6 +31,7 @@ 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; @@ -465,7 +466,7 @@ public class Action { List effectList = data.getStringList(actionKey + "effects"); List effectLocs = data.getStringList(actionKey + "effect-locations"); for (String s : effectList) { - Effect effect = Quests.getEffect(s); + Effect effect = Effect.valueOf(s.toUpperCase()); Location l = Quests.getLocation(effectLocs.get(effectList.indexOf(s))); if (effect == null) { 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!"); @@ -633,11 +634,12 @@ public class Action { List durations = data.getIntegerList(actionKey + "potion-effect-durations"); List amplifiers = data.getIntegerList(actionKey + "potion-effect-amplifiers"); for (String s : types) { - PotionEffect effect = Quests.getPotionEffect(s, durations.get(types.indexOf(s)), amplifiers.get(types.indexOf(s))); - if (effect == null) { + 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 { diff --git a/main/src/main/java/me/blackvein/quests/actions/ActionFactory.java b/main/src/main/java/me/blackvein/quests/actions/ActionFactory.java index 9e51fcb08..fe09d2d3e 100644 --- a/main/src/main/java/me/blackvein/quests/actions/ActionFactory.java +++ b/main/src/main/java/me/blackvein/quests/actions/ActionFactory.java @@ -1379,7 +1379,7 @@ public class ActionFactory implements ConversationAbandonedListener { public Prompt acceptInput(ConversationContext context, String input) { Player player = (Player) context.getForWhom(); if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - if (Quests.getEffect(input.toUpperCase()) != null) { + if (Effect.valueOf(input.toUpperCase()) != null) { LinkedList effects; if (context.getSessionData(CK.E_EFFECTS) != null) { effects = (LinkedList) context.getSessionData(CK.E_EFFECTS); diff --git a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java index ba7d15a49..6a1639f2d 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java +++ b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java @@ -275,8 +275,6 @@ public class CmdExecutor implements CommandExecutor { adminReset(cs, args); } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_REMOVE") : "remove")) { adminRemove(cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_TOGGLEGUI") : "togglegui")) { - adminToggieGUI(cs, args); } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_RELOAD") : "reload")) { adminReload(cs); } else { @@ -783,42 +781,6 @@ public class CmdExecutor implements CommandExecutor { } } - private void adminToggieGUI(final CommandSender cs, String[] args) { - if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.togglegui")) { - try { - int i = Integer.parseInt(args[1]); - if (plugin.getDependencies().getCitizens().getNPCRegistry().getById(i) == null) { - String msg = Lang.get("errorNPCID"); - msg = msg.replace("errorNPCID", ChatColor.DARK_PURPLE + "" + i + ChatColor.RED); - cs.sendMessage(ChatColor.RED + msg); - } else if (plugin.getQuestNpcGuis().contains(i)) { - LinkedList temp = plugin.getQuestNpcGuis(); - temp.remove(plugin.getQuestNpcGuis().indexOf(i)); - plugin.setQuestNpcGuis(temp); - plugin.updateData(); - String msg = Lang.get("disableNPCGUI"); - msg = msg.replace("", ChatColor.DARK_PURPLE + plugin.getDependencies().getCitizens().getNPCRegistry().getById(i).getName() + ChatColor.YELLOW); - cs.sendMessage(ChatColor.YELLOW + msg); - } else { - LinkedList temp = plugin.getQuestNpcGuis(); - temp.add(i); - plugin.setQuestNpcGuis(temp); - plugin.updateData(); - String msg = Lang.get("enableNPCGUI"); - msg = msg.replace("", ChatColor.DARK_PURPLE + plugin.getDependencies().getCitizens().getNPCRegistry().getById(i).getName() + ChatColor.YELLOW); - cs.sendMessage(ChatColor.YELLOW + msg); - } - } catch (NumberFormatException nfe) { - cs.sendMessage(ChatColor.RED + Lang.get("inputNum")); - } catch (Exception ex) { - ex.printStackTrace(); - cs.sendMessage(ChatColor.RED + Lang.get("unknownError")); - } - } else { - cs.sendMessage(ChatColor.RED + Lang.get("noPermission")); - } - } - private void adminGivePoints(final CommandSender cs, String[] args) { if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.givepoints")) { Player target = getPlayer(args[1]); diff --git a/main/src/main/java/me/blackvein/quests/listeners/NpcListener.java b/main/src/main/java/me/blackvein/quests/listeners/NpcListener.java index 64e1328eb..d6b10d103 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/NpcListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/NpcListener.java @@ -18,7 +18,6 @@ import java.util.Map.Entry; import org.bukkit.ChatColor; import org.bukkit.Material; -import org.bukkit.conversations.Conversation; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -183,15 +182,10 @@ public class NpcListener implements Listener { } } if (npcQuests.isEmpty() == false && npcQuests.size() >= 1) { - if (plugin.getQuestNpcGuis().contains(evt.getNPC().getId())) { - quester.showGUIDisplay(evt.getNPC(), npcQuests); - return; - } - Conversation c = plugin.getNpcConversationFactory().buildConversation(player); - c.getContext().setSessionData("quests", npcQuests); - c.getContext().setSessionData("npc", evt.getNPC().getName()); - c.begin(); + quester.showGUIDisplay(evt.getNPC(), npcQuests); + return; } else if (npcQuests.size() == 1) { + // TODO can this block even be reached? Quest q = npcQuests.get(0); if (!quester.getCompletedQuests().contains(q.getName())) { if (quester.getCurrentQuests().size() < plugin.getSettings().getMaxQuests() || plugin.getSettings().getMaxQuests() < 1) { diff --git a/main/src/main/resources/data.yml b/main/src/main/resources/data.yml deleted file mode 100644 index 223ec0cb2..000000000 --- a/main/src/main/resources/data.yml +++ /dev/null @@ -1 +0,0 @@ -#Kindly do not manually edit GUI data! \ No newline at end of file diff --git a/main/src/main/resources/plugin.yml b/main/src/main/resources/plugin.yml index c2a9f810e..fe061b584 100644 --- a/main/src/main/resources/plugin.yml +++ b/main/src/main/resources/plugin.yml @@ -77,9 +77,6 @@ permissions: quests.admin.remove: description: Remove a completed quest from a player default: op - quests.admin.togglegui: - description: Toggle GUI Quest Display on an NPC - default: op quests.admin.reload: description: Safely reload the plugin default: op diff --git a/main/src/main/resources/strings.yml b/main/src/main/resources/strings.yml index fe6d1b549..bb48718fa 100644 --- a/main/src/main/resources/strings.yml +++ b/main/src/main/resources/strings.yml @@ -46,8 +46,6 @@ COMMAND_QUESTADMIN_RESET: "reset" COMMAND_QUESTADMIN_RESET_HELP: " [player] - Clear all Quests data of a player" COMMAND_QUESTADMIN_REMOVE: "remove" COMMAND_QUESTADMIN_REMOVE_HELP: " [player] [quest] - Remove a completed quest from a player" -COMMAND_QUESTADMIN_TOGGLEGUI: "togglegui" -COMMAND_QUESTADMIN_TOGGLEGUI_HELP: " [npc id] - Toggle GUI Quest Display on an NPC" COMMAND_QUESTADMIN_RELOAD: "reload" COMMAND_QUESTADMIN_RELOAD_HELP: " - Safely reload the plugin" questEditorHeader: "Create Quest" @@ -710,8 +708,6 @@ takeQuestPoints: "Took away Quest Points from ." questPointsTaken: " took away Quest Points." giveQuestPoints: "Gave Quest Points from ." questPointsGiven: " gave you Quest Points." -enableNPCGUI: " will now provide a GUI Quest Display." -disableNPCGUI: " will no longer provide a GUI Quest Display." invalidMinimum: "Input must be at least !" invalidRange: "Input must be between and !" invalidOption: "Invalid option!"