From 6a1010022cc87e908787b2d0f7350a4708a4a8bd Mon Sep 17 00:00:00 2001 From: okx-code Date: Wed, 18 Jan 2023 21:38:11 +0000 Subject: [PATCH] add /rankup noconfirm --- .../sh/okx/rankup/commands/RankupCommand.java | 27 ++++ .../rankup/messages/NullMessageBuilder.java | 2 +- src/main/resources/config.yml | 7 +- src/main/resources/plugin.yml | 4 + .../sh/okx/rankup/RankupCommandsTest.java | 5 - .../DisabledNoConfirmCommandTest.java | 27 ++++ .../commands/EnabledNoConfirmCommandTest.java | 23 ++++ src/test/resources/noconfirm/config.yml | 116 ++++++++++++++++++ 8 files changed, 204 insertions(+), 7 deletions(-) delete mode 100644 src/test/java/sh/okx/rankup/RankupCommandsTest.java create mode 100644 src/test/java/sh/okx/rankup/commands/DisabledNoConfirmCommandTest.java create mode 100644 src/test/java/sh/okx/rankup/commands/EnabledNoConfirmCommandTest.java create mode 100644 src/test/resources/noconfirm/config.yml diff --git a/src/main/java/sh/okx/rankup/commands/RankupCommand.java b/src/main/java/sh/okx/rankup/commands/RankupCommand.java index b24fd68..e446015 100644 --- a/src/main/java/sh/okx/rankup/commands/RankupCommand.java +++ b/src/main/java/sh/okx/rankup/commands/RankupCommand.java @@ -1,8 +1,10 @@ package sh.okx.rankup.commands; +import java.util.Arrays; import java.util.Map; import java.util.WeakHashMap; import lombok.RequiredArgsConstructor; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -29,6 +31,11 @@ public class RankupCommand implements CommandExecutor { return true; } + if (plugin.getConfig().getBoolean("enable-noconfirm", true) && args.length > 0 && args[0].equalsIgnoreCase("noconfirm")) { + handleNoConfirm(sender, label, Arrays.copyOfRange(args, 1, args.length)); + return true; + } + // check if player if (!(sender instanceof Player)) { return false; @@ -39,6 +46,7 @@ public class RankupCommand implements CommandExecutor { if (!plugin.getHelper().checkRankup(player)) { return true; } + RankElement rankElement = rankups.getByPlayer(player); FileConfiguration config = plugin.getConfig(); @@ -79,4 +87,23 @@ public class RankupCommand implements CommandExecutor { } return true; } + + private void handleNoConfirm(CommandSender sender, String label, String[] args) { + if (sender.hasPermission("rankup.noconfirm.other") && args.length > 0) { + Player player = Bukkit.getPlayer(args[0]); + if (player == null) { + sender.sendMessage(ChatColor.RED + "Player not found: " + args[0]); + } else { + plugin.getHelper().rankup(player); + sender.sendMessage(ChatColor.GREEN + "Triggered no-confirmation rankup for " + player.getName()); + } + } else { + if (!(sender instanceof Player)) { + sender.sendMessage("/" + label + " noconfirm "); + return; + } + + plugin.getHelper().rankup((Player) sender); + } + } } diff --git a/src/main/java/sh/okx/rankup/messages/NullMessageBuilder.java b/src/main/java/sh/okx/rankup/messages/NullMessageBuilder.java index dbea283..f1263e2 100644 --- a/src/main/java/sh/okx/rankup/messages/NullMessageBuilder.java +++ b/src/main/java/sh/okx/rankup/messages/NullMessageBuilder.java @@ -30,7 +30,7 @@ public class NullMessageBuilder implements MessageBuilder { @Override public MessageBuilder replaceSeconds(long seconds, long secondsLeft) { - return null; + return this; } @Override diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 52e5467..780b54c 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -24,7 +24,7 @@ prestiges: true # will override the /ranks command ranks-gui: false -# whether or not /prestige and /prestiges should be enabled. +# whether /prestige and /prestiges should be enabled. # when a player reaches the top rank, they can do /prestige to return to the first rank, # but you will be able to grant them an additional "prestige" group or additional items. # @@ -46,6 +46,11 @@ notify-update: true # use commands to change a player's group or permission. permission-rankup: false +# if players can use /rankup noconfirm to bypass any confirmation +# the permission rankup.noconfirm is used for this command, but it is true by default +# the console can always do /rankup noconfirm +enable-noconfirm: true + # how people should confirm ranking up # options are: gui, text or none confirmation-type: 'gui' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 5b95e1b..81e3f92 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -36,6 +36,7 @@ permissions: rankup.prestiges: true rankup.auto: true rankup.maxrankup: true + rankup.noconfirm: true rankup.admin: children: # if a player can see if the plugin needs updating when they run /pru @@ -47,6 +48,7 @@ permissions: # if a player receives notifications to update rankup when they log in. rankup.notify: true rankup.playtime: true + rankup.noconfirm.other: true default: op rankup.rankup: default: true @@ -60,6 +62,8 @@ permissions: default: true rankup.maxrankup: default: true + rankup.noconfirm: + default: true rankup.playtime: description: Use all /rankup3 playtime subcommands for anyone. children: diff --git a/src/test/java/sh/okx/rankup/RankupCommandsTest.java b/src/test/java/sh/okx/rankup/RankupCommandsTest.java deleted file mode 100644 index db09752..0000000 --- a/src/test/java/sh/okx/rankup/RankupCommandsTest.java +++ /dev/null @@ -1,5 +0,0 @@ -package sh.okx.rankup; - -public class RankupCommandsTest extends RankupTest { - -} diff --git a/src/test/java/sh/okx/rankup/commands/DisabledNoConfirmCommandTest.java b/src/test/java/sh/okx/rankup/commands/DisabledNoConfirmCommandTest.java new file mode 100644 index 0000000..d5f6e42 --- /dev/null +++ b/src/test/java/sh/okx/rankup/commands/DisabledNoConfirmCommandTest.java @@ -0,0 +1,27 @@ +package sh.okx.rankup.commands; + +import static org.junit.jupiter.api.Assertions.*; + +import be.seeseemelk.mockbukkit.entity.PlayerMock; +import org.junit.jupiter.api.Test; +import sh.okx.rankup.RankupTest; + +public class DisabledNoConfirmCommandTest extends RankupTest { + + public DisabledNoConfirmCommandTest() { + super("noconfirm"); + } + + @Test + public void testNoConfirmDisabled() { + PlayerMock player = server.addPlayer(); + player.addAttachment(plugin, "rankup.rankup", true); + player.addAttachment(plugin, "rankup.noconfirm", true); + + plugin.getPermissions().addGroup(player.getUniqueId(), "A"); + plugin.getEconomy().setPlayer(player, 10000); + + plugin.getCommand("rankup").execute(player, "rankup", new String[] {"noconfirm"}); + assertFalse(plugin.getPermissions().inGroup(player.getUniqueId(), "B")); + } +} diff --git a/src/test/java/sh/okx/rankup/commands/EnabledNoConfirmCommandTest.java b/src/test/java/sh/okx/rankup/commands/EnabledNoConfirmCommandTest.java new file mode 100644 index 0000000..f52bc9c --- /dev/null +++ b/src/test/java/sh/okx/rankup/commands/EnabledNoConfirmCommandTest.java @@ -0,0 +1,23 @@ +package sh.okx.rankup.commands; + +import static org.junit.jupiter.api.Assertions.*; + +import be.seeseemelk.mockbukkit.entity.PlayerMock; +import org.junit.jupiter.api.Test; +import sh.okx.rankup.RankupTest; + +public class EnabledNoConfirmCommandTest extends RankupTest { + + @Test + public void testNoConfirmEnabled() { + PlayerMock player = server.addPlayer(); + player.addAttachment(plugin, "rankup.rankup", true); + player.addAttachment(plugin, "rankup.noconfirm", true); + + plugin.getPermissions().addGroup(player.getUniqueId(), "A"); + plugin.getEconomy().setPlayer(player, 10000); + + plugin.getCommand("rankup").execute(player, "rankup", new String[] {"noconfirm"}); + assertTrue(plugin.getPermissions().inGroup(player.getUniqueId(), "B")); + } +} diff --git a/src/test/resources/noconfirm/config.yml b/src/test/resources/noconfirm/config.yml new file mode 100644 index 0000000..8bc4244 --- /dev/null +++ b/src/test/resources/noconfirm/config.yml @@ -0,0 +1,116 @@ +# this is used for letting you know that you need to update/change your config file +version: 10 + +# the locale to use for messages +# all messages can be customised but this allows you to +# choose messages that are already translated +# locales can be found in the locale/ folder +locale: en + +# interval (in minutes) to check to autorankup players +# ranking up manually will always be enabled +# set to 0 to disable +autorankup-interval: 0 + +# whether /ranks and /prestiges should be enabled (true) or disabled (false) +# /rankup3 reload will not do anything if this is changed, +# you will have to restart your server. +ranks: true +# you can alternatively negate the permission rankup.prestiges +# this will also make the command not autocomplete in 1.13 +prestiges: true + +# whether to enable the /ranks GUI. +# will override the /ranks command +ranks-gui: false + +# whether /prestige and /prestiges should be enabled. +# when a player reaches the top rank, they can do /prestige to return to the first rank, +# but you will be able to grant them an additional "prestige" group or additional items. +# +# if you do not want this command to autocomplete, make sure +# you negate the permission rankup.prestige with your permissions plugin. +# if enabled, a prestiges.yml file will be generated with some example prestiges +# You must restart your server when you change this for it to work! +prestige: false + +# if true, players with the permission rankup.notify will receive notifications when they join +# to update if the server is on an older version of Rankup. +notify-update: true + +# if rankups and prestiges should be by permissions +# if false, players will be checked for if they have a group of the same name as in rankups.yml, +# and automatically added and taken away from those groups. +# if true, players will be checked for the permission rankup.rank.RANK, where RANK +# is the rankup in rankups.yml. Nothing will automatically happen on rankup, so you must +# use commands to change a player's group or permission. +permission-rankup: false + +# if players can use /rankup noconfirm to bypass any confirmation +# the permission rankup.noconfirm is used for this command, but it is true by default +# the console can always do /rankup noconfirm +enable-noconfirm: false + +# how people should confirm ranking up +# options are: gui, text or none +confirmation-type: 'gui' + +# how long, in seconds, people have to wait between a successful /rankup or /prestige +# set to 0 to disable. +cooldown: 1 + +# if enabled, players can run /maxrankup to rankup as many times as possible, +# before they fail the requirements for the next rank. +# the permission rankup.maxrankup is used for this command, but it is given by default. +# note that /maxrankup, if enabled, has no confirmation. +max-rankup: + # You must restart your server if you enable or disable /maxrankup! + enabled: false + # whether to send a message for each rankup a player does + # if set to true, the chat may be spammed for each rankup a player goes through with /maxrankup + # if set to false, only the last rankup will be shown (if a player starts on rank A, then does + # /maxrankup and ranks up to B and then C, it will just say "player has ranked up to C") + individual-messages: true + +# options when using the text rankup confirmation +text: + # the time in seconds for a player to + # confirm by typing /rankup again + timeout: 10 + +# placeholders: +# https://okx.sh/rankup/Placeholders.html +placeholders: + # format for money. for more information, see + # https://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html + money-format: "#,##0.##" + percent-format: "0.##" + # the format used for requirements + simple-format: "#.##" + # used for current_rank and next_rank placeholders when a player is not in anything in rankups.yml + not-in-ladder: "None" + # used in the current_prestige placeholders when a player hasn't prestiged yet + no-prestige: "None" + # used in the next_rank and next_prestige placeholders when a player is at the highest rank or prestige + highest-rank: "None" + # used in the %rankup_status_[rank]% placeholders + status: + complete: "Complete" + current: "Current" + incomplete: "Incomplete" + last-rank-display-name: "last rank" + +# what to shorten money by. +# ie 1000 -> 1k +# set to an empty list to disable +# for each entry here, it counts as increasing by a factor of 1,000 +# the first represents thousands (1,000) then millions (1,000,000) then billions (1,000,000,000) etc. +# this is used in the "| shortmoney" filter +shorten: +- 'K' +- 'M' +- 'B' +- 'T' +- 'Q' +- 'Qu' +- 'S' \ No newline at end of file