diff --git a/src/main/java/world/bentobox/bentobox/database/objects/Island.java b/src/main/java/world/bentobox/bentobox/database/objects/Island.java index 94b7d6975..cf68acb7c 100644 --- a/src/main/java/world/bentobox/bentobox/database/objects/Island.java +++ b/src/main/java/world/bentobox/bentobox/database/objects/Island.java @@ -692,4 +692,12 @@ public class Island implements DataObject { public Location getSpawnPoint(Environment islandType) { return spawnPoint.get(islandType); } + + /** + * Removes all of a specified rank from the member list + * @param coopRank - rank value + */ + public void removeRank(Integer coopRank) { + members.values().removeIf(coopRank::equals); + } } \ No newline at end of file diff --git a/src/main/java/world/bentobox/bentobox/listeners/JoinLeaveListener.java b/src/main/java/world/bentobox/bentobox/listeners/JoinLeaveListener.java index 93b93d527..785d49a8f 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/JoinLeaveListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/JoinLeaveListener.java @@ -84,9 +84,27 @@ public class JoinLeaveListener implements Listener { @EventHandler(priority = EventPriority.NORMAL) public void onPlayerQuit(final PlayerQuitEvent event) { - // Remove any coop associations + // Remove any coops if all the island players have left + plugin.getIWM().getOverWorlds().forEach(w -> { + Island island = plugin.getIslands().getIsland(w, User.getInstance(event.getPlayer())); + // Are there any online players still for this island? + if (island != null && !plugin.getServer().getOnlinePlayers().stream() + .filter(p -> !event.getPlayer().equals(p)) + .anyMatch(p -> plugin.getIslands().getMembers(w, event.getPlayer().getUniqueId()).contains(p.getUniqueId()))) { + // No, there are no more players online on this island + // Tell players they are being removed + island.getMembers().entrySet().stream() + .filter(e -> e.getValue() == RanksManager.COOP_RANK) + .forEach(e -> User.getInstance(e.getKey()) + .sendMessage("island.team.uncoop.all-members-logged-off", TextVariables.NAME, plugin.getPlayers().getName(island.getOwner()))); + // Remove any coop players on this island + island.removeRank(RanksManager.COOP_RANK); + } + }); + // Remove any coop associations from the player logging out plugin.getIslands().clearRank(RanksManager.COOP_RANK, event.getPlayer().getUniqueId()); players.save(event.getPlayer().getUniqueId()); User.removePlayer(event.getPlayer()); + } } diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index ee29b6ab1..7bddde961 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -277,6 +277,7 @@ commands: cannot-uncoop-member: "&cYou cannot uncoop a team member!" player-not-cooped: "&cPlayer is not cooped!" you-are-no-longer-a-coop-member: "&cYou are no longer a coop member of [name]'s island" + all-members-logged-off: "&cAll island members logged off so you are no longer a coop member of [name]'s island" trust: description: "give a player trusted rank on your island" parameters: ""