text component: remove connection dependency, fix reconnecting possible after failing loading of version mapping

This commit is contained in:
Bixilon 2021-02-14 23:19:43 +01:00
parent 5d75930264
commit f5e1d94284
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
14 changed files with 226 additions and 282 deletions

View File

@ -24,7 +24,7 @@ class ComponentParser : CommandParser() {
@Throws(CommandParseException::class)
override fun parse(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader): Any? {
try {
return BaseComponent(connection.version, stringReader.readJson().asJsonObject)
return BaseComponent(connection.version.localeManager, stringReader.readJson().asJsonObject)
} catch (exception: Exception) {
stringReader.skip(-1)
throw InvalidComponentCommandParseException(stringReader, stringReader.read().toString(), exception)

View File

@ -81,11 +81,11 @@ public class Slot {
if (nbt.containsKey("display")) {
CompoundTag display = nbt.getCompoundTag("display");
if (display.containsKey("Name")) {
this.customDisplayName = ChatComponent.valueOf(this.version, display.getStringTag("Name").getValue());
this.customDisplayName = ChatComponent.valueOf(this.version.getLocaleManager(), display.getStringTag("Name").getValue());
}
if (display.containsKey("Lore")) {
for (StringTag lore : display.getListTag("Lore").<StringTag>getValue()) {
this.lore.add(ChatComponent.valueOf(this.version, lore.getValue()));
this.lore.add(ChatComponent.valueOf(this.version.getLocaleManager(), lore.getValue()));
}
}
}

View File

@ -1,239 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.mappings.versions;
import com.google.common.collect.HashBiMap;
import com.google.gson.JsonObject;
import de.bixilon.minosoft.Minosoft;
import de.bixilon.minosoft.config.ConfigurationPaths;
import de.bixilon.minosoft.data.Mappings;
import de.bixilon.minosoft.data.assets.AssetsManager;
import de.bixilon.minosoft.data.assets.Resources;
import de.bixilon.minosoft.data.locale.minecraft.MinecraftLocaleManager;
import de.bixilon.minosoft.protocol.protocol.ConnectionStates;
import de.bixilon.minosoft.protocol.protocol.Packets;
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
import de.bixilon.minosoft.util.CountUpAndDownLatch;
import de.bixilon.minosoft.util.Util;
import de.bixilon.minosoft.util.logging.Log;
import de.bixilon.minosoft.util.logging.LogLevels;
import javax.annotation.Nullable;
import java.util.HashMap;
public class Version {
private final int versionId;
private final int protocolId;
private final HashMap<ConnectionStates, HashBiMap<Packets.Serverbound, Integer>> serverboundPacketMapping;
private final HashMap<ConnectionStates, HashBiMap<Packets.Clientbound, Integer>> clientboundPacketMapping;
String versionName;
VersionMapping mapping;
boolean isGettingLoaded;
private AssetsManager assetsManager;
private MinecraftLocaleManager localeManager;
public Version(String versionName, int versionId, int protocolId, HashMap<ConnectionStates, HashBiMap<Packets.Serverbound, Integer>> serverboundPacketMapping, HashMap<ConnectionStates, HashBiMap<Packets.Clientbound, Integer>> clientboundPacketMapping) {
this.versionName = versionName;
this.versionId = versionId;
this.protocolId = protocolId;
this.serverboundPacketMapping = serverboundPacketMapping;
this.clientboundPacketMapping = clientboundPacketMapping;
}
public Packets.Clientbound getPacketByCommand(ConnectionStates state, int command) {
if (this.clientboundPacketMapping.containsKey(state) && this.clientboundPacketMapping.get(state).containsValue(command)) {
return this.clientboundPacketMapping.get(state).inverse().get(command);
}
return null;
}
public Integer getCommandByPacket(Packets.Serverbound packet) {
if (this.serverboundPacketMapping.containsKey(packet.getState()) && this.serverboundPacketMapping.get(packet.getState()).containsKey(packet)) {
return this.serverboundPacketMapping.get(packet.getState()).get(packet);
}
return null;
}
public HashMap<ConnectionStates, HashBiMap<Packets.Clientbound, Integer>> getClientboundPacketMapping() {
return this.clientboundPacketMapping;
}
public HashMap<ConnectionStates, HashBiMap<Packets.Serverbound, Integer>> getServerboundPacketMapping() {
return this.serverboundPacketMapping;
}
public VersionMapping getMapping() {
return this.mapping;
}
public void setMapping(VersionMapping mapping) {
this.mapping = mapping;
}
public boolean isGettingLoaded() {
return this.isGettingLoaded;
}
public void setGettingLoaded(boolean gettingLoaded) {
this.isGettingLoaded = gettingLoaded;
}
public boolean isFlattened() {
return this.versionId >= ProtocolDefinition.FLATTING_VERSION_ID;
}
public String getVersionName() {
return this.versionName;
}
public void setVersionName(String versionName) {
this.versionName = versionName;
}
public int getVersionId() {
return this.versionId;
}
@Override
public int hashCode() {
return getVersionId();
}
@Override
public boolean equals(Object obj) {
if (super.equals(obj)) {
return true;
}
if (obj == null) {
return false;
}
if (hashCode() != obj.hashCode()) {
return false;
}
return getVersionName().equals(this.versionName);
}
@Override
public String toString() {
return getVersionName();
}
public int getProtocolId() {
return this.protocolId;
}
public boolean isLoaded() {
return getMapping() != null && getMapping().isFullyLoaded();
}
public AssetsManager getAssetsManager() {
return this.assetsManager;
}
public void setAssetsManager(AssetsManager assetsManager) {
this.assetsManager = assetsManager;
}
public MinecraftLocaleManager getLocaleManager() {
return this.localeManager;
}
public void initializeAssetManger(CountUpAndDownLatch latch) throws Exception {
if (this.assetsManager != null) {
return;
}
if (!isFlattened() && getVersionId() != ProtocolDefinition.PRE_FLATTENING_VERSION_ID) {
this.assetsManager = Versions.PRE_FLATTENING_VERSION.getAssetsManager();
this.localeManager = Versions.PRE_FLATTENING_VERSION.getLocaleManager();
return;
}
this.assetsManager = new AssetsManager(Minosoft.getConfig().getBoolean(ConfigurationPaths.BooleanPaths.DEBUG_VERIFY_ASSETS), Resources.getAssetVersionByVersion(this));
this.assetsManager.downloadAllAssets(latch);
this.localeManager = new MinecraftLocaleManager(this);
this.localeManager.load(this, Minosoft.getConfig().getString(ConfigurationPaths.StringPaths.GENERAL_LANGUAGE));
}
public void load(CountUpAndDownLatch latch) throws Exception {
if (isLoaded()) {
// already loaded
return;
}
if (!isFlattened() && this != Versions.PRE_FLATTENING_VERSION && !Versions.PRE_FLATTENING_VERSION.isLoaded()) {
// no matter what, we need the version mapping for all pre flattening versions
Versions.PRE_FLATTENING_VERSION.load(latch);
}
if (isGettingLoaded()) {
// async: we don't wanna load this version twice, skip
return;
}
latch.countUp();
this.isGettingLoaded = true;
initializeAssetManger(latch);
Log.verbose(String.format("Loading mappings for version %s...", this));
long startTime = System.currentTimeMillis();
if (this.mapping == null) {
this.mapping = new VersionMapping(this);
}
if (getVersionId() == ProtocolDefinition.PRE_FLATTENING_VERSION_ID && Versions.PRE_FLATTENING_MAPPING == null) {
Versions.PRE_FLATTENING_MAPPING = this.mapping;
} else {
this.mapping.setParentMapping(Versions.PRE_FLATTENING_MAPPING);
}
HashMap<String, JsonObject> files;
try {
files = Util.readJsonTarStream(AssetsManager.readAssetAsStreamByHash(Resources.getAssetVersionByVersion(this).getMinosoftMappings()));
} catch (Exception e) {
// should not happen, but if this version is not flattened, we can fallback to the flatten mappings. Some things might not work...
Log.printException(e, LogLevels.VERBOSE);
if (isFlattened() || getVersionId() == ProtocolDefinition.FLATTING_VERSION_ID) {
throw e;
}
files = new HashMap<>();
}
latch.addCount(Mappings.VALUES.length);
for (Mappings mapping : Mappings.VALUES) {
JsonObject data = null;
if (files.containsKey(mapping.getFilename() + ".json")) {
data = files.get(mapping.getFilename() + ".json");
}
if (data == null) {
loadVersionMappings(mapping, ProtocolDefinition.DEFAULT_MOD, null);
latch.countDown();
continue;
}
for (String mod : data.keySet()) {
loadVersionMappings(mapping, mod, data.getAsJsonObject(mod));
}
latch.countDown();
}
if (!files.isEmpty()) {
Log.verbose(String.format("Loaded mappings for version %s in %dms (%s)", this, (System.currentTimeMillis() - startTime), getVersionName()));
} else {
Log.verbose(String.format("Could not load mappings for version %s. Some features will be unavailable.", this));
}
this.isGettingLoaded = false;
latch.countDown();
}
public void loadVersionMappings(Mappings type, String mod, @Nullable JsonObject data) {
this.mapping.load(type, mod, data, this);
}
}

View File

@ -0,0 +1,174 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.mappings.versions
import com.google.common.collect.HashBiMap
import com.google.gson.JsonObject
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.ConfigurationPaths
import de.bixilon.minosoft.data.Mappings
import de.bixilon.minosoft.data.assets.AssetsManager
import de.bixilon.minosoft.data.assets.Resources
import de.bixilon.minosoft.data.locale.minecraft.MinecraftLocaleManager
import de.bixilon.minosoft.protocol.protocol.ConnectionStates
import de.bixilon.minosoft.protocol.protocol.Packets.Clientbound
import de.bixilon.minosoft.protocol.protocol.Packets.Serverbound
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.CountUpAndDownLatch
import de.bixilon.minosoft.util.Util
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
data class Version(
var versionName: String,
val versionId: Int,
val protocolId: Int,
val serverboundPacketMapping: Map<ConnectionStates, HashBiMap<Serverbound, Int>>,
val clientboundPacketMapping: Map<ConnectionStates, HashBiMap<Clientbound, Int>>,
) {
var isLoaded = false
var isGettingLoaded = false
val mapping: VersionMapping = VersionMapping(this)
lateinit var assetsManager: AssetsManager
lateinit var localeManager: MinecraftLocaleManager
fun getPacketByCommand(state: ConnectionStates, command: Int): Clientbound? {
return clientboundPacketMapping[state]?.inverse()?.get(command)
}
fun getCommandByPacket(packet: Serverbound): Int? {
return serverboundPacketMapping[packet.state]?.get(packet)
}
fun isFlattened(): Boolean {
return versionId >= ProtocolDefinition.FLATTING_VERSION_ID
}
private fun initializeAssetManger(latch: CountUpAndDownLatch) {
if (this::assetsManager.isInitialized) {
return
}
if (!isFlattened() && versionId != ProtocolDefinition.PRE_FLATTENING_VERSION_ID) {
assetsManager = Versions.PRE_FLATTENING_VERSION.assetsManager
localeManager = Versions.PRE_FLATTENING_VERSION.localeManager
return
}
assetsManager = AssetsManager(Minosoft.getConfig().getBoolean(ConfigurationPaths.BooleanPaths.DEBUG_VERIFY_ASSETS), Resources.getAssetVersionByVersion(this))
assetsManager.downloadAllAssets(latch)
localeManager = MinecraftLocaleManager(this)
localeManager.load(this, Minosoft.getConfig().getString(ConfigurationPaths.StringPaths.GENERAL_LANGUAGE))
}
fun load(latch: CountUpAndDownLatch) {
if (isLoaded || isGettingLoaded) {
// already loaded or is getting loaded
return
}
if (!isFlattened() && this !== Versions.PRE_FLATTENING_VERSION && !Versions.PRE_FLATTENING_VERSION.isLoaded) {
// no matter what, we need the version mapping for all pre flattening versions
try {
Versions.PRE_FLATTENING_VERSION.load(latch)
} catch (exception: Exception) {
Versions.PRE_FLATTENING_VERSION.unload()
Versions.PRE_FLATTENING_MAPPING = null
throw exception
}
}
latch.countUp()
isGettingLoaded = true
Log.verbose(String.format("Loading mappings for version %s...", this))
initializeAssetManger(latch)
val startTime = System.currentTimeMillis()
if (versionId == ProtocolDefinition.PRE_FLATTENING_VERSION_ID) {
Versions.PRE_FLATTENING_MAPPING = mapping
} else {
mapping.parentMapping = Versions.PRE_FLATTENING_MAPPING
}
val files: Map<String, JsonObject> = try {
Util.readJsonTarStream(AssetsManager.readAssetAsStreamByHash(Resources.getAssetVersionByVersion(this).minosoftMappings))
} catch (e: Exception) {
// should not happen, but if this version is not flattened, we can fallback to the flatten mappings. Some things might not work...
Log.printException(e, LogLevels.VERBOSE)
if (isFlattened()) {
throw e
}
if (versionId == ProtocolDefinition.PRE_FLATTENING_VERSION_ID) {
Versions.PRE_FLATTENING_MAPPING = null
}
mapOf()
}
latch.addCount(Mappings.VALUES.size)
for (mapping in Mappings.VALUES) {
var data: JsonObject? = null
files[mapping.filename + ".json"]?.let {
data = it
}
if (data == null) {
loadVersionMappings(mapping, ProtocolDefinition.DEFAULT_MOD, null)
latch.countDown()
continue
}
for ((mod, json) in data!!.entrySet()) {
check(json is JsonObject) { "Invalid mod json" }
loadVersionMappings(mapping, mod, json)
}
latch.countDown()
}
if (files.isNotEmpty()) {
Log.verbose(String.format("Loaded mappings for version %s in %dms (%s)", this, (System.currentTimeMillis() - startTime), versionName))
} else {
Log.verbose(String.format("Could not load mappings for version %s. Some features will be unavailable.", this))
}
isGettingLoaded = false
latch.countDown()
}
private fun loadVersionMappings(type: Mappings, mod: String, data: JsonObject?) {
mapping.load(type, mod, data, this)
}
fun unload() {
mapping.unload()
if (mapping.parentMapping == mapping) {
mapping.parentMapping = null
}
isLoaded = false
isGettingLoaded = false
}
override fun hashCode(): Int {
return versionId
}
override fun equals(other: Any?): Boolean {
if (super.equals(other)) {
return true
}
if (other == null) {
return false
}
return if (hashCode() != other.hashCode()) {
false
} else {
versionName == versionName
}
}
override fun toString(): String {
return versionName
}
}

View File

@ -34,7 +34,7 @@ import javafx.util.Pair
import java.util.*
class VersionMapping(var version: Version) {
class VersionMapping(var version: Version?) {
private val availableFeatures = HashSet<Mappings>()
private val motiveIdMap = HashBiMap.create<Int, Motive>(30)
@ -79,7 +79,7 @@ class VersionMapping(var version: Version) {
}
fun getItem(itemId: Int): Item? {
return if (!version.isFlattened) {
return if (version!!.isFlattened()) {
getItem(itemId ushr 16, itemId and 0xFFFF)
} else {
getItemByIdIgnoreFlattened(itemId)
@ -325,15 +325,15 @@ class VersionMapping(var version: Version) {
val block = loadBlockState(ModIdentifier(mod, identifierName!!), statesJson)
var blockId = getBlockId(block.identifier)
if (this.version.isFlattened) {
if (this.version!!.isFlattened()) {
// map block id
blockId!!.blocks.add(block)
}
val blockNumericId = getBlockId(statesJson, !version.isFlattened)
val blockNumericId = getBlockId(statesJson, version.isFlattened())
if (StaticConfiguration.DEBUG_MODE) {
checkIfBlockIsIsPresent(blockNumericId, block.identifier, blockIdMap)
}
if (!version.isFlattened) {
if (!version.isFlattened()) {
// map block id
if (blockId == null) {
blockId = BlockId(block.identifier)

View File

@ -21,9 +21,10 @@ import de.bixilon.minosoft.protocol.protocol.Packets;
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
import java.util.HashMap;
import java.util.Map;
public class Versions {
public static final Version LOWEST_VERSION_SUPPORTED = new Version("Automatic", -1, -1, null, null);
public static final Version LOWEST_VERSION_SUPPORTED = new Version("Automatic", -1, -1, Map.of(), Map.of());
private static final HashBiMap<Integer, Version> VERSION_ID_MAP = HashBiMap.create(500);
private static final HashBiMap<Integer, Version> VERSION_PROTOCOL_ID_MAP = HashBiMap.create(500);
private static final HashBiMap<String, Version> VERSION_NAME_MAP = HashBiMap.create(500);
@ -57,8 +58,8 @@ public class Versions {
return VERSION_ID_MAP.get(versionId);
}
HashMap<ConnectionStates, HashBiMap<Packets.Serverbound, Integer>> serverboundPacketMapping;
HashMap<ConnectionStates, HashBiMap<Packets.Clientbound, Integer>> clientboundPacketMapping;
Map<ConnectionStates, HashBiMap<Packets.Serverbound, Integer>> serverboundPacketMapping;
Map<ConnectionStates, HashBiMap<Packets.Clientbound, Integer>> clientboundPacketMapping;
if (versionJson.get("mapping").isJsonPrimitive()) {
// inherits or copies mapping from an other version
Version parent = VERSION_ID_MAP.get(versionJson.get("mapping").getAsInt());

View File

@ -17,7 +17,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import de.bixilon.minosoft.data.mappings.versions.Version;
import de.bixilon.minosoft.data.locale.minecraft.MinecraftLocaleManager;
import de.bixilon.minosoft.gui.rendering.font.Font;
import de.bixilon.minosoft.gui.rendering.font.FontBindings;
import de.bixilon.minosoft.gui.rendering.hud.HUDScale;
@ -42,11 +42,11 @@ public class BaseComponent extends ChatComponent {
public BaseComponent() {
}
public BaseComponent(Version version, String text) {
this(version, null, text);
public BaseComponent(MinecraftLocaleManager localeManager, String text) {
this(localeManager, null, text);
}
public BaseComponent(Version version, @Nullable ChatComponent parent, String text) {
public BaseComponent(MinecraftLocaleManager localeManager, @Nullable ChatComponent parent, String text) {
// legacy String
StringBuilder currentText = new StringBuilder();
RGBColor color = ChatColors.WHITE;
@ -99,23 +99,23 @@ public class BaseComponent extends ChatComponent {
}
}
public BaseComponent(Version version, JsonObject json) {
this(version, null, json);
public BaseComponent(MinecraftLocaleManager localeManager, JsonObject json) {
this(localeManager, null, json);
}
@SuppressWarnings("unchecked")
public BaseComponent(Version version, @Nullable TextComponent parent, JsonElement data) {
public BaseComponent(MinecraftLocaleManager localeManager, @Nullable TextComponent parent, JsonElement data) {
MultiChatComponent thisTextComponent = null;
if (data instanceof JsonObject json) {
if (json.has("text")) {
String text = json.get("text").getAsString();
if (text.contains(String.valueOf(ProtocolDefinition.TEXT_COMPONENT_SPECIAL_PREFIX_CHAR))) {
// legacy text component
this.parts.add(new BaseComponent(version, text));
this.parts.add(new BaseComponent(localeManager, text));
return;
}
RGBColor color;
if (parent != null && parent.getColor() != null) {
if (parent != null) {
color = parent.getColor();
} else {
color = null;
@ -167,14 +167,14 @@ public class BaseComponent extends ChatComponent {
final TextComponent parentParameter = thisTextComponent == null ? parent : thisTextComponent;
if (json.has("extra")) {
JsonArray extras = json.getAsJsonArray("extra");
extras.forEach((extra -> this.parts.add(new BaseComponent(version, parentParameter, extra))));
extras.forEach((extra -> this.parts.add(new BaseComponent(localeManager, parentParameter, extra))));
}
if (json.has("translate")) {
this.parts.add(new BaseComponent(version, version.getLocaleManager().translate(json.get("translate").getAsString(), json.getAsJsonArray("with"))));
this.parts.add(new BaseComponent(localeManager, localeManager.translate(json.get("translate").getAsString(), json.getAsJsonArray("with"))));
}
} else if (data instanceof JsonPrimitive primitive) {
this.parts.add(new BaseComponent(version, parent, primitive.getAsString()));
this.parts.add(new BaseComponent(localeManager, parent, primitive.getAsString()));
}
}
@ -237,8 +237,8 @@ public class BaseComponent extends ChatComponent {
return this;
}
public BaseComponent append(Version version, String message) {
this.parts.add(new BaseComponent(version, message));
public BaseComponent append(MinecraftLocaleManager localeManager, String message) {
this.parts.add(new BaseComponent(localeManager, message));
return this;
}

View File

@ -17,7 +17,7 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import de.bixilon.minosoft.data.mappings.versions.Version;
import de.bixilon.minosoft.data.locale.minecraft.MinecraftLocaleManager;
import de.bixilon.minosoft.gui.rendering.font.Font;
import de.bixilon.minosoft.gui.rendering.font.FontBindings;
import de.bixilon.minosoft.gui.rendering.hud.HUDScale;
@ -35,11 +35,11 @@ public abstract class ChatComponent {
return valueOf(null, null, raw);
}
public static ChatComponent valueOf(Version version, Object raw) {
return valueOf(version, null, raw);
public static ChatComponent valueOf(MinecraftLocaleManager localeManager, Object raw) {
return valueOf(localeManager, null, raw);
}
public static ChatComponent valueOf(Version version, @Nullable TextComponent parent, Object raw) {
public static ChatComponent valueOf(MinecraftLocaleManager localeManager, @Nullable TextComponent parent, Object raw) {
if (raw == null) {
return new BaseComponent();
}
@ -57,13 +57,13 @@ public abstract class ChatComponent {
try {
json = JsonParser.parseString((String) raw).getAsJsonObject();
} catch (JsonParseException | IllegalStateException ignored) {
return new BaseComponent(version, (String) raw);
return new BaseComponent(localeManager, (String) raw);
}
} else {
return new BaseComponent(version, parent, raw.toString());
return new BaseComponent(localeManager, parent, raw.toString());
// throw new IllegalArgumentException(String.format("%s is not a valid type here!", raw.getClass().getSimpleName()));
}
return new BaseComponent(version, parent, json);
return new BaseComponent(localeManager, parent, json);
}
/**

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.gui.main;
import com.google.common.collect.Sets;
import com.google.gson.JsonObject;
import de.bixilon.minosoft.Minosoft;
import de.bixilon.minosoft.data.mappings.versions.Version;
@ -24,13 +25,13 @@ import de.bixilon.minosoft.protocol.protocol.LANServerListener;
import de.bixilon.minosoft.util.ServerAddress;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Set;
public class Server {
private static int highestServerId;
private final int id;
private final ArrayList<Connection> connections = new ArrayList<>();
private final Set<Connection> connections = Sets.newConcurrentHashSet();
private ChatComponent name;
private ChatComponent addressName;
private String address;
@ -158,7 +159,7 @@ public class Server {
this.desiredVersion = versionId;
}
public ArrayList<Connection> getConnections() {
public Set<Connection> getConnections() {
return this.connections;
}

View File

@ -304,8 +304,8 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
}
// ToDo: show progress dialog
connection.connect(this.server.getLastPing().getAddress(), version, new CountUpAndDownLatch(1));
connection.registerEvent(new EventInvokerCallback<>(this::handleConnectionCallback));
connection.connect(this.server.getLastPing().getAddress(), version, new CountUpAndDownLatch(1));
}, "ConnectThread").start();
}
@ -346,7 +346,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
}
this.optionsConnect.setDisable(false);
this.optionsSessions.setDisable(false);
this.optionsSessions.setDisable(true);
});
}

View File

@ -147,6 +147,11 @@ public class Connection {
} catch (Exception e) {
Log.printException(e, LogLevels.DEBUG);
Log.fatal(String.format("Could not load version %s. This version seems to be unsupported!", version));
if (this.customMapping.getVersion() != null) {
this.customMapping.getVersion().getMapping().setParentMapping(null);
}
this.customMapping.setVersion(null);
version.unload();
this.lastException = new MappingsLoadingException("Mappings could not be loaded", e);
setConnectionState(ConnectionStates.FAILED_NO_RETRY);
}
@ -178,7 +183,9 @@ public class Connection {
public void disconnect() {
this.network.disconnect();
this.handleThread.interrupt();
if (this.handleThread != null) {
this.handleThread.interrupt();
}
}
public Player getPlayer() {

View File

@ -30,7 +30,7 @@ public class PacketStatusResponse extends ClientboundPacket {
@Override
public boolean read(InByteBuffer buffer) {
this.response = new ServerListPing(buffer.getConnection().getVersion(), buffer.readJSON());
this.response = new ServerListPing(null, buffer.readJSON());
return true;
}

View File

@ -14,7 +14,7 @@
package de.bixilon.minosoft.protocol.ping;
import com.google.gson.JsonObject;
import de.bixilon.minosoft.data.mappings.versions.Version;
import de.bixilon.minosoft.data.locale.minecraft.MinecraftLocaleManager;
import de.bixilon.minosoft.data.text.BaseComponent;
import de.bixilon.minosoft.data.text.ChatComponent;
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
@ -31,7 +31,7 @@ public class ServerListPing {
private final String serverBrand;
byte[] favicon;
public ServerListPing(Version version, JsonObject json) {
public ServerListPing(MinecraftLocaleManager localeManager, JsonObject json) {
int protocolId = json.getAsJsonObject("version").get("protocol").getAsInt();
if (protocolId == ProtocolDefinition.QUERY_PROTOCOL_VERSION_ID) {
// Server did not send us a version, trying 1.8
@ -49,7 +49,7 @@ public class ServerListPing {
if (json.get("description").isJsonPrimitive()) {
this.motd = ChatComponent.valueOf(json.get("description").getAsString());
} else {
this.motd = new BaseComponent(version, json.getAsJsonObject("description"));
this.motd = new BaseComponent(localeManager, json.getAsJsonObject("description"));
}
this.serverBrand = json.getAsJsonObject("version").get("name").getAsString();

View File

@ -206,7 +206,7 @@ public class InByteBuffer {
}
public ChatComponent readChatComponent() {
return ChatComponent.valueOf(this.connection.getVersion(), readString());
return ChatComponent.valueOf(this.connection.getVersion().getLocaleManager(), readString());
}
@IntRange(from = 0)