From f94a6b0b87846e59fed7d4d5de80fa6c6a7255ce Mon Sep 17 00:00:00 2001 From: Momshroom Date: Thu, 11 May 2023 23:33:18 -0500 Subject: [PATCH] Add confirmation to jobs skipquest and fixed it not being possible to skip quests with multiword names --- .../jobs/commands/list/skipquest.java | 22 +++++++++++++++++-- .../jobs/config/LanguageManager.java | 1 + .../java/com/gamingmesh/jobs/stuff/Util.java | 3 +++ src/main/resources/locale/messages_it_IT.yml | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java b/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java index 32961c9d..3bf9a793 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java @@ -2,6 +2,7 @@ package com.gamingmesh.jobs.commands.list; import java.util.List; +import com.gamingmesh.jobs.stuff.Util; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -24,8 +25,8 @@ public class skipquest implements Cmd { LC.info_FeatureNotEnabled.sendMessage(sender); return null; } - - if (args.length != 2 && args.length != 3) { + // Needs to allow longer so multiword quest names work + if (args.length < 2) { return false; } @@ -106,6 +107,23 @@ public class skipquest implements Cmd { econ.getEconomy().withdrawPlayer(player, amount); } + // Add confirmation if configured + if (Jobs.getGCManager().EnableConfirmation) { + java.util.UUID uuid = jPlayer.getUniqueId(); + + if (!Util.SKIPCONFIRM.contains(uuid)) { + Util.SKIPCONFIRM.add(uuid); + + plugin.getServer().getScheduler().runTaskLater(plugin, () -> Util.SKIPCONFIRM.remove(uuid), + 20 * Jobs.getGCManager().ConfirmExpiryTime); + + Language.sendMessage(sender, "command.skipquest.confirmationNeed", "[questName]", + job.getDisplayName(), "[time]", Jobs.getGCManager().ConfirmExpiryTime); + return true; + } + + Util.SKIPCONFIRM.remove(uuid); + } jPlayer.replaceQuest(old); diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index 2c6d9442..72bad4a6 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -482,6 +482,7 @@ public class LanguageManager { c.get("command.skipquest.help.info", "Skip defined quest and get new one"); c.get("command.skipquest.help.args", "[jobname] [questname] (playerName)"); c.get("command.skipquest.output.questSkipForCost", "&2You skipped the quest and paid:&e %amount%$"); + c.get("command.skipquest.confirmationNeed", "&cAre you sure you want to skip&e [questName]&c quest? Type the command again within&6 [time] seconds &cto confirm!"); Jobs.getGCManager().getCommandArgs().put("skipquest", Arrays.asList("[jobname]", "[questname]", "[playername]")); c.get("command.quests.help.info", "List available quests"); diff --git a/src/main/java/com/gamingmesh/jobs/stuff/Util.java b/src/main/java/com/gamingmesh/jobs/stuff/Util.java index 8f1be8a8..5e82a31f 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/Util.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/Util.java @@ -50,6 +50,9 @@ public final class Util { public static final List LEAVECONFIRM = new ArrayList<>(); + // for confirmation of skipping quest + public static final List SKIPCONFIRM = new ArrayList<>(); + public static List getPistonRetractBlocks(BlockPistonRetractEvent event) { if (Version.isCurrentEqualOrHigher(Version.v1_8_R1)) { return new ArrayList<>(event.getBlocks()); diff --git a/src/main/resources/locale/messages_it_IT.yml b/src/main/resources/locale/messages_it_IT.yml index 9be29aca..399bea74 100644 --- a/src/main/resources/locale/messages_it_IT.yml +++ b/src/main/resources/locale/messages_it_IT.yml @@ -470,6 +470,7 @@ command: args: '[jobname] [questname] (playerName)' output: questSkipForCost: '&2You skipped the quest and paid:&e %amount%$' + confirmationNeed: '&cAre you sure you want to skip&e [questName]&c quest? Type the command again within&6 [time] seconds &cto confirm!' quests: help: info: List available quests