Adds admin command to reset all island flags to default

Used when an admin wants to change the default flag settings for all
islands and reset every one in the world.
This commit is contained in:
tastybento 2019-02-16 22:31:46 -08:00
parent af6ec400d1
commit 063303ad0e
4 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,37 @@
package world.bentobox.bentobox.api.commands.admin;
import java.util.List;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.user.User;
/**
* Admin command to reset all islands in a world to the default flag setting in the game mode config.yml
* @author tastybento
* @since 1.3.0
*/
public class AdminResetFlagsCommand extends ConfirmableCommand {
public AdminResetFlagsCommand(CompositeCommand parent) {
super(parent, "resetflags");
}
@Override
public void setup() {
setPermission("admin.resetflags");
setOnlyPlayer(false);
setDescription("commands.admin.resetflags.description");
}
@Override
public boolean execute(User user, String label, List<String> args) {
// Everything's fine, we can set the island as spawn :)
askConfirmation(user, () -> {
getIslands().resetAllFlags(getWorld());
user.sendMessage("general.success");
});
return true;
}
}

View File

@ -940,4 +940,14 @@ public class IslandsManager {
public Optional<Island> getIslandById(String uniqueId) {
return Optional.ofNullable(islandCache.getIslandById(uniqueId));
}
/**
* Resets all flags to gamemode config.yml default
* @param world - world
* @since 1.3.0
*/
public void resetAllFlags(World world) {
islandCache.resetAllFlags(world);
this.saveAll();
}
}

View File

@ -22,6 +22,9 @@ import world.bentobox.bentobox.util.Util;
public class IslandCache {
@NonNull
private Map<@NonNull Location, @NonNull Island> islandsByLocation;
/**
* Map of all islands with island uniqueId as key
*/
@NonNull
private Map<@NonNull String, @NonNull Island> islandsById;
/**
@ -262,4 +265,14 @@ public class IslandCache {
public Island getIslandById(String uniqueId) {
return islandsById.get(uniqueId);
}
/**
* Resets all islands in this game mode to default flag settings
* @param world - world
* @since 1.3.0
*/
public void resetAllFlags(World world) {
World w = Util.getWorld(world);
islandsById.values().stream().filter(i -> i.getWorld().equals(w)).forEach(i -> i.setFlagsDefaults());
}
}

View File

@ -197,6 +197,8 @@ commands:
save:
parameters: "<schem name>"
description: "save the copied clipboard"
resetflags:
description: "Reset all islands to default flag settings in config.yml"
world:
description: "Manage world settings"
delete: