diff --git a/core/build.gradle b/core/build.gradle
index 86e6933c..e94fcd3a 100644
--- a/core/build.gradle
+++ b/core/build.gradle
@@ -3,6 +3,9 @@ description = "Core code shared by all versions"
dependencies {
implementation project(":smylib:core")
+ implementation 'org.apache.logging.log4j:log4j-api:2.8.1'
+ implementation 'com.google.code.gson:gson:2.11.0'
+ implementation 'javax.xml.bind:jaxb-api:2.3.1'
testImplementation project(":smylib:testing")
}
\ No newline at end of file
diff --git a/core/src/main/java/net/smyler/terramap/Terramap.java b/core/src/main/java/net/smyler/terramap/Terramap.java
new file mode 100644
index 00000000..3028d6d1
--- /dev/null
+++ b/core/src/main/java/net/smyler/terramap/Terramap.java
@@ -0,0 +1,31 @@
+package net.smyler.terramap;
+
+import com.google.gson.Gson;
+import net.smyler.terramap.http.HttpClient;
+import org.apache.logging.log4j.Logger;
+
+public interface Terramap {
+
+ static Terramap instance() {
+ return InstanceHolder.instance;
+ }
+
+ String MOD_ID = "terramap";
+
+ Logger logger();
+
+ HttpClient http();
+
+ Gson gson();
+
+ Gson gsonPretty();
+
+ class InstanceHolder {
+ private static Terramap instance;
+ public static void setInstance(Terramap instance) {
+ instance.logger().info("Setting Terramap instance of class {}", instance.getClass().getName());
+ InstanceHolder.instance = instance;
+ }
+ }
+
+}
diff --git a/core/src/main/java/net/smyler/terramap/TerramapResources.java b/core/src/main/java/net/smyler/terramap/TerramapResources.java
index 0743f911..d5dfdc99 100644
--- a/core/src/main/java/net/smyler/terramap/TerramapResources.java
+++ b/core/src/main/java/net/smyler/terramap/TerramapResources.java
@@ -4,8 +4,7 @@
public final class TerramapResources {
- public static final String MOD_ID = "terramap";
- public static final Identifier TEXTURES = new Identifier(MOD_ID, "textures");
+ public static final Identifier TEXTURES = new Identifier(Terramap.MOD_ID, "textures");
public static final Identifier GUI_TEXTURES = TEXTURES.resolve("gui");
public static final Identifier SPRITES = GUI_TEXTURES.resolve("sprites");
diff --git a/forge/src/main/java/fr/thesmyler/terramap/files/kml/KmlDocument.java b/core/src/main/java/net/smyler/terramap/files/kml/KmlDocument.java
similarity index 95%
rename from forge/src/main/java/fr/thesmyler/terramap/files/kml/KmlDocument.java
rename to core/src/main/java/net/smyler/terramap/files/kml/KmlDocument.java
index 2f483c7e..6278d744 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/files/kml/KmlDocument.java
+++ b/core/src/main/java/net/smyler/terramap/files/kml/KmlDocument.java
@@ -1,4 +1,4 @@
-package fr.thesmyler.terramap.files.kml;
+package net.smyler.terramap.files.kml;
import java.util.ArrayList;
import java.util.List;
diff --git a/forge/src/main/java/fr/thesmyler/terramap/files/kml/KmlFile.java b/core/src/main/java/net/smyler/terramap/files/kml/KmlFile.java
similarity index 67%
rename from forge/src/main/java/fr/thesmyler/terramap/files/kml/KmlFile.java
rename to core/src/main/java/net/smyler/terramap/files/kml/KmlFile.java
index f6c3602e..f8b347de 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/files/kml/KmlFile.java
+++ b/core/src/main/java/net/smyler/terramap/files/kml/KmlFile.java
@@ -1,9 +1,11 @@
-package fr.thesmyler.terramap.files.kml;
+package net.smyler.terramap.files.kml;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@@ -13,10 +15,8 @@
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
-import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
-import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
+import net.smyler.terramap.Terramap;
-import fr.thesmyler.terramap.TerramapMod;
@XmlRootElement(name="kml")
public class KmlFile {
@@ -39,19 +39,18 @@ public void save(File file, boolean compressed) throws IOException {
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
try(OutputStream stream = Files.newOutputStream(file.toPath())) {
if(compressed) {
- try(ZipArchiveOutputStream compressedStream = new ZipArchiveOutputStream(stream)) {
- ZipArchiveEntry entry = new ZipArchiveEntry("terramap.kml");
- compressedStream.putArchiveEntry(entry);
+ try(ZipOutputStream compressedStream = new ZipOutputStream(stream)) {
+ ZipEntry entry = new ZipEntry("terramap.kml");
+ compressedStream.putNextEntry(entry);
marshaller.marshal(this, compressedStream);
- compressedStream.closeArchiveEntry();
}
} else {
marshaller.marshal(this, stream);
}
}
} catch(JAXBException e) {
- TerramapMod.logger.error("Something went seriously wrong when saving a kml file. Save aborted.");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Something went seriously wrong when saving a kml file. Save aborted.");
+ Terramap.instance().logger().catching(e);
}
}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/files/kml/KmlPlacemark.java b/core/src/main/java/net/smyler/terramap/files/kml/KmlPlacemark.java
similarity index 95%
rename from forge/src/main/java/fr/thesmyler/terramap/files/kml/KmlPlacemark.java
rename to core/src/main/java/net/smyler/terramap/files/kml/KmlPlacemark.java
index 639b5379..e4e2b731 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/files/kml/KmlPlacemark.java
+++ b/core/src/main/java/net/smyler/terramap/files/kml/KmlPlacemark.java
@@ -1,4 +1,4 @@
-package fr.thesmyler.terramap.files.kml;
+package net.smyler.terramap.files.kml;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
diff --git a/forge/src/main/java/fr/thesmyler/terramap/files/kml/KmlPoint.java b/core/src/main/java/net/smyler/terramap/files/kml/KmlPoint.java
similarity index 95%
rename from forge/src/main/java/fr/thesmyler/terramap/files/kml/KmlPoint.java
rename to core/src/main/java/net/smyler/terramap/files/kml/KmlPoint.java
index d26e8977..87c6f345 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/files/kml/KmlPoint.java
+++ b/core/src/main/java/net/smyler/terramap/files/kml/KmlPoint.java
@@ -1,4 +1,4 @@
-package fr.thesmyler.terramap.files.kml;
+package net.smyler.terramap.files.kml;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
diff --git a/core/src/main/java/net/smyler/terramap/http/HttpClient.java b/core/src/main/java/net/smyler/terramap/http/HttpClient.java
new file mode 100644
index 00000000..90c53453
--- /dev/null
+++ b/core/src/main/java/net/smyler/terramap/http/HttpClient.java
@@ -0,0 +1,23 @@
+package net.smyler.terramap.http;
+
+import net.smyler.terramap.Terramap;
+
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * Asynchronous HTTP client abstraction.
+ * The implementation should focus on implementing
+ * efficient GET requests with compliant caching.
+ * Implementations should support cancellation of the CompletableFuture.
+ *
+ * Access the singleton from {@link Terramap#http()}
+ *
+ * @author Smyler
+ */
+public interface HttpClient {
+
+ CompletableFuture get(String url);
+
+ void setMaxConcurrentRequests(String host, int maxConcurrentRequests);
+
+}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/util/CopyrightHolder.java b/core/src/main/java/net/smyler/terramap/util/CopyrightHolder.java
similarity index 92%
rename from forge/src/main/java/fr/thesmyler/terramap/util/CopyrightHolder.java
rename to core/src/main/java/net/smyler/terramap/util/CopyrightHolder.java
index 0892346a..46225126 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/util/CopyrightHolder.java
+++ b/core/src/main/java/net/smyler/terramap/util/CopyrightHolder.java
@@ -1,4 +1,4 @@
-package fr.thesmyler.terramap.util;
+package net.smyler.terramap.util;
import net.smyler.smylib.text.Text;
diff --git a/forge/src/main/java/fr/thesmyler/terramap/util/geo/GeoServices.java b/core/src/main/java/net/smyler/terramap/util/geo/GeoServices.java
similarity index 90%
rename from forge/src/main/java/fr/thesmyler/terramap/util/geo/GeoServices.java
rename to core/src/main/java/net/smyler/terramap/util/geo/GeoServices.java
index f9e2f2a8..6140e08d 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/util/geo/GeoServices.java
+++ b/core/src/main/java/net/smyler/terramap/util/geo/GeoServices.java
@@ -1,4 +1,4 @@
-package fr.thesmyler.terramap.util.geo;
+package net.smyler.terramap.util.geo;
import java.awt.Desktop;
import java.io.File;
@@ -14,12 +14,11 @@
import java.text.DecimalFormatSymbols;
import java.util.Locale;
-import fr.thesmyler.terramap.TerramapMod;
-import fr.thesmyler.terramap.files.kml.KmlDocument;
-import fr.thesmyler.terramap.files.kml.KmlFile;
-import fr.thesmyler.terramap.files.kml.KmlPlacemark;
-import fr.thesmyler.terramap.files.kml.KmlPoint;
-import net.smyler.terramap.util.geo.GeoUtil;
+import net.smyler.terramap.files.kml.KmlDocument;
+import net.smyler.terramap.files.kml.KmlFile;
+import net.smyler.terramap.files.kml.KmlPlacemark;
+import net.smyler.terramap.files.kml.KmlPoint;
+import net.smyler.terramap.Terramap;
/**
* Utility class to open various geo services such as osm, Google Maps, Earth, etc...
@@ -65,8 +64,8 @@ public static String formatStringWithCoords(String str, int zoomLevel, double lo
.replace("{longitude}", dispLong)
.replace("{place}", dispPlace);
} catch (UnsupportedEncodingException e) {
- TerramapMod.logger.error("Failed to format a string with coordinates: ");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to format a string with coordinates: ");
+ Terramap.instance().logger().catching(e);
}
return str;
}
@@ -124,8 +123,8 @@ public static void openInGoogleEarthPro(double lon, double lat) {
Desktop.getDesktop().open(file);
file.deleteOnExit();
} catch(Exception e) {
- TerramapMod.logger.error("There was an error when trying to open a place in Google Earth");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("There was an error when trying to open a place in Google Earth");
+ Terramap.instance().logger().catching(e);
}
}
@@ -134,10 +133,10 @@ public static void openURI(String uriStr) {
URI uri = new URI(uriStr);
Desktop.getDesktop().browse(uri);
} catch (IOException | UnsupportedOperationException e) {
- TerramapMod.logger.error("Failed to open uri: " + uriStr);
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to open uri: {}", uriStr);
+ Terramap.instance().logger().catching(e);
} catch (URISyntaxException e) {
- TerramapMod.logger.error("Tried to open a malformed URI: " + uriStr);
+ Terramap.instance().logger().error("Tried to open a malformed URI: {}", uriStr);
}
}
diff --git a/fabric/src/main/java/net/smyler/terramap/TerramapFabricMod.java b/fabric/src/main/java/net/smyler/terramap/TerramapFabricMod.java
index d3a12b47..b6336fac 100644
--- a/fabric/src/main/java/net/smyler/terramap/TerramapFabricMod.java
+++ b/fabric/src/main/java/net/smyler/terramap/TerramapFabricMod.java
@@ -1,20 +1,53 @@
package net.smyler.terramap;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import net.fabricmc.api.ModInitializer;
import net.minecraft.client.Minecraft;
import net.smyler.smylib.SmyLib;
import net.smyler.smylib.game.WrappedMinecraft;
+import net.smyler.smylib.json.TextJsonAdapter;
+import net.smyler.smylib.text.Text;
+import net.smyler.terramap.http.HttpClient;
import org.apache.logging.log4j.Logger;
import static org.apache.logging.log4j.LogManager.getLogger;
-public class TerramapFabricMod implements ModInitializer {
+public class TerramapFabricMod implements ModInitializer, Terramap {
+
+ private final Logger logger = getLogger("terramap");
+ private final Gson gson = new GsonBuilder()
+ .registerTypeAdapter(Text.class, new TextJsonAdapter())
+ .create();
+ private final Gson gsonPretty = new GsonBuilder()
+ .registerTypeAdapter(Text.class, new TextJsonAdapter())
+ .setPrettyPrinting()
+ .create();
- public static final Logger LOGGER = getLogger("terramap");
@Override
public void onInitialize() {
- LOGGER.info("Initializing Terramap");
- SmyLib.initializeGameClient(new WrappedMinecraft(Minecraft.getInstance()), LOGGER);
+ this.logger.info("Initializing Terramap");
+ SmyLib.initializeGameClient(new WrappedMinecraft(Minecraft.getInstance()), this.logger);
+ }
+
+ @Override
+ public Logger logger() {
+ return this.logger;
+ }
+
+ @Override
+ public HttpClient http() {
+ return null;
+ }
+
+ @Override
+ public Gson gson() {
+ return this.gson;
+ }
+
+ @Override
+ public Gson gsonPretty() {
+ return this.gsonPretty;
}
}
diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/SmyLibGuiTextures.java b/forge/src/main/java/fr/thesmyler/smylibgui/SmyLibGuiTextures.java
index a33075c3..f72623af 100644
--- a/forge/src/main/java/fr/thesmyler/smylibgui/SmyLibGuiTextures.java
+++ b/forge/src/main/java/fr/thesmyler/smylibgui/SmyLibGuiTextures.java
@@ -1,7 +1,7 @@
package fr.thesmyler.smylibgui;
-import fr.thesmyler.terramap.TerramapMod;
import net.minecraft.util.ResourceLocation;
+import net.smyler.terramap.Terramap;
public final class SmyLibGuiTextures {
@@ -10,7 +10,7 @@ private SmyLibGuiTextures() {}
public static final ResourceLocation WIDGET_TEXTURES;
static {
- WIDGET_TEXTURES = new ResourceLocation(TerramapMod.MODID, "textures/gui/widgets.png");
+ WIDGET_TEXTURES = new ResourceLocation(Terramap.MOD_ID, "textures/gui/widgets.png");
}
}
diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/util/Cursors.java b/forge/src/main/java/fr/thesmyler/smylibgui/util/Cursors.java
index 2d901543..8c00effc 100644
--- a/forge/src/main/java/fr/thesmyler/smylibgui/util/Cursors.java
+++ b/forge/src/main/java/fr/thesmyler/smylibgui/util/Cursors.java
@@ -2,13 +2,13 @@
import java.nio.IntBuffer;
+import net.smyler.terramap.Terramap;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Cursor;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
-import fr.thesmyler.terramap.TerramapMod;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.util.ResourceLocation;
@@ -19,11 +19,11 @@
//TODO Have a wrapper class for lwjgl cursors
public final class Cursors {
- public static final Cursor CURSOR_MOVE = loadCursorFromTexture(new ResourceLocation(TerramapMod.MODID, "textures/gui/cursors/move.png"), 32, 32);
- public static final Cursor CURSOR_RESIZE_VERTICAL = loadCursorFromTexture(new ResourceLocation(TerramapMod.MODID, "textures/gui/cursors/resize_vertical.png"), 16, 32);
- public static final Cursor CURSOR_RESIZE_HORIZONTAL = loadCursorFromTexture(new ResourceLocation(TerramapMod.MODID, "textures/gui/cursors/resize_horizontal.png"), 32, 16);
- public static final Cursor CURSOR_RESIZE_DIAGONAL_1 = loadCursorFromTexture(new ResourceLocation(TerramapMod.MODID, "textures/gui/cursors/resize_diag1.png"), 32, 32);
- public static final Cursor CURSOR_RESIZE_DIAGONAL_2 = loadCursorFromTexture(new ResourceLocation(TerramapMod.MODID, "textures/gui/cursors/resize_diag2.png"), 32, 32);
+ public static final Cursor CURSOR_MOVE = loadCursorFromTexture(new ResourceLocation(Terramap.MOD_ID, "textures/gui/cursors/move.png"), 32, 32);
+ public static final Cursor CURSOR_RESIZE_VERTICAL = loadCursorFromTexture(new ResourceLocation(Terramap.MOD_ID, "textures/gui/cursors/resize_vertical.png"), 16, 32);
+ public static final Cursor CURSOR_RESIZE_HORIZONTAL = loadCursorFromTexture(new ResourceLocation(Terramap.MOD_ID, "textures/gui/cursors/resize_horizontal.png"), 32, 16);
+ public static final Cursor CURSOR_RESIZE_DIAGONAL_1 = loadCursorFromTexture(new ResourceLocation(Terramap.MOD_ID, "textures/gui/cursors/resize_diag1.png"), 32, 32);
+ public static final Cursor CURSOR_RESIZE_DIAGONAL_2 = loadCursorFromTexture(new ResourceLocation(Terramap.MOD_ID, "textures/gui/cursors/resize_diag2.png"), 32, 32);
static {
if(Minecraft.IS_RUNNING_ON_MAC) {
@@ -66,8 +66,8 @@ private static Cursor loadCursorFromTexture(ResourceLocation loc, int hotX, int
try {
return new Cursor(width, height, hotX, hotY, 1, buffer, BufferUtils.createIntBuffer(1));
} catch (LWJGLException e) {
- TerramapMod.logger.error("Failed to load a cutom cursor for " + loc);
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to load a custom cursor for {}", loc);
+ Terramap.instance().logger().catching(e);
}
}
return Mouse.getNativeCursor();
diff --git a/forge/src/main/java/fr/thesmyler/terramap/TerramapClientContext.java b/forge/src/main/java/fr/thesmyler/terramap/TerramapClientContext.java
index d5bdc498..f2edf566 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/TerramapClientContext.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/TerramapClientContext.java
@@ -38,12 +38,12 @@
import net.buildtheearth.terraplusplus.projection.mercator.WebMercatorProjection;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
-import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
+import net.smyler.terramap.Terramap;
import org.jetbrains.annotations.NotNull;
import static net.smyler.smylib.SmyLib.getGameClient;
@@ -89,12 +89,15 @@ public class TerramapClientContext {
private final ClientSaveManager saveManager;
public TerramapClientContext() {
- this.saveManager = new ClientSaveManager(getGameClient().gameDirectory().resolve("terramap"));
+ this.saveManager = new ClientSaveManager(
+ getGameClient().gameDirectory().resolve("terramap"),
+ Terramap.instance().gsonPretty()
+ );
try {
this.saveManager.createDirectoryIfNecessary();
} catch (IOException exception) {
- TerramapMod.logger.error("An error occurred when preparing Terramap's save directory");
- TerramapMod.logger.catching(exception);
+ Terramap.instance().logger().error("An error occurred when preparing Terramap's save directory");
+ Terramap.instance().logger().catching(exception);
}
this.reloadState();
}
@@ -156,8 +159,8 @@ public TerrainPreview getTerrainPreview() {
public void setGeneratorSettings(EarthGeneratorSettings genSettings) {
if(genSettings != null && this.hasSledgehammer() && !TerramapUtil.isBteCompatible(genSettings)) {
- TerramapMod.logger.error("Terramap server is reporting a projection which is not compatible with BTE, yet Sledgehammer is installer on the proxy!!");
- TerramapMod.logger.error("The proxy will be assuming a BTE projection, things will not work!");
+ Terramap.instance().logger().error("Terramap server is reporting a projection which is not compatible with BTE, yet Sledgehammer is installer on the proxy!!");
+ Terramap.instance().logger().error("The proxy will be assuming a BTE projection, things will not work!");
//TODO Warning on the GUI
}
this.getSavedState().generatorSettings = genSettings;
@@ -238,7 +241,7 @@ public String getTpCommand() {
}
public void setTpCommand(String tpCmd) {
- TerramapMod.logger.info("Setting tp command defined by server");
+ Terramap.instance().logger().info("Setting tp command defined by server");
this.tpCommand = tpCmd;
}
@@ -250,38 +253,38 @@ public void reloadState() {
MinecraftServerInfo serverInfo = getGameClient().currentServerInfo();
if(this.proxyForceGlobalSettings && this.proxyUUID != null) {
this.state = this.saveManager.loadProxyState(this.proxyUUID);
- TerramapMod.logger.debug("Loaded proxy saved state for UUID {} (forced by proxy)", this.proxyUUID);
+ Terramap.instance().logger().debug("Loaded proxy saved state for UUID {} (forced by proxy)", this.proxyUUID);
} else if(this.worldUUID != null) {
this.state = this.saveManager.loadWorldState(this.worldUUID);
- TerramapMod.logger.debug("Loaded world saved state for UUID {}", this.worldUUID);
+ Terramap.instance().logger().debug("Loaded world saved state for UUID {}", this.worldUUID);
} else if(this.proxyUUID != null) {
this.state = this.saveManager.loadProxyState(this.proxyUUID);
- TerramapMod.logger.debug("Loaded proxy saved state for UUID {} (world unknown)", this.proxyUUID);
+ Terramap.instance().logger().debug("Loaded proxy saved state for UUID {} (world unknown)", this.proxyUUID);
} else if (serverInfo != null) {
this.state = this.saveManager.loadServerState(serverInfo);
- TerramapMod.logger.debug("Loaded server saved state for server {} ({})",serverInfo.name, serverInfo.host);
+ Terramap.instance().logger().debug("Loaded server saved state for server {} ({})",serverInfo.name, serverInfo.host);
} else {
this.state = this.saveManager.getDefaultState();
- TerramapMod.logger.debug("Went back to default state");
+ Terramap.instance().logger().debug("Went back to default state");
}
}
public void saveState() {
- ServerData servData = Minecraft.getMinecraft().getCurrentServerData();
+ MinecraftServerInfo servData = getGameClient().currentServerInfo();
if(this.proxyForceGlobalSettings && this.proxyUUID != null) {
this.saveManager.saveProxyState(this.proxyUUID, this.state);
- TerramapMod.logger.debug("Saved proxy state for UUID {} (forced by proxy)", this.proxyUUID);
+ Terramap.instance().logger().debug("Saved proxy state for UUID {} (forced by proxy)", this.proxyUUID);
} else if(this.worldUUID != null) {
this.saveManager.saveWorldState(this.worldUUID, this.state);
- TerramapMod.logger.debug("Saved world state for UUID {}", this.worldUUID);
+ Terramap.instance().logger().debug("Saved world state for UUID {}", this.worldUUID);
} else if(this.proxyUUID != null) {
this.saveManager.saveProxyState(this.proxyUUID, this.state);
- TerramapMod.logger.debug("Saved proxy state for UUID {} (world unknown)", this.proxyUUID);
+ Terramap.instance().logger().debug("Saved proxy state for UUID {} (world unknown)", this.proxyUUID);
} else if (servData != null) {
this.saveManager.saveServerState(servData, this.state);
- TerramapMod.logger.debug("Saved server state for server {} ({})",servData.serverName, servData.serverIP);
+ Terramap.instance().logger().debug("Saved server state for server {} ({})",servData.name, servData.host);
} else {
- TerramapMod.logger.debug("Did not save state for unreliable context");
+ Terramap.instance().logger().debug("Did not save state for unreliable context");
}
}
@@ -495,7 +498,7 @@ public void tryShowWelcomeToast() {
new TextureToast(
getGameClient().translator().format("terramap.toasts.welcome.title"),
getGameClient().translator().format("terramap.toasts.welcome.text", key),
- new ResourceLocation(TerramapMod.MODID, "logo/50.png")));
+ new ResourceLocation(Terramap.MOD_ID, "logo/50.png")));
this.setHasShownWelcomeMessage(true);
}
}
@@ -521,7 +524,7 @@ public static TerramapClientContext getContext() {
}
public static void resetContext() {
- TerramapMod.logger.info("Reseting client context");
+ Terramap.instance().logger().info("Reseting client context");
TiledMapProvider.SERVER.setLastError(null);
TiledMapProvider.PROXY.setLastError(null);
TerramapClientContext.instance = new TerramapClientContext();
diff --git a/forge/src/main/java/fr/thesmyler/terramap/TerramapConfig.java b/forge/src/main/java/fr/thesmyler/terramap/TerramapConfig.java
index c9f41022..5d83465b 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/TerramapConfig.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/TerramapConfig.java
@@ -5,6 +5,7 @@
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import net.smyler.terramap.Terramap;
import static net.smyler.smylib.SmyLib.getGameClient;
@@ -14,7 +15,7 @@
* Terramap's config
*
*/
-@Config(modid=TerramapMod.MODID)
+@Config(modid=Terramap.MOD_ID)
public class TerramapConfig {
public static final class Minimap {
@@ -288,10 +289,10 @@ public static final class Server {
public static boolean enableDebugMaps = false;
public static void sync() {
- ConfigManager.sync(TerramapMod.MODID, Config.Type.INSTANCE);
+ ConfigManager.sync(Terramap.MOD_ID, Config.Type.INSTANCE);
}
- @Mod.EventBusSubscriber(modid = TerramapMod.MODID)
+ @Mod.EventBusSubscriber(modid = Terramap.MOD_ID)
private static class EventHandler {
/**
@@ -301,7 +302,7 @@ private static class EventHandler {
*/
@SubscribeEvent
public static void onConfigChanged(final ConfigChangedEvent.OnConfigChangedEvent event) {
- if (event.getModID().equals(TerramapMod.MODID)) {
+ if (event.getModID().equals(Terramap.MOD_ID)) {
TerramapConfig.sync();
}
TerramapMod.proxy.onConfigChanged(event);
diff --git a/forge/src/main/java/fr/thesmyler/terramap/TerramapMod.java b/forge/src/main/java/fr/thesmyler/terramap/TerramapMod.java
index 80ab932b..c65fec1e 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/TerramapMod.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/TerramapMod.java
@@ -6,10 +6,12 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import fr.thesmyler.terramap.util.json.EarthGeneratorSettingsAdapter;
-import net.buildtheearth.terraplusplus.generator.EarthGenerator;
import net.buildtheearth.terraplusplus.generator.EarthGeneratorSettings;
import net.smyler.smylib.json.TextJsonAdapter;
import net.smyler.smylib.text.Text;
+import net.smyler.terramap.Terramap;
+import net.smyler.terramap.http.HttpClient;
+import net.smyler.terramap.http.TerraplusplusHttpClient;
import org.apache.logging.log4j.Logger;
import fr.thesmyler.terramap.TerramapVersion.InvalidVersionString;
@@ -29,27 +31,26 @@
import net.minecraftforge.fml.relauncher.Side;
//TODO Credit TwelveMonkeys in the readme
-@Mod(modid=TerramapMod.MODID, useMetadata=true, dependencies="required-after:terraplusplus@[1.0.569,)")
-public class TerramapMod {
+@Mod(modid=Terramap.MOD_ID, useMetadata=true, dependencies="required-after:terraplusplus@[1.0.569,)")
+public class TerramapMod implements Terramap {
- public static final String MODID = "terramap";
- public static final String AUTHOR_EMAIL = "smyler at mail dot com";
public static final String STYLE_UPDATE_HOSTNAME = "styles.terramap.thesmyler.fr";
private static TerramapVersion version; // Read from the metadata
+ private final HttpClient http = new TerraplusplusHttpClient();
+
// These are notable versions
public static final TerramapVersion OLDEST_COMPATIBLE_CLIENT = new TerramapVersion(1, 0, 0, ReleaseType.BETA, 6, 0);
- public static final TerramapVersion OLDEST_COMPATIBLE_SERVER = new TerramapVersion(1, 0, 0, ReleaseType.BETA, 6, 0);
public static final TerramapVersion OLDEST_TERRA121_TERRAMAP_VERSION = new TerramapVersion(1, 0, 0, ReleaseType.BETA, 6, 7);
- public static Logger logger;
+ private Logger logger;
- public static final Gson GSON = new GsonBuilder()
+ private final Gson gson = new GsonBuilder()
.registerTypeAdapter(EarthGeneratorSettings.class, new EarthGeneratorSettingsAdapter())
.registerTypeAdapter(Text.class, new TextJsonAdapter())
.create();
- public static final Gson GSON_PRETTY = new GsonBuilder()
+ private final Gson gsonPretty = new GsonBuilder()
.registerTypeAdapter(EarthGeneratorSettings.class, new EarthGeneratorSettingsAdapter())
.registerTypeAdapter(Text.class, new TextJsonAdapter())
.setPrettyPrinting()
@@ -63,19 +64,20 @@ public class TerramapMod {
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
- logger = event.getModLog();
+ this.logger = event.getModLog();
+ Terramap.InstanceHolder.setInstance(this);
String versionStr = event.getModMetadata().version;
if (System.getProperties().containsKey("terramap.debug")) {
- logger.info("Debug flag is set, forcing a development version string.");
+ this.logger.info("Debug flag is set, forcing a development version string.");
versionStr= "${version}";
}
try {
TerramapMod.version = new TerramapVersion(versionStr);
} catch(InvalidVersionString e) {
- logger.error("Failed to parse Terramap version number from string " + versionStr + ", will be assuming a 1.0.0 release.");
+ this.logger.error("Failed to parse Terramap version number from string {}, will be assuming a 1.0.0 release.", versionStr);
TerramapMod.version = new TerramapVersion(1, 0, 0);
}
- TerramapMod.logger.info("Terramap version: " + getVersion());
+ this.logger.info("Terramap version: {}", getVersion());
TerramapMod.proxy.preInit(event);
File mapStyleFile = new File(event.getModConfigurationDirectory().getAbsolutePath() + "/terramap_user_styles.json");
MapStylesLibrary.setConfigMapFile(mapStyleFile);
@@ -108,4 +110,24 @@ public void onServerStarts(FMLServerStartingEvent event) {
}
+ @Override
+ public Logger logger() {
+ return this.logger;
+ }
+
+ @Override
+ public HttpClient http() {
+ return this.http;
+ }
+
+ @Override
+ public Gson gson() {
+ return this.gson;
+ }
+
+ @Override
+ public Gson gsonPretty() {
+ return this.gsonPretty;
+ }
+
}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/TerramapVersion.java b/forge/src/main/java/fr/thesmyler/terramap/TerramapVersion.java
index f077733d..ce594719 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/TerramapVersion.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/TerramapVersion.java
@@ -3,6 +3,7 @@
import java.util.Arrays;
import java.util.Map;
+import net.smyler.terramap.Terramap;
import org.jetbrains.annotations.NotNull;
import org.apache.logging.log4j.util.Strings;
@@ -302,12 +303,12 @@ public TerraDependency getTerraDependency() {
public static TerramapVersion getClientVersion(EntityPlayerMP player) {
Map modList = NetworkDispatcher.get(player.connection.netManager).getModList();
TerramapVersion version = null;
- String remoteVersion = modList.get(TerramapMod.MODID);
+ String remoteVersion = modList.get(Terramap.MOD_ID);
if(remoteVersion != null) {
try {
version = new TerramapVersion(remoteVersion);
} catch(InvalidVersionString e) {
- TerramapMod.logger.warn("Failed to parse a client's Terramap version: " + remoteVersion + " : " + e.getLocalizedMessage());
+ Terramap.instance().logger().warn("Failed to parse a client's Terramap version: {} : {}", remoteVersion, e.getLocalizedMessage());
}
}
return version;
diff --git a/forge/src/main/java/fr/thesmyler/terramap/eventhandlers/ClientTerramapEventHandler.java b/forge/src/main/java/fr/thesmyler/terramap/eventhandlers/ClientTerramapEventHandler.java
index 7d5d2b6b..64be5dfa 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/eventhandlers/ClientTerramapEventHandler.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/eventhandlers/ClientTerramapEventHandler.java
@@ -2,12 +2,11 @@
import fr.thesmyler.smylibgui.event.HudScreenInitEvent;
import fr.thesmyler.terramap.TerramapClientContext;
-import fr.thesmyler.terramap.TerramapMod;
import fr.thesmyler.terramap.gui.HudScreenHandler;
import fr.thesmyler.terramap.gui.screens.LayerRenderingOffsetPopup;
import fr.thesmyler.terramap.gui.widgets.map.MapLayer;
import fr.thesmyler.terramap.input.KeyBindings;
-import fr.thesmyler.terramap.util.geo.GeoServices;
+import net.smyler.terramap.util.geo.GeoServices;
import net.buildtheearth.terraplusplus.projection.GeographicProjection;
import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException;
import net.buildtheearth.terraplusplus.util.CardinalDirection;
@@ -25,6 +24,7 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.smyler.smylib.gui.popups.Popup;
+import net.smyler.terramap.Terramap;
import java.util.Objects;
@@ -81,7 +81,7 @@ public void onClientConnected(ClientConnectedToServerEvent event) {
@SubscribeEvent
public void onChangeDimension(PlayerChangedDimensionEvent event) {
// Not called on client...
- TerramapMod.logger.info(event.player.world.isRemote);
+ Terramap.instance().logger().info(event.player.world.isRemote);
if(event.player.world.isRemote) {
TerramapClientContext.getContext().resetWorld();
}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/eventhandlers/ServerTerramapEventHandler.java b/forge/src/main/java/fr/thesmyler/terramap/eventhandlers/ServerTerramapEventHandler.java
index ad4588ae..8f8f0af5 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/eventhandlers/ServerTerramapEventHandler.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/eventhandlers/ServerTerramapEventHandler.java
@@ -10,6 +10,7 @@
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
+import net.smyler.terramap.Terramap;
@SideOnly(Side.SERVER)
public class ServerTerramapEventHandler {
@@ -25,14 +26,14 @@ public void onPlayerLoggedIn(PlayerLoggedInEvent event){
if(TerramapConfig.SERVER.joinWithoutModMessage.length() > 0)
player.sendMessage(ITextComponent.Serializer.fromJsonLenient(TerramapConfig.SERVER.joinWithoutModMessage));
} catch(Exception e) {
- TerramapMod.logger.error("Failed to send custom join message to client, make sure your json text is valid");
+ Terramap.instance().logger().error("Failed to send custom join message to client, make sure your json text is valid");
}
} else if(remoteVersion.isOlder(TerramapMod.OLDEST_COMPATIBLE_CLIENT)){
try {
if(TerramapConfig.SERVER.joinWithOutdatedModMessage.length() > 0)
player.sendMessage(ITextComponent.Serializer.fromJsonLenient(TerramapConfig.SERVER.joinWithOutdatedModMessage));
} catch(Exception e) {
- TerramapMod.logger.error("Failed to send custom join message to client, make sure your json text is valid");
+ Terramap.instance().logger().error("Failed to send custom join message to client, make sure your json text is valid");
}
}
}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/screens/LayerRenderingOffsetPopup.java b/forge/src/main/java/fr/thesmyler/terramap/gui/screens/LayerRenderingOffsetPopup.java
index 0dba7f3c..c703b128 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/gui/screens/LayerRenderingOffsetPopup.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/gui/screens/LayerRenderingOffsetPopup.java
@@ -27,7 +27,7 @@
import net.smyler.smylib.math.Vec2dMutable;
import static fr.thesmyler.terramap.gui.widgets.map.MapLayerRegistry.OFFSET_PREVIEW;
-import static fr.thesmyler.terramap.util.geo.GeoServices.formatZoomLevelForDisplay;
+import static net.smyler.terramap.util.geo.GeoServices.formatZoomLevelForDisplay;
import static net.smyler.smylib.SmyLib.getGameClient;
import static net.smyler.smylib.text.ImmutableText.ofTranslation;
diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/screens/TerramapScreen.java b/forge/src/main/java/fr/thesmyler/terramap/gui/screens/TerramapScreen.java
index 034ec170..ace1778c 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/gui/screens/TerramapScreen.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/gui/screens/TerramapScreen.java
@@ -9,13 +9,14 @@
import net.smyler.smylib.gui.sprites.WarningWidget;
import net.smyler.smylib.text.ImmutableText;
import net.smyler.smylib.text.TextStyle;
+import net.smyler.terramap.Terramap;
+import net.smyler.terramap.util.geo.GeoServices;
import org.jetbrains.annotations.Nullable;
import fr.thesmyler.terramap.gui.widgets.map.*;
import fr.thesmyler.terramap.gui.widgets.map.layer.OnlineRasterMapLayer;
import fr.thesmyler.terramap.maps.raster.CachingRasterTiledMap;
import fr.thesmyler.terramap.maps.raster.imp.UrlTiledMap;
-import fr.thesmyler.terramap.util.geo.*;
import net.buildtheearth.terraplusplus.generator.EarthGeneratorSettings;
import net.smyler.smylib.Color;
import net.smyler.smylib.game.GameClient;
@@ -65,7 +66,7 @@
import net.minecraft.util.ITabCompleter;
import static fr.thesmyler.terramap.gui.widgets.map.MapLayerRegistry.LayerRegistration;
-import static fr.thesmyler.terramap.util.geo.GeoServices.formatZoomLevelForDisplay;
+import static net.smyler.terramap.util.geo.GeoServices.formatZoomLevelForDisplay;
import static net.smyler.smylib.Color.WHITE;
import static net.smyler.smylib.Color.YELLOW;
import static net.smyler.smylib.SmyLib.getGameClient;
@@ -539,7 +540,7 @@ public boolean shouldPauseGame() {
}
private boolean search(String text) {
- TerramapMod.logger.info("Geo search: " + text);
+ Terramap.instance().logger().info("Geo search: {}", text);
//TODO Search
return true; // Let the search box loose focus
}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/screens/config/TerramapConfigScreen.java b/forge/src/main/java/fr/thesmyler/terramap/gui/screens/config/TerramapConfigScreen.java
index d91d0982..7c8a30f9 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/gui/screens/config/TerramapConfigScreen.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/gui/screens/config/TerramapConfigScreen.java
@@ -7,6 +7,7 @@
import net.smyler.smylib.game.GameClient;
import net.smyler.smylib.game.Key;
import net.smyler.smylib.game.Translator;
+import net.smyler.terramap.Terramap;
import org.jetbrains.annotations.Nullable;
import net.smyler.smylib.gui.containers.FlexibleWidgetContainer;
@@ -23,7 +24,6 @@
import net.smyler.smylib.gui.widgets.text.TextFieldWidget;
import net.smyler.smylib.gui.widgets.text.TextWidget;
import fr.thesmyler.terramap.TerramapClientContext;
-import fr.thesmyler.terramap.TerramapMod;
import fr.thesmyler.terramap.TerramapConfig;
import fr.thesmyler.terramap.maps.raster.MapStylesLibrary;
@@ -179,8 +179,8 @@ public void init() {
try {
Desktop.getDesktop().open(MapStylesLibrary.getFile());
} catch (IOException e) {
- TerramapMod.logger.error("Failed to open map style config file: ");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to open map style config file: ");
+ Terramap.instance().logger().catching(e);
}
}));
diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/RibbonCompassWidget.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/RibbonCompassWidget.java
index f3a2235f..5700bd8a 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/RibbonCompassWidget.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/RibbonCompassWidget.java
@@ -2,6 +2,7 @@
import net.smyler.smylib.gui.DrawContext;
import net.smyler.smylib.gui.GlState;
+import net.smyler.terramap.Terramap;
import org.lwjgl.opengl.GL11;
import net.smyler.smylib.gui.containers.WidgetContainer;
@@ -9,7 +10,6 @@
import fr.thesmyler.smylibgui.util.TextureUtil.TextureProperties;
import fr.thesmyler.smylibgui.util.TextureUtil.UnknownTextureException;
import net.smyler.smylib.gui.widgets.Widget;
-import fr.thesmyler.terramap.TerramapMod;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
@@ -21,8 +21,8 @@
public class RibbonCompassWidget implements Widget {
- private static final ResourceLocation COMPASS_BACKGROUND_TEXTURE = new ResourceLocation(TerramapMod.MODID, "textures/gui/compass_ribbon_background.png");
- private static final ResourceLocation COMPASS_INDICATOR_TEXTURE = new ResourceLocation(TerramapMod.MODID, "textures/gui/compass_ribbon_indicator.png");
+ private static final ResourceLocation COMPASS_BACKGROUND_TEXTURE = new ResourceLocation(Terramap.MOD_ID, "textures/gui/compass_ribbon_background.png");
+ private static final ResourceLocation COMPASS_INDICATOR_TEXTURE = new ResourceLocation(Terramap.MOD_ID, "textures/gui/compass_ribbon_indicator.png");
private float x, y;
private final int z;
@@ -43,8 +43,8 @@ public RibbonCompassWidget(float x, float y, int z, float width) {
this.indicatorHeight = p2.getHeight();
this.indicatorWidth = p2.getWidth();
} catch (UnknownTextureException e) {
- TerramapMod.logger.error("Failed to get texture heiht for ribbon compass");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to get texture heiht for ribbon compass");
+ Terramap.instance().logger().catching(e);
this.height = 16;
}
}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/MapMenuWidget.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/MapMenuWidget.java
index 1cd8569c..39fe1aff 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/MapMenuWidget.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/MapMenuWidget.java
@@ -9,7 +9,7 @@
import net.smyler.smylib.gui.Font;
import net.smyler.terramap.util.geo.GeoPoint;
import net.smyler.terramap.util.geo.GeoPointReadOnly;
-import fr.thesmyler.terramap.util.geo.GeoServices;
+import net.smyler.terramap.util.geo.GeoServices;
import net.buildtheearth.terraplusplus.control.PresetEarthGui;
import net.buildtheearth.terraplusplus.generator.EarthGeneratorSettings;
import net.buildtheearth.terraplusplus.projection.GeographicProjection;
diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/MapWidget.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/MapWidget.java
index 4a19ae56..08827eb7 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/MapWidget.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/MapWidget.java
@@ -19,7 +19,6 @@
import net.smyler.smylib.gui.widgets.text.TextAlignment;
import net.smyler.smylib.gui.widgets.text.TextWidget;
import fr.thesmyler.terramap.MapContext;
-import fr.thesmyler.terramap.TerramapMod;
import fr.thesmyler.terramap.gui.widgets.markers.MarkerControllerManager;
import fr.thesmyler.terramap.gui.widgets.markers.controllers.FeatureVisibilityController;
import fr.thesmyler.terramap.gui.widgets.markers.controllers.MainPlayerMarkerController;
@@ -30,10 +29,11 @@
import fr.thesmyler.terramap.gui.widgets.markers.controllers.RightClickMarkerController;
import fr.thesmyler.terramap.gui.widgets.markers.markers.Marker;
import fr.thesmyler.terramap.gui.widgets.markers.markers.entities.MainPlayerMarker;
-import fr.thesmyler.terramap.util.CopyrightHolder;
+import net.smyler.terramap.util.CopyrightHolder;
import net.minecraft.profiler.Profiler;
import net.smyler.smylib.text.ImmutableText;
import net.smyler.smylib.text.Text;
+import net.smyler.terramap.Terramap;
import net.smyler.terramap.util.geo.GeoPoint;
import net.smyler.terramap.util.geo.GeoPointMutable;
import net.smyler.terramap.util.geo.GeoPointReadOnly;
@@ -383,7 +383,7 @@ private void updateMarkers(float mouseX, float mouseY) {
if(id != null && id.equals(this.restoreTrackingId)) {
this.controller.track(markerToAdd);
this.restoreTrackingId = null;
- TerramapMod.logger.debug("Restored tracking with " + id);
+ Terramap.instance().logger().debug("Restored tracking with {}", id);
}
}
}
@@ -745,8 +745,8 @@ public void restore(SavedMapState state) {
try {
layer = this.createLayer(layerState.type);
} catch (IllegalArgumentException e) {
- TerramapMod.logger.warn("Could not restore a map layer. Did someone mess with the save file?");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().warn("Could not restore a map layer. Did someone mess with the save file?");
+ Terramap.instance().logger().catching(e);
continue;
}
this.setLayerZ(layer, layerState.z);
@@ -758,8 +758,8 @@ public void restore(SavedMapState state) {
try {
layer.loadSettings(layerState.settings);
} catch (Exception e) {
- TerramapMod.logger.error("Caught exception when loading layer settings. Did someone mess with the save file?");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Caught exception when loading layer settings. Did someone mess with the save file?");
+ Terramap.instance().logger().catching(e);
}
}
Map controllers = this.getVisibilityControllers();
diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/McChunksLayer.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/McChunksLayer.java
index 0d11f6f2..8decd780 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/McChunksLayer.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/McChunksLayer.java
@@ -15,11 +15,11 @@
import net.smyler.smylib.gui.widgets.buttons.ToggleButtonWidget;
import net.smyler.smylib.gui.widgets.text.TextWidget;
import fr.thesmyler.terramap.TerramapClientContext;
-import fr.thesmyler.terramap.TerramapMod;
import fr.thesmyler.terramap.gui.widgets.map.MapLayer;
import fr.thesmyler.terramap.gui.widgets.map.MapWidget;
import net.smyler.smylib.gui.DrawContext;
import net.smyler.smylib.gui.Font;
+import net.smyler.terramap.Terramap;
import net.smyler.terramap.util.geo.GeoPointImmutable;
import net.smyler.terramap.util.geo.GeoPointMutable;
import net.smyler.terramap.util.geo.GeoPointReadOnly;
@@ -120,7 +120,7 @@ public void loadSettings(JsonObject json) {
this.setRenderBlocks(json.get("renderBlocks").getAsBoolean());
this.loadColor(json.getAsJsonObject("colorBlocks"), this::setColorBlocks);
} catch (NullPointerException | ClassCastException | IllegalStateException e) {
- TerramapMod.logger.warn("Failed to load mc boundaries layer settings: {}", json);
+ Terramap.instance().logger().warn("Failed to load mc boundaries layer settings: {}", json);
}
}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/OnlineRasterMapLayer.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/OnlineRasterMapLayer.java
index fb1102ab..56b4daf9 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/OnlineRasterMapLayer.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/OnlineRasterMapLayer.java
@@ -13,7 +13,7 @@
import fr.thesmyler.terramap.gui.widgets.map.MapWidget;
import fr.thesmyler.terramap.maps.raster.RasterTiledMap;
import fr.thesmyler.terramap.maps.raster.imp.ColorTiledMap;
-import fr.thesmyler.terramap.util.CopyrightHolder;
+import net.smyler.terramap.util.CopyrightHolder;
import net.smyler.smylib.game.GameClient;
import net.smyler.smylib.gui.DrawContext;
import net.smyler.smylib.gui.Font;
diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RasterMapLayer.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RasterMapLayer.java
index 17529db2..460ae88d 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RasterMapLayer.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RasterMapLayer.java
@@ -10,11 +10,11 @@
import fr.thesmyler.terramap.gui.widgets.map.MapWidget;
import fr.thesmyler.terramap.maps.raster.RasterTile;
import fr.thesmyler.terramap.maps.raster.RasterTiledMap;
-import fr.thesmyler.terramap.util.geo.*;
import net.smyler.smylib.Color;
import net.smyler.smylib.gui.DrawContext;
import net.smyler.smylib.gui.Font;
import net.smyler.terramap.util.geo.GeoPointReadOnly;
+import net.smyler.terramap.util.geo.GeoServices;
import net.smyler.terramap.util.geo.TilePos;
import net.smyler.terramap.util.geo.TilePos.InvalidTilePositionException;
import net.smyler.smylib.math.Mat2d;
diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/markers/MarkerControllerManager.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/markers/MarkerControllerManager.java
index 3216d426..a14709f3 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/markers/MarkerControllerManager.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/markers/MarkerControllerManager.java
@@ -6,13 +6,13 @@
import java.util.Map;
import fr.thesmyler.terramap.MapContext;
-import fr.thesmyler.terramap.TerramapMod;
import fr.thesmyler.terramap.gui.widgets.markers.controllers.AnimalMarkerController;
import fr.thesmyler.terramap.gui.widgets.markers.controllers.MainPlayerMarkerController;
import fr.thesmyler.terramap.gui.widgets.markers.controllers.MarkerController;
import fr.thesmyler.terramap.gui.widgets.markers.controllers.MobMarkerController;
import fr.thesmyler.terramap.gui.widgets.markers.controllers.OtherPlayerMarkerController;
import fr.thesmyler.terramap.gui.widgets.markers.controllers.RightClickMarkerController;
+import net.smyler.terramap.Terramap;
public abstract class MarkerControllerManager {
@@ -31,9 +31,9 @@ public static void registerController(Class extends MarkerController>> contr
controller.newInstance();
CONTROLLER_CLASSES.get(context).add(controller);
} catch(Exception e) {
- TerramapMod.logger.error("Failed to create a test marker controller instance for " + controller.getCanonicalName());
- TerramapMod.logger.error("This marker controller class will not be registered. See stack trace for details.");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to create a test marker controller instance for {}", controller.getCanonicalName());
+ Terramap.instance().logger().error("This marker controller class will not be registered. See stack trace for details.");
+ Terramap.instance().logger().catching(e);
}
}
@@ -44,9 +44,9 @@ public static MarkerController>[] createControllers(MapContext context) {
try {
controllers[i++] = clazz.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
- TerramapMod.logger.error("Failed to create a marker controller, things will be unstable!");
- TerramapMod.logger.error("Failed to instantiate " + clazz.getCanonicalName());
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to create a marker controller, things will be unstable!");
+ Terramap.instance().logger().error("Failed to instantiate {}", clazz.getCanonicalName());
+ Terramap.instance().logger().catching(e);
}
}
return controllers;
diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/markers/markers/entities/AbstractLivingMarker.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/markers/markers/entities/AbstractLivingMarker.java
index 5824c6ba..f75f84be 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/markers/markers/entities/AbstractLivingMarker.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/markers/markers/entities/AbstractLivingMarker.java
@@ -6,11 +6,11 @@
import fr.thesmyler.smylibgui.util.RenderUtil;
import fr.thesmyler.terramap.MapContext;
import fr.thesmyler.terramap.TerramapClientContext;
-import fr.thesmyler.terramap.TerramapMod;
import fr.thesmyler.terramap.gui.widgets.map.MapWidget;
import fr.thesmyler.terramap.gui.widgets.markers.controllers.MarkerController;
import fr.thesmyler.terramap.gui.widgets.markers.markers.AbstractMovingMarker;
import net.smyler.smylib.gui.DrawContext;
+import net.smyler.terramap.Terramap;
import net.smyler.terramap.util.geo.GeoPointImmutable;
import net.buildtheearth.terraplusplus.projection.GeographicProjection;
import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException;
@@ -24,7 +24,7 @@
public abstract class AbstractLivingMarker extends AbstractMovingMarker {
- protected static final ResourceLocation ENTITY_MARKERS_TEXTURE = new ResourceLocation(TerramapMod.MODID, "textures/gui/entity_markers.png");
+ protected static final ResourceLocation ENTITY_MARKERS_TEXTURE = new ResourceLocation(Terramap.MOD_ID, "textures/gui/entity_markers.png");
protected ResourceLocation texture;
protected int u, v, textureWidth, textureHeight;
diff --git a/forge/src/main/java/fr/thesmyler/terramap/maps/raster/CachingRasterTiledMap.java b/forge/src/main/java/fr/thesmyler/terramap/maps/raster/CachingRasterTiledMap.java
index 9c2d7a48..5488cecb 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/maps/raster/CachingRasterTiledMap.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/maps/raster/CachingRasterTiledMap.java
@@ -4,8 +4,8 @@
import java.util.LinkedList;
import java.util.Map;
-import fr.thesmyler.terramap.TerramapMod;
import fr.thesmyler.terramap.TerramapConfig;
+import net.smyler.terramap.Terramap;
import net.smyler.terramap.util.geo.TilePos;
import net.smyler.terramap.util.geo.TilePosImmutable;
import net.smyler.terramap.util.geo.WebMercatorBounds;
@@ -108,8 +108,8 @@ private void prepareLowTiles() {
try {
this.getTile(zoom, x, y).getTexture();
} catch (Throwable e) {
- TerramapMod.logger.error("Failed to load a low level texture for map: %s-%sv%s at %s/%s/%s", this.getId(), this.getProvider(), this.getProviderVersion(),zoom, x, y);
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to load a low level texture for map: %s-%sv%s at %s/%s/%s", this.getId(), this.getProvider(), this.getProviderVersion(),zoom, x, y);
+ Terramap.instance().logger().catching(e);
}
}
}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/maps/raster/MapStylesLibrary.java b/forge/src/main/java/fr/thesmyler/terramap/maps/raster/MapStylesLibrary.java
index 299157f4..e1857e23 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/maps/raster/MapStylesLibrary.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/maps/raster/MapStylesLibrary.java
@@ -1,17 +1,12 @@
package fr.thesmyler.terramap.maps.raster;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.io.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
-import java.util.concurrent.CompletableFuture;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
@@ -21,13 +16,9 @@
import fr.thesmyler.terramap.TerramapConfig;
import fr.thesmyler.terramap.maps.raster.imp.UrlTiledMap;
import net.smyler.smylib.text.Text;
+import net.smyler.terramap.Terramap;
import net.smyler.terramap.util.geo.WebMercatorBounds;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufInputStream;
-import net.buildtheearth.terraplusplus.util.http.Http;
-import static fr.thesmyler.terramap.TerramapMod.GSON;
-import static fr.thesmyler.terramap.TerramapMod.GSON_PRETTY;
public class MapStylesLibrary {
@@ -76,9 +67,9 @@ public static void loadBuiltIns() {
baseMaps.putAll(loadFromJson(json.toString(), TiledMapProvider.BUILT_IN));
}
} catch(Exception e) {
- TerramapMod.logger.fatal("Failed to read built-in map styles, Terramap is likely to not work properly!");
- TerramapMod.logger.fatal("Path: " + path);
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().fatal("Failed to read built-in map styles, Terramap is likely to not work properly!");
+ Terramap.instance().logger().fatal("Path: {}", path);
+ Terramap.instance().logger().catching(e);
TiledMapProvider.BUILT_IN.setLastError(e);
}
@@ -89,8 +80,8 @@ public static void loadInternals() {
try {
// We currently have no internal styles
} catch(Exception e) {
- TerramapMod.logger.error("Failed to load internal map styles");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to load internal map styles");
+ Terramap.instance().logger().catching(e);
TiledMapProvider.INTERNAL.setLastError(e);
}
}
@@ -101,7 +92,7 @@ public static void loadInternals() {
* parses it as redirect as would most browsers
* and does a request to the corresponding url.
* The body of that request is then parsed as a map style json config file.
- *
+ *
* This should be called after {@link #loadBuiltIns()} so it overwrites it.
*
* @param hostname - the hostname to lookup
@@ -112,18 +103,18 @@ public static void loadFromOnline(String hostname) {
try {
url = resolveUpdateURL(hostname);
} catch (UnknownHostException | NamingException e1) {
- TerramapMod.logger.error("Failed to resolve map styles urls!");
- TerramapMod.logger.catching(e1);
+ Terramap.instance().logger().error("Failed to resolve map styles urls!");
+ Terramap.instance().logger().catching(e1);
return;
}
- CompletableFuture request = Http.get(url);
- request.whenComplete((b, e) -> {
+
+ Terramap.instance().http().get(url).whenComplete((b, e) -> {
if(e != null) {
- TerramapMod.logger.error("Failed to download updated map style file!");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to download updated map style file!");
+ Terramap.instance().logger().catching(e);
TiledMapProvider.ONLINE.setLastError(e);
}
- try(BufferedReader txtReader = new BufferedReader(new InputStreamReader(new ByteBufInputStream(b)))) {
+ try(BufferedReader txtReader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(b)))) {
StringBuilder json = new StringBuilder();
String line = txtReader.readLine();
while(line != null) {
@@ -132,8 +123,8 @@ public static void loadFromOnline(String hostname) {
}
baseMaps.putAll(loadFromJson(json.toString(), TiledMapProvider.ONLINE));
} catch(Exception f) {
- TerramapMod.logger.error("Failed to parse updated map style file!");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to parse updated map style file!");
+ Terramap.instance().logger().catching(e);
TiledMapProvider.ONLINE.setLastError(e);
}
});
@@ -146,18 +137,18 @@ public static void loadFromOnline(String hostname) {
public static void loadFromConfigFile() {
TiledMapProvider.CUSTOM.setLastError(null);
if(configMapsFile == null) {
- TerramapMod.logger.error("Map config file was null!");
+ Terramap.instance().logger().error("Map config file was null!");
TiledMapProvider.CUSTOM.setLastError(new NullPointerException("Map style config files was null"));
return;
}
if(!configMapsFile.exists()) {
try {
- TerramapMod.logger.debug("Map config file did not exist, creating a blank one.");
+ Terramap.instance().logger().debug("Map config file did not exist, creating a blank one.");
MapStyleFile mapFile = new MapStyleFile(new MapFileMetadata(0, "Add custom map styles here. See an example at styles.terramap.thesmyler.fr (open in your browser, do not add http or https prefix)"));
- Files.write(configMapsFile.toPath(), GSON_PRETTY.toJson(mapFile).getBytes(Charset.defaultCharset()));
+ Files.write(configMapsFile.toPath(), Terramap.instance().gsonPretty().toJson(mapFile).getBytes(Charset.defaultCharset()));
} catch (IOException e) {
- TerramapMod.logger.error("Failed to create map style config file!");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to create map style config file!");
+ Terramap.instance().logger().catching(e);
TiledMapProvider.CUSTOM.setLastError(e);
}
@@ -165,8 +156,8 @@ public static void loadFromConfigFile() {
try {
userMaps.putAll(loadFromFile(configMapsFile, TiledMapProvider.CUSTOM));
} catch (Exception e) {
- TerramapMod.logger.error("Failed to read map style config file!");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to read map style config file!");
+ Terramap.instance().logger().catching(e);
TiledMapProvider.CUSTOM.setLastError(e);
}
}
@@ -231,12 +222,12 @@ private static Map loadFromFile(File file, TiledMapProvider
}
private static Map loadFromJson(String json, TiledMapProvider provider) {
- MapStyleFile savedStyles = GSON.fromJson(json, MapStyleFile.class);
+ MapStyleFile savedStyles = Terramap.instance().gson().fromJson(json, MapStyleFile.class);
Map styles = new HashMap<>();
for(String id: savedStyles.maps.keySet()) {
UrlTiledMap style = readFromSaved(id, savedStyles.maps.get(id), provider, savedStyles.metadata.version, savedStyles.metadata.comment);
if(!TerramapConfig.enableDebugMaps && style.isDebug()) {
- TerramapMod.logger.info("Not loading debug map style " + style.getId());
+ Terramap.instance().logger().info("Not loading debug map style {}", style.getId());
continue;
}
styles.put(id, style);
@@ -281,6 +272,7 @@ private static class SavedMapStyle {
}
+ @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
private static class MapStyleFile {
Map maps;
diff --git a/forge/src/main/java/fr/thesmyler/terramap/maps/raster/imp/ColorTiledMap.java b/forge/src/main/java/fr/thesmyler/terramap/maps/raster/imp/ColorTiledMap.java
index f255c88b..3e222272 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/maps/raster/imp/ColorTiledMap.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/maps/raster/imp/ColorTiledMap.java
@@ -1,9 +1,9 @@
package fr.thesmyler.terramap.maps.raster.imp;
import net.smyler.smylib.Color;
-import fr.thesmyler.terramap.TerramapMod;
import fr.thesmyler.terramap.maps.raster.CachingRasterTiledMap;
import fr.thesmyler.terramap.maps.raster.TiledMapProvider;
+import net.smyler.terramap.Terramap;
import net.smyler.terramap.util.ImageUtil;
import net.smyler.terramap.util.geo.TilePosImmutable;
import net.minecraft.client.Minecraft;
@@ -26,7 +26,7 @@ public ColorTiledMap(Color color, String name) {
TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
DynamicTexture texture = new DynamicTexture(ImageUtil.imageFromColor(256, 256, this.color.asRGBInt()));
this.textureLocation = textureManager.getDynamicTextureLocation(
- TerramapMod.MODID + ":color_tile_" + this.color.asHexString(), texture);
+ Terramap.MOD_ID + ":color_tile_" + this.color.asHexString(), texture);
} else {
this.textureLocation = null;
}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/maps/raster/imp/UrlRasterTile.java b/forge/src/main/java/fr/thesmyler/terramap/maps/raster/imp/UrlRasterTile.java
index e469f3bb..8b922f5e 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/maps/raster/imp/UrlRasterTile.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/maps/raster/imp/UrlRasterTile.java
@@ -1,19 +1,16 @@
package fr.thesmyler.terramap.maps.raster.imp;
import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.net.URL;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import javax.imageio.ImageIO;
import fr.thesmyler.terramap.maps.raster.RasterTile;
+import net.smyler.terramap.Terramap;
import net.smyler.terramap.util.geo.TilePosImmutable;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufInputStream;
-import net.buildtheearth.terraplusplus.util.http.Disk;
-import net.buildtheearth.terraplusplus.util.http.Http;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.TextureManager;
@@ -28,7 +25,7 @@ public class UrlRasterTile implements RasterTile {
private final TilePosImmutable pos;
private final String url;
private ResourceLocation texture = null;
- private CompletableFuture textureTask;
+ private CompletableFuture textureTask;
public UrlRasterTile(String urlPattern, TilePosImmutable pos) {
@@ -62,7 +59,7 @@ public boolean isTextureAvailable() {
public ResourceLocation getTexture() throws Throwable {
if(this.texture == null) {
if(this.textureTask == null) {
- this.textureTask = Http.get(this.getURL());
+ this.textureTask = Terramap.instance().http().get(this.getURL());
} else this.tryLoadingTexture();
}
return this.texture;
@@ -85,11 +82,11 @@ private void tryLoadingTexture() throws Throwable {
}
Minecraft mc = Minecraft.getMinecraft();
TextureManager textureManager = mc.getTextureManager();
- ByteBuf buf = this.textureTask.get();
+ byte[] buf = this.textureTask.get();
if(buf == null) throw new IOException("404 response");
- try (ByteBufInputStream is = new ByteBufInputStream(buf)) {
+ try (ByteArrayInputStream is = new ByteArrayInputStream(buf)) {
BufferedImage image = ImageIO.read(is);
- if(image == null) throw new IOException("Failed to read image! url: " + this.getURL() + " file: " + Disk.cacheFileFor(new URL(this.getURL()).getFile()).toString());
+ if(image == null) throw new IOException("Failed to read image! url: " + this.getURL());
this.texture = textureManager.getDynamicTextureLocation("textures/gui/maps/" + this.getURL(), new DynamicTexture(image));
}
}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/maps/raster/imp/UrlTiledMap.java b/forge/src/main/java/fr/thesmyler/terramap/maps/raster/imp/UrlTiledMap.java
index c3f0f7f2..8d44a545 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/maps/raster/imp/UrlTiledMap.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/maps/raster/imp/UrlTiledMap.java
@@ -6,14 +6,14 @@
import com.google.common.base.Strings;
-import fr.thesmyler.terramap.TerramapMod;
import fr.thesmyler.terramap.TerramapConfig;
import fr.thesmyler.terramap.maps.raster.CachingRasterTiledMap;
import fr.thesmyler.terramap.maps.raster.MapStylesLibrary;
import fr.thesmyler.terramap.maps.raster.TiledMapProvider;
import fr.thesmyler.terramap.network.SP2CMapStylePacket;
-import fr.thesmyler.terramap.util.CopyrightHolder;
+import net.smyler.terramap.util.CopyrightHolder;
import net.smyler.smylib.text.Text;
+import net.smyler.terramap.Terramap;
import net.smyler.terramap.util.ImageUtil;
import net.smyler.terramap.util.geo.TilePosImmutable;
import net.smyler.terramap.util.geo.WebMercatorBounds;
@@ -116,8 +116,8 @@ public void setup() {
Http.setMaximumConcurrentRequestsTo(url, this.getMaxConcurrentRequests());
}
} catch(IllegalArgumentException | MalformedURLException e) {
- TerramapMod.logger.error("Failed to set max concurrent requests for host. Url :" + url);
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to set max concurrent requests for host. Url :{}", url);
+ Terramap.instance().logger().catching(e);
}
}
super.setup();
@@ -277,7 +277,7 @@ public void registerErrorTexture() {
TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
int[] color = {170, 211, 223};
DynamicTexture texture = new DynamicTexture(ImageUtil.imageFromColor(256, 256, color));
- this.errorTileTexture = textureManager.getDynamicTextureLocation(TerramapMod.MODID + ":error_tile_texture", texture);
+ this.errorTileTexture = textureManager.getDynamicTextureLocation(Terramap.MOD_ID + ":error_tile_texture", texture);
}
}
\ No newline at end of file
diff --git a/forge/src/main/java/fr/thesmyler/terramap/network/P2CSledgehammerHelloPacket.java b/forge/src/main/java/fr/thesmyler/terramap/network/P2CSledgehammerHelloPacket.java
index 385a01bb..53f974b7 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/network/P2CSledgehammerHelloPacket.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/network/P2CSledgehammerHelloPacket.java
@@ -10,6 +10,7 @@
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
+import net.smyler.terramap.Terramap;
public class P2CSledgehammerHelloPacket implements IMessage {
@@ -55,7 +56,7 @@ public P2CSledgehammerHelloPacketHandler(){}
@Override
public IMessage onMessage(P2CSledgehammerHelloPacket pkt, MessageContext ctx) {
Minecraft.getMinecraft().addScheduledTask(() -> {
- TerramapMod.logger.info("Got Sledgehammer hello, remote version is " + pkt.sledgehammerVersion);
+ Terramap.instance().logger().info("Got Sledgehammer hello, remote version is {}", pkt.sledgehammerVersion);
TerramapClientContext.getContext().setSledgehammerVersion(pkt.sledgehammerVersion);
TerramapClientContext.getContext().setPlayersSynchronizedByProxy(pkt.syncPlayers);
TerramapClientContext.getContext().setSpectatorsSynchronizedByProxy(pkt.syncSpectators);
diff --git a/forge/src/main/java/fr/thesmyler/terramap/network/RemoteSynchronizer.java b/forge/src/main/java/fr/thesmyler/terramap/network/RemoteSynchronizer.java
index 750a4624..7fd6187f 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/network/RemoteSynchronizer.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/network/RemoteSynchronizer.java
@@ -24,6 +24,7 @@
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
+import net.smyler.terramap.Terramap;
public abstract class RemoteSynchronizer {
@@ -45,7 +46,7 @@ public static void syncPlayers(WorldServer world) {
}
for(RegisteredForUpdatePlayer player: RemoteSynchronizer.playersToUpdate.values()) {
if(ctime - player.lastRegisterTime > TerramapConfig.SERVER.syncHeartbeatTimeout - 10000 && !player.noticeSent) {
- TerramapMod.logger.debug("Sending registration expires notice to " + player.player.getName());
+ Terramap.instance().logger().debug("Sending registration expires notice to {}", player.player.getName());
TerramapNetworkManager.CHANNEL_MAPSYNC.sendTo(new SP2CRegistrationExpiresPacket(), player.player);
player.noticeSent = true;
}
@@ -54,7 +55,7 @@ public static void syncPlayers(WorldServer world) {
while (iterator.hasNext()) {
RegisteredForUpdatePlayer player = iterator.next();
if(ctime - player.lastRegisterTime > TerramapConfig.SERVER.syncHeartbeatTimeout) {
- TerramapMod.logger.debug("Unregistering " + player.player.getName() + " from map update as it did not renew its registration");
+ Terramap.instance().logger().debug("Unregistering {} from map update as it did not renew its registration", player.player.getName());
iterator.remove();
TerramapNetworkManager.CHANNEL_MAPSYNC.sendTo(new SP2CRegistrationExpiresPacket(), player.player);
}
@@ -63,13 +64,13 @@ public static void syncPlayers(WorldServer world) {
public static void registerPlayerForUpdates(EntityPlayerMP player) {
if(PermissionManager.hasPermission(player, Permission.RADAR_PLAYERS)) {
- TerramapMod.logger.debug("Registering player for map updates: " + player.getDisplayNameString());
+ Terramap.instance().logger().debug("Registering player for map updates: {}", player.getDisplayNameString());
RemoteSynchronizer.playersToUpdate.put(player.getPersistentID(), new RegisteredForUpdatePlayer(player, System.currentTimeMillis()));
}
}
public static void unregisterPlayerForUpdates(EntityPlayerMP player) {
- TerramapMod.logger.debug("Unregistering player for map updates: " + player.getDisplayNameString());
+ Terramap.instance().logger().debug("Unregistering player for map updates: {}", player.getDisplayNameString());
RemoteSynchronizer.playersToUpdate.remove(player.getPersistentID());
}
@@ -123,12 +124,12 @@ public static void sendMapStylesToClient(EntityPlayerMP player) {
}
public static void onServerHello(S2CTerramapHelloPacket pkt) {
- TerramapMod.logger.info("Got server hello, remote version is " + pkt.serverVersion);
+ Terramap.instance().logger().info("Got server hello, remote version is " + pkt.serverVersion);
String jsonWorldSettings = null;
if(pkt.worldSettings != null) {
jsonWorldSettings = pkt.worldSettings.toString();
}
- TerramapMod.logger.debug(
+ Terramap.instance().logger().debug(
"Server version: " + pkt.serverVersion + "\t" +
"Server worldSettings: " + jsonWorldSettings + "\t" +
"Server UUID: " + pkt.worldUUID + "\t" +
@@ -156,7 +157,7 @@ public static void onServerHello(S2CTerramapHelloPacket pkt) {
ctx.setAllowsDecoRadar(pkt.enableDecoRadar);
ctx.setServerWarpSupport(pkt.hasWarpSupport);
} catch (InvalidVersionString e) {
- TerramapMod.logger.warn("Failed to parse server version! will act as if the server did not have Terramap installed");
+ Terramap.instance().logger().warn("Failed to parse server version! will act as if the server did not have Terramap installed");
}
ctx.tryShowWelcomeToast();
}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/network/SP2CMapStylePacket.java b/forge/src/main/java/fr/thesmyler/terramap/network/SP2CMapStylePacket.java
index 17e93537..766c79c3 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/network/SP2CMapStylePacket.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/network/SP2CMapStylePacket.java
@@ -5,10 +5,10 @@
import com.google.gson.JsonParseException;
import net.smyler.smylib.text.Text;
+import net.smyler.terramap.Terramap;
import org.apache.logging.log4j.util.Strings;
import fr.thesmyler.terramap.TerramapClientContext;
-import fr.thesmyler.terramap.TerramapMod;
import fr.thesmyler.terramap.TerramapConfig;
import fr.thesmyler.terramap.maps.raster.TiledMapProvider;
import fr.thesmyler.terramap.maps.raster.imp.UrlTiledMap;
@@ -19,7 +19,6 @@
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
-import static fr.thesmyler.terramap.TerramapMod.GSON;
public class SP2CMapStylePacket implements IMessage {
@@ -80,10 +79,10 @@ public void fromBytes(ByteBuf buf) {
String key = NetworkUtil.decodeStringFromByteBuf(buf);
String copyrightJson = NetworkUtil.decodeStringFromByteBuf(buf);
try {
- Text copyright = GSON.fromJson(copyrightJson, Text.class);
+ Text copyright = Terramap.instance().gson().fromJson(copyrightJson, Text.class);
copyrights.put(key, copyright);
} catch (JsonParseException e) {
- TerramapMod.logger.warn("Received invalid map style copyright from server.");
+ Terramap.instance().logger().warn("Received invalid map style copyright from server.");
}
}
this.copyrights = copyrights;
@@ -129,7 +128,7 @@ public void toBytes(ByteBuf buf) {
buf.writeInt(this.copyrights.size());
for(String key: this.copyrights.keySet()) {
NetworkUtil.encodeStringToByteBuf(key, buf);
- NetworkUtil.encodeStringToByteBuf(GSON.toJson(this.copyrights.get(key)), buf);
+ NetworkUtil.encodeStringToByteBuf(Terramap.instance().gson().toJson(this.copyrights.get(key)), buf);
}
buf.writeInt(this.minZoom);
buf.writeInt(this.maxZoom);
@@ -185,16 +184,16 @@ public SP2CMapStylePacketTerramapHandler() {}
public IMessage onMessage(SP2CMapStylePacket message, MessageContext ctx) {
try {
UrlTiledMap map = message.getTiledMap(TiledMapProvider.SERVER);
- TerramapMod.logger.debug("Got custom map style from server: " + map.getId() + " / " + String.join(";", map.getUrlPatterns()));
+ Terramap.instance().logger().debug("Got custom map style from server: {} / {}", map.getId(), String.join(";", map.getUrlPatterns()));
if(!TerramapConfig.enableDebugMaps && map.isDebug()) {
- TerramapMod.logger.debug("Ignoring debug map from server: " + map.getId());
+ Terramap.instance().logger().debug("Ignoring debug map from server: {}", map.getId());
return null;
}
Minecraft.getMinecraft().addScheduledTask(() -> TerramapClientContext.getContext().addServerMapStyle(map));
} catch(Exception e) {
- TerramapMod.logger.error("Failed to unpack a map style sent by the server");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to unpack a map style sent by the server");
+ Terramap.instance().logger().catching(e);
TiledMapProvider.SERVER.setLastError(e);
}
return null;
@@ -210,15 +209,15 @@ public SP2CMapStylePacketSledgehammerHandler() {}
public IMessage onMessage(SP2CMapStylePacket message, MessageContext ctx) {
try {
UrlTiledMap map = message.getTiledMap(TiledMapProvider.PROXY);
- TerramapMod.logger.debug("Got custom map style from proxy: " + map.getId() + " / " + String.join(";", map.getUrlPatterns()));
+ Terramap.instance().logger().debug("Got custom map style from proxy: {} / {}", map.getId(), String.join(";", map.getUrlPatterns()));
if(!TerramapConfig.enableDebugMaps && map.isDebug()) {
- TerramapMod.logger.debug("Ignoring debug map from proxy: " + map.getId());
+ Terramap.instance().logger().debug("Ignoring debug map from proxy: {}", map.getId());
return null;
}
Minecraft.getMinecraft().addScheduledTask(() -> TerramapClientContext.getContext().addProxyMapStyle(map));
} catch(Exception e) {
- TerramapMod.logger.error("Failed to unpack a map style sent by the proxy");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to unpack a map style sent by the proxy");
+ Terramap.instance().logger().catching(e);
TiledMapProvider.PROXY.setLastError(e);
}
return null;
diff --git a/forge/src/main/java/fr/thesmyler/terramap/network/TerramapNetworkManager.java b/forge/src/main/java/fr/thesmyler/terramap/network/TerramapNetworkManager.java
index ab79743f..56b86282 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/network/TerramapNetworkManager.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/network/TerramapNetworkManager.java
@@ -1,6 +1,5 @@
package fr.thesmyler.terramap.network;
-import fr.thesmyler.terramap.TerramapMod;
import fr.thesmyler.terramap.network.P2CSledgehammerHelloPacket.P2CSledgehammerHelloPacketHandler;
import fr.thesmyler.terramap.network.S2CTerramapHelloPacket.S2CTerramapHelloPacketHandler;
import fr.thesmyler.terramap.network.S2CTpCommandPacket.S2CTpCommandPacketHandler;
@@ -12,42 +11,19 @@
import fr.thesmyler.terramap.network.playersync.SP2CPlayerSyncPacket.S2CPlayerSyncPacketHandler;
import fr.thesmyler.terramap.network.playersync.SP2CRegistrationExpiresPacket;
import fr.thesmyler.terramap.network.playersync.SP2CRegistrationExpiresPacket.S2CRegistrationExpiresPacketHandler;
-import fr.thesmyler.terramap.network.warps.C2SPCreateWarpPacket;
-import fr.thesmyler.terramap.network.warps.C2SPCreateWarpPacket.C2SPCreateWarpPacketHandler;
-import fr.thesmyler.terramap.network.warps.C2SPEditWarpPacket;
-import fr.thesmyler.terramap.network.warps.C2SPEditWarpPacket.C2SPEditWarpPacketHandler;
-import fr.thesmyler.terramap.network.warps.C2SPRequestMultiWarpPacket;
-import fr.thesmyler.terramap.network.warps.C2SPRequestMultiWarpPacket.C2SPRequestMultiWarpPacketHandler;
-import fr.thesmyler.terramap.network.warps.C2SPRequestWarpPacket;
-import fr.thesmyler.terramap.network.warps.C2SPRequestWarpPacket.C2SPRequestWarpPacketHandler;
-import fr.thesmyler.terramap.network.warps.SP2CCreateWarpConfirmationPacket;
-import fr.thesmyler.terramap.network.warps.SP2CCreateWarpConfirmationPacket.SP2CCreateWarpConfirmationPacketProxyHandler;
-import fr.thesmyler.terramap.network.warps.SP2CCreateWarpConfirmationPacket.SP2CCreateWarpConfirmationPacketServerHandler;
-import fr.thesmyler.terramap.network.warps.SP2CEditWarpConfirmationPacket;
-import fr.thesmyler.terramap.network.warps.SP2CEditWarpConfirmationPacket.SP2CEditWarpConfirmationPacketProxyHandler;
-import fr.thesmyler.terramap.network.warps.SP2CEditWarpConfirmationPacket.SP2CEditWarpConfirmationPacketServerHandler;
-import fr.thesmyler.terramap.network.warps.SP2CMultiWarpPacket;
-import fr.thesmyler.terramap.network.warps.SP2CMultiWarpPacket.SP2CMultiWarpPacketProxyHandler;
-import fr.thesmyler.terramap.network.warps.SP2CMultiWarpPacket.SP2CMultiWarpPacketServerHandler;
-import fr.thesmyler.terramap.network.warps.SP2CWarpCommandPacket;
-import fr.thesmyler.terramap.network.warps.SP2CWarpCommandPacket.SP2CWarpCommandPacketProxyHandler;
-import fr.thesmyler.terramap.network.warps.SP2CWarpCommandPacket.SP2CWarpCommandPacketServerHandler;
-import fr.thesmyler.terramap.network.warps.SP2CWarpPacket;
-import fr.thesmyler.terramap.network.warps.SP2CWarpPacket.SP2CWarpPacketProxyHandler;
-import fr.thesmyler.terramap.network.warps.SP2CWarpPacket.SP2CWarpPacketServerHandler;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;
+import net.smyler.terramap.Terramap;
-//TODO Test the warp protocol
public abstract class TerramapNetworkManager {
// The channel instances
- public static final SimpleNetworkWrapper CHANNEL_TERRAMAP = NetworkRegistry.INSTANCE.newSimpleChannel(TerramapMod.MODID + ":terramap");
- public static final SimpleNetworkWrapper CHANNEL_MAPSYNC = NetworkRegistry.INSTANCE.newSimpleChannel(TerramapMod.MODID + ":mapsync");
- public static final SimpleNetworkWrapper CHANNEL_SLEDGEHAMMER = NetworkRegistry.INSTANCE.newSimpleChannel(TerramapMod.MODID + ":sh"); // Forge does not support channel names longer than 20
+ public static final SimpleNetworkWrapper CHANNEL_TERRAMAP = NetworkRegistry.INSTANCE.newSimpleChannel(Terramap.MOD_ID + ":terramap");
+ public static final SimpleNetworkWrapper CHANNEL_MAPSYNC = NetworkRegistry.INSTANCE.newSimpleChannel(Terramap.MOD_ID + ":mapsync");
+ public static final SimpleNetworkWrapper CHANNEL_SLEDGEHAMMER = NetworkRegistry.INSTANCE.newSimpleChannel(Terramap.MOD_ID + ":sh"); // Forge does not support channel names longer than 20
/**
* Registers the handlers
@@ -58,15 +34,6 @@ public static void registerHandlers(Side side){
registerTerramapS2C(S2C_TERRAMAP_HELLO_DISCRIMINATOR, S2CTerramapHelloPacketHandler.class, S2CTerramapHelloPacket.class);
registerTerramapS2C(S2C_TERRAMAP_TPCMD_DISCRIMINATOR, S2CTpCommandPacketHandler.class, S2CTpCommandPacket.class);
registerTerramapS2C(S2C_TERRAMAP_MAPSTYLE_DISCRIMINATOR, SP2CMapStylePacketTerramapHandler.class, SP2CMapStylePacket.class);
- registerTerramapC2S(C2S_TERRAMAP_REQUEST_WARP_DISCRIMINATOR, C2SPRequestWarpPacketHandler.class, C2SPRequestWarpPacket.class);
- registerTerramapS2C(S2C_TERRAMAP_WARP_DISCRIMINATOR, SP2CWarpPacketServerHandler.class, SP2CWarpPacket.class);
- registerTerramapC2S(C2S_TERRAMAP_REQUEST_MULTI_WARP_DISCRIMINATOR, C2SPRequestMultiWarpPacketHandler.class, C2SPRequestMultiWarpPacket.class);
- registerTerramapS2C(S2C_TERRAMAP_MULTI_WARP_DISCRIMINATOR, SP2CMultiWarpPacketServerHandler.class, SP2CMultiWarpPacket.class);
- registerTerramapC2S(C2S_TERRAMAP_CREATE_WARP_DISCRIMINATOR, C2SPCreateWarpPacketHandler.class, C2SPCreateWarpPacket.class);
- registerTerramapS2C(S2C_TERRAMAP_CREATE_WARP_CONFIRMATION_DISCRIMINATOR, SP2CCreateWarpConfirmationPacketServerHandler.class, SP2CCreateWarpConfirmationPacket.class);
- registerTerramapC2S(C2S_TERRAMAP_EDIT_WARP_DISCRIMINATOR, C2SPEditWarpPacketHandler.class, C2SPEditWarpPacket.class);
- registerTerramapS2C(S2C_TERRAMAP_EDIT_WARP_CONFIRMATION_DISCRIMINATOR, SP2CEditWarpConfirmationPacketServerHandler.class, SP2CEditWarpConfirmationPacket.class);
- registerTerramapS2C(S2C_TERRAMAP_WARP_COMMAND_DISCRIMINATOR, SP2CWarpCommandPacketServerHandler.class, SP2CWarpCommandPacket.class);
registerMapsyncCP2S(C2SP_MAPSYNC_REGISTER_DISCRIMINATOR, C2SRegisterForUpdatesPacketHandler.class, C2SPRegisterForUpdatesPacket.class);
registerMapsyncSP2C(SP2C_MAPSYNC_PLAYERSYNC_DISCRIMINATOR, S2CPlayerSyncPacketHandler.class, SP2CPlayerSyncPacket.class);
@@ -74,15 +41,6 @@ public static void registerHandlers(Side side){
registerSledgehammerP2C(P2C_SH_HELLO_DISCRIMINATOR, P2CSledgehammerHelloPacketHandler.class, P2CSledgehammerHelloPacket.class);
registerSledgehammerP2C(P2C_SH_MAPSTYLE_DISCRIMINATOR, SP2CMapStylePacketSledgehammerHandler.class, SP2CMapStylePacket.class);
- registerSledgehammerC2P(C2P_SH_REQUEST_WARP_DISCRIMINATOR, C2SPRequestWarpPacketHandler.class, C2SPRequestWarpPacket.class);
- registerSledgehammerP2C(P2C_SH_WARP_DISCRIMINATOR, SP2CWarpPacketProxyHandler.class, SP2CWarpPacket.class);
- registerSledgehammerC2P(C2P_SH_REQUEST_MULTI_WARP_DISCRIMINATOR, C2SPRequestMultiWarpPacketHandler.class, C2SPRequestMultiWarpPacket.class);
- registerSledgehammerP2C(P2C_SH_MULTI_WARP_DISCRIMINATOR, SP2CMultiWarpPacketProxyHandler.class, SP2CMultiWarpPacket.class);
- registerSledgehammerC2P(C2P_SH_CREATE_WARP_DISCRIMINATOR, C2SPCreateWarpPacketHandler.class, C2SPCreateWarpPacket.class);
- registerSledgehammerP2C(P2C_SH_CREATE_WARP_CONFIRMATION_DISCRIMINATOR, SP2CCreateWarpConfirmationPacketProxyHandler.class, SP2CCreateWarpConfirmationPacket.class);
- registerSledgehammerC2P(C2P_SH_EDIT_WARP_DISCRIMINATOR, C2SPEditWarpPacketHandler.class, C2SPEditWarpPacket.class);
- registerSledgehammerP2C(P2C_SH_EDIT_WARP_CONFIRMATION_DISCRIMINATOR, SP2CEditWarpConfirmationPacketProxyHandler.class, SP2CEditWarpConfirmationPacket.class);
- registerSledgehammerP2C(P2C_SH_WARP_COMMAND_DISCRIMINATOR, SP2CWarpCommandPacketProxyHandler.class, SP2CWarpCommandPacket.class);
}
@@ -90,15 +48,6 @@ public static void registerHandlers(Side side){
private static final int S2C_TERRAMAP_HELLO_DISCRIMINATOR = 0;
private static final int S2C_TERRAMAP_TPCMD_DISCRIMINATOR = 1;
private static final int S2C_TERRAMAP_MAPSTYLE_DISCRIMINATOR = 2;
- private static final int C2S_TERRAMAP_REQUEST_WARP_DISCRIMINATOR = 3;
- private static final int S2C_TERRAMAP_WARP_DISCRIMINATOR = 4;
- private static final int C2S_TERRAMAP_REQUEST_MULTI_WARP_DISCRIMINATOR = 5;
- private static final int S2C_TERRAMAP_MULTI_WARP_DISCRIMINATOR = 6;
- private static final int C2S_TERRAMAP_CREATE_WARP_DISCRIMINATOR = 7;
- private static final int S2C_TERRAMAP_CREATE_WARP_CONFIRMATION_DISCRIMINATOR = 8;
- private static final int C2S_TERRAMAP_EDIT_WARP_DISCRIMINATOR = 9;
- private static final int S2C_TERRAMAP_EDIT_WARP_CONFIRMATION_DISCRIMINATOR = 10;
- private static final int S2C_TERRAMAP_WARP_COMMAND_DISCRIMINATOR = 11;
// terramap:mapsync
private static final int C2SP_MAPSYNC_REGISTER_DISCRIMINATOR = 0;
@@ -108,15 +57,6 @@ public static void registerHandlers(Side side){
//terramap:sh
private static final int P2C_SH_HELLO_DISCRIMINATOR = 0;
private static final int P2C_SH_MAPSTYLE_DISCRIMINATOR = 2;
- private static final int C2P_SH_REQUEST_WARP_DISCRIMINATOR = 3;
- private static final int P2C_SH_WARP_DISCRIMINATOR = 4;
- private static final int C2P_SH_REQUEST_MULTI_WARP_DISCRIMINATOR = 5;
- private static final int P2C_SH_MULTI_WARP_DISCRIMINATOR = 6;
- private static final int C2P_SH_CREATE_WARP_DISCRIMINATOR = 7;
- private static final int P2C_SH_CREATE_WARP_CONFIRMATION_DISCRIMINATOR = 8;
- private static final int C2P_SH_EDIT_WARP_DISCRIMINATOR = 9;
- private static final int P2C_SH_EDIT_WARP_CONFIRMATION_DISCRIMINATOR = 10;
- private static final int P2C_SH_WARP_COMMAND_DISCRIMINATOR = 11;
private static void registerTerramapS2C(int discriminator, Class extends IMessageHandler> handlerclass, Class msgclass) {
CHANNEL_TERRAMAP.registerMessage(handlerclass, msgclass, discriminator, Side.CLIENT);
diff --git a/forge/src/main/java/fr/thesmyler/terramap/network/playersync/SP2CRegistrationExpiresPacket.java b/forge/src/main/java/fr/thesmyler/terramap/network/playersync/SP2CRegistrationExpiresPacket.java
index c32ccd12..34338946 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/network/playersync/SP2CRegistrationExpiresPacket.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/network/playersync/SP2CRegistrationExpiresPacket.java
@@ -1,11 +1,11 @@
package fr.thesmyler.terramap.network.playersync;
import fr.thesmyler.terramap.TerramapClientContext;
-import fr.thesmyler.terramap.TerramapMod;
import io.netty.buffer.ByteBuf;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
+import net.smyler.terramap.Terramap;
public class SP2CRegistrationExpiresPacket implements IMessage {
@@ -24,7 +24,7 @@ public static class S2CRegistrationExpiresPacketHandler implements IMessageHandl
@Override
public C2SPRegisterForUpdatesPacket onMessage(SP2CRegistrationExpiresPacket message, MessageContext ctx) {
if(TerramapClientContext.getContext().needsUpdate()) {
- TerramapMod.logger.debug("Renewing registration for map update to server");
+ Terramap.instance().logger().debug("Renewing registration for map update to server");
return new C2SPRegisterForUpdatesPacket(true);
}
return null;
diff --git a/forge/src/main/java/fr/thesmyler/terramap/network/warps/AbstractWarpFilter.java b/forge/src/main/java/fr/thesmyler/terramap/network/warps/AbstractWarpFilter.java
deleted file mode 100644
index b2008837..00000000
--- a/forge/src/main/java/fr/thesmyler/terramap/network/warps/AbstractWarpFilter.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package fr.thesmyler.terramap.network.warps;
-
-import io.netty.buffer.ByteBuf;
-
-/**
- * Used to filter warps in multi warp requests
- *
- * TODO Implement warp filtering
- *
- * @author SmylerMC
- *
- */
-public abstract class AbstractWarpFilter {
-
- public abstract void writeToByteBuf(ByteBuf buf);
-
- public static AbstractWarpFilter readFromByteBuf(ByteBuf buf) {
- return null;
- }
-
-}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/network/warps/C2SPCreateWarpPacket.java b/forge/src/main/java/fr/thesmyler/terramap/network/warps/C2SPCreateWarpPacket.java
deleted file mode 100644
index 565d925b..00000000
--- a/forge/src/main/java/fr/thesmyler/terramap/network/warps/C2SPCreateWarpPacket.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package fr.thesmyler.terramap.network.warps;
-
-import fr.thesmyler.terramap.warp.Warp;
-import io.netty.buffer.ByteBuf;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
-import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
-
-public class C2SPCreateWarpPacket implements IMessage {
-
- private long requestId;
- private Warp warp;
-
- public C2SPCreateWarpPacket(long requestId, Warp warp) {
- this.requestId = requestId;
- this.warp = warp;
- }
- public C2SPCreateWarpPacket() {}
-
- @Override
- public void fromBytes(ByteBuf buf) {
- this.requestId = buf.readLong();
- this.warp = Warp.readWarpFromByteBuf(buf);
- }
-
- @Override
- public void toBytes(ByteBuf buf) {
- buf.writeLong(this.requestId);
- this.warp.encodeToByteBuf(buf);
- }
-
- public static class C2SPCreateWarpPacketHandler implements IMessageHandler {
-
- @Override
- public SP2CCreateWarpConfirmationPacket onMessage(C2SPCreateWarpPacket pkt, MessageContext ctx) {
- return new SP2CCreateWarpConfirmationPacket(pkt.requestId, WarpRequestStatus.NOT_IMPLEMENTED);
- }
-
- }
-
-}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/network/warps/C2SPEditWarpPacket.java b/forge/src/main/java/fr/thesmyler/terramap/network/warps/C2SPEditWarpPacket.java
deleted file mode 100644
index bee8c10e..00000000
--- a/forge/src/main/java/fr/thesmyler/terramap/network/warps/C2SPEditWarpPacket.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package fr.thesmyler.terramap.network.warps;
-
-import fr.thesmyler.terramap.warp.Warp;
-import io.netty.buffer.ByteBuf;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
-import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
-
-public class C2SPEditWarpPacket implements IMessage {
-
- private long requestId;
- private Warp warp;
-
- public C2SPEditWarpPacket(long requestId, Warp warp) {
- this.requestId = requestId;
- this.warp = warp;
- }
- public C2SPEditWarpPacket() {}
-
- @Override
- public void fromBytes(ByteBuf buf) {
- this.requestId = buf.readLong();
- this.warp = Warp.readWarpFromByteBuf(buf);
- }
-
- @Override
- public void toBytes(ByteBuf buf) {
- buf.writeLong(this.requestId);
- this.warp.encodeToByteBuf(buf);
- }
-
- public static class C2SPEditWarpPacketHandler implements IMessageHandler {
-
- @Override
- public SP2CEditWarpConfirmationPacket onMessage(C2SPEditWarpPacket pkt, MessageContext ctx) {
- return new SP2CEditWarpConfirmationPacket(pkt.requestId, WarpRequestStatus.NOT_IMPLEMENTED);
- }
-
- }
-
-}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/network/warps/C2SPRequestMultiWarpPacket.java b/forge/src/main/java/fr/thesmyler/terramap/network/warps/C2SPRequestMultiWarpPacket.java
deleted file mode 100644
index 9ffc783a..00000000
--- a/forge/src/main/java/fr/thesmyler/terramap/network/warps/C2SPRequestMultiWarpPacket.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package fr.thesmyler.terramap.network.warps;
-
-import fr.thesmyler.terramap.network.NetworkUtil;
-import io.netty.buffer.ByteBuf;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
-import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
-
-public class C2SPRequestMultiWarpPacket implements IMessage {
-
- private long requestId;
- private AbstractWarpFilter[] filters;
- private String[] keys;
-
- public C2SPRequestMultiWarpPacket() {}
-
- @Override
- public void fromBytes(ByteBuf buf) {
- this.requestId = buf.readLong();
- this.filters = new AbstractWarpFilter[buf.readInt()];
- for(int i=0; i {
-
- @Override
- public SP2CMultiWarpPacket onMessage(C2SPRequestMultiWarpPacket pkt, MessageContext ctx) {
- return new SP2CMultiWarpPacket(pkt.requestId, WarpRequestStatus.NOT_IMPLEMENTED);
- }
-
- }
-
-}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/network/warps/C2SPRequestWarpPacket.java b/forge/src/main/java/fr/thesmyler/terramap/network/warps/C2SPRequestWarpPacket.java
deleted file mode 100644
index 20cba3cf..00000000
--- a/forge/src/main/java/fr/thesmyler/terramap/network/warps/C2SPRequestWarpPacket.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package fr.thesmyler.terramap.network.warps;
-
-import fr.thesmyler.terramap.network.NetworkUtil;
-import io.netty.buffer.ByteBuf;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
-import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
-
-public class C2SPRequestWarpPacket implements IMessage {
-
- private long requestId;
- private String warpId;
-
- public C2SPRequestWarpPacket(long id, String warpId) {
- this.requestId = id;
- this.warpId = warpId;
- }
-
- public C2SPRequestWarpPacket() {}
-
- @Override
- public void fromBytes(ByteBuf buf) {
- this.requestId = buf.readLong();
- this.warpId = NetworkUtil.decodeStringFromByteBuf(buf);
- }
-
- @Override
- public void toBytes(ByteBuf buf) {
- buf.writeLong(this.requestId);
- NetworkUtil.encodeStringToByteBuf(this.warpId, buf);
- }
-
- public static class C2SPRequestWarpPacketHandler implements IMessageHandler {
-
- @Override
- public SP2CWarpPacket onMessage(C2SPRequestWarpPacket pkt, MessageContext ctx) {
- return new SP2CWarpPacket(pkt.requestId, WarpRequestStatus.NOT_IMPLEMENTED, null);
- }
-
- }
-
-}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/network/warps/SP2CCreateWarpConfirmationPacket.java b/forge/src/main/java/fr/thesmyler/terramap/network/warps/SP2CCreateWarpConfirmationPacket.java
deleted file mode 100644
index 44d6937e..00000000
--- a/forge/src/main/java/fr/thesmyler/terramap/network/warps/SP2CCreateWarpConfirmationPacket.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package fr.thesmyler.terramap.network.warps;
-
-import io.netty.buffer.ByteBuf;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
-import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
-
-public class SP2CCreateWarpConfirmationPacket implements IMessage {
-
- private long requestId;
- private WarpRequestStatus status;
-
- public SP2CCreateWarpConfirmationPacket(long requestId, WarpRequestStatus status) {
- this.requestId = requestId;
- this.status = status;
- }
-
- public SP2CCreateWarpConfirmationPacket() {}
-
- @Override
- public void fromBytes(ByteBuf buf) {
- this.requestId = buf.readLong();
- this.status = WarpRequestStatus.getFromNetworkCode(buf.readByte());
- }
-
- @Override
- public void toBytes(ByteBuf buf) {
- buf.writeLong(this.requestId);
- buf.writeByte(this.status.getNetworkCode());
- }
-
- public static class SP2CCreateWarpConfirmationPacketServerHandler implements IMessageHandler {
-
- @Override
- public IMessage onMessage(SP2CCreateWarpConfirmationPacket message, MessageContext ctx) {
- //TODO SP2CCreateWarpConfirmationPacketHandler
- return null;
- }
-
- }
-
- public static class SP2CCreateWarpConfirmationPacketProxyHandler implements IMessageHandler {
-
- @Override
- public IMessage onMessage(SP2CCreateWarpConfirmationPacket message, MessageContext ctx) {
- //TODO SP2CCreateWarpConfirmationPacketProxyHandler
- return null;
- }
-
- }
-
-}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/network/warps/SP2CEditWarpConfirmationPacket.java b/forge/src/main/java/fr/thesmyler/terramap/network/warps/SP2CEditWarpConfirmationPacket.java
deleted file mode 100644
index 5e7d91b7..00000000
--- a/forge/src/main/java/fr/thesmyler/terramap/network/warps/SP2CEditWarpConfirmationPacket.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package fr.thesmyler.terramap.network.warps;
-
-import io.netty.buffer.ByteBuf;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
-import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
-
-public class SP2CEditWarpConfirmationPacket implements IMessage {
-
- private long requestId;
- private WarpRequestStatus status;
-
- public SP2CEditWarpConfirmationPacket(long requestId, WarpRequestStatus status) {
- this.requestId = requestId;
- this.status = status;
- }
-
- public SP2CEditWarpConfirmationPacket() {}
-
- @Override
- public void fromBytes(ByteBuf buf) {
- this.requestId = buf.readLong();
- this.status = WarpRequestStatus.getFromNetworkCode(buf.readByte());
- }
-
- @Override
- public void toBytes(ByteBuf buf) {
- buf.writeLong(this.requestId);
- buf.writeByte(this.status.getNetworkCode());
- }
-
- public static class SP2CEditWarpConfirmationPacketServerHandler implements IMessageHandler {
-
- @Override
- public IMessage onMessage(SP2CEditWarpConfirmationPacket message, MessageContext ctx) {
- //TODO SP2CEditWarpConfirmationPacketServerHandler
- return null;
- }
-
- }
-
- public static class SP2CEditWarpConfirmationPacketProxyHandler implements IMessageHandler {
-
- @Override
- public IMessage onMessage(SP2CEditWarpConfirmationPacket message, MessageContext ctx) {
- //TODO SP2CEditWarpConfirmationPacketProxyHandler
- return null;
- }
-
- }
-
-}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/network/warps/SP2CMultiWarpPacket.java b/forge/src/main/java/fr/thesmyler/terramap/network/warps/SP2CMultiWarpPacket.java
deleted file mode 100644
index 6461940d..00000000
--- a/forge/src/main/java/fr/thesmyler/terramap/network/warps/SP2CMultiWarpPacket.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package fr.thesmyler.terramap.network.warps;
-
-import fr.thesmyler.terramap.warp.Warp;
-import io.netty.buffer.ByteBuf;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
-import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
-
-public class SP2CMultiWarpPacket implements IMessage {
-
- private long requestId;
- private WarpRequestStatus status;
- private Warp[] warps;
-
- public SP2CMultiWarpPacket(long requestId, WarpRequestStatus status, Warp... warps) {
- this.requestId = requestId;
- this.status = status;
- this.warps = warps;
- }
-
- public SP2CMultiWarpPacket() {}
-
- @Override
- public void fromBytes(ByteBuf buf) {
- this.requestId = buf.readLong();
- this.status = WarpRequestStatus.getFromNetworkCode(buf.readByte());
- if(status.isSuccess()) {
- this.warps = new Warp[buf.readInt()];
- for(int i=0; i < this.warps.length; i++) {
- this.warps[i] = Warp.readWarpFromByteBuf(buf);
- }
- } else {
- this.warps = new Warp[0];
- }
- }
-
- @Override
- public void toBytes(ByteBuf buf) {
- buf.writeLong(this.requestId);
- buf.writeByte(this.status.getNetworkCode());
- buf.writeInt(this.warps.length);
- for(Warp warp: this.warps) {
- warp.encodeToByteBuf(buf);
- }
- }
-
- public static class SP2CMultiWarpPacketServerHandler implements IMessageHandler {
-
- @Override
- public IMessage onMessage(SP2CMultiWarpPacket message, MessageContext ctx) {
- //TODO SP2CMultiWarpPacketServerHandler
- return null;
- }
-
- }
-
- public static class SP2CMultiWarpPacketProxyHandler implements IMessageHandler {
-
- @Override
- public IMessage onMessage(SP2CMultiWarpPacket message, MessageContext ctx) {
- //TODO SP2CMultiWarpPacketProxyHandler
- return null;
- }
-
- }
-
-}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/network/warps/SP2CWarpCommandPacket.java b/forge/src/main/java/fr/thesmyler/terramap/network/warps/SP2CWarpCommandPacket.java
deleted file mode 100644
index c2fddd04..00000000
--- a/forge/src/main/java/fr/thesmyler/terramap/network/warps/SP2CWarpCommandPacket.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package fr.thesmyler.terramap.network.warps;
-
-import fr.thesmyler.terramap.network.NetworkUtil;
-import io.netty.buffer.ByteBuf;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
-import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
-
-public class SP2CWarpCommandPacket implements IMessage {
-
- public String cmd = "";
-
- public SP2CWarpCommandPacket(String cmd) {
- this.cmd = cmd;
- }
-
- public SP2CWarpCommandPacket() {}
-
- @Override
- public void fromBytes(ByteBuf buf) {
- this.cmd = NetworkUtil.decodeStringFromByteBuf(buf);
- }
-
- @Override
- public void toBytes(ByteBuf buf) {
- NetworkUtil.encodeStringToByteBuf(this.cmd, buf);
- }
-
- public static class SP2CWarpCommandPacketServerHandler implements IMessageHandler {
-
- public SP2CWarpCommandPacketServerHandler() {}
-
- @Override
- public IMessage onMessage(SP2CWarpCommandPacket message, MessageContext ctx) {
- return null;
- }
-
- }
-
- public static class SP2CWarpCommandPacketProxyHandler implements IMessageHandler {
-
- public SP2CWarpCommandPacketProxyHandler() {}
-
- @Override
- public IMessage onMessage(SP2CWarpCommandPacket message, MessageContext ctx) {
- return null;
- }
-
- }
-
-}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/network/warps/SP2CWarpPacket.java b/forge/src/main/java/fr/thesmyler/terramap/network/warps/SP2CWarpPacket.java
deleted file mode 100644
index f13dbab4..00000000
--- a/forge/src/main/java/fr/thesmyler/terramap/network/warps/SP2CWarpPacket.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package fr.thesmyler.terramap.network.warps;
-
-import org.jetbrains.annotations.Nullable;
-
-import fr.thesmyler.terramap.warp.Warp;
-import io.netty.buffer.ByteBuf;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
-import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
-
-public class SP2CWarpPacket implements IMessage {
-
- private long requestId;
- private WarpRequestStatus status;
- private Warp warp;
-
- public SP2CWarpPacket(long requestId, WarpRequestStatus status, @Nullable Warp warp) {
- this.requestId = requestId;
- this.status = status;
- this.warp = warp;
- }
-
- public SP2CWarpPacket() {}
-
- @Override
- public void fromBytes(ByteBuf buf) {
- this.requestId = buf.readLong();
- this.status = WarpRequestStatus.getFromNetworkCode(buf.readByte());
- }
-
- @Override
- public void toBytes(ByteBuf buf) {
- buf.writeLong(this.requestId);
- buf.writeByte(this.status.getNetworkCode());
- if(this.warp != null) {
- this.warp.encodeToByteBuf(buf);
- }
- }
-
- public static class SP2CWarpPacketServerHandler implements IMessageHandler {
-
- @Override
- public IMessage onMessage(SP2CWarpPacket message, MessageContext ctx) {
- //TODO SP2CWarpPacketServerHandler
- return null;
- }
-
- }
-
- public static class SP2CWarpPacketProxyHandler implements IMessageHandler {
-
- @Override
- public IMessage onMessage(SP2CWarpPacket message, MessageContext ctx) {
- //TODO SP2CWarpPacketProxyHandler
- return null;
- }
-
- }
-
-}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/network/warps/WarpRequestStatus.java b/forge/src/main/java/fr/thesmyler/terramap/network/warps/WarpRequestStatus.java
deleted file mode 100644
index 27c90baa..00000000
--- a/forge/src/main/java/fr/thesmyler/terramap/network/warps/WarpRequestStatus.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package fr.thesmyler.terramap.network.warps;
-
-public enum WarpRequestStatus {
-
- OK(0x00, true), // Everything went fine, the request has been handled
- MULTIPART(0x01, true), // To many matching warps, other packets will follow
- TOO_MANY(0x02, false), // To many matching warps, this request will not be handled
- NO_SUCH_WARP(0x03, false), // The warp did not exist
- NOT_IMPLEMENTED(0x04, false), // Warps are not supported
- INVALID_FILTER(0x05, false), // The request contained an invalid filter
- INVALID_KEYS(0x06, false), // One of the keys requested cannot be included in multi request
- FORBIDDEN(0x07, false), // The user did not have the required permission to make that request
- UNKNOWN(Byte.MAX_VALUE, false); // The status code was not known
-
- private final byte code;
- private final boolean success;
-
- WarpRequestStatus(int networkCode, boolean success) {
- this.code = (byte)networkCode;
- this.success = success;
- }
-
- public byte getNetworkCode() {
- return this.code;
- }
-
- public boolean isSuccess() {
- return this.success;
- }
-
- public boolean isError() {
- return ! this.success;
- }
-
- public static WarpRequestStatus getFromNetworkCode(byte code) {
- for(WarpRequestStatus value: WarpRequestStatus.values()) {
- if(value.code == code) return value;
- }
- return UNKNOWN;
- }
-
-}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/proxy/TerramapClientProxy.java b/forge/src/main/java/fr/thesmyler/terramap/proxy/TerramapClientProxy.java
index 8fc067ca..18c0e28f 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/proxy/TerramapClientProxy.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/proxy/TerramapClientProxy.java
@@ -25,8 +25,8 @@
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.smyler.smylib.SmyLib;
-import net.smyler.smylib.game.GameClient;
import net.smyler.smylib.game.WrappedMinecraft;
+import net.smyler.terramap.Terramap;
import javax.imageio.ImageIO;
@@ -39,26 +39,26 @@ public Side getSide() {
@Override
public void preInit(FMLPreInitializationEvent event) {
- TerramapMod.logger.debug("Terramap client pre-init");
+ Terramap.instance().logger().debug("Terramap client pre-init");
TerramapNetworkManager.registerHandlers(Side.CLIENT);
if (!ImageIO.getImageReadersBySuffix("webp").hasNext()) {
- TerramapMod.logger.warn("ImageIO does not have WebP support, triggering a plugin scan!");
+ Terramap.instance().logger().warn("ImageIO does not have WebP support, triggering a plugin scan!");
ImageIO.scanForPlugins();
if (ImageIO.getImageReadersBySuffix("webp").hasNext()) {
- TerramapMod.logger.info("Found a WebP ImageIO reader.");
+ Terramap.instance().logger().info("Found a WebP ImageIO reader.");
} else {
- TerramapMod.logger.error("Could not find a WebP ImageIO reader! WebP will not be supported.");
+ Terramap.instance().logger().error("Could not find a WebP ImageIO reader! WebP will not be supported.");
}
}
}
@Override
public void init(FMLInitializationEvent event) {
- TerramapMod.logger.debug("Terramap client init");
+ Terramap.instance().logger().debug("Terramap client init");
WrappedMinecraft game = new WrappedMinecraft(Minecraft.getMinecraft());
MinecraftForge.EVENT_BUS.register(HudScreen.class);
MinecraftForge.EVENT_BUS.register(game);
- SmyLib.initializeGameClient(game, TerramapMod.logger);
+ SmyLib.initializeGameClient(game, Terramap.instance().logger());
if ("true".equals(System.getProperty("terramap.showTestScreen"))) {
game.showTestScreen();
}
@@ -90,13 +90,13 @@ public GameType getGameMode(EntityPlayer e) {
NetworkPlayerInfo i = connection.getPlayerInfo(e.getUniqueID());
if(i != null) return i.getGameType();
}
- TerramapMod.logger.error("Failed to determine player gamemode.");
+ Terramap.instance().logger().error("Failed to determine player gamemode.");
return GameType.NOT_SET;
}
@Override
public void onConfigChanged(OnConfigChangedEvent event) {
- if (event.getModID().equals(TerramapMod.MODID)) {
+ if (event.getModID().equals(Terramap.MOD_ID)) {
if(TerramapMod.proxy.isClient() && HudScreen.getContent() != null) {
HudScreenHandler.updateMinimap();
}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/proxy/TerramapServerProxy.java b/forge/src/main/java/fr/thesmyler/terramap/proxy/TerramapServerProxy.java
index def16acf..f2a2c4ef 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/proxy/TerramapServerProxy.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/proxy/TerramapServerProxy.java
@@ -1,6 +1,5 @@
package fr.thesmyler.terramap.proxy;
-import fr.thesmyler.terramap.TerramapMod;
import fr.thesmyler.terramap.command.TerrashowCommand;
import fr.thesmyler.terramap.command.TilesetReloadCommand;
import fr.thesmyler.terramap.eventhandlers.ServerTerramapEventHandler;
@@ -14,6 +13,7 @@
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.relauncher.Side;
+import net.smyler.terramap.Terramap;
public class TerramapServerProxy extends TerramapProxy {
@@ -24,13 +24,13 @@ public Side getSide() {
@Override
public void preInit(FMLPreInitializationEvent event) {
- TerramapMod.logger.debug("Terramap server pre-init");
+ Terramap.instance().logger().debug("Terramap server pre-init");
TerramapNetworkManager.registerHandlers(Side.SERVER);
}
@Override
public void init(FMLInitializationEvent event) {
- TerramapMod.logger.debug("Terramap server init");
+ Terramap.instance().logger().debug("Terramap server init");
MinecraftForge.EVENT_BUS.register(new ServerTerramapEventHandler());
}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/saving/client/ClientSaveManager.java b/forge/src/main/java/fr/thesmyler/terramap/saving/client/ClientSaveManager.java
index a37562b5..bd5f4450 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/saving/client/ClientSaveManager.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/saving/client/ClientSaveManager.java
@@ -1,12 +1,8 @@
package fr.thesmyler.terramap.saving.client;
import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
import net.smyler.smylib.game.MinecraftServerInfo;
-import fr.thesmyler.terramap.TerramapMod;
-import fr.thesmyler.terramap.util.json.EarthGeneratorSettingsAdapter;
-import net.buildtheearth.terraplusplus.generator.EarthGeneratorSettings;
-import net.minecraft.client.multiplayer.ServerData;
+import net.smyler.terramap.Terramap;
import java.io.*;
import java.nio.file.Path;
@@ -25,24 +21,22 @@ public class ClientSaveManager {
private Path worldDirectory;
private Path serverDirectory;
private Path proxyDirectory;
+ private final Gson gson;
private static final String EXTENSION = ".json";
private static final String DEFAULT_SAVE_PATH = "/assets/terramap/defaultstate.json";
- private static final Gson GSON = new GsonBuilder()
- .registerTypeAdapter(EarthGeneratorSettings.class, new EarthGeneratorSettingsAdapter())
- .setPrettyPrinting()
- .create();
/**
* Constructs a new {@link ClientSaveManager} given a save directory.
*
* @param saveDirectory a path to a directory where data will be saved
*/
- public ClientSaveManager(Path saveDirectory) {
+ public ClientSaveManager(Path saveDirectory, Gson gson) {
this.saveDirectory = saveDirectory.toAbsolutePath();
this.worldDirectory = this.saveDirectory.resolve("worlds");
this.serverDirectory = this.saveDirectory.resolve("servers");
this.proxyDirectory = this.saveDirectory.resolve("proxies");
+ this.gson = gson;
}
/**
@@ -58,8 +52,8 @@ public SavedClientState loadWorldState(UUID worldUUID) {
}
/**
- * Loads a {@link SavedClientState} associated with a specific server, given the server's {@link ServerData}.
- * This method will usually be used when a remote world cannot be uniquely identified and we can only identify the server.
+ * Loads a {@link SavedClientState} associated with a specific server, given the server's {@link MinecraftServerInfo}.
+ * This method will usually be used when a remote world cannot be uniquely identified, and we can only identify the server.
*
* @param serverInfo the information of the server to retrieve the save for
*
@@ -88,14 +82,14 @@ public SavedClientState loadProxyState(UUID proxyUUID) {
public SavedClientState getDefaultState() {
InputStream stream = this.getClass().getResourceAsStream(DEFAULT_SAVE_PATH);
if (stream == null) {
- TerramapMod.logger.error("Missing internal resource: default client state");
+ Terramap.instance().logger().error("Missing internal resource: default client state");
return new SavedClientState();
}
try (InputStreamReader reader = new InputStreamReader(stream)) {
- return GSON.fromJson(reader, SavedClientState.class);
+ return this.gson.fromJson(reader, SavedClientState.class);
} catch (IOException e) {
- TerramapMod.logger.error("Failed to read internal default map state");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to read internal default map state");
+ Terramap.instance().logger().catching(e);
return new SavedClientState();
}
}
@@ -113,14 +107,14 @@ public void saveWorldState(UUID worldUUID, SavedClientState state) {
}
/**
- * Saves a {@link SavedClientState} associated with a specific server, given the server's {@link ServerData}.
- * This method will usually be used when a remote world cannot be uniquely identified and we can only identify the server.
+ * Saves a {@link SavedClientState} associated with a specific server, given the server's {@link MinecraftServerInfo}.
+ * This method will usually be used when a remote world cannot be uniquely identified, and we can only identify the server.
*
* @param serverData the information of the server to retrieve the save for
* @param state the state to save
*/
- public void saveServerState(ServerData serverData, SavedClientState state) {
- this.saveStateToPath(this.serverDirectory.resolve(serverData.serverIP + EXTENSION), state);
+ public void saveServerState(MinecraftServerInfo serverData, SavedClientState state) {
+ this.saveStateToPath(this.serverDirectory.resolve(serverData.host + EXTENSION), state);
}
/**
@@ -147,31 +141,31 @@ public void createDirectoryIfNecessary() throws IOException {
private SavedClientState loadFromPath(Path path) {
try (FileReader reader = new FileReader(path.toFile())) {
- return GSON.fromJson(reader, SavedClientState.class);
+ return this.gson.fromJson(reader, SavedClientState.class);
} catch (FileNotFoundException ignored) {
// Let's not spam the console when it's just a new save.
} catch (IOException e) {
- TerramapMod.logger.error("Failed to read a saved client state, will fallback to a new one");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to read a saved client state, will fallback to a new one");
+ Terramap.instance().logger().catching(e);
}
return this.getDefaultState();
}
private void saveStateToPath(Path path, SavedClientState state) {
try (FileWriter writer = new FileWriter(path.toFile())) {
- GSON.toJson(state, writer);
+ this.gson.toJson(state, writer);
} catch (IOException e) {
- TerramapMod.logger.error("Failed to save a client state");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to save a client state");
+ Terramap.instance().logger().catching(e);
}
}
private Path prepareDirectory(Path directory) throws IOException {
if (!exists(directory)) {
- TerramapMod.logger.debug("Created directory " + directory);
+ Terramap.instance().logger().debug("Created directory {}", directory);
createDirectories(directory);
} else if (!isDirectory(directory) || ! isWritable(directory)) {
- TerramapMod.logger.error(directory + " exists and is not a directory, or is not writeable. Terramap will fallback to a temporary directory instead.");
+ Terramap.instance().logger().error("{} exists and is not a directory, or is not writeable. Terramap will fallback to a temporary directory instead.", directory);
directory = createTempDirectory(directory, "terramap");
directory.toFile().deleteOnExit();
}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/saving/server/TerramapServerPreferences.java b/forge/src/main/java/fr/thesmyler/terramap/saving/server/TerramapServerPreferences.java
index 250f91d0..08c6cf88 100644
--- a/forge/src/main/java/fr/thesmyler/terramap/saving/server/TerramapServerPreferences.java
+++ b/forge/src/main/java/fr/thesmyler/terramap/saving/server/TerramapServerPreferences.java
@@ -8,13 +8,11 @@
import java.util.Map;
import java.util.UUID;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
-import fr.thesmyler.terramap.TerramapMod;
import fr.thesmyler.terramap.TerramapConfig;
import net.minecraft.world.WorldServer;
+import net.smyler.terramap.Terramap;
/**
*
@@ -30,7 +28,6 @@ public class TerramapServerPreferences {
private static boolean loggedDebugError = false;
private static long lastErrorLog = Long.MIN_VALUE;
- private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
/**
* Tells whether the given player should be visible on the map on a given world
@@ -48,8 +45,8 @@ public static boolean shouldDisplayPlayer(WorldServer world, UUID uuid) {
}
} catch(Exception e) {
if(!loggedDebugError) {
- TerramapMod.logger.error("Failed to get player display preferences. This error will only be displayed once.");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to get player display preferences. This error will only be displayed once.");
+ Terramap.instance().logger().catching(e);
loggedDebugError = true;
}
return TerramapConfig.SERVER.playersDisplayDefault;
@@ -75,8 +72,8 @@ public static void setShouldDisplayPlayer(WorldServer world, UUID uuid, boolean
}
saveWorldPreferences(world);
} catch(Exception e) {
- TerramapMod.logger.error("Failed to set player display preferences! See stack trace:");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to set player display preferences! See stack trace:");
+ Terramap.instance().logger().catching(e);
}
}
@@ -94,12 +91,12 @@ public static UUID getWorldUUID(WorldServer world) {
uuid = UUID.randomUUID();
prefs.world_uuid = uuid;
saveWorldPreferences(world);
- TerramapMod.logger.info("Generated uuid " + uuid + " for world " + world.getSaveHandler().getWorldDirectory().getName());
+ Terramap.instance().logger().info("Generated uuid {} for world {}", uuid, world.getSaveHandler().getWorldDirectory().getName());
}
return uuid;
}
} catch(Exception e) {
- TerramapMod.logger.warn("Failed to get world UUID, using 0 instead!");
+ Terramap.instance().logger().warn("Failed to get world UUID, using 0 instead!");
}
return new UUID(0, 0);
}
@@ -111,7 +108,7 @@ public static void unloadWorldPreferences(WorldServer world) {
TerramapServerPreferences.preferences.remove(file.getAbsolutePath());
}
} catch(Exception e) {
- TerramapMod.logger.warn("Failed to unload a world server preferences");
+ Terramap.instance().logger().warn("Failed to unload a world server preferences");
}
}
@@ -131,8 +128,8 @@ public static void saveWorldPreferences(WorldServer world) {
} catch(Exception e) {
long t = System.currentTimeMillis();
if(t > lastErrorLog + 10000) {
- TerramapMod.logger.error("Failed to save server preferences");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to save server preferences");
+ Terramap.instance().logger().catching(e);
lastErrorLog = t;
}
}
@@ -153,8 +150,8 @@ public static void saveAllPreferences() {
} catch(Exception e) {
long t = System.currentTimeMillis();
if(t > lastErrorLog + 10000) {
- TerramapMod.logger.error("Failed to save server preferences");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to save server preferences");
+ Terramap.instance().logger().catching(e);
lastErrorLog = t;
}
}
@@ -171,14 +168,14 @@ public static void loadWorldPreferences(WorldServer world) {
if(fileToLoad.exists()) {
try {
String text = String.join("\n", Files.readAllLines(fileToLoad.toPath(), Charset.defaultCharset()));
- preferences = GSON.fromJson(text, WorldPreferences.class);
+ preferences = Terramap.instance().gsonPretty().fromJson(text, WorldPreferences.class);
} catch (IOException | JsonSyntaxException e) {
- TerramapMod.logger.error("Failed to load server preference file, setting to default");
- TerramapMod.logger.catching(e);
+ Terramap.instance().logger().error("Failed to load server preference file, setting to default");
+ Terramap.instance().logger().catching(e);
preferences = new WorldPreferences();
}
} else {
- TerramapMod.logger.info("Loaded new empty server preferences as file did not exist");
+ Terramap.instance().logger().info("Loaded new empty server preferences as file did not exist");
}
synchronized(TerramapServerPreferences.preferences) {
TerramapServerPreferences.preferences.put(fileToLoad.getAbsolutePath(), preferences);
@@ -186,7 +183,7 @@ public static void loadWorldPreferences(WorldServer world) {
}
private static void save(File file, WorldPreferences preferences) throws IOException {
- String str = GSON.toJson(preferences);
+ String str = Terramap.instance().gsonPretty().toJson(preferences);
Files.write(file.toPath(), str.getBytes(Charset.defaultCharset()));
}
diff --git a/forge/src/main/java/fr/thesmyler/terramap/warp/Warp.java b/forge/src/main/java/fr/thesmyler/terramap/warp/Warp.java
deleted file mode 100644
index 556f4e19..00000000
--- a/forge/src/main/java/fr/thesmyler/terramap/warp/Warp.java
+++ /dev/null
@@ -1,100 +0,0 @@
-package fr.thesmyler.terramap.warp;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import fr.thesmyler.terramap.network.NetworkUtil;
-import io.netty.buffer.ByteBuf;
-
-/**
- *
- * @author Smyler
- *
- * TODO Implement warps
- *
- */
-public class Warp {
-
- private final Map properties = new HashMap<>();
-
- public Warp(String id) {
- this.setProperty("id", id);
- }
-
- public String getId() {
- return this.getProperty("id");
- }
-
- public boolean hasProperty(String key) {
- return this.properties.containsKey(key);
- }
-
- public String getProperty(String property) {
- return this.properties.getOrDefault(property, "");
- }
-
- public void setProperty(String key, String value) {
- if(value == null || value.length() == 0) {
- this.properties.remove(key);
- } else {
- this.properties.put(key, value);
- }
- }
-
- public Set getPropertyKeys() {
- return this.properties.keySet();
- }
-
- /**
- * Returns a warp with the same id as this one and the same properties as this one for the specified ones
- *
- * @param properties
- * @return
- */
- public Warp getCopyWithStrippedProperties(String... properties) {
- Warp warp = new Warp(this.getId());
- for(String key: properties) {
- warp.setProperty(key, this.getProperty(key));
- }
- return warp;
- }
-
- public void encodeToByteBuf(ByteBuf buf) {
- buf.writeInt(this.properties.size() - 1); // Id is assumed
- NetworkUtil.encodeStringToByteBuf(this.getId(), buf);
- for(String key: this.properties.keySet()) {
- if(key.equals("id")) continue;
- NetworkUtil.encodeStringToByteBuf(key, buf);
- NetworkUtil.encodeStringToByteBuf(this.properties.get(key), buf);
- }
- }
-
- public void encodeToByteBuf(ByteBuf buf, String ... properties) {
- Map validProperties = new HashMap<>();
- for(String key: properties) {
- if(!key.equals("id") && this.properties.containsKey(key)) {
- validProperties.put(key, this.getProperty(key));
- }
- }
- buf.writeInt(validProperties.size());
- NetworkUtil.encodeStringToByteBuf(this.getId(), buf);
- for(String key: validProperties.keySet()) {
- NetworkUtil.encodeStringToByteBuf(key, buf);
- NetworkUtil.encodeStringToByteBuf(validProperties.get(key), buf);
- }
- }
-
- public static Warp readWarpFromByteBuf(ByteBuf buf) {
- int keyCount = buf.readInt();
- String id = NetworkUtil.decodeStringFromByteBuf(buf);
- Warp warp = new Warp(id);
- for(int i=0; i get(String url) {
+ CompletableFuture future = Http.get(url);
+ CompletableFuture result = future.thenApply(ByteBufUtil::getBytes);
+ result.exceptionally(t -> {
+ if (t instanceof CancellationException) {
+ System.out.println("Was cancelled");
+ }
+ future.cancel(true);
+ return null;
+ });
+ return result;
+ }
+
+ @Override
+ public void setMaxConcurrentRequests(String host, int maxConcurrentRequests) {
+ Http.setMaximumConcurrentRequestsTo(host, maxConcurrentRequests);
+ }
+
+}
diff --git a/forge/src/test/java/fr/thesmyler/terramap/TerramapTest.java b/forge/src/test/java/fr/thesmyler/terramap/TerramapTest.java
index b78eed0e..86cc1f04 100644
--- a/forge/src/test/java/fr/thesmyler/terramap/TerramapTest.java
+++ b/forge/src/test/java/fr/thesmyler/terramap/TerramapTest.java
@@ -2,16 +2,24 @@
import fr.thesmyler.terramap.maps.raster.MapStylesLibrary;
import net.smyler.smylib.SmyLibTest;
+import net.smyler.terramap.Terramap;
import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.BeforeEach;
-public class TerramapTest extends SmyLibTest {
+public class TerramapTest extends SmyLibTest implements Terramap {
+ private final Logger logger = LogManager.getLogger("Terramap unit test");
@BeforeEach
public void initTerramap() {
- TerramapMod.logger = LogManager.getLogger("Terramap unit test");
+ Terramap.InstanceHolder.setInstance(this);
MapStylesLibrary.reload();
TerramapClientContext.resetContext();
}
+ @Override
+ public Logger logger() {
+ return this.logger;
+ }
+
}
diff --git a/smylib/testing/src/main/java/net/smyler/smylib/gui/DummyGlState.java b/smylib/testing/src/main/java/net/smyler/smylib/gui/DummyGlState.java
index 71e62edf..77376e56 100644
--- a/smylib/testing/src/main/java/net/smyler/smylib/gui/DummyGlState.java
+++ b/smylib/testing/src/main/java/net/smyler/smylib/gui/DummyGlState.java
@@ -36,4 +36,29 @@ public void disableColorLogic() {
}
+ @Override
+ public void pushViewMatrix() {
+
+ }
+
+ @Override
+ public void rotate(double angle) {
+
+ }
+
+ @Override
+ public void translate(double x, double y) {
+
+ }
+
+ @Override
+ public void scale(double x, double y) {
+
+ }
+
+ @Override
+ public void popViewMatrix() {
+
+ }
+
}