From 64bf6ca6ff79b3962e9fceb9426c72f598f516eb Mon Sep 17 00:00:00 2001 From: Blackvein Date: Mon, 15 Oct 2012 07:25:37 -0700 Subject: [PATCH] Started production of QuestFactory (in-game Quest designer) --- src/me/blackvein/quests/PlayerListener.java | 14 - src/me/blackvein/quests/QuestFactory.java | 343 ++++++++++++++++++++ src/me/blackvein/quests/Quester.java | 1 + src/me/blackvein/quests/Quests.java | 17 +- src/plugin.yml | 5 +- 5 files changed, 360 insertions(+), 20 deletions(-) create mode 100644 src/me/blackvein/quests/QuestFactory.java diff --git a/src/me/blackvein/quests/PlayerListener.java b/src/me/blackvein/quests/PlayerListener.java index 0d7ee7c75..2411a63d5 100644 --- a/src/me/blackvein/quests/PlayerListener.java +++ b/src/me/blackvein/quests/PlayerListener.java @@ -118,20 +118,6 @@ public class PlayerListener implements Listener { boolean canOpen = true; - if(evt.getBlock().getType().equals(Material.BREWING_STAND) && plugin.allowOtherBrewing == false && evt.getPlayer().getName().contains("_computercraft_") == false && evt.getPlayer().getName().contains("_buildcraft_") == false && evt.getPlayer().getName().contains("_redpower_") == false){ - - if(plugin.brewers.containsKey(evt.getBlock().getLocation())){ - - if(evt.getPlayer().getName().equalsIgnoreCase(plugin.brewers.get(evt.getBlock().getLocation())) == false){ - evt.getPlayer().sendMessage(ChatColor.RED + "You may not break other players' Brewing Stands."); - evt.setCancelled(true); - canOpen = false; - } - - } - - } - if(canOpen == true){ Quester quester = plugin.getQuester(evt.getPlayer().getName()); diff --git a/src/me/blackvein/quests/QuestFactory.java b/src/me/blackvein/quests/QuestFactory.java new file mode 100644 index 000000000..8950aa0db --- /dev/null +++ b/src/me/blackvein/quests/QuestFactory.java @@ -0,0 +1,343 @@ +package me.blackvein.quests; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.conversations.*; +import org.bukkit.entity.Player; + +public class QuestFactory implements ConversationAbandonedListener { + + Quests quests; + Map editSessions = new HashMap(); + ConversationFactory convoCreator; + static final ChatColor BOLD = ChatColor.BOLD; + static final ChatColor AQUA = ChatColor.AQUA; + static final ChatColor BLUE = ChatColor.BLUE; + static final ChatColor GOLD = ChatColor.GOLD; + static final ChatColor RED = ChatColor.RED; + static final ChatColor DARKRED = ChatColor.DARK_RED; + static final ChatColor YELLOW = ChatColor.YELLOW; + static final ChatColor RESET = ChatColor.RESET; + + File questsFile; + + @SuppressWarnings("LeakingThisInConstructor") + public QuestFactory(Quests plugin){ + + quests = plugin; + questsFile = new File(plugin.getDataFolder(), "quests.yml"); + + //Ensure to initialize convoCreator last, to ensure that 'this' is fully initialized before it is passed + this.convoCreator = new ConversationFactory(plugin) + .withModality(false) + .withLocalEcho(false) + .withPrefix(new QuestCreatorPrefix()) + .withFirstPrompt(new MenuPrompt()) + .withTimeout(3600) + .thatExcludesNonPlayersWithMessage("Console may not perform this operation!") + .addConversationAbandonedListener(this); + + } + + @Override + public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) { + + + + } + + private class QuestCreatorPrefix implements ConversationPrefix { + + @Override + public String getPrefix(ConversationContext context){ + + return ""; + + } + + } + + private class MenuPrompt extends FixedSetPrompt { + + public MenuPrompt(){ + + super ("1", "2", "3"); + + } + + @Override + public String getPromptText(ConversationContext context){ + + String text = + GOLD + "- Quest Editor -\n" + + BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Create a Quest\n" + + BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Edit a Quest\n" + + BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Delete a Quest" + ; + + return text; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input){ + + if(input.equalsIgnoreCase("1")) + return new QuestNamePrompt(); + + return null; + + } + + } + + private class CreateMenuPrompt extends FixedSetPrompt { + + public CreateMenuPrompt(){ + + super("1", "2", "3", "4", "5", "6"); + + } + + @Override + public String getPromptText(ConversationContext context){ + + String text = + GOLD + "- Quest: " + AQUA + context.getSessionData("questName") + GOLD + " -\n"; + + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set name\n"; + + if(context.getSessionData("askMessage") == null) + text += BLUE + "" + BOLD + "2" + RESET + RED + " - Set ask message " + DARKRED + "(Required, none set)\n"; + else + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set ask message (\"" + context.getSessionData("askMessage") + "\")\n"; + + if(context.getSessionData("finishMessage") == null) + text += BLUE + "" + BOLD + "3" + RESET + RED + " - Set finish message " + DARKRED + "(Required, none set)\n"; + else + text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Set finish message (\"" + context.getSessionData("finishMessage") + "\")\n"; + + if(context.getSessionData("redoDelay") == null) + text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Set redo delay (None set)"; + else + text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Set redo delay (" + Quests.getTime((Long)context.getSessionData("redoDelay")) + ")"; + + if(context.getSessionData("npcStart") == null && quests.citizens != null) + text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set NPC start (None set)"; + else if(quests.citizens != null) + text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set NPC start (" + quests.citizens.getNPCRegistry().getById((Integer)context.getSessionData("npcStart")).getName() + ")"; + + if(context.getSessionData("blockStart") == null){ + + if(quests.citizens != null) + text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set Block start (None set)"; + else + text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set Block start (None set)"; + + }else{ + + if(quests.citizens != null){ + Location l = (Location) context.getSessionData("blockStart"); + text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set Block start (" + l.getWorld().getName() + ", " + l.getBlockX() + ", " + l.getBlockY() + ", " + l.getBlockZ() + ")"; + }else{ + Location l = (Location) context.getSessionData("blockStart"); + text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set Block start (" + l.getWorld().getName() + ", " + l.getBlockX() + ", " + l.getBlockY() + ", " + l.getBlockZ() + ")"; + } + + } + + return text; + + } + + @Override + public Prompt acceptValidatedInput(ConversationContext context, String input){ + + if(input.equalsIgnoreCase("1")){ + + return new SetNamePrompt(); + + }else if(input.equalsIgnoreCase("2")){ + + return new AskMessagePrompt(); + + }else if(input.equalsIgnoreCase("3")){ + + return new FinishMessagePrompt(); + + }else if(input.equalsIgnoreCase("4")){ + + return new RedoDelayPrompt(); + + } + + return null; + + } + + } + + private class QuestNamePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context){ + + String text = + AQUA + "Create new Quest " + GOLD + "- Enter a name for the Quest (Or enter \'cancel\' to return to the main menu)" + ; + + return text; + + } + + @Override + public Prompt acceptInput(ConversationContext context, String input){ + + if(input.equalsIgnoreCase("cancel") == false){ + + for(Quest q : quests.quests){ + + if(q.name.equalsIgnoreCase(input)){ + + context.getForWhom().sendRawMessage(ChatColor.RED + "Quest already exists!"); + return new QuestNamePrompt(); + + } + + } + + context.setSessionData("questName", input); + return new CreateMenuPrompt(); + + }else{ + + return new MenuPrompt(); + + } + + } + + } + + private class SetNpcStartPrompt extends NumericPrompt { + + @Override + public String getPromptText(ConversationContext context){ + + return ChatColor.YELLOW + "Enter NPC ID (or -1 to return)"; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, Number input){ + + if(input.intValue() != -1){ + + if(quests.citizens.getNPCRegistry().getById(input.intValue()) == null){ + context.getForWhom().sendRawMessage(ChatColor.RED + "No NPC exists with that id!"); + return new SetNpcStartPrompt(); + }else{ + context.setSessionData("") + } + + }else{ + return new CreateMenuPrompt(); + } + context.setSessionData("questName", input); + + return new CreateMenuPrompt(); + + } + + } + + private class SetNamePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context){ + + return ChatColor.YELLOW + "Enter Quest name (or \'cancel\' to return)"; + + } + + @Override + public Prompt acceptInput(ConversationContext context, String input){ + + if(input.equalsIgnoreCase("cancel") == false) + context.setSessionData("questName", input); + + return new CreateMenuPrompt(); + + } + + } + + private class AskMessagePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context){ + + return ChatColor.YELLOW + "Enter ask message (or \'cancel\' to return)"; + + } + + @Override + public Prompt acceptInput(ConversationContext context, String input){ + + if(input.equalsIgnoreCase("cancel") == false) + context.setSessionData("askMessage", input); + + return new CreateMenuPrompt(); + + } + + } + + private class FinishMessagePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context){ + + return ChatColor.YELLOW + "Enter finish message (or \'cancel\' to return)"; + + } + + @Override + public Prompt acceptInput(ConversationContext context, String input){ + + if(input.equalsIgnoreCase("cancel") == false) + context.setSessionData("finishMessage", input); + + return new CreateMenuPrompt(); + + } + + } + + private class RedoDelayPrompt extends NumericPrompt{ + + @Override + public String getPromptText(ConversationContext context){ + + return ChatColor.YELLOW + "Enter amount of time (in milliseconds)"; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, Number input){ + + if(input.longValue() < 0) + context.getForWhom().sendRawMessage(ChatColor.RED + "Amount must be a positive number."); + else + context.setSessionData("redoDelay", input.longValue()); + + return new CreateMenuPrompt(); + + } + + } + +} diff --git a/src/me/blackvein/quests/Quester.java b/src/me/blackvein/quests/Quester.java index 77fe1bce3..98b13d237 100644 --- a/src/me/blackvein/quests/Quester.java +++ b/src/me/blackvein/quests/Quester.java @@ -20,6 +20,7 @@ import org.bukkit.potion.PotionType; public class Quester { String name; + boolean editorMode = false; Quest currentQuest; String questToTake; Stage currentStage; diff --git a/src/me/blackvein/quests/Quests.java b/src/me/blackvein/quests/Quests.java index 4d04ec8ff..bfe0e1269 100644 --- a/src/me/blackvein/quests/Quests.java +++ b/src/me/blackvein/quests/Quests.java @@ -38,6 +38,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ public static Permission permission = null; public static mcMMO mcmmo = null; ConversationFactory conversationFactory; + QuestFactory questFactory; Heroes heroes; Vault vault = null; CitizensPlugin citizens; @@ -52,12 +53,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ boolean allowCommandsForNpcQuests = false; boolean showQuestReqs = true; boolean allowQuitting = true; - boolean allowOtherBrewing = true; boolean debug = false; boolean load = false; int killDelay = 0; public final static Logger log = Logger.getLogger("Minecraft"); - Map brewers = new HashMap(); @Override public void onEnable() { @@ -73,6 +72,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ .thatExcludesNonPlayersWithMessage("Console may not perform this conversation!") .addConversationAbandonedListener(this); + questFactory = new QuestFactory(this); + try { if (getServer().getPluginManager().getPlugin("Citizens") != null) { citizens = (CitizensPlugin) getServer().getPluginManager().getPlugin("Citizens"); @@ -277,7 +278,13 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ @Override public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { - if (cmd.getName().equalsIgnoreCase("quest")) { + if(cmd.getName().equalsIgnoreCase("editor")){ + + questFactory.convoCreator.buildConversation((Conversable) cs).begin(); + + } + + else if (cmd.getName().equalsIgnoreCase("quest")) { if (cs instanceof Player) { @@ -2371,7 +2378,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ break; } - if (config.contains("quests." + s + ".stages.ordered" + s2 + ".reach-location-radii")) { + if (config.contains("quests." + s + ".stages.ordered." + s2 + ".reach-location-radii")) { if (Quests.checkList(config.getList("quests." + s + ".stages.ordered." + s2 + ".reach-location-radii"), Integer.class)) { @@ -2394,7 +2401,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ break; } - if (config.contains("quests." + s + ".stages.ordered" + s2 + ".reach-location-names")) { + if (config.contains("quests." + s + ".stages.ordered." + s2 + ".reach-location-names")) { if (Quests.checkList(config.getList("quests." + s + ".stages.ordered." + s2 + ".reach-location-names"), String.class)) { diff --git a/src/plugin.yml b/src/plugin.yml index a3ce01231..b60496e13 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -65,4 +65,7 @@ commands: aliases: [questsadmin] quest: description: Quest command - permission: quests.quest \ No newline at end of file + permission: quests.quest + editor: + description: Editor + permission: quests.editor \ No newline at end of file