Added coop removal when all island members log out.

Needs to be tested.
This commit is contained in:
tastybento 2018-12-09 22:54:37 -08:00
parent 3e07554d3b
commit 3dd7126ca9
3 changed files with 28 additions and 1 deletions

View File

@ -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);
}
}

View File

@ -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());
}
}

View File

@ -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: "<player>"