mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-23 11:15:24 +01:00
Added AdminResetsAddCommand and AdminResetsRemoveCommand
This commit is contained in:
parent
ac2f45ac8c
commit
a415a65e7e
@ -0,0 +1,50 @@
|
||||
package world.bentobox.bentobox.api.commands.admin.resets;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Poslovitch
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public class AdminResetsAddCommand extends CompositeCommand {
|
||||
|
||||
public AdminResetsAddCommand(AdminResetsCommand parent) {
|
||||
super(parent, "add");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.admin.resets.add.description");
|
||||
setParametersHelp("commands.admin.resets.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().setResets(getWorld(), target, getPlayers().getResets(getWorld(), target) + Integer.valueOf(args.get(1)));
|
||||
user.sendMessage("commands.admin.resets.add.success",
|
||||
TextVariables.NAME, args.get(0), TextVariables.NUMBER, args.get(1),
|
||||
"[total]", String.valueOf(getPlayers().getResets(getWorld(), target)));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -18,6 +18,8 @@ public class AdminResetsCommand extends CompositeCommand {
|
||||
|
||||
new AdminResetsSetCommand(this);
|
||||
new AdminResetsResetCommand(this);
|
||||
new AdminResetsAddCommand(this);
|
||||
new AdminResetsRemoveCommand(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,52 @@
|
||||
package world.bentobox.bentobox.api.commands.admin.resets;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Poslovitch
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public class AdminResetsRemoveCommand extends CompositeCommand {
|
||||
|
||||
public AdminResetsRemoveCommand(AdminResetsCommand parent) {
|
||||
super(parent, "remove");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.admin.resets.remove.description");
|
||||
setParametersHelp("commands.admin.resets.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 {
|
||||
// Make sure it cannot go under 0.
|
||||
int newResets = Math.max(getPlayers().getResets(getWorld(), target) - Integer.valueOf(args.get(1)), 0);
|
||||
getPlayers().setResets(getWorld(), target, newResets);
|
||||
user.sendMessage("commands.admin.resets.remove.success",
|
||||
TextVariables.NAME, args.get(0), TextVariables.NUMBER, args.get(1),
|
||||
"[total]", String.valueOf(newResets));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -60,6 +60,14 @@ commands:
|
||||
parameters: "<player>"
|
||||
success-everyone: "&aSuccessfully reset &beveryone&a's resets to &b0&a."
|
||||
success: "&aSuccessfully reset &b[name]&a's resets to &b0&a."
|
||||
add:
|
||||
description: "adds resets to the player"
|
||||
parameters: "<player> <resets>"
|
||||
success: "&aSuccessfully added &b[number] &aresets to &b[name], increasing the total to &b[total]&a resets."
|
||||
remove:
|
||||
description: "removes resets to the player"
|
||||
parameters: "<player> <resets>"
|
||||
success: "&aSuccessfully removed &b[number] &aresets to &b[name], decreasing the total to &b[total]&a resets."
|
||||
purge:
|
||||
parameters: "[days]"
|
||||
description: "purge islands abandoned for more than [days]"
|
||||
|
Loading…
Reference in New Issue
Block a user