Added /bsb range set <player> <range>

This commit is contained in:
Florian CUNY 2018-07-19 12:22:01 +02:00
parent 04db135f60
commit 90be5e5de6
2 changed files with 74 additions and 0 deletions

View File

@ -20,6 +20,7 @@ public class AdminRangeCommand extends CompositeCommand {
setDescription("commands.admin.range.description"); setDescription("commands.admin.range.description");
new AdminRangeDisplayCommand(this); new AdminRangeDisplayCommand(this);
new AdminRangeSetCommand(this);
} }
@Override @Override

View File

@ -0,0 +1,73 @@
package us.tastybento.bskyblock.commands.admin.range;
import org.apache.commons.lang.StringUtils;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.localization.TextVariables;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island;
import java.util.List;
import java.util.UUID;
public class AdminRangeSetCommand extends CompositeCommand {
public AdminRangeSetCommand(CompositeCommand parent) {
super(parent, "set");
}
@Override
public void setup() {
setPermission("admin.range.set");
setParameters("commands.admin.range.set.parameters");
setDescription("commands.admin.range.set.description");
}
@Override
public boolean execute(User user, String label, List<String> args) {
if (args.size() != 2) {
// Show help
showHelp(this, user);
return false;
}
// Get target player
UUID targetUUID = getPlayers().getUUID(args.get(0));
if (targetUUID == null) {
user.sendMessage("general.errors.unknown-player");
return false;
}
if (!getPlugin().getIslands().hasIsland(getWorld(), targetUUID)) {
user.sendMessage("general.errors.player-has-no-island");
return false;
}
// Get new range
if (!StringUtils.isNumeric(args.get(1))) {
user.sendMessage("commands.admin.range.set.invalid-value.not-numeric", TextVariables.NUMBER, args.get(1));
return false;
}
int range = Integer.valueOf(args.get(1));
// Get island
Island island = getIslands().getIsland(getWorld(), targetUUID);
// Do some sanity checks to make sure the new protection range won't cause problems
if (range <= 1) {
user.sendMessage("commands.admin.range.set.invalid-value.too-low", TextVariables.NUMBER, args.get(1));
return false;
}
if (range >= island.getRange()) {
user.sendMessage("commands.admin.range.set.invalid-value.too-high", TextVariables.NUMBER, args.get(1));
return false;
}
if (range == island.getProtectionRange()) {
user.sendMessage("commands.admin.range.set.invalid-value.same-as-before", TextVariables.NUMBER, args.get(1));
return false;
}
// Well, now it can be applied without taking any risks !
island.setProtectionRange(range);
return true;
}
}