Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /kitreset command #3909

Merged
merged 5 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/Kit.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public void setTime(final User user) throws Exception {
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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
JRoy marked this conversation as resolved.
Show resolved Hide resolved
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) {
mdcfe marked this conversation as resolved.
Show resolved Hide resolved
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();
}
}
}
4 changes: 4 additions & 0 deletions Essentials/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=/<command> <kit> [player]
kitResetOther=\u00a76Resetting kit \u00a7c{0} \u00a76cooldown for \u00a7c{1}\u00a76.
kits=\u00a76Kits\:\u00a7r {0}
kittycannonCommandDescription=Throw an exploding kitten at your opponent.
kittycannonCommandUsage=/<command>
Expand Down
4 changes: 4 additions & 0 deletions Essentials/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ commands:
description: Obtains the specified kit or views all available kits.
usage: /<command> [kit] [player]
aliases: [ekit,kits,ekits]
kitreset:
description: Resets the cooldown on the specified kit.
usage: /<command> <kit> [player]
aliases: [ekitreset, kitr, resetkit, eresetkit]
mdcfe marked this conversation as resolved.
Show resolved Hide resolved
kittycannon:
description: Throw an exploding kitten at your opponent.
usage: /<command>
Expand Down