Skip to content

Commit

Permalink
Fix player data not being copied on respawn
Browse files Browse the repository at this point in the history
  • Loading branch information
pjon1 authored and sisby-folk committed Oct 11, 2024
1 parent 11b939c commit e0a2e86
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/folk/sisby/surveyor/PlayerSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static PlayerSummary of(UUID uuid, MinecraftServer server) {
}

SurveyorExploration exploration();
void copyExploration(PlayerSummary oldSummary);

String username();

Expand Down Expand Up @@ -100,6 +101,10 @@ public int viewDistance() {
return 0;
}

@Override
public void copyExploration(PlayerSummary oldSummary) {
}

public record OfflinePlayerExploration(Set<UUID> sharedPlayers, Map<RegistryKey<World>, Map<ChunkPos, BitSet>> terrain, Map<RegistryKey<World>, Map<RegistryKey<Structure>, LongSet>> structures, boolean personal) implements SurveyorExploration {
public static OfflinePlayerExploration ofMerged(Set<SurveyorExploration> explorations) {
Set<UUID> sharedPlayers = new HashSet<>();
Expand Down Expand Up @@ -134,6 +139,10 @@ public SurveyorExploration exploration() {
return null;
}

@Override
public void copyExploration(PlayerSummary oldSummary) {
}

@Override
public String username() {
return player.getGameProfile().getName();
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/folk/sisby/surveyor/SurveyorExploration.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ static SurveyorExploration ofShared(UUID player, MinecraftServer server) {

Set<UUID> sharedPlayers();

default void copyFrom(SurveyorExploration oldExploration) {
terrain().putAll(oldExploration.terrain());
structures().putAll(oldExploration.structures());
}

boolean personal();

default boolean exploredChunk(RegistryKey<World> worldKey, ChunkPos pos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e0a2e86

Please sign in to comment.