Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 84 additions & 58 deletions Common/src/main/java/journeymap_webmap/WebMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,25 @@ public class WebMap
private Javalin app = null;
private static WebMap INSTANCE;

public WebMap(Javalin app)
{
this.app = app;
}

public static WebMap getInstance()
{
if (INSTANCE == null)
{
INSTANCE = new WebMap();
INSTANCE = new WebMap(null);
}
return INSTANCE;
}

public static WebMap getInstance(Javalin app)
{
if (INSTANCE == null)
{
INSTANCE = new WebMap(app);
}
return INSTANCE;
}
Expand All @@ -44,77 +58,89 @@ public void start()
{
if (!started)
{
findPort(true);
initialise();
started = true;
logger.info("WebMap is now listening on port {}", port);
try
{
logger.info("starting webmap server");
findPort(true);
initialise();
started = true;
logger.info("WebMap is now listening on port {}", port);
}
catch (Exception e)
{
logger.error("Failed to start webmap server: ", e);
}
}
}

private void initialise()
{
try
{
app = Javalin.create(config -> {
String assetsRootProperty = System.getProperty("journeymap.webmap.assets_root", null);
File testFile = new File("../src/main/resources" + FileHandler.ASSETS_WEBMAP);

if (assetsRootProperty != null)
{
logger.info("Detected 'journeymap.webmap.assets_root' property, serving static files from: " + assetsRootProperty);
config.staticFiles.add(assetsRootProperty, Location.EXTERNAL);
}
else if (testFile.exists())
{
try
{
String assets = testFile.getCanonicalPath();
logger.info("Development environment detected, serving static files from the filesystem.: " + assets);
config.staticFiles.add(testFile.getCanonicalPath(), Location.EXTERNAL);
}
catch (IOException e)
{
logger.error("WebMap error finding local assets path", e);
}
}
else
{
File dir = new File(FileHandler.getMinecraftDirectory(), Constants.WEB_DIR);
if (dir.exists())
{
dir.delete();
}
if (!dir.exists())
if (app == null)
{
app = Javalin.create(config -> {
String assetsRootProperty = System.getProperty("journeymap.webmap.assets_root", null);
File testFile = new File("../src/main/resources" + FileHandler.ASSETS_WEBMAP);

if (assetsRootProperty != null)
{
logger.info("Attempting to copy web content to {}", new File(Constants.JOURNEYMAP_DIR, "web"));
boolean created = FileHandler.copyResources(dir, ResourceLocation.fromNamespaceAndPath(MOD_ID, "web"), "", false);
logger.info("Web content copied successfully: {}", created);
logger.info("Detected 'journeymap.webmap.assets_root' property, serving static files from: " + assetsRootProperty);
config.staticFiles.add(assetsRootProperty, Location.EXTERNAL);
}

if (dir.exists())
else if (testFile.exists())
{
logger.info("Loading web content from local: {}", dir.getPath());
config.staticFiles.add(dir.getPath(), Location.EXTERNAL);
try
{
String assets = testFile.getCanonicalPath();
logger.info("Development environment detected, serving static files from the filesystem.: " + assets);
config.staticFiles.add(testFile.getCanonicalPath(), Location.EXTERNAL);
}
catch (IOException e)
{
logger.error("WebMap error finding local assets path", e);
}
}
else
{
logger.info("Loading web content from jar: {}", FileHandler.ASSETS_WEBMAP);
config.staticFiles.add(FileHandler.ASSETS_WEBMAP, Location.CLASSPATH);
File dir = new File(FileHandler.getMinecraftDirectory(), Constants.WEB_DIR);
if (dir.exists())
{
dir.delete();
}
if (!dir.exists())
{
logger.info("Attempting to copy web content to {}", new File(Constants.JOURNEYMAP_DIR, "web"));
boolean created = FileHandler.copyResources(dir, ResourceLocation.fromNamespaceAndPath(MOD_ID, "web"), "", false);
logger.info("Web content copied successfully: {}", created);
}

if (dir.exists())
{
logger.info("Loading web content from local: {}", dir.getPath());
config.staticFiles.add(dir.getPath(), Location.EXTERNAL);
}
else
{
logger.info("Loading web content from jar: {}", FileHandler.ASSETS_WEBMAP);
config.staticFiles.add(FileHandler.ASSETS_WEBMAP, Location.CLASSPATH);
}
}
}
})
.before(ctx -> {
ctx.header("Access-Control-Allow-Origin", "*");
ctx.header("Cache-Control", "no-cache");
})
.get("/waypoint/{id}/icon", Waypoints::iconGet)
.get("/data/{type}", Data::dataGet)
.get("/logs", Log::logGet)
.get("/polygons", Polygons::polygonsGet)
.get("/resources", Resources::resourcesGet)
.get("/skin/{uuid}", Skin::skinGet)
.get("/status", Status::statusGet)
.get("/tiles/tile.png", Tiles::tilesGet);
})
.before(ctx -> {
ctx.header("Access-Control-Allow-Origin", "*");
ctx.header("Cache-Control", "no-cache");
})
.get("/waypoint/{id}/icon", Waypoints::iconGet)
.get("/data/{type}", Data::dataGet)
.get("/logs", Log::logGet)
.get("/polygons", Polygons::polygonsGet)
.get("/resources", Resources::resourcesGet)
.get("/skin/{uuid}", Skin::skinGet)
.get("/status", Status::statusGet)
.get("/tiles/tile.png", Tiles::tilesGet);
}

app.start(port);
}
catch (Exception e)
Expand Down
2 changes: 1 addition & 1 deletion Fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

plugins {
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'fabric-loom' version '1.10-SNAPSHOT'
id 'net.darkhax.curseforgegradle' version '1.+'
id 'io.github.juuxel.loom-quiltflower' version '1.8.0'
}
Expand Down
6 changes: 4 additions & 2 deletions NeoForge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ configurations.all {
dependencies {
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
implementation group: "info.journeymap", name: "journeymap-api-neoforge", version: "${project.journeymap_api_version}-${project.minecraft_version}-SNAPSHOT", changing: true
implementation group: 'io.javalin', name: 'javalin', version: project.javalin_version

implementation("io.javalin:javalin:${project.javalin_version}")
shade group: 'io.javalin', name: 'javalin', version: project.javalin_version
additionalRuntimeClasspath("io.javalin:javalin:${project.javalin_version}")

shade group: 'info.journeymap', name: 'webmap-client', version: project.journeymap_webmap_version, changing: true

//external libs shade
shade group: 'io.javalin', name: 'javalin', version: project.javalin_version
compileOnly project(":Common")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,105 @@
package journeymap_webmap;


import io.javalin.Javalin;
import io.javalin.http.staticfiles.Location;
import journeymap.client.io.FileHandler;
import journeymap_webmap.routes.Data;
import journeymap_webmap.routes.Log;
import journeymap_webmap.routes.Polygons;
import journeymap_webmap.routes.Resources;
import journeymap_webmap.routes.Skin;
import journeymap_webmap.routes.Status;
import journeymap_webmap.routes.Tiles;
import journeymap_webmap.routes.Waypoints;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;

import static journeymap.common.Journeymap.MOD_ID;

@Mod(Constants.MOD_ID)
public class JourneymapWebmapNeoForge
{
public static final Logger logger = LoggerFactory.getLogger("webmap");

public JourneymapWebmapNeoForge(IEventBus eventBus)
{
eventBus.addListener(this::clientSetupEvent);
}

private void clientSetupEvent(FMLClientSetupEvent event)
{
WebMap.getInstance(create());
}

private Javalin create()
{
return Javalin.create(config -> {
String assetsRootProperty = System.getProperty("journeymap.webmap.assets_root", null);
File testFile = new File("../src/main/resources" + FileHandler.ASSETS_WEBMAP);

if (assetsRootProperty != null)
{
logger.info("Detected 'journeymap.webmap.assets_root' property, serving static files from: " + assetsRootProperty);
config.staticFiles.add(assetsRootProperty, Location.EXTERNAL);
}
else if (testFile.exists())
{
try
{
String assets = testFile.getCanonicalPath();
logger.info("Development environment detected, serving static files from the filesystem.: " + assets);
config.staticFiles.add(testFile.getCanonicalPath(), Location.EXTERNAL);
}
catch (IOException e)
{
logger.error("WebMap error finding local assets path", e);
}
}
else
{
File dir = new File(FileHandler.getMinecraftDirectory(), journeymap.client.Constants.WEB_DIR);
if (dir.exists())
{
dir.delete();
}
if (!dir.exists())
{
logger.info("Attempting to copy web content to {}", new File(journeymap.client.Constants.JOURNEYMAP_DIR, "web"));
boolean created = FileHandler.copyResources(dir, ResourceLocation.fromNamespaceAndPath(MOD_ID, "web"), "", false);
logger.info("Web content copied successfully: {}", created);
}

if (dir.exists())
{
logger.info("Loading web content from local: {}", dir.getPath());
config.staticFiles.add(dir.getPath(), Location.EXTERNAL);
}
else
{
logger.info("Loading web content from jar: {}", FileHandler.ASSETS_WEBMAP);
config.staticFiles.add(FileHandler.ASSETS_WEBMAP, Location.CLASSPATH);
}
}
})
.before(ctx -> {
ctx.header("Access-Control-Allow-Origin", "*");
ctx.header("Cache-Control", "no-cache");
})
.get("/waypoint/{id}/icon", Waypoints::iconGet)
.get("/data/{type}", Data::dataGet)
.get("/logs", Log::logGet)
.get("/polygons", Polygons::polygonsGet)
.get("/resources", Resources::resourcesGet)
.get("/skin/{uuid}", Skin::skinGet)
.get("/status", Status::statusGet)
.get("/tiles/tile.png", Tiles::tilesGet);
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading