Add an admin delete homes command
https://github.com/BentoBoxWorld/BentoBox/issues/1900 This admin command removes all homes from a specified island.
This commit is contained in:
parent
bf62f18de5
commit
17ac4f688a
|
@ -0,0 +1,78 @@
|
|||
package world.bentobox.bentobox.api.commands.admin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* Deletes all named homes from an island
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class AdminDeleteHomesCommand extends ConfirmableCommand {
|
||||
|
||||
public AdminDeleteHomesCommand(CompositeCommand parent) {
|
||||
super(parent, "deletehomes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("mod.deletehomes");
|
||||
setOnlyPlayer(false);
|
||||
setParametersHelp("commands.admin.deletehomes.parameters");
|
||||
setDescription("commands.admin.deletehomes.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecute(User user, String label, List<String> args) {
|
||||
if (args.size() != 1) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// Get target player
|
||||
UUID targetUUID = Util.getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
return false;
|
||||
}
|
||||
// Get island
|
||||
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
||||
if (island == null) {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
}
|
||||
// Confirm
|
||||
askConfirmation(user, user.getTranslation("commands.admin.deletehomes.warning"), () -> deleteHomes(user, targetUUID, island));
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean deleteHomes(User user, UUID targetUUID, Island island) {
|
||||
island.removeHomes();
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
if (args.isEmpty()) {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return Optional.empty();
|
||||
}
|
||||
List<String> options = new ArrayList<>(Util.getOnlinePlayerList(user));
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
}
|
|
@ -92,6 +92,8 @@ public abstract class DefaultAdminCommand extends CompositeCommand {
|
|||
new AdminSettingsCommand(this);
|
||||
// Location
|
||||
new AdminSetProtectionCenterCommand(this);
|
||||
// Delete homes
|
||||
new AdminDeleteHomesCommand(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1444,6 +1444,16 @@ public class Island implements DataObject, MetaDataAble {
|
|||
return getHomes().remove(name.toLowerCase()) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all homes from this island except the default home
|
||||
* @return true if any non-default homes removed
|
||||
* @since 1.20.0
|
||||
*/
|
||||
public boolean removeHomes() {
|
||||
setChanged();
|
||||
return getHomes().keySet().removeIf(k -> !k.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename a home
|
||||
* @param oldName - old name of home
|
||||
|
@ -1542,4 +1552,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -622,11 +622,11 @@ public class IslandsManager {
|
|||
return result;
|
||||
}
|
||||
|
||||
private void tryIsland(CompletableFuture<Location> result, Location islandLoc, @NonNull User user, String number) {
|
||||
private void tryIsland(CompletableFuture<Location> result, Location islandLoc, @NonNull User user, String name) {
|
||||
Util.getChunkAtAsync(islandLoc).thenRun(() -> {
|
||||
World w = islandLoc.getWorld();
|
||||
if (isSafeLocation(islandLoc)) {
|
||||
setHomeLocation(user, islandLoc, number);
|
||||
setHomeLocation(user, islandLoc, name);
|
||||
result.complete(islandLoc.clone().add(new Vector(0.5D,0,0.5D)));
|
||||
return;
|
||||
} else {
|
||||
|
@ -634,14 +634,14 @@ public class IslandsManager {
|
|||
// Try the default location
|
||||
Location dl = islandLoc.clone().add(new Vector(0.5D, 5D, 2.5D));
|
||||
if (isSafeLocation(dl)) {
|
||||
setHomeLocation(user, dl, number);
|
||||
setHomeLocation(user, dl, name);
|
||||
result.complete(dl);
|
||||
return;
|
||||
}
|
||||
// Try just above the bedrock
|
||||
dl = islandLoc.clone().add(new Vector(0.5D, 5D, 0.5D));
|
||||
if (isSafeLocation(dl)) {
|
||||
setHomeLocation(user, dl, number);
|
||||
setHomeLocation(user, dl, name);
|
||||
result.complete(dl);
|
||||
return;
|
||||
}
|
||||
|
@ -649,7 +649,7 @@ public class IslandsManager {
|
|||
for (int y = islandLoc.getBlockY(); y < w.getMaxHeight(); y++) {
|
||||
dl = new Location(w, islandLoc.getX() + 0.5D, y, islandLoc.getZ() + 0.5D);
|
||||
if (isSafeLocation(dl)) {
|
||||
setHomeLocation(user, dl, number);
|
||||
setHomeLocation(user, dl, name);
|
||||
result.complete(dl);
|
||||
return;
|
||||
}
|
||||
|
@ -869,6 +869,7 @@ public class IslandsManager {
|
|||
return getHomeLocation(island, name);
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
private void migrateHomes(@NonNull World world, @NonNull UUID uuid, String name, Island island) {
|
||||
Map<Location, Integer> homes = plugin
|
||||
.getPlayers()
|
||||
|
|
|
@ -391,6 +391,10 @@ commands:
|
|||
description: "deletes a player's island"
|
||||
cannot-delete-owner: "&c All island members have to be kicked from the island before deleting it."
|
||||
deleted-island: "&a Island at &e [xyz] &a has been successfully deleted."
|
||||
deletehomes:
|
||||
parameters: "<player>"
|
||||
description: "deletes all named homes from an island"
|
||||
warning: "&c All named homes will be deleted from the island!"
|
||||
why:
|
||||
parameters: "<player>"
|
||||
description: "toggle console protection debug reporting"
|
||||
|
|
Loading…
Reference in New Issue