Added AdminDeathsAddCommand and AdminDeathsRemoveCommand

Implements https://github.com/BentoBoxWorld/BentoBox/issues/950
This commit is contained in:
Florian CUNY 2019-09-28 14:37:29 +02:00
parent d9dc337de9
commit 6799c43a0a
4 changed files with 108 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -21,6 +21,8 @@ public class AdminDeathsCommand extends CompositeCommand {
new AdminDeathsResetCommand(this);
new AdminDeathsSetCommand(this);
new AdminDeathsAddCommand(this);
new AdminDeathsRemoveCommand(this);
}
@Override

View File

@ -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;
}
}

View File

@ -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: