Replace config setting for quitting with per-quest option, fixes #615

This commit is contained in:
PikaMug 2019-06-07 02:06:59 -04:00
parent ccc6b976b8
commit 62a4629f34
8 changed files with 53 additions and 27 deletions

View File

@ -14,6 +14,7 @@ package me.blackvein.quests;
public class Options {
private boolean allowCommands = true;
private boolean allowQuitting = true;
private boolean useDungeonsXLPlugin = false;
private boolean usePartiesPlugin = true;
@ -25,6 +26,14 @@ public class Options {
this.allowCommands = allowCommands;
}
public boolean getAllowQuitting() {
return allowQuitting;
}
public void setAllowQuitting(boolean allowQuitting) {
this.allowQuitting = allowQuitting;
}
public boolean getUseDungeonsXLPlugin() {
return useDungeonsXLPlugin;
}

View File

@ -833,6 +833,7 @@ public class QuestFactory implements ConversationAbandonedListener {
Long repeatCyclePln = null;
Long cooldownPln = null;
boolean allowCommandsOpt = true;
boolean allowQuittingOpt = true;
boolean useDungeonsXLPluginOpt = false;
boolean usePartiesPluginOpt = true;
if (cc.getSessionData(CK.Q_START_NPC) != null) {
@ -952,6 +953,9 @@ public class QuestFactory implements ConversationAbandonedListener {
if (cc.getSessionData(CK.OPT_ALLOW_COMMANDS) != null) {
allowCommandsOpt = (Boolean) cc.getSessionData(CK.OPT_ALLOW_COMMANDS);
}
if (cc.getSessionData(CK.OPT_ALLOW_QUITTING) != null) {
allowQuittingOpt = (Boolean) cc.getSessionData(CK.OPT_ALLOW_QUITTING);
}
if (cc.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN) != null) {
useDungeonsXLPluginOpt = (Boolean) cc.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN);
}
@ -1421,6 +1425,7 @@ public class QuestFactory implements ConversationAbandonedListener {
}
ConfigurationSection sch = cs.createSection("options");
sch.set("allow-commands", allowCommandsOpt);
sch.set("allow-quitting", allowQuittingOpt);
sch.set("use-dungeonsxl-plugin", useDungeonsXLPluginOpt);
sch.set("use-parties-plugin", usePartiesPluginOpt);
}
@ -1536,6 +1541,7 @@ public class QuestFactory implements ConversationAbandonedListener {
}
Options opt = q.getOptions();
cc.setSessionData(CK.OPT_ALLOW_COMMANDS, opt.getAllowCommands());
cc.setSessionData(CK.OPT_ALLOW_QUITTING, opt.getAllowQuitting());
cc.setSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN, opt.getUseDungeonsXLPlugin());
cc.setSessionData(CK.OPT_USE_PARTIES_PLUGIN, opt.getUsePartiesPlugin());
// Stages (Objectives)

View File

@ -247,8 +247,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
return Optional.empty();
}
public List<CustomReward> getCustomRewards() {
return customRewards;
}
@ -1781,6 +1779,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
if (config.contains("quests." + questKey + ".options.allow-commands")) {
opts.setAllowCommands(config.getBoolean("quests." + questKey + ".options.allow-commands"));
}
if (config.contains("quests." + questKey + ".options.allow-quitting")) {
opts.setAllowQuitting(config.getBoolean("quests." + questKey + ".options.allow-quitting"));
} else if (getConfig().contains("allow-quitting")) {
// Legacy
opts.setAllowQuitting(getConfig().getBoolean("allow-quitting"));
}
if (config.contains("quests." + questKey + ".options.use-dungeonsxl-plugin")) {
opts.setUseDungeonsXLPlugin(config.getBoolean("quests." + questKey + ".options.use-dungeonsxl-plugin"));
}

View File

@ -23,7 +23,6 @@ public class Settings {
private int acceptTimeout = 20;
private boolean allowCommands = true;
private boolean allowCommandsForNpcQuests = false;
private boolean allowQuitting = true;
private boolean askConfirmation = true;
private boolean genFilesOnJoin = true;
private boolean ignoreLockedQuests = false;
@ -61,12 +60,6 @@ public class Settings {
public void setAllowCommandsForNpcQuests(boolean allowCommandsForNpcQuests) {
this.allowCommandsForNpcQuests = allowCommandsForNpcQuests;
}
public boolean canAllowQuitting() {
return allowQuitting;
}
public void setAllowQuitting(boolean allowQuitting) {
this.allowQuitting = allowQuitting;
}
public boolean canAskConfirmation() {
return askConfirmation;
}
@ -169,7 +162,6 @@ public class Settings {
acceptTimeout = config.getInt("accept-timeout", 20);
allowCommands = config.getBoolean("allow-command-questing", true);
allowCommandsForNpcQuests = config.getBoolean("allow-command-quests-with-npcs", false);
allowQuitting = config.getBoolean("allow-quitting", true);
askConfirmation = config.getBoolean("ask-confirmation", true);
genFilesOnJoin = config.getBoolean("generate-files-on-join", true);
ignoreLockedQuests = config.getBoolean("ignore-locked-quests", false);

View File

@ -612,16 +612,16 @@ public class CmdExecutor implements CommandExecutor {
}
private void questsQuit(final Player player, String[] args) {
if (plugin.getSettings().canAllowQuitting() == true) {
if (((Player) player).hasPermission("quests.quit")) {
if (args.length == 1) {
player.sendMessage(ChatColor.RED + Lang.get(player, "COMMAND_QUIT_HELP"));
return;
}
Quester quester = plugin.getQuester(player.getUniqueId());
if (quester.getCurrentQuests().isEmpty() == false) {
Quest q = plugin.getQuest(MiscUtil.concatArgArray(args, 1, args.length - 1, ' '));
if (q != null) {
if (((Player) player).hasPermission("quests.quit")) {
if (args.length == 1) {
player.sendMessage(ChatColor.RED + Lang.get(player, "COMMAND_QUIT_HELP"));
return;
}
Quester quester = plugin.getQuester(player.getUniqueId());
if (quester.getCurrentQuests().isEmpty() == false) {
Quest q = plugin.getQuest(MiscUtil.concatArgArray(args, 1, args.length - 1, ' '));
if (q != null) {
if (q.getOptions().getAllowQuitting()) {
QuestQuitEvent event = new QuestQuitEvent(q, quester);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
@ -635,16 +635,16 @@ public class CmdExecutor implements CommandExecutor {
quester.loadData();
quester.updateJournal();
} else {
player.sendMessage(ChatColor.RED + Lang.get(player, "questNotFound"));
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "questQuitDisabled"));
}
} else {
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "noActiveQuest"));
player.sendMessage(ChatColor.RED + Lang.get(player, "questNotFound"));
}
} else {
player.sendMessage(ChatColor.RED + Lang.get(player, "NoPermission"));
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "noActiveQuest"));
}
} else {
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "questQuitDisabled"));
player.sendMessage(ChatColor.RED + Lang.get(player, "NoPermission"));
}
}

View File

@ -33,7 +33,7 @@ public class OptionsPrompt extends FixedSetPrompt {
private StringPrompt tempPrompt;
public OptionsPrompt(Quests plugin, QuestFactory qf) {
super("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11");
super("1", "2", "3");
this.plugin = plugin;
factory = qf;
}
@ -110,7 +110,16 @@ public class OptionsPrompt extends FixedSetPrompt {
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");
if (context.getSessionData(CK.OPT_ALLOW_QUITTING) == null) {
boolean defaultOpt = new Options().getAllowQuitting();
text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("optAllowQuitting") + " ("
+ (defaultOpt ? ChatColor.GREEN + String.valueOf(defaultOpt) : ChatColor.RED + String.valueOf(defaultOpt)) + ChatColor.YELLOW + ")\n";
} else {
boolean quittingOpt = (Boolean) context.getSessionData(CK.OPT_ALLOW_QUITTING);
text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("optAllowQuitting") + " ("
+ (quittingOpt ? ChatColor.GREEN + String.valueOf(quittingOpt) : ChatColor.RED + String.valueOf(quittingOpt)) + ChatColor.YELLOW + ")\n";
}
text += ChatColor.GREEN + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("done");
return text;
}
@ -121,6 +130,10 @@ public class OptionsPrompt extends FixedSetPrompt {
tempPrompt = new GeneralPrompt();
return new TrueFalsePrompt();
} else if (input.equalsIgnoreCase("2")) {
tempKey = CK.OPT_ALLOW_QUITTING;
tempPrompt = new GeneralPrompt();
return new TrueFalsePrompt();
} else if (input.equalsIgnoreCase("3")) {
tempKey = null;
tempPrompt = null;
return factory.returnToMenu();

View File

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

View File

@ -500,6 +500,7 @@ optGeneral: "General"
optMultiplayer: "Multiplayer"
optBooleanPrompt: "Enter '<true>' or '<false>', <clear>, <cancel>"
optAllowCommands: "Allow commands during quest"
optAllowQuitting: "Allow quitting during quest"
optCommandsDenied: "You cannot use commands during <quest>."
optUseDungeonsXLPlugin: "Use DungeonsXL plugin"
optUsePartiesPlugin: "Use Parties plugin"
@ -701,7 +702,7 @@ pageSelectionNum: "Page selection must be a number."
pageSelectionPosNum: "Page selection must be a positive number."
questTakeDisabled: "Taking Quests via commands has been disabled."
questQuit: "You have quit <quest>"
questQuitDisabled: "Quitting Quests has been disabled."
questQuitDisabled: "Quitting this quest has been disabled."
questsUnknownCommand: "Unknown Quests command. Type /quests for help."
pageNotExist: "Page does not exist."
pageFooter: "- Page <current> of <all> -"