fix duplicated version mappings loading

This commit is contained in:
Bixilon 2020-09-03 17:09:40 +02:00
parent fad06a58a1
commit da589cd6b4
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 21 additions and 4 deletions

View File

@ -25,6 +25,7 @@ public class Version {
final HashMap<ConnectionStates, HashBiMap<Packets.Serverbound, Integer>> serverboundPacketMapping; final HashMap<ConnectionStates, HashBiMap<Packets.Serverbound, Integer>> serverboundPacketMapping;
final HashMap<ConnectionStates, HashBiMap<Packets.Clientbound, Integer>> clientboundPacketMapping; final HashMap<ConnectionStates, HashBiMap<Packets.Clientbound, Integer>> clientboundPacketMapping;
VersionMapping mapping; VersionMapping mapping;
boolean isGettingLoaded;
public Version(String versionName, int protocolVersion, HashMap<ConnectionStates, HashBiMap<Packets.Serverbound, Integer>> serverboundPacketMapping, HashMap<ConnectionStates, HashBiMap<Packets.Clientbound, Integer>> clientboundPacketMapping) { public Version(String versionName, int protocolVersion, HashMap<ConnectionStates, HashBiMap<Packets.Serverbound, Integer>> serverboundPacketMapping, HashMap<ConnectionStates, HashBiMap<Packets.Clientbound, Integer>> clientboundPacketMapping) {
this.versionName = versionName; this.versionName = versionName;
@ -76,6 +77,15 @@ public class Version {
this.mapping = mapping; this.mapping = mapping;
} }
public boolean isGettingLoaded() {
return isGettingLoaded;
}
public void setGettingLoaded(boolean gettingLoaded) {
isGettingLoaded = gettingLoaded;
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (super.equals(obj)) { if (super.equals(obj)) {

View File

@ -134,6 +134,10 @@ public class Versions {
if (protocolId < ProtocolDefinition.FLATTING_VERSION_ID) { if (protocolId < ProtocolDefinition.FLATTING_VERSION_ID) {
version = versionMap.get(ProtocolDefinition.PRE_FLATTENING_VERSION_ID); version = versionMap.get(ProtocolDefinition.PRE_FLATTENING_VERSION_ID);
} }
if (version.isGettingLoaded()) {
return;
}
version.setGettingLoaded(true);
Log.verbose(String.format("Loading mappings for version %s...", version)); Log.verbose(String.format("Loading mappings for version %s...", version));
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
@ -161,7 +165,7 @@ public class Versions {
} }
Log.verbose(String.format("Loaded mappings for version %s in %dms (%s)", version, (System.currentTimeMillis() - startTime), version.getVersionName())); Log.verbose(String.format("Loaded mappings for version %s in %dms (%s)", version, (System.currentTimeMillis() - startTime), version.getVersionName()));
version.setGettingLoaded(false);
} }
public static void unloadUnnecessaryVersions(int necessary) { public static void unloadUnnecessaryVersions(int necessary) {

View File

@ -275,7 +275,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
} }
public void refresh() { public void refresh() {
Log.info(String.format("Refreshing server status (serverName=\"%s\", address=\"%s\"", server.getName(), server.getAddress())); Log.info(String.format("Refreshing server status (serverName=\"%s\", address=\"%s\")", server.getName(), server.getAddress()));
if (server.getLastPing() == null) { if (server.getLastPing() == null) {
// server was not pinged, don't even try, only costs memory and cpu // server was not pinged, don't even try, only costs memory and cpu
return; return;

View File

@ -207,11 +207,14 @@ public class Connection {
} }
public void setVersion(Version version) { public void setVersion(Version version) {
if (this.version == version) {
return;
}
this.version = version; this.version = version;
this.customMapping.setVersion(version); this.customMapping.setVersion(version);
try { try {
Versions.loadVersionMappings(version.getProtocolVersion()); Versions.loadVersionMappings(version.getProtocolVersion());
customMapping.setVersion(version);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
Log.fatal(String.format("Could not load mapping for %s. This version seems to be unsupported!", version)); Log.fatal(String.format("Could not load mapping for %s. This version seems to be unsupported!", version));

View File

@ -65,7 +65,7 @@ public class PacketHandler {
if (version == null) { if (version == null) {
Log.fatal(String.format("Server is running on unknown version or a invalid version was forced (version=%d, brand=\"%s\")", versionId, pkg.getResponse().getServerBrand())); Log.fatal(String.format("Server is running on unknown version or a invalid version was forced (version=%d, brand=\"%s\")", versionId, pkg.getResponse().getServerBrand()));
} else { } else {
connection.setVersion(version); connection.setVersion(version);
} }
Log.info(String.format("Status response received: %s/%s online. MotD: '%s'", pkg.getResponse().getPlayerOnline(), pkg.getResponse().getMaxPlayers(), pkg.getResponse().getMotd().getColoredMessage())); Log.info(String.format("Status response received: %s/%s online. MotD: '%s'", pkg.getResponse().getPlayerOnline(), pkg.getResponse().getMaxPlayers(), pkg.getResponse().getMotd().getColoredMessage()));
connection.handleCallbacks(pkg.getResponse()); connection.handleCallbacks(pkg.getResponse());