Skip to content

Commit

Permalink
Fix create portal error + fix standalone jar error when there are spa…
Browse files Browse the repository at this point in the history
…ces in the path

Signed-off-by: Seppe Volkaerts <[email protected]>
  • Loading branch information
Cybermaxke committed Oct 20, 2023
1 parent 8e9d1fa commit 767bb93
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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) {
Expand All @@ -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" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<URL>();
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);
Expand Down

0 comments on commit 767bb93

Please sign in to comment.