mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-06 00:18:36 +01:00
Added AdminDeathsAddCommand and AdminDeathsRemoveCommand
Implements https://github.com/BentoBoxWorld/BentoBox/issues/950
This commit is contained in:
parent
d9dc337de9
commit
6799c43a0a
@ -0,0 +1,50 @@
|
||||
package world.bentobox.bentobox.api.commands.admin.deaths;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @since 1.8.0
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public class AdminDeathsAddCommand extends CompositeCommand {
|
||||
|
||||
public AdminDeathsAddCommand(AdminDeathsCommand parent) {
|
||||
super(parent, "add");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.admin.deaths.add.description");
|
||||
setParametersHelp("commands.admin.deaths.add.parameters");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, @NonNull List<String> args) {
|
||||
if (args.size() != 2) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
|
||||
UUID target = getPlayers().getUUID(args.get(0));
|
||||
if (target == null) {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
} else if (!NumberUtils.isNumber(args.get(1)) || Integer.valueOf(args.get(1)) < 0) {
|
||||
user.sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, args.get(1));
|
||||
} else {
|
||||
getPlayers().setDeaths(getWorld(), target, getPlayers().getDeaths(getWorld(), target) + Integer.valueOf(args.get(1)));
|
||||
user.sendMessage("commands.admin.deaths.add.success",
|
||||
TextVariables.NAME, args.get(0), TextVariables.NUMBER, args.get(1),
|
||||
"[total]", String.valueOf(getPlayers().getDeaths(getWorld(), target)));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -21,6 +21,8 @@ public class AdminDeathsCommand extends CompositeCommand {
|
||||
|
||||
new AdminDeathsResetCommand(this);
|
||||
new AdminDeathsSetCommand(this);
|
||||
new AdminDeathsAddCommand(this);
|
||||
new AdminDeathsRemoveCommand(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,48 @@
|
||||
package world.bentobox.bentobox.api.commands.admin.deaths;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @since 1.8.0
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public class AdminDeathsRemoveCommand extends CompositeCommand {
|
||||
|
||||
public AdminDeathsRemoveCommand(AdminDeathsCommand parent) {
|
||||
super(parent, "remove");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.admin.deaths.remove.description");
|
||||
setParametersHelp("commands.admin.deaths.remove.parameters");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, @NonNull List<String> args) {
|
||||
if (args.size() != 2) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
|
||||
UUID target = getPlayers().getUUID(args.get(0));
|
||||
if (target == null) {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
} else if (!NumberUtils.isNumber(args.get(1)) || Integer.valueOf(args.get(1)) < 0) {
|
||||
user.sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, args.get(1));
|
||||
} else {
|
||||
getPlayers().setDeaths(getWorld(), target, getPlayers().getDeaths(getWorld(), target) - Integer.valueOf(args.get(1)));
|
||||
user.sendMessage("commands.admin.deaths.remove.success", TextVariables.NAME, args.get(0), TextVariables.NUMBER, args.get(1));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -334,6 +334,14 @@ commands:
|
||||
description: "sets deaths of the player"
|
||||
parameters: "<player> <deaths>"
|
||||
success: "&aSuccessfully set &b[name]&a's deaths to &b[number]&a."
|
||||
add:
|
||||
description: "adds deaths to the player"
|
||||
parameters: "<player> <deaths>"
|
||||
success: "&aSuccessfully added &b[number] &adeaths to &b[name], increasing the total to &b[total]&a deaths."
|
||||
remove:
|
||||
description: "removes deaths to the player"
|
||||
parameters: "<player> <deaths>"
|
||||
success: "&aSuccessfully removed &b[number] &adeaths to &b[name], decreasing the total to &b[total]&a deaths."
|
||||
bentobox:
|
||||
description: "BentoBox admin command"
|
||||
about:
|
||||
|
Loading…
Reference in New Issue
Block a user