NEW per-quest Options section, part 2. Fixes #624

This commit is contained in:
PikaMug 2019-04-23 15:52:17 -04:00
parent def44fb8b3
commit 181e60584f
7 changed files with 62 additions and 20 deletions

View File

@ -1,22 +1,31 @@
package me.blackvein.quests;
public class Options {
private boolean useDungeonsXLPlugin = false;
private boolean usePartiesPlugin = true;
public boolean getUseDungeonsXLPlugin() {
return useDungeonsXLPlugin;
}
public void setUseDungeonsXLPlugin(boolean useDungeonsXLPlugin) {
this.useDungeonsXLPlugin = useDungeonsXLPlugin;
}
public boolean getUsePartiesPlugin() {
return usePartiesPlugin;
}
public void setUsePartiesPlugin(boolean usePartiesPlugin) {
this.usePartiesPlugin = usePartiesPlugin;
}
private boolean allowCommands = true;
private boolean useDungeonsXLPlugin = false;
private boolean usePartiesPlugin = true;
public boolean getAllowCommands() {
return allowCommands;
}
public void setAllowCommands(boolean allowCommands) {
this.allowCommands = allowCommands;
}
public boolean getUseDungeonsXLPlugin() {
return useDungeonsXLPlugin;
}
public void setUseDungeonsXLPlugin(boolean useDungeonsXLPlugin) {
this.useDungeonsXLPlugin = useDungeonsXLPlugin;
}
public boolean getUsePartiesPlugin() {
return usePartiesPlugin;
}
public void setUsePartiesPlugin(boolean usePartiesPlugin) {
this.usePartiesPlugin = usePartiesPlugin;
}
}

View File

@ -825,6 +825,7 @@ public class QuestFactory implements ConversationAbandonedListener {
String endDatePln = null;
Long repeatCyclePln = null;
Long cooldownPln = null;
boolean allowCommandsOpt = true;
boolean useDungeonsXLPluginOpt = false;
boolean usePartiesPluginOpt = true;
if (cc.getSessionData(CK.Q_START_NPC) != null) {
@ -941,6 +942,9 @@ public class QuestFactory implements ConversationAbandonedListener {
if (cc.getSessionData(CK.PLN_COOLDOWN) != null) {
cooldownPln = (Long) cc.getSessionData(CK.PLN_COOLDOWN);
}
if (cc.getSessionData(CK.OPT_ALLOW_COMMANDS) != null) {
allowCommandsOpt = (Boolean) cc.getSessionData(CK.OPT_ALLOW_COMMANDS);
}
if (cc.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN) != null) {
useDungeonsXLPluginOpt = (Boolean) cc.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN);
}
@ -1395,6 +1399,7 @@ public class QuestFactory implements ConversationAbandonedListener {
cs.set("planner", null);
}
ConfigurationSection sch = cs.createSection("options");
sch.set("allow-commands", allowCommandsOpt);
sch.set("use-dungeonsxl-plugin", useDungeonsXLPluginOpt);
sch.set("use-parties-plugin", usePartiesPluginOpt);
}
@ -1509,6 +1514,7 @@ public class QuestFactory implements ConversationAbandonedListener {
cc.setSessionData(CK.PLN_COOLDOWN, pln.getCooldown());
}
Options opt = q.getOptions();
cc.setSessionData(CK.OPT_ALLOW_COMMANDS, opt.getAllowCommands());
cc.setSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN, opt.getUseDungeonsXLPlugin());
cc.setSessionData(CK.OPT_USE_PARTIES_PLUGIN, opt.getUsePartiesPlugin());
// Stages (Objectives)

View File

@ -1738,6 +1738,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
private void loadQuestOptions(FileConfiguration config, ConfigurationSection questsSection, Quest quest, String questKey) throws SkipQuest {
Options opts = quest.getOptions();
if (config.contains("quests." + questKey + ".options.allow-commands")) {
opts.setAllowCommands(config.getBoolean("quests." + questKey + ".options.allow-commands"));
}
if (config.contains("quests." + questKey + ".options.use-dungeonsxl-plugin")) {
opts.setUseDungeonsXLPlugin(config.getBoolean("quests." + questKey + ".options.use-dungeonsxl-plugin"));
}

View File

@ -386,6 +386,15 @@ public class PlayerListener implements Listener {
Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId());
if (quester.getCurrentQuests().isEmpty() == false) {
for (Quest quest : quester.getCurrentQuests().keySet()) {
if (!quest.getOptions().getAllowCommands()) {
if (!evt.getMessage().startsWith("/quest")) {
evt.getPlayer().sendMessage(ChatColor.RED + Lang.get(evt.getPlayer(), "optCommandsDenied").replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.RED));
evt.setCancelled(true);
plugin.getLogger().info("Player " + evt.getPlayer().getName() + " tried to use command " + evt.getMessage()
+ " but was denied because they are currently on quest " + quest.getName());
return;
}
}
Stage currentStage = quester.getCurrentStage(quest);
if (currentStage == null) {
plugin.getLogger().severe("currentStage was null for " + quester.getUUID().toString() + " on command for quest " + quest.getName());

View File

@ -89,14 +89,26 @@ public class OptionsPrompt extends FixedSetPrompt {
String lang = Lang.get("questEditorOpts") + ": " + Lang.get("optGeneral");
lang = lang.replace("<quest>", ChatColor.AQUA + (String) context.getSessionData(CK.Q_NAME) + ChatColor.DARK_AQUA);
text = ChatColor.DARK_AQUA + lang + "\n";
text += ChatColor.RED + "WIP" + "\n";
text += ChatColor.GREEN + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("done");
if (context.getSessionData(CK.OPT_ALLOW_COMMANDS) == null) {
boolean defaultOpt = new Options().getAllowCommands();
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("optAllowCommands") + " ("
+ (defaultOpt ? ChatColor.GREEN + String.valueOf(defaultOpt) : ChatColor.RED + String.valueOf(defaultOpt)) + ChatColor.YELLOW + ")\n";
} else {
boolean commandsOpt = (Boolean) context.getSessionData(CK.OPT_ALLOW_COMMANDS);
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("optAllowCommands") + " ("
+ (commandsOpt ? ChatColor.GREEN + String.valueOf(commandsOpt) : ChatColor.RED + String.valueOf(commandsOpt)) + ChatColor.YELLOW + ")\n";
}
text += ChatColor.GREEN + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("done");
return text;
}
@Override
public Prompt acceptInput(ConversationContext context, String input) {
if (input.equalsIgnoreCase("1")) {
tempKey = CK.OPT_ALLOW_COMMANDS;
tempPrompt = new GeneralPrompt();
return new TrueFalsePrompt();
} else if (input.equalsIgnoreCase("2")) {
tempKey = null;
tempPrompt = null;
return factory.returnToMenu();

View File

@ -129,6 +129,7 @@ public class CK {
public static final String PLN_REPEAT_CYCLE = "repeatCyclePln";
public static final String PLN_COOLDOWN = "cooldownPln";
// Options
public static final String OPT_ALLOW_COMMANDS = "allowCommandsOpt";
public static final String OPT_USE_DUNGEONSXL_PLUGIN = "useDungeonsXLPluginOpt";
public static final String OPT_USE_PARTIES_PLUGIN = "usePartiesPluginOpt";
// Events

View File

@ -509,6 +509,8 @@ plnTooLate: "<quest> was last active <time> ago."
optGeneral: "General"
optMultiplayer: "Multiplayer"
optBooleanPrompt: "Enter '<true>' or '<false>', <clear>, <cancel>"
optAllowCommands: "Allow commands during quest"
optCommandsDenied: "You cannot use commands during <quest>."
optUseDungeonsXLPlugin: "Use DungeonsXL plugin"
optUsePartiesPlugin: "Use Parties plugin"
rewSetMoney: "Set money reward"