From e0a2e86835b31f4c36309bd4e8a7abd922acf1f8 Mon Sep 17 00:00:00 2001 From: pjon1 <10749401+pjon1@users.noreply.github.com> Date: Sun, 6 Oct 2024 01:10:30 +0200 Subject: [PATCH] Fix player data not being copied on respawn --- .../java/folk/sisby/surveyor/PlayerSummary.java | 14 ++++++++++++++ .../folk/sisby/surveyor/SurveyorExploration.java | 5 +++++ .../surveyor/mixin/MixinServerPlayerEntity.java | 5 +++++ 3 files changed, 24 insertions(+) diff --git a/src/main/java/folk/sisby/surveyor/PlayerSummary.java b/src/main/java/folk/sisby/surveyor/PlayerSummary.java index c66d53f..eb349e0 100644 --- a/src/main/java/folk/sisby/surveyor/PlayerSummary.java +++ b/src/main/java/folk/sisby/surveyor/PlayerSummary.java @@ -45,6 +45,7 @@ static PlayerSummary of(UUID uuid, MinecraftServer server) { } SurveyorExploration exploration(); + void copyExploration(PlayerSummary oldSummary); String username(); @@ -100,6 +101,10 @@ public int viewDistance() { return 0; } + @Override + public void copyExploration(PlayerSummary oldSummary) { + } + public record OfflinePlayerExploration(Set sharedPlayers, Map, Map> terrain, Map, Map, LongSet>> structures, boolean personal) implements SurveyorExploration { public static OfflinePlayerExploration ofMerged(Set explorations) { Set sharedPlayers = new HashSet<>(); @@ -134,6 +139,10 @@ public SurveyorExploration exploration() { return null; } + @Override + public void copyExploration(PlayerSummary oldSummary) { + } + @Override public String username() { return player.getGameProfile().getName(); @@ -179,6 +188,11 @@ public SurveyorExploration exploration() { return exploration; } + @Override + public void copyExploration(PlayerSummary oldSummary) { + exploration.copyFrom(((ServerPlayerEntitySummary) oldSummary).exploration); + } + @Override public int viewDistance() { return viewDistance; diff --git a/src/main/java/folk/sisby/surveyor/SurveyorExploration.java b/src/main/java/folk/sisby/surveyor/SurveyorExploration.java index d1357c0..7e47d0a 100644 --- a/src/main/java/folk/sisby/surveyor/SurveyorExploration.java +++ b/src/main/java/folk/sisby/surveyor/SurveyorExploration.java @@ -56,6 +56,11 @@ static SurveyorExploration ofShared(UUID player, MinecraftServer server) { Set sharedPlayers(); + default void copyFrom(SurveyorExploration oldExploration) { + terrain().putAll(oldExploration.terrain()); + structures().putAll(oldExploration.structures()); + } + boolean personal(); default boolean exploredChunk(RegistryKey worldKey, ChunkPos pos) { diff --git a/src/main/java/folk/sisby/surveyor/mixin/MixinServerPlayerEntity.java b/src/main/java/folk/sisby/surveyor/mixin/MixinServerPlayerEntity.java index 0eed8a5..3b89e60 100644 --- a/src/main/java/folk/sisby/surveyor/mixin/MixinServerPlayerEntity.java +++ b/src/main/java/folk/sisby/surveyor/mixin/MixinServerPlayerEntity.java @@ -61,6 +61,11 @@ public void onDeath(DamageSource damageSource, CallbackInfo ci) { ); } + @Inject(method = "copyFrom", at = @At("TAIL")) + public void copyFrom(MixinServerPlayerEntity oldPlayer, boolean alive, CallbackInfo ci) { + surveyor$summary.copyExploration(oldPlayer.surveyor$summary); + } + @Override public PlayerSummary surveyor$getSummary() { return surveyor$summary;