mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-17 04:41:40 +01:00
Add AdminSetSpawnPointCommand to change an island's spawn point (#1295)
Implements #937.
This commit is contained in:
parent
ae63125f50
commit
40240c7225
@ -0,0 +1,94 @@
|
||||
package world.bentobox.bentobox.api.commands.admin;
|
||||
|
||||
|
||||
import org.bukkit.World;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* This command sets spawn point for island at admin location for island on which admin is located.
|
||||
* This command is only for player entity.
|
||||
* @author BONNe
|
||||
* @since 1.13.0
|
||||
*/
|
||||
public class AdminSetSpawnPointCommand extends ConfirmableCommand
|
||||
{
|
||||
/**
|
||||
* Sub-command constructor
|
||||
*
|
||||
* @param parent - the parent composite command
|
||||
*/
|
||||
public AdminSetSpawnPointCommand(CompositeCommand parent)
|
||||
{
|
||||
super(parent, "setspawnpoint");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setup()
|
||||
{
|
||||
this.setPermission("admin.setspawnpoint");
|
||||
this.setOnlyPlayer(true);
|
||||
this.setDescription("commands.admin.setspawnpoint.description");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method finds an island in user location and asks confirmation if spawn point
|
||||
* must be changed to that location.
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args)
|
||||
{
|
||||
Optional<Island> optionalIsland = this.getIslands().getIslandAt(user.getLocation());
|
||||
|
||||
if (optionalIsland.isPresent() &&
|
||||
(optionalIsland.get().hasNetherIsland() ||
|
||||
!World.Environment.NETHER.equals(user.getLocation().getWorld().getEnvironment())) &&
|
||||
(optionalIsland.get().hasEndIsland() ||
|
||||
!World.Environment.THE_END.equals(user.getLocation().getWorld().getEnvironment())))
|
||||
{
|
||||
// Everything's fine, we can set the location as spawn point for island :)
|
||||
this.askConfirmation(user, user.getTranslation("commands.admin.setspawnpoint.confirmation"),
|
||||
() -> this.setSpawnPoint(user, optionalIsland.get()));
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
user.sendMessage("commands.admin.setspawnpoint.no-island-here");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method changes spawn point for island at given user location.
|
||||
* @param user User who initiate spawn point change.
|
||||
* @param island Island which is targeted by user.
|
||||
*/
|
||||
private void setSpawnPoint(User user, Island island)
|
||||
{
|
||||
island.setSpawnPoint(Objects.requireNonNull(user.getLocation().getWorld()).getEnvironment(),
|
||||
user.getLocation());
|
||||
user.sendMessage("commands.admin.setspawnpoint.success");
|
||||
|
||||
if (!island.isSpawn())
|
||||
{
|
||||
island.getPlayersOnIsland().forEach(player ->
|
||||
User.getInstance(player).sendMessage("commands.admin.setspawnpoint.island-spawnpoint-changed",
|
||||
"[user]", user.getName()));
|
||||
}
|
||||
}
|
||||
}
|
@ -246,6 +246,12 @@ commands:
|
||||
no-island-here: "&c There is no island here."
|
||||
confirmation: "&c Are you sure you want to set this island as the spawn for this world?"
|
||||
success: "&a Successfully set this island as the spawn for this world."
|
||||
setspawnpoint:
|
||||
description: "set current location as spawn point for this island"
|
||||
no-island-here: "&c There is no island here."
|
||||
confirmation: "&c Are you sure you want to set this location as the spawn point for this island?"
|
||||
success: "&a Successfully set this location as the spawn point for this island."
|
||||
island-spawnpoint-changed: "&a [user] changed this island spawn point."
|
||||
settings:
|
||||
parameters: "[player]"
|
||||
description: "open system settings or island settings for player"
|
||||
|
Loading…
Reference in New Issue
Block a user