From 767bb934ca9a480aff42f7a09706a6189d60307c Mon Sep 17 00:00:00 2001 From: Seppe Volkaerts Date: Sat, 21 Oct 2023 00:26:34 +0200 Subject: [PATCH] Fix create portal error + fix standalone jar error when there are spaces in the path Signed-off-by: Seppe Volkaerts --- .../org/lanternpowered/terre/portals/Portals.kt | 15 +++++++++++---- .../lanternpowered/terre/impl/StandaloneMain.java | 10 +++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/portals/src/main/kotlin/org/lanternpowered/terre/portals/Portals.kt b/portals/src/main/kotlin/org/lanternpowered/terre/portals/Portals.kt index d5f5ff8..a3b07e1 100644 --- a/portals/src/main/kotlin/org/lanternpowered/terre/portals/Portals.kt +++ b/portals/src/main/kotlin/org/lanternpowered/terre/portals/Portals.kt @@ -102,6 +102,9 @@ object Portals { } } + private suspend fun portalExists(name: String) = + mutex.withLock { portalData.containsKey(name) } + /** * Creates a new portal with the given parameters. */ @@ -110,7 +113,7 @@ object Portals { ): PortalData { val data = PortalData(name, type, position, origin, destination) mutex.withLock { - check(portalData.containsKey(name)) { "The name '$name' is already used." } + check(!portalData.containsKey(name)) { "The name '$name' is already used." } portalData[name] = data val originServer = Proxy.servers[origin] if (originServer != null) @@ -161,7 +164,7 @@ object Portals { val destination = if (args.size > 2) { args[2] } else { - send("Please specify the destination of the portal".text()) + send("Please specify the destination of the portal.".text()) return@SimpleCommandExecutor } var position: Vec2f = player.position @@ -178,7 +181,7 @@ object Portals { "type" -> { val typeName = args.getOrNull(index++) if (typeName == null) { - send("No portal type specified".text()) + send("No portal type specified.".text()) return@SimpleCommandExecutor } type = PortalTypeRegistry[typeName] ?: run { @@ -196,7 +199,7 @@ object Portals { val x = args.getOrNull(index++) val y = args.getOrNull(index++) if (x == null || y == null) { - send("No position specified".text()) + send("No position specified.".text()) return@SimpleCommandExecutor } if (x.toFloatOrNull() == null || y.toFloatOrNull() == null) { @@ -207,6 +210,10 @@ object Portals { } } } + if (portalExists(name)) { + send("Portal name ".text() + name.text(color = Colors.Red) + " is already in use.".text()) + return@SimpleCommandExecutor + } createPortal(name, origin, destination, type, position) } "delete" -> { diff --git a/standalone/src/main/java/org/lanternpowered/terre/impl/StandaloneMain.java b/standalone/src/main/java/org/lanternpowered/terre/impl/StandaloneMain.java index d4bdb57..d1ac752 100644 --- a/standalone/src/main/java/org/lanternpowered/terre/impl/StandaloneMain.java +++ b/standalone/src/main/java/org/lanternpowered/terre/impl/StandaloneMain.java @@ -10,12 +10,12 @@ package org.lanternpowered.terre.impl; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; import java.nio.file.FileSystems; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.ArrayList; @@ -42,15 +42,15 @@ public static void main(final String... args) { if (!location.toString().endsWith(".jar")) throw new IllegalStateException("Not executed from a jar."); - final URI jarUri; + final Path jarPath; try { - jarUri = new URI("jar", location.toURI().toString(), null); - } catch (final URISyntaxException ex) { + jarPath = Paths.get(location.toURI()); + } catch (URISyntaxException ex) { throw new IllegalStateException(ex); } final var env = Map.of("create", "true"); final var urls = new ArrayList(); - try (final var fileSystem = FileSystems.newFileSystem(jarUri, env)) { + try (final var fileSystem = FileSystems.newFileSystem(jarPath, env)) { final var libsPath = fileSystem.getPath("libs"); final var outputLibsPath = Paths.get("libs"); Files.createDirectories(outputLibsPath);