From fccf796eeb068f04794ae1946098b3a4445a8214 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Fri, 5 Feb 2021 14:35:38 -0500 Subject: [PATCH] Add /kitreset command (#3909) Co-authored-by: darbyjack Closes #163. Ports #2645, which had its branch messed up by merges. --- .../java/com/earth2me/essentials/Kit.java | 4 ++ .../essentials/commands/Commandkitreset.java | 68 +++++++++++++++++++ .../src/main/resources/messages.properties | 4 ++ Essentials/src/main/resources/plugin.yml | 4 ++ 4 files changed, 80 insertions(+) create mode 100644 Essentials/src/main/java/com/earth2me/essentials/commands/Commandkitreset.java diff --git a/Essentials/src/main/java/com/earth2me/essentials/Kit.java b/Essentials/src/main/java/com/earth2me/essentials/Kit.java index 3f6588b77..9db9f91d9 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Kit.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Kit.java @@ -75,6 +75,10 @@ public class Kit { user.setKitTimestamp(kitName, time.getTimeInMillis()); } + public void resetTime(final User user) { + user.setKitTimestamp(kitName, 0); + } + public void chargeUser(final User user) throws Exception { charge.charge(user); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkitreset.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkitreset.java new file mode 100644 index 000000000..2129c347c --- /dev/null +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkitreset.java @@ -0,0 +1,68 @@ +package com.earth2me.essentials.commands; + +import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.User; +import org.bukkit.Server; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static com.earth2me.essentials.I18n.tl; + +public class Commandkitreset extends EssentialsCommand { + public Commandkitreset() { + super("kitreset"); + } + + @Override + protected void run(Server server, User user, String commandLabel, String[] args) throws Exception { + if (args.length < 1) { + throw new NotEnoughArgumentsException(); + } + + final String kitName = args[0]; + if (ess.getKits().getKit(kitName) == null) { + throw new Exception(tl("kitNotFound")); + } + + User target = user; + if (args.length > 1 && user.isAuthorized("essentials.kitreset.others")) { + target = getPlayer(server, user, args, 1); + } + + target.setKitTimestamp(kitName, 0); + if (user.equals(target)) { + user.sendMessage(tl("kitReset", kitName)); + } else { + user.sendMessage(tl("kitResetOther", kitName, target.getDisplayName())); + } + } + + @Override + protected void run(Server server, CommandSource sender, String commandLabel, String[] args) throws Exception { + if (args.length < 2) { + throw new NotEnoughArgumentsException(); + } + + final String kitName = args[0]; + if (ess.getKits().getKit(kitName) == null) { + throw new Exception(tl("kitNotFound")); + } + + final User target = getPlayer(server, sender, args, 1); + target.setKitTimestamp(kitName, 0); + sender.sendMessage(tl("kitResetOther", kitName, target.getDisplayName())); + } + + @Override + protected List getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) { + if (args.length == 1) { + return new ArrayList<>(ess.getKits().getKits().getKeys(false)); + } else if (args.length == 2 && sender.isAuthorized("essentials.kitreset.others", ess)) { + return getPlayers(server, sender); + } else { + return Collections.emptyList(); + } + } +} diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index 8d39e5920..b475907e9 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -405,6 +405,10 @@ kitItem=\u00a76- \u00a7f{0} kitNotFound=\u00a74That kit does not exist. kitOnce=\u00a74You can''t use that kit again. kitReceive=\u00a76Received kit\u00a7c {0}\u00a76. +kitReset=\u00a76Reset cooldown for kit \u00a7c{0}\u00a76. +kitresetCommandDescription=Resets the cooldown on the specified kit. +kitresetCommandUsage=/ [player] +kitResetOther=\u00a76Resetting kit \u00a7c{0} \u00a76cooldown for \u00a7c{1}\u00a76. kits=\u00a76Kits\:\u00a7r {0} kittycannonCommandDescription=Throw an exploding kitten at your opponent. kittycannonCommandUsage=/ diff --git a/Essentials/src/main/resources/plugin.yml b/Essentials/src/main/resources/plugin.yml index 26e95a656..d4f1fa2bd 100644 --- a/Essentials/src/main/resources/plugin.yml +++ b/Essentials/src/main/resources/plugin.yml @@ -260,6 +260,10 @@ commands: description: Obtains the specified kit or views all available kits. usage: / [kit] [player] aliases: [ekit,kits,ekits] + kitreset: + description: Resets the cooldown on the specified kit. + usage: / [player] + aliases: [ekitreset, kitr, ekitr, resetkit, eresetkit] kittycannon: description: Throw an exploding kitten at your opponent. usage: /