Add /kitreset command (#3909)

Co-authored-by: darbyjack <admin@glaremasters.me>

Closes #163. Ports #2645, which had its branch messed up by merges.
This commit is contained in:
Josh Roy 2021-02-05 14:35:38 -05:00 committed by GitHub
parent 500edb7860
commit fccf796eeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 80 additions and 0 deletions

View File

@ -75,6 +75,10 @@ public class Kit {
user.setKitTimestamp(kitName, time.getTimeInMillis()); user.setKitTimestamp(kitName, time.getTimeInMillis());
} }
public void resetTime(final User user) {
user.setKitTimestamp(kitName, 0);
}
public void chargeUser(final User user) throws Exception { public void chargeUser(final User user) throws Exception {
charge.charge(user); charge.charge(user);
} }

View File

@ -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<String> 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();
}
}
}

View File

@ -405,6 +405,10 @@ kitItem=\u00a76- \u00a7f{0}
kitNotFound=\u00a74That kit does not exist. kitNotFound=\u00a74That kit does not exist.
kitOnce=\u00a74You can''t use that kit again. kitOnce=\u00a74You can''t use that kit again.
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76. kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
kitReset=\u00a76Reset cooldown for kit \u00a7c{0}\u00a76.
kitresetCommandDescription=Resets the cooldown on the specified kit.
kitresetCommandUsage=/<command> <kit> [player]
kitResetOther=\u00a76Resetting kit \u00a7c{0} \u00a76cooldown for \u00a7c{1}\u00a76.
kits=\u00a76Kits\:\u00a7r {0} kits=\u00a76Kits\:\u00a7r {0}
kittycannonCommandDescription=Throw an exploding kitten at your opponent. kittycannonCommandDescription=Throw an exploding kitten at your opponent.
kittycannonCommandUsage=/<command> kittycannonCommandUsage=/<command>

View File

@ -260,6 +260,10 @@ commands:
description: Obtains the specified kit or views all available kits. description: Obtains the specified kit or views all available kits.
usage: /<command> [kit] [player] usage: /<command> [kit] [player]
aliases: [ekit,kits,ekits] aliases: [ekit,kits,ekits]
kitreset:
description: Resets the cooldown on the specified kit.
usage: /<command> <kit> [player]
aliases: [ekitreset, kitr, ekitr, resetkit, eresetkit]
kittycannon: kittycannon:
description: Throw an exploding kitten at your opponent. description: Throw an exploding kitten at your opponent.
usage: /<command> usage: /<command>