Fix issue where old player objects were not cleaned up properly.

This is caused by an issue with the event order in Spigot (and Spigot derivatives), so the fix is rather hacky.
This commit is contained in:
Alexander Söderberg
2020-06-23 18:36:53 +02:00
parent f4724a3c87
commit 55cf34508a
5 changed files with 46 additions and 18 deletions

View File

@ -2917,7 +2917,7 @@ public class Plot {
*/
public void reEnter() {
TaskManager.runTaskLater(() -> {
for (PlotPlayer pp : Plot.this.getPlayersInPlot()) {
for (PlotPlayer<?> pp : Plot.this.getPlayersInPlot()) {
PlotListener.plotExit(pp, Plot.this);
PlotListener.plotEntry(pp, Plot.this);
}
@ -2925,18 +2925,19 @@ public class Plot {
}
public void debug(@NotNull final String message) {
final Collection<PlotPlayer<?>> players = PlotPlayer.getDebugModePlayersInPlot(this);
if (players.isEmpty()) {
return;
}
final String string = Captions.PLOT_DEBUG.getTranslated().replace("%plot%", this.toString())
.replace("%message%", message);
for (final PlotPlayer<?> player : players) {
if (isOwner(player.getUUID()) ||
Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_DEBUG_OTHER)) {
player.sendMessage(string);
try {
final Collection<PlotPlayer<?>> players = PlotPlayer.getDebugModePlayersInPlot(this);
if (players.isEmpty()) {
return;
}
}
final String string =
Captions.PLOT_DEBUG.getTranslated().replace("%plot%", this.toString()).replace("%message%", message);
for (final PlotPlayer<?> player : players) {
if (isOwner(player.getUUID()) || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_DEBUG_OTHER)) {
player.sendMessage(string);
}
}
} catch (final Exception ignored) {}
}
/**

View File

@ -30,6 +30,7 @@ import com.plotsquared.core.player.PlotPlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@ -55,6 +56,17 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
}
}
/**
* Remove a player from the player map
*
* @param uuid Player to remove
*/
public void removePlayer(@NotNull final UUID uuid) {
synchronized (playerLock) {
this.playerMap.remove(uuid);
}
}
/**
* Get the player from its UUID if it is stored in the player map.
*
@ -110,7 +122,7 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
}
}
@NotNull protected abstract P createPlayer(@NotNull final UUID uuid);
@NotNull public abstract P createPlayer(@NotNull final UUID uuid);
/**
* Get an an offline player object from the player's UUID
@ -134,7 +146,7 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
* @return Unmodifiable collection of players
*/
public Collection<P> getPlayers() {
return Collections.unmodifiableCollection(this.playerMap.values());
return Collections.unmodifiableCollection(new ArrayList<>(this.playerMap.values()));
}