mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-30 13:07:46 +01:00
Added /bsb range set <player> <range>
This commit is contained in:
parent
04db135f60
commit
90be5e5de6
@ -20,6 +20,7 @@ public class AdminRangeCommand extends CompositeCommand {
|
||||
setDescription("commands.admin.range.description");
|
||||
|
||||
new AdminRangeDisplayCommand(this);
|
||||
new AdminRangeSetCommand(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user