Added AdminSetspawnCommand

#441
This commit is contained in:
Florian CUNY 2019-01-04 21:33:17 +01:00
parent 85fac3112f
commit e3574e5ee3
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,51 @@
package world.bentobox.bentobox.api.commands.admin;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import java.util.List;
import java.util.Optional;
/**
* Admin command (only player) to set an island as the world's spawn.
* @author Poslovitch
* @since 1.1
*/
public class AdminSetspawnCommand extends ConfirmableCommand {
public AdminSetspawnCommand(CompositeCommand parent) {
super(parent, "setspawn");
}
@Override
public void setup() {
setPermission("admin.setspawn");
setOnlyPlayer(true);
setDescription("commands.admin.setspawn.description");
}
@Override
public boolean execute(User user, String label, List<String> args) {
Optional<Island> island = getIslands().getIslandAt(user.getLocation());
if (island.isPresent()) {
// Check if the island is already a spawn
if (island.map(Island::isSpawn).orElse(false)) {
user.sendMessage("commands.admin.setspawn.already-spawn");
return false;
}
// Everything's fine, we can set the island as spawn :)
askConfirmation(user, "commands.admin.setspawn.confirmation", () -> {
getIslands().setSpawn(island.get());
user.sendMessage("general.success");
});
return true;
} else {
user.sendMessage("commands.admin.setspawn.no-island-here");
return false;
}
}
}

View File

@ -154,6 +154,11 @@ commands:
description: "set a player's rank on their island"
unknown-rank: "&cUnknown rank!"
rank-set: "&aRank set from [from] to [to]."
setspawn:
description: "set an Island as spawn for this world"
already-spawn: "&cThis island is already a spawn!"
no-island-here: "&cThere is no island here."
confirmation: "&cAre you sure you want to set this Island as the spawn for this world?"
schem:
parameters: "<load/copy/paste/pos1/pos2/save>"
description: "manipulate schems"