mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-24 03:35:11 +01:00
Handles setspawn better when a player owns the island
Island members were not being cleared from the island properly. It should be done via IslandManager and not directly on the island object because the island manager holds a number of ownership maps. Also the player needs to have their island home locations cleared. Further, any members of the island also need to be completely cleared from the island. Finally, as this is similar to unregistering the player from the island, the event should be fired so that any addons know the island is no longer owned and the owner no longer owns an island.
This commit is contained in:
parent
564f60bab3
commit
9a3d4bef03
@ -2,9 +2,16 @@ package world.bentobox.bentobox.api.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
|
||||
@ -38,14 +45,35 @@ public class AdminSetspawnCommand extends ConfirmableCommand {
|
||||
}
|
||||
|
||||
// Everything's fine, we can set the island as spawn :)
|
||||
askConfirmation(user, user.getTranslation("commands.admin.setspawn.confirmation"), () -> {
|
||||
getIslands().setSpawn(island.get());
|
||||
user.sendMessage("general.success");
|
||||
});
|
||||
askConfirmation(user, user.getTranslation("commands.admin.setspawn.confirmation"), () -> setSpawn(user, island.get()));
|
||||
return true;
|
||||
} else {
|
||||
user.sendMessage("commands.admin.setspawn.no-island-here");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void setSpawn(User user, Island i) {
|
||||
if (!i.getMembers().isEmpty()) {
|
||||
if (i.getOwner() != null) {
|
||||
// Fire event
|
||||
IslandBaseEvent event = IslandEvent.builder()
|
||||
.island(i)
|
||||
.location(i.getCenter())
|
||||
.reason(IslandEvent.Reason.UNREGISTERED)
|
||||
.involvedPlayer(i.getOwner())
|
||||
.admin(true)
|
||||
.build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
// If island is owned, then unregister the owner and any members
|
||||
new ImmutableSet.Builder<UUID>().addAll(i.getMembers().keySet()).build().forEach(m -> {
|
||||
getIslands().removePlayer(getWorld(), m);
|
||||
getPlayers().clearHomeLocations(getWorld(), m);
|
||||
});
|
||||
}
|
||||
getIslands().setSpawn(i);
|
||||
user.sendMessage("general.success");
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user