From 5d9a9e8c976e774bb82c474ce530855d7762d37b Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Tue, 22 Jun 2021 07:31:57 -0400 Subject: [PATCH] Config setting to toggle saving in trial mode --- .../java/me/blackvein/quests/Settings.java | 15 +++++-- .../convo/actions/main/ActionMainPrompt.java | 31 +++++++------ .../conditions/main/ConditionMainPrompt.java | 19 ++++---- .../convo/quests/main/QuestMainPrompt.java | 44 ++++++++++--------- main/src/main/resources/config.yml | 1 + 5 files changed, 63 insertions(+), 47 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/Settings.java b/main/src/main/java/me/blackvein/quests/Settings.java index aa1c6dab9..f32ea5bb4 100644 --- a/main/src/main/java/me/blackvein/quests/Settings.java +++ b/main/src/main/java/me/blackvein/quests/Settings.java @@ -12,12 +12,11 @@ package me.blackvein.quests; -import java.io.File; -import java.io.IOException; - +import me.blackvein.quests.util.Lang; import org.bukkit.configuration.file.FileConfiguration; -import me.blackvein.quests.util.Lang; +import java.io.File; +import java.io.IOException; public class Settings { @@ -39,6 +38,7 @@ public class Settings { private boolean showQuestReqs = true; private boolean showQuestTitles = true; private int strictPlayerMovement = 0; + private boolean trialSave = true; private int topLimit = 150; private boolean translateNames = false; private boolean translateSubCommands = false; @@ -149,6 +149,12 @@ public class Settings { public void setStrictPlayerMovement(final int strictPlayerMovement) { this.strictPlayerMovement = strictPlayerMovement; } + public boolean canTrialSave() { + return trialSave; + } + public void setTrialSave(final boolean trialSave) { + this.trialSave = trialSave; + } public int getTopLimit() { return topLimit; } @@ -193,6 +199,7 @@ public class Settings { showQuestReqs = config.getBoolean("show-requirements", true); showQuestTitles = config.getBoolean("show-titles", true); strictPlayerMovement = config.getInt("strict-player-movement", 0); + trialSave = config.getBoolean("trial-save", true); topLimit = config.getInt("top-limit", 150); translateNames = config.getBoolean("translate-names", true); translateSubCommands = config.getBoolean("translate-subcommands", false); diff --git a/main/src/main/java/me/blackvein/quests/convo/actions/main/ActionMainPrompt.java b/main/src/main/java/me/blackvein/quests/convo/actions/main/ActionMainPrompt.java index e296ebd85..2cbf31085 100644 --- a/main/src/main/java/me/blackvein/quests/convo/actions/main/ActionMainPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/actions/main/ActionMainPrompt.java @@ -12,20 +12,6 @@ package me.blackvein.quests.convo.actions.main; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.Prompt; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - import me.blackvein.quests.Quest; import me.blackvein.quests.QuestMob; import me.blackvein.quests.Quests; @@ -45,6 +31,19 @@ import me.blackvein.quests.util.ConfigUtil; import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; import me.blackvein.quests.util.MiscUtil; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.UUID; public class ActionMainPrompt extends ActionsEditorNumericPrompt { @@ -1032,6 +1031,10 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt { @Override public Prompt acceptInput(final ConversationContext context, final String input) { if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) { + if (plugin.hasLimitedAccess(context.getForWhom()) && !plugin.getSettings().canTrialSave()) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("noPermission")); + return new ActionMainPrompt(context); + } plugin.getActionFactory().saveAction(context); return Prompt.END_OF_CONVERSATION; } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) { diff --git a/main/src/main/java/me/blackvein/quests/convo/conditions/main/ConditionMainPrompt.java b/main/src/main/java/me/blackvein/quests/convo/conditions/main/ConditionMainPrompt.java index d69de16f7..40a470694 100644 --- a/main/src/main/java/me/blackvein/quests/convo/conditions/main/ConditionMainPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/conditions/main/ConditionMainPrompt.java @@ -12,14 +12,6 @@ package me.blackvein.quests.convo.conditions.main; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.Prompt; - import me.blackvein.quests.Quest; import me.blackvein.quests.Quests; import me.blackvein.quests.Stage; @@ -33,6 +25,13 @@ import me.blackvein.quests.events.editor.conditions.ConditionsEditorPostOpenNume import me.blackvein.quests.events.editor.conditions.ConditionsEditorPostOpenStringPromptEvent; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.Lang; +import org.bukkit.ChatColor; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; public class ConditionMainPrompt extends ConditionsEditorNumericPrompt { @@ -527,6 +526,10 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt { @Override public Prompt acceptInput(final ConversationContext context, final String input) { if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) { + if (plugin.hasLimitedAccess(context.getForWhom()) && !plugin.getSettings().canTrialSave()) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("noPermission")); + return new ConditionMainPrompt(context); + } plugin.getConditionFactory().saveCondition(context); return Prompt.END_OF_CONVERSATION; } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) { diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/main/QuestMainPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/main/QuestMainPrompt.java index 2ff119ee7..416400bed 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/main/QuestMainPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/main/QuestMainPrompt.java @@ -12,28 +12,7 @@ package me.blackvein.quests.convo.quests.main; -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.Prompt; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - import com.sk89q.worldguard.protection.managers.RegionManager; - import me.blackvein.quests.Quest; import me.blackvein.quests.Quests; import me.blackvein.quests.convo.generic.ItemStackPrompt; @@ -51,6 +30,25 @@ import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; import net.citizensnpcs.api.CitizensAPI; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; public class QuestMainPrompt extends QuestsEditorNumericPrompt { @@ -815,6 +813,10 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt { @Override public Prompt acceptInput(final ConversationContext context, final String input) { if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) { + if (plugin.hasLimitedAccess(context.getForWhom()) && !plugin.getSettings().canTrialSave()) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("noPermission")); + return new QuestMainPrompt(context); + } if (context.getSessionData(CK.Q_ASK_MESSAGE) == null) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorNeedAskMessage")); return new QuestMainPrompt(context); diff --git a/main/src/main/resources/config.yml b/main/src/main/resources/config.yml index b6052b38b..1f7a7a2fe 100644 --- a/main/src/main/resources/config.yml +++ b/main/src/main/resources/config.yml @@ -32,6 +32,7 @@ storage-data: connection-timeout: 5000 storage-method: player-data: yaml +trial-save: true top-limit: 150 translate-names: true translate-subcommands: false \ No newline at end of file