mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-23 08:57:39 +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
This commit is contained in:
parent
854ecf0b47
commit
9aa7f5e879
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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*
|
||||
|
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user