Skip to content

Commit

Permalink
Potential fix for players not converted properly (#1513)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Dec 22, 2022
1 parent 69ea7f9 commit abff691
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
Expand Up @@ -83,14 +83,20 @@ public PlayersListener(SuperiorSkyblockPlugin plugin) {

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
private void onPlayerLogin(PlayerLoginEvent e) {
SuperiorPlayer superiorPlayer = plugin.getPlayers().getSuperiorPlayer(e.getPlayer());
List<SuperiorPlayer> duplicatedPlayers = plugin.getPlayers().matchAllPlayers(_superiorPlayer ->
_superiorPlayer != superiorPlayer && _superiorPlayer.getName().equalsIgnoreCase(e.getPlayer().getName()));
List<SuperiorPlayer> duplicatedPlayers = plugin.getPlayers().matchAllPlayers(superiorPlayer ->
superiorPlayer.getName().equalsIgnoreCase(e.getPlayer().getName()));

if (!duplicatedPlayers.isEmpty()) {
Log.info("Changing UUID of " + superiorPlayer.getName() + " to " + superiorPlayer.getUniqueId());
for (SuperiorPlayer duplicatePlayer : duplicatedPlayers) {
plugin.getPlayers().replacePlayers(duplicatePlayer, superiorPlayer);
}
Log.info("Changing UUID of " + e.getPlayer().getName() + " to " + e.getPlayer().getUniqueId());

// We first want to remove all original players.
duplicatedPlayers.forEach(plugin.getPlayers().getPlayersContainer()::removePlayer);

// We now want to create the new player.
SuperiorPlayer newPlayer = plugin.getPlayers().getSuperiorPlayer(e.getPlayer());

// We now want to replace all existing players
duplicatedPlayers.forEach(originalPlayer -> plugin.getPlayers().replacePlayers(originalPlayer, newPlayer));
}
}

Expand Down
Expand Up @@ -138,12 +138,17 @@ public List<SuperiorPlayer> matchAllPlayers(Predicate<? super SuperiorPlayer> pr
public void replacePlayers(SuperiorPlayer originPlayer, SuperiorPlayer newPlayer) {
Log.debug(Debug.REPLACE_PLAYER, originPlayer.getName(), newPlayer.getName());

this.playersContainer.removePlayer(originPlayer);

newPlayer.merge(originPlayer);

for (Island island : plugin.getGrid().getIslands())
island.replacePlayers(originPlayer, newPlayer);
// We first want to replace the player for his own island
Island playerIsland = originPlayer.getIsland();
if (playerIsland != null)
playerIsland.replacePlayers(originPlayer, newPlayer);

for (Island island : plugin.getGrid().getIslands()) {
if (island != playerIsland)
island.replacePlayers(originPlayer, newPlayer);
}

plugin.getEventsBus().callPlayerReplaceEvent(originPlayer, newPlayer);
}
Expand Down

0 comments on commit abff691

Please sign in to comment.