store UUID instead of whole Player object

This commit is contained in:
unurled 2024-04-27 20:50:53 +02:00
parent 50d0b9a1bf
commit 0fbaf8905e
Signed by: unurled
GPG key ID: FDBC9CBE1F82423F

View file

@ -32,7 +32,7 @@ public class ClientBuildManager extends Manager {
private final List<ClientBuild> builds = new ArrayList<>();
/** a map of players that have ClientBuild displayed */
private final Map<Player, List<String>> playerBlocks = new HashMap<>();
private final Map<UUID, List<String>> playerBlocks = new HashMap<>();
private final Map<UUID, Map<Location, BlockData>> temporaryBlocks = new HashMap<>();
private final Map<UUID, Map<Location, BlockData>> temporaryPreviousBlocks = new HashMap<>();
@ -65,10 +65,10 @@ public class ClientBuildManager extends Manager {
dh.set("sr.clientbuild." + build.getName(), json);
}
for (Entry<Player, List<String>> entry : playerBlocks.entrySet()) {
for (Entry<UUID, List<String>> entry : playerBlocks.entrySet()) {
for (String name : entry.getValue()) {
// save for player
dh.set(SR_PLAYERS_CLIENTBUILD + entry.getKey().getUniqueId() + "." + name, "true");
dh.set(SR_PLAYERS_CLIENTBUILD + entry.getKey() + "." + name, "true");
}
}
}
@ -111,7 +111,7 @@ public class ClientBuildManager extends Manager {
List<String> names = new ArrayList<>(dh.getKeysAll(SR_PLAYERS_CLIENTBUILD + p.getUniqueId()));
playerBlocks.put(p, names);
playerBlocks.put(p.getUniqueId(), names);
for (String name : names) {
ClientBuild build = getBuild(name);
@ -124,7 +124,7 @@ public class ClientBuildManager extends Manager {
@EventHandler
public void onPlayerQuit(@NotNull PlayerQuitEvent e) {
Player p = e.getPlayer();
List<String> names = playerBlocks.get(p);
List<String> names = playerBlocks.get(p.getUniqueId());
if (names == null) {
return;
}
@ -151,9 +151,9 @@ public class ClientBuildManager extends Manager {
dh.set(SR_PLAYERS_CLIENTBUILD + p.getUniqueId() + "." + name, "true");
}
playerBlocks.get(p).clear();
playerBlocks.get(p.getUniqueId()).clear();
playerBlocks.remove(p);
playerBlocks.remove(p.getUniqueId());
}
public List<String> getBuildNames() {
@ -188,18 +188,18 @@ public class ClientBuildManager extends Manager {
}
public List<String> getPlayerBuilds(Player p) {
return playerBlocks.get(p);
return playerBlocks.get(p.getUniqueId());
}
public void displayToPlayer(@NotNull Player p, @NotNull ClientBuild build) {
playerBlocks.get(p).add(build.getName());
playerBlocks.get(p.getUniqueId()).add(build.getName());
for (Entry<Location, BlockData> entry : build.getBlocks().entrySet()) {
p.sendBlockChange(entry.getKey(), entry.getValue());
}
}
public void removeDisplayFromPlayer(@NotNull Player p, @NotNull ClientBuild build) {
playerBlocks.get(p).remove(build.getName());
playerBlocks.get(p.getUniqueId()).remove(build.getName());
for (Entry<Location, BlockData> entry : build.getBlocks().entrySet()) {
p.sendBlockChange(entry.getKey(), entry.getKey().getBlock().getBlockData());
}