Skip to content

Commit

Permalink
Merge branch '1.18.2' into 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
thexaero committed Jul 23, 2024
2 parents c7c5a60 + f4c0e1d commit 460ae7c
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import xaero.pac.common.server.claims.IServerRegionClaims;
import xaero.pac.common.server.claims.player.api.IServerPlayerClaimInfoAPI;
import xaero.pac.common.server.claims.player.task.PlayerClaimReplaceSpreadoutTask;
import xaero.pac.common.server.expiration.ObjectManagerIOExpirableObject;
import xaero.pac.common.server.parties.party.IServerParty;
import xaero.pac.common.server.player.config.IPlayerConfig;

Expand All @@ -41,7 +42,7 @@
import java.util.UUID;
import java.util.stream.Stream;

public interface IServerPlayerClaimInfo<DC extends IPlayerDimensionClaims<?>> extends IServerPlayerClaimInfoAPI, IPlayerClaimInfo<DC> {
public interface IServerPlayerClaimInfo<DC extends IPlayerDimensionClaims<?>> extends IServerPlayerClaimInfoAPI, IPlayerClaimInfo<DC>, ObjectManagerIOExpirableObject {

//internal api

Expand Down Expand Up @@ -71,10 +72,8 @@ default Stream<Entry<ResourceLocation, IPlayerDimensionClaimsAPI>> getStream(){
}

public Stream<Entry<ResourceLocation, DC>> getFullStream();

public void registerActivity();

public long getConfirmedActivity();
public long getRegisteredActivity();

public boolean isReplacementInProgress();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public final class ServerPlayerClaimInfo extends PlayerClaimInfo<ServerPlayerCla
private IPlayerConfig playerConfig;
private boolean dirty;
protected boolean beenUsed;
private long confirmedActivity;
private boolean hasBeenActive;
private long registeredActivity;
private boolean replacementInProgress;
private final Deque<PlayerClaimReplaceSpreadoutTask> replaceTaskQueue;

Expand All @@ -62,7 +61,7 @@ public ServerPlayerClaimInfo(IPlayerConfig playerConfig, String username, UUID p
this.playerConfig = playerConfig;
this.replaceTaskQueue = replaceSpreadoutTasks;
if(manager.getExpirationHandler() != null)
confirmActivity(manager.getExpirationHandler().getServerInfo());
this.registeredActivity = manager.getExpirationHandler().getServerInfo().getTotalUseTime();
}

@Override
Expand Down Expand Up @@ -143,25 +142,19 @@ public Stream<Entry<ResourceLocation, PlayerDimensionClaims>> getFullStream(){
}

@Override
public void confirmActivity(ServerInfo serverInfo) {
confirmedActivity = serverInfo.getTotalUseTime();
hasBeenActive = false;
}

public void setConfirmedActivity(long lastActiveTime) {
this.confirmedActivity = lastActiveTime;
}

public boolean hasBeenActive() {
return hasBeenActive;
public void registerActivity(ServerInfo serverInfo) {
if(serverInfo.getTotalUseTime() < registeredActivity)
return;
registeredActivity = serverInfo.getTotalUseTime();
setDirty(true);
}

public void registerActivity() {
hasBeenActive = true;
public void setRegisteredActivity(long registeredActivity) {
this.registeredActivity = registeredActivity;
}

public long getConfirmedActivity() {
return confirmedActivity;
public long getRegisteredActivity() {
return registeredActivity;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected void onObjectLoad(ServerPlayerClaimInfo loadedObject) {
IPlayerConfig playerConfig = playerInfo.getConfig();
if(!Objects.equals(loadedObject.getPlayerId(), PlayerConfig.EXPIRED_CLAIM_UUID) && !Objects.equals(loadedObject.getPlayerId(), PlayerConfig.SERVER_CLAIM_UUID))
playerInfo.setPlayerUsername(loadedObject.getPlayerUsername());
playerInfo.setConfirmedActivity(loadedObject.getConfirmedActivity());
playerInfo.setRegisteredActivity(loadedObject.getRegisteredActivity());
loadedObject.getFullStream().forEach(
e -> {
ResourceLocation dim = e.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public CompoundTag serialize(ServerPlayerClaimInfo object) {
object.getFullStream().forEach(e -> dimensions.put(e.getKey().toString(), playerDimensionClaimsNbtSerializer.serialize(e.getValue())));
nbt.put("dimensions", dimensions);
nbt.putString("username", object.getPlayerUsername());
nbt.putLong("confirmedActivity", object.getConfirmedActivity());
nbt.putLong("confirmedActivity", object.getRegisteredActivity());
return nbt;
}

Expand All @@ -57,7 +57,7 @@ public ServerPlayerClaimInfo deserialize(UUID id, ServerPlayerClaimInfoManager m
Map<ResourceLocation, PlayerDimensionClaims> claims = new HashMap<>();
dimensionsTag.getAllKeys().forEach(key -> claims.put(new ResourceLocation(key), playerDimensionClaimsNbtSerializer.deserialize(id, key, dimensionsTag.getCompound(key))));
ServerPlayerClaimInfo result = new ServerPlayerClaimInfo(manager.getConfig(id), username, id, claims, manager, new ArrayDeque<>());
result.setConfirmedActivity(nbt.getLong("confirmedActivity"));
result.setRegisteredActivity(nbt.getLong("confirmedActivity"));
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
import xaero.pac.common.server.io.ObjectManagerIOObject;

public interface ObjectManagerIOExpirableObject extends ObjectManagerIOObject {

public boolean hasBeenActive();

public void confirmActivity(ServerInfo serverInfo);
public void registerActivity(ServerInfo serverInfo);

public long getConfirmedActivity();
public long getRegisteredActivity();

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,14 @@ public void onTick(IServerData<IServerClaimsManager<IPlayerChunkClaim, IServerPl

expirationHandler.preExpirationCheck(object);

boolean hasBeenActive = object.hasBeenActive();//since last check
if(!hasBeenActive)
hasBeenActive = expirationHandler.checkIfActive(object);
if(object.getConfirmedActivity() > serverInfo.getTotalUseTime()) {//last active in the future!
OpenPartiesAndClaims.LOGGER.warn("Mod use time seems to have been reset! This could happen due to the data/server-info.nbt file corruption, with a backup being likely created. Defaulting to the time of a confirmed activity...");
serverInfo.setTotalUseTime(object.getConfirmedActivity());
if(object.getRegisteredActivity() > serverInfo.getTotalUseTime()) {//last active in the future!
OpenPartiesAndClaims.LOGGER.warn("Mod use time seems to have been reset! This could happen due to the data/server-info.nbt file corruption, with a backup being likely created. Defaulting to the time of a registered activity...");
serverInfo.setTotalUseTime(object.getRegisteredActivity());
serverData.getServerInfoIO().save();
}
if(hasBeenActive) {
object.confirmActivity(serverInfo);
object.setDirty(true);
} else if(serverInfo.getTotalUseTime() - object.getConfirmedActivity() > expirationTime) {
if(expirationHandler.checkIfActive(object))
object.registerActivity(serverInfo);
else if(serverInfo.getTotalUseTime() - object.getRegisteredActivity() > expirationTime) {
OpenPartiesAndClaims.LOGGER.debug("Object expired and is being removed: " + object);
expirationHandler.onElementExpirationBegin();
if(expirationHandler.expire(object, serverData)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import xaero.pac.common.parties.party.member.IPartyMember;
import xaero.pac.common.parties.party.member.PartyMemberRank;
import xaero.pac.common.parties.party.member.api.IPartyMemberAPI;
import xaero.pac.common.server.expiration.ObjectManagerIOExpirableObject;
import xaero.pac.common.server.info.ServerInfo;
import xaero.pac.common.server.parties.party.api.IServerPartyAPI;

import javax.annotation.Nonnull;
Expand All @@ -37,7 +39,7 @@ public interface IServerParty
M extends IPartyMember,
I extends IPartyPlayerInfo,
A extends IPartyAlly
> extends IServerPartyAPI, IParty<M, I, A> {
> extends IServerPartyAPI, IParty<M, I, A>, ObjectManagerIOExpirableObject {

//internal api

Expand Down Expand Up @@ -91,5 +93,5 @@ default Stream<IPartyAllyAPI> getAllyPartiesStream() {
default boolean setRank(@Nonnull IPartyMemberAPI member, @Nonnull PartyMemberRank rank) {
return setRankTyped((M)member, rank);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,26 @@
package xaero.pac.common.server.parties.party;

import net.minecraft.world.entity.player.Player;
import xaero.pac.common.claims.player.IPlayerChunkClaim;
import xaero.pac.common.claims.player.IPlayerClaimPosList;
import xaero.pac.common.claims.player.IPlayerDimensionClaims;
import xaero.pac.common.parties.party.IPartyPlayerInfo;
import xaero.pac.common.parties.party.ally.IPartyAlly;
import xaero.pac.common.parties.party.member.IPartyMember;
import xaero.pac.common.server.IServerData;
import xaero.pac.common.server.claims.IServerClaimsManager;
import xaero.pac.common.server.claims.IServerDimensionClaimsManager;
import xaero.pac.common.server.claims.IServerRegionClaims;
import xaero.pac.common.server.claims.player.IServerPlayerClaimInfo;

public final class PlayerLogInPartyAssigner {

public <
M extends IPartyMember,
I extends IPartyPlayerInfo,
A extends IPartyAlly
> void assign(IPartyManager<IServerParty<M,I,A>> partyManager, Player player, PartyPlayerInfoUpdater partyMemberInfoUpdater) {
IServerParty<M,I,?> playerParty = partyManager.getPartyByMember(player.getUUID());
public void assign(IServerData<IServerClaimsManager<IPlayerChunkClaim, IServerPlayerClaimInfo<IPlayerDimensionClaims<IPlayerClaimPosList>>, IServerDimensionClaimsManager<IServerRegionClaims>>, IServerParty<IPartyMember, IPartyPlayerInfo, IPartyAlly>>
serverData, Player player, PartyPlayerInfoUpdater partyMemberInfoUpdater) {
IServerParty<IPartyMember, IPartyPlayerInfo, IPartyAlly> playerParty = serverData.getPartyManager().getPartyByMember(player.getUUID());
if(playerParty != null) {
partyMemberInfoUpdater.update(playerParty, playerParty.getMemberInfo(player.getUUID()), player.getGameProfile());
((ServerParty) (Object)playerParty).registerActivity();
playerParty.registerActivity(serverData.getServerInfo());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public final class ServerParty extends Party implements IServerParty<PartyMember

private final PartyManager managedBy;
private boolean dirty;
private long confirmedActivity;
private boolean hasBeenActive;
private long registeredActivity;
private ServerParty nextInChain;
private ServerParty prevInChain;
private boolean destroyed;
Expand All @@ -59,7 +58,7 @@ protected ServerParty(PartyManager managedBy, PartyMember owner, UUID id, List<P
this.inviteByUsername = inviteByUsername;
this.allyByUsername = allyByUsername;
this.usernameByAlly = usernameByAlly;
confirmActivity(managedBy.getExpirationHandler().getServerInfo());
this.registeredActivity = managedBy.getExpirationHandler().getServerInfo().getTotalUseTime();
}

@Override
Expand Down Expand Up @@ -277,26 +276,20 @@ public Stream<ServerPlayer> getOnlineMemberStream() {
}

@Override
public void confirmActivity(ServerInfo serverInfo) {
confirmedActivity = serverInfo.getTotalUseTime();
hasBeenActive = false;
}

public void setConfirmedActivity(long lastActiveTime) {
this.confirmedActivity = lastActiveTime;
}

public boolean hasBeenActive() {
return hasBeenActive;
public void registerActivity(ServerInfo serverInfo) {
if(serverInfo.getTotalUseTime() < registeredActivity)
return;
registeredActivity = serverInfo.getTotalUseTime();
setDirty(true);
}

public void registerActivity() {
hasBeenActive = true;
public void setRegisteredActivity(long registeredActivity) {
this.registeredActivity = registeredActivity;
}

@Override
public long getConfirmedActivity() {
return confirmedActivity;
public long getRegisteredActivity() {
return registeredActivity;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public PartyNbtSerializer(PartyMemberNbtSerializer partyMemberNbtSerializer,
public CompoundTag serialize(ServerParty party) {
CompoundTag result = new CompoundTag();
result.put("owner", partyMemberNbtSerializer.serialize(party.getOwner()));
result.putLong("confirmedActivity", party.getConfirmedActivity());
result.putLong("confirmedActivity", party.getRegisteredActivity());
ListTag membersTag = new ListTag();
ListTag invitesTag = new ListTag();
ListTag alliesTag = new ListTag();
Expand All @@ -69,7 +69,7 @@ public CompoundTag serialize(ServerParty party) {
@Override
public ServerParty deserialize(String id, PartyManager manager, CompoundTag serializedData) {
PartyMember owner = partyMemberNbtSerializer.deserialize(serializedData.getCompound("owner"), true);
long confirmedActivity = serializedData.getLong("confirmedActivity");
long registeredActivity = serializedData.getLong("confirmedActivity");

ListTag membersTag = serializedData.getList("members", Tag.TAG_COMPOUND);
ListTag invitesTag = serializedData.getList("invites", Tag.TAG_COMPOUND);
Expand All @@ -91,7 +91,7 @@ public ServerParty deserialize(String id, PartyManager manager, CompoundTag seri
allies.put(ally, new PartyAlly(ally));
});
ServerParty result = ServerParty.Builder.begin().setManagedBy(manager).setOwner(owner).setId(UUID.fromString(id)).setMemberInfo(members).setInvitedPlayers(invites).setAllyParties(allies).build();
result.setConfirmedActivity(confirmedActivity);
result.setRegisteredActivity(registeredActivity);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class PartySnapshot implements GsonSnapshot {
private final List<PartyMemberSnapshot> members;
private final List<PartyInviteSnapshot> invitedPlayers;
private final List<String> allyParties;
private long confirmedActivity;
private long registeredActivity;

public PartySnapshot(PartyMemberSnapshot owner) {
super();
Expand Down Expand Up @@ -69,12 +69,12 @@ public PartyMemberSnapshot getOwner() {
return owner;
}

public void setConfirmedActivity(long confirmedActivity) {
this.confirmedActivity = confirmedActivity;
public void setRegisteredActivity(long registeredActivity) {
this.registeredActivity = registeredActivity;
}

public long getConfirmedActivity() {
return confirmedActivity;
public long getRegisteredActivity() {
return registeredActivity;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ public ServerParty convert(String id, PartyManager manager, PartySnapshot data)
allies.put(ally, new PartyAlly(ally));
});
ServerParty result = ServerParty.Builder.begin().setManagedBy(manager).setOwner(owner).setId(UUID.fromString(id)).setMemberInfo(members).setInvitedPlayers(invites).setAllyParties(allies).build();
result.setConfirmedActivity(data.getConfirmedActivity());
result.setRegisteredActivity(data.getRegisteredActivity());
return result;
}

@Override
public PartySnapshot convert(ServerParty party) {
PartySnapshot result = new PartySnapshot(partyMemberSnapshotConverter.convert(party.getOwner()));
result.setConfirmedActivity(party.getConfirmedActivity());
result.setRegisteredActivity(party.getRegisteredActivity());
party.getTypedInvitedPlayersStream().forEach(p -> result.addInvitedPlayer(partyInviteSnapshotConverter.convert(p)));
party.getTypedAllyPartiesStream().forEach(a -> result.addAllyParty(a.toString()));
party.getTypedMemberInfoStream().filter(mi -> mi != party.getOwner()).forEach(mi -> result.addMember(partyMemberSnapshotConverter.convert((PartyMember) mi)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void handlePreWorldJoin(ServerPlayer player, IServerData<IServerClaimsMan

serverData.getForceLoadManager().updateTicketsFor(serverData.getPlayerConfigs(), player.getUUID(), false);

serverData.getPlayerPartyAssigner().assign(serverData.getPartyManager(), player, serverData.getPartyMemberInfoUpdater());
serverData.getPlayerPartyAssigner().assign(serverData, player, serverData.getPartyMemberInfoUpdater());

PlayerFullPartySync playerFullPartySync = new PlayerFullPartySync((PartySynchronizer)(Object)serverData.getPartyManager().getPartySynchronizer());

Expand Down Expand Up @@ -97,7 +97,7 @@ public void handlePreWorldJoin(ServerPlayer player, IServerData<IServerClaimsMan
);
playerData.setOftenSyncedPartyMemberInfo(new PartyMemberDynamicInfoSyncable(player.getUUID(), true));

serverData.getServerClaimsManager().getPlayerInfo(player.getUUID()).registerActivity();
serverData.getServerClaimsManager().getPlayerInfo(player.getUUID()).registerActivity(serverData.getServerInfo());
}

public void handlePostWorldJoin(ServerPlayer player, IServerData<IServerClaimsManager<IPlayerChunkClaim, IServerPlayerClaimInfo<IPlayerDimensionClaims<IPlayerClaimPosList>>, IServerDimensionClaimsManager<IServerRegionClaims>>, IServerParty<IPartyMember, IPartyPlayerInfo, IPartyAlly>> serverData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@
import xaero.pac.common.server.claims.IServerRegionClaims;
import xaero.pac.common.server.claims.player.IServerPlayerClaimInfo;
import xaero.pac.common.server.parties.party.IServerParty;
import xaero.pac.common.server.parties.party.ServerParty;
import xaero.pac.common.server.parties.party.sync.IPartyMemberDynamicInfoSynchronizer;

public class PlayerLogoutHandler {

public void handle(ServerPlayer player, IServerData<IServerClaimsManager<IPlayerChunkClaim, IServerPlayerClaimInfo<IPlayerDimensionClaims<IPlayerClaimPosList>>, IServerDimensionClaimsManager<IServerRegionClaims>>, IServerParty<IPartyMember, IPartyPlayerInfo, IPartyAlly>> serverData) {
public void handle(ServerPlayer player, IServerData<IServerClaimsManager<IPlayerChunkClaim, IServerPlayerClaimInfo<IPlayerDimensionClaims<IPlayerClaimPosList>>, IServerDimensionClaimsManager<IServerRegionClaims>>, IServerParty<IPartyMember, IPartyPlayerInfo, IPartyAlly>>
serverData) {
serverData.getForceLoadManager().updateTicketsFor(serverData.getPlayerConfigs(), player.getUUID(), true);
//PlayerMainCapability playerMainCap = (PlayerMainCapability) player.getCapability(PlayerCapabilityProvider.MAIN_CAP).orElse(null);
IServerParty<IPartyMember, IPartyPlayerInfo, IPartyAlly> playerParty = serverData.getPartyManager().getPartyByMember(player.getUUID());
if(playerParty != null) {
((ServerParty)(Object)playerParty).registerActivity();
playerParty.registerActivity(serverData.getServerInfo());
IPartyMemberDynamicInfoSynchronizer<IServerParty<IPartyMember, IPartyPlayerInfo, IPartyAlly>> partyOftenSyncedSync = serverData.getPartyManager().getPartySynchronizer().getOftenSyncedInfoSync();
partyOftenSyncedSync.handlePlayerLeave(playerParty, player);
}
if(serverData.getServerClaimsManager().hasPlayerInfo(player.getUUID())) {
serverData.getServerClaimsManager().getPlayerInfo(player.getUUID()).registerActivity();
serverData.getServerClaimsManager().getPlayerInfo(player.getUUID()).registerActivity(serverData.getServerInfo());
}

serverData.getServerTickHandler().getLazyPacketSender().clearForPlayer(player);
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Project
version=0.23.1
version=0.23.2
group=xaero.pac

# Common
Expand Down

0 comments on commit 460ae7c

Please sign in to comment.