diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/ServerListController.kt b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/ServerListController.kt index 24438a103..e9d0c3663 100644 --- a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/ServerListController.kt +++ b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/ServerListController.kt @@ -40,7 +40,6 @@ import de.bixilon.minosoft.gui.eros.main.InfoPane import de.bixilon.minosoft.gui.eros.main.play.server.card.FaviconManager.saveFavicon import de.bixilon.minosoft.gui.eros.main.play.server.card.ServerCard import de.bixilon.minosoft.gui.eros.main.play.server.card.ServerCardController -import de.bixilon.minosoft.gui.eros.main.play.server.type.types.CustomServerType import de.bixilon.minosoft.gui.eros.main.play.server.type.types.ServerType import de.bixilon.minosoft.gui.eros.modding.invoker.JavaFXEventListener import de.bixilon.minosoft.gui.eros.util.JavaFXUtil @@ -282,20 +281,12 @@ class ServerListController : EmbeddedJavaFXController(), Refreshable { val actions: Array = arrayOf( Button("Delete").apply { - if (server !is ErosServer) { - isDisable = true - } + val type = serverType + isDisable = type.readOnly setOnAction { - SimpleErosConfirmationDialog(confirmButtonText = "minosoft:general.delete".toResourceLocation(), description = TranslatableComponents.EROS_DELETE_SERVER_CONFIRM_DESCRIPTION(serverCard.server.name, serverCard.server.address), onConfirm = { - val type = serverType - if (type !is CustomServerType) { - return@SimpleErosConfirmationDialog - } - type.servers.remove(server) - }).show() + SimpleErosConfirmationDialog(confirmButtonText = "minosoft:general.delete".toResourceLocation(), description = TranslatableComponents.EROS_DELETE_SERVER_CONFIRM_DESCRIPTION(serverCard.server.name, serverCard.server.address), onConfirm = { type.remove(server) }).show() } ctext = TranslatableComponents.GENERAL_DELETE - isDisable = serverType.readOnly }, Button("Edit").apply { if (server !is ErosServer) { @@ -402,13 +393,8 @@ class ServerListController : EmbeddedJavaFXController(), Refreshable { @FXML fun addServer() { - ServerModifyDialog(onUpdate = { name, address, forcedVersion, profiles, queryVersion -> - val type = serverType - if (type !is CustomServerType) { - return@ServerModifyDialog - } - type.servers += ErosServer(profile = ErosProfileManager.selected, name = ChatComponent.of(name), address = address, forcedVersion = forcedVersion, profiles = profiles.toMutableMap(), queryVersion = queryVersion) - }).show() + val type = serverType ?: return + ServerModifyDialog(onUpdate = type::add).show() } override fun refresh() { diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/type/types/CustomServerType.kt b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/type/types/CustomServerType.kt index 7357d4d32..9253a0e70 100644 --- a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/type/types/CustomServerType.kt +++ b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/type/types/CustomServerType.kt @@ -21,10 +21,13 @@ import de.bixilon.kutil.observer.list.ListObserver.Companion.observeList import de.bixilon.kutil.observer.list.ListObserver.Companion.observedList import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfile import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager +import de.bixilon.minosoft.config.profile.profiles.eros.server.entries.AbstractServer import de.bixilon.minosoft.config.profile.profiles.eros.server.entries.ErosServer import de.bixilon.minosoft.data.registries.identified.ResourceLocation +import de.bixilon.minosoft.data.text.ChatComponent import de.bixilon.minosoft.gui.eros.main.play.server.card.ServerCard import de.bixilon.minosoft.protocol.network.connection.status.StatusConnectionStates +import de.bixilon.minosoft.protocol.versions.Version import de.bixilon.minosoft.util.KUtil.toResourceLocation import org.kordamp.ikonli.Ikon import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid @@ -42,6 +45,7 @@ object CustomServerType : ServerType { ErosProfileManager::selected.observe(this, true) { profile -> servers.clear() servers += ErosProfileManager.selected.server.entries + this.profile = profile profile.server::entries.observeList(this) { if (profile !== this.profile) throw RemoveObserver() @@ -63,4 +67,13 @@ object CustomServerType : ServerType { } } } + + override fun remove(server: AbstractServer) { + profile?.server?.entries?.remove(server) + } + + override fun add(name: String, address: String, forcedVersion: Version?, profiles: Map, queryVersion: Boolean) { + val profile = this.profile ?: return + profile.server.entries += ErosServer(profile = profile, name = ChatComponent.of(name), address = address, forcedVersion = forcedVersion, profiles = profiles.toMutableMap(), queryVersion = queryVersion) + } } diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/type/types/LANServerType.kt b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/type/types/LANServerType.kt index 39970cfe1..3e1095db2 100644 --- a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/type/types/LANServerType.kt +++ b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/type/types/LANServerType.kt @@ -14,11 +14,13 @@ package de.bixilon.minosoft.gui.eros.main.play.server.type.types import de.bixilon.kutil.collections.CollectionUtil.synchronizedListOf +import de.bixilon.kutil.exception.Broken import de.bixilon.kutil.observer.list.ListObserver.Companion.observedList import de.bixilon.minosoft.config.profile.profiles.eros.server.entries.AbstractServer import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.gui.eros.main.play.server.card.ServerCard import de.bixilon.minosoft.protocol.protocol.LANServerListener +import de.bixilon.minosoft.protocol.versions.Version import de.bixilon.minosoft.util.KUtil.toResourceLocation import org.kordamp.ikonli.Ikon import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid @@ -34,4 +36,7 @@ object LANServerType : ServerType { override fun refresh(cards: List) { LANServerListener.clear() } + + override fun remove(server: AbstractServer) = Broken("read only?") + override fun add(name: String, address: String, forcedVersion: Version?, profiles: Map, queryVersion: Boolean) = Broken("read only") } diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/type/types/ServerType.kt b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/type/types/ServerType.kt index 0e6d48c9c..c08eae144 100644 --- a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/type/types/ServerType.kt +++ b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/type/types/ServerType.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 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. * @@ -15,7 +15,9 @@ package de.bixilon.minosoft.gui.eros.main.play.server.type.types import de.bixilon.minosoft.config.profile.profiles.eros.server.entries.AbstractServer import de.bixilon.minosoft.data.language.translate.Translatable +import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.gui.eros.main.play.server.card.ServerCard +import de.bixilon.minosoft.protocol.versions.Version import org.kordamp.ikonli.Ikon interface ServerType : Translatable { @@ -27,6 +29,9 @@ interface ServerType : Translatable { fun refresh(cards: List) + fun remove(server: AbstractServer) + fun add(name: String, address: String, forcedVersion: Version?, profiles: Map, queryVersion: Boolean) + companion object { val TYPES = setOf(