Fix data stored on join being lost on Bungee

Bungee doesn't resend a join game for old servers, so we will have to keep data stored there across server switches
This likely fixes other issues with chunk data writing after server switches on legacy servers as well
This commit is contained in:
Nassim Jahnke 2022-05-19 12:30:21 +02:00
parent 854ecf0b47
commit 9aa7f5e879
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
6 changed files with 43 additions and 8 deletions

View File

@ -29,4 +29,13 @@ package com.viaversion.viaversion.api.connection;
* @see UserConnection#put(StorableObject)
*/
public interface StorableObject {
/**
* Returns whether the object should be uncached on a server switch.
*
* @return whether the object should be uncached on a server switch
*/
default boolean clearOnServerSwitch() {
return true;
}
}

View File

@ -92,6 +92,7 @@ public interface UserConnection {
/**
* Adds an entity tracker to the user connection.
* Does not override existing entity trackers.
*
* @param protocolClass protocol class
* @param tracker entity tracker
@ -100,9 +101,18 @@ public interface UserConnection {
/**
* Clear stored objects and entity trackers.
* Used for Bungee when switching servers.
*/
void clearStoredObjects();
default void clearStoredObjects() {
clearStoredObjects(false);
}
/**
* Clear stored objects and entity trackers.
* If cleared for a proxy server switch, some stored objects and tracker data will be retained.
*
* @param isServerSwitch whether the clear is due to a server switch
*/
void clearStoredObjects(boolean isServerSwitch);
/**
* Sends a raw packet to the connection on the current thread.

View File

@ -184,7 +184,7 @@ public class BungeeServerHandler implements Listener {
// Refresh the pipes
List<ProtocolPathEntry> protocolPath = Via.getManager().getProtocolManager().getProtocolPath(info.getProtocolVersion(), protocolId);
ProtocolPipeline pipeline = user.getProtocolInfo().getPipeline();
user.clearStoredObjects();
user.clearStoredObjects(true);
pipeline.cleanPipes();
if (protocolPath == null) {
// TODO Check Bungee Supported Protocols? *shrugs*

View File

@ -115,13 +115,22 @@ public class UserConnectionImpl implements UserConnection {
@Override
public void addEntityTracker(Class<? extends Protocol> protocolClass, EntityTracker tracker) {
entityTrackers.put(protocolClass, tracker);
if (!entityTrackers.containsKey(protocolClass)) {
entityTrackers.put(protocolClass, tracker);
}
}
@Override
public void clearStoredObjects() {
storedObjects.clear();
entityTrackers.clear();
public void clearStoredObjects(boolean isServerSwitch) {
if (isServerSwitch) {
storedObjects.values().removeIf(StorableObject::clearOnServerSwitch);
for (EntityTracker tracker : entityTrackers.values()) {
tracker.clearEntities();
}
} else {
storedObjects.clear();
entityTrackers.clear();
}
}
@Override

View File

@ -287,7 +287,9 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPack
@Override
public void init(final UserConnection user) {
user.put(new SequenceStorage());
user.put(new DimensionRegistryStorage());
if (!user.has(DimensionRegistryStorage.class)) {
user.put(new DimensionRegistryStorage());
}
addEntityTracker(user, new EntityTrackerBase(user, Entity1_19Types.PLAYER));
}

View File

@ -34,4 +34,9 @@ public final class DimensionRegistryStorage implements StorableObject {
public void setDimensions(final Map<CompoundTag, String> dimensions) {
this.dimensions = dimensions;
}
@Override
public boolean clearOnServerSwitch() {
return false;
}
}