Started production of QuestFactory (in-game Quest designer)

This commit is contained in:
Blackvein 2012-10-15 07:25:37 -07:00
parent 2fa387fd5b
commit 64bf6ca6ff
5 changed files with 360 additions and 20 deletions

View File

@ -118,20 +118,6 @@ public class PlayerListener implements Listener {
boolean canOpen = true; 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){ if(canOpen == true){
Quester quester = plugin.getQuester(evt.getPlayer().getName()); Quester quester = plugin.getQuester(evt.getPlayer().getName());

View File

@ -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<Player, Quest> editSessions = new HashMap<Player, Quest>();
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();
}
}
}

View File

@ -20,6 +20,7 @@ import org.bukkit.potion.PotionType;
public class Quester { public class Quester {
String name; String name;
boolean editorMode = false;
Quest currentQuest; Quest currentQuest;
String questToTake; String questToTake;
Stage currentStage; Stage currentStage;

View File

@ -38,6 +38,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{
public static Permission permission = null; public static Permission permission = null;
public static mcMMO mcmmo = null; public static mcMMO mcmmo = null;
ConversationFactory conversationFactory; ConversationFactory conversationFactory;
QuestFactory questFactory;
Heroes heroes; Heroes heroes;
Vault vault = null; Vault vault = null;
CitizensPlugin citizens; CitizensPlugin citizens;
@ -52,12 +53,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{
boolean allowCommandsForNpcQuests = false; boolean allowCommandsForNpcQuests = false;
boolean showQuestReqs = true; boolean showQuestReqs = true;
boolean allowQuitting = true; boolean allowQuitting = true;
boolean allowOtherBrewing = true;
boolean debug = false; boolean debug = false;
boolean load = false; boolean load = false;
int killDelay = 0; int killDelay = 0;
public final static Logger log = Logger.getLogger("Minecraft"); public final static Logger log = Logger.getLogger("Minecraft");
Map<Location, String> brewers = new HashMap<Location, String>();
@Override @Override
public void onEnable() { public void onEnable() {
@ -73,6 +72,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{
.thatExcludesNonPlayersWithMessage("Console may not perform this conversation!") .thatExcludesNonPlayersWithMessage("Console may not perform this conversation!")
.addConversationAbandonedListener(this); .addConversationAbandonedListener(this);
questFactory = new QuestFactory(this);
try { try {
if (getServer().getPluginManager().getPlugin("Citizens") != null) { if (getServer().getPluginManager().getPlugin("Citizens") != null) {
citizens = (CitizensPlugin) getServer().getPluginManager().getPlugin("Citizens"); citizens = (CitizensPlugin) getServer().getPluginManager().getPlugin("Citizens");
@ -277,7 +278,13 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{
@Override @Override
public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { 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) { if (cs instanceof Player) {
@ -2371,7 +2378,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{
break; 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)) { 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; 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)) { if (Quests.checkList(config.getList("quests." + s + ".stages.ordered." + s2 + ".reach-location-names"), String.class)) {

View File

@ -65,4 +65,7 @@ commands:
aliases: [questsadmin] aliases: [questsadmin]
quest: quest:
description: Quest command description: Quest command
permission: quests.quest permission: quests.quest
editor:
description: Editor
permission: quests.editor