3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

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
Dieser Commit ist enthalten in:
Nassim Jahnke 2022-05-19 12:30:21 +02:00
Ursprung 854ecf0b47
Commit 9aa7f5e879
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
6 geänderte Dateien mit 43 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -29,4 +29,13 @@ package com.viaversion.viaversion.api.connection;
* @see UserConnection#put(StorableObject) * @see UserConnection#put(StorableObject)
*/ */
public interface 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;
}
} }

Datei anzeigen

@ -92,6 +92,7 @@ public interface UserConnection {
/** /**
* Adds an entity tracker to the user connection. * Adds an entity tracker to the user connection.
* Does not override existing entity trackers.
* *
* @param protocolClass protocol class * @param protocolClass protocol class
* @param tracker entity tracker * @param tracker entity tracker
@ -100,9 +101,18 @@ public interface UserConnection {
/** /**
* Clear stored objects and entity trackers. * 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. * Sends a raw packet to the connection on the current thread.

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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