Skip to content

Commit

Permalink
1.12.2 webmap backport (#14)
Browse files Browse the repository at this point in the history
* started the port of the 1.12.2 webmap to 1.7.10
  • Loading branch information
mysticdrew authored Mar 10, 2024
1 parent 9360731 commit 5a82f53
Show file tree
Hide file tree
Showing 56 changed files with 869 additions and 9,014 deletions.
7 changes: 7 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@
* For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph
*/
dependencies {
// shadowImplementation("ar.com.hjg:pngj:2.1.0") //TODO: remove the code and use the dependency instead
shadowImplementation("javax.servlet:javax.servlet-api:4.0.1")
shadowImplementation("info.journeymap:webmap-client:0.8-SNAPSHOT")
shadowImplementation("io.javalin:javalin:4.6.8")

implementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.8.0-beta4'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.8.0-beta4'
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ forceEnableMixins = false

# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated into your jar. It is your
# responsibility to check the license and request permission for distribution if required.
usesShadowedDependencies = false
usesShadowedDependencies = true

# If disabled, won't remove unused classes from shadowed dependencies. Some libraries use reflection to access
# their own classes, making the minimization unreliable.
minimizeShadowedDependencies = true
minimizeShadowedDependencies = false

# If disabled, won't rename the shadowed classes.
relocateShadowedDependencies = true
Expand Down
1 change: 1 addition & 0 deletions project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ unlimited=Unlimited
noRadar=NoRadar
curse_release_type=release
dateFormat=yyyy-MM-dd-HH:mm:ss
journeymap_webmap_version=1.0-SNAPSHOT
14 changes: 14 additions & 0 deletions repositories.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Add any additional repositories for your dependencies here

repositories {
mavenCentral()

maven {
name = "JourneyMap"
url = "https://jm.gserv.me/repository/maven-snapshots/"
}
maven {
name = "jitpack"
url = "https://jitpack.io"
}
}
9 changes: 8 additions & 1 deletion src/main/java/journeymap/client/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
import org.lwjgl.input.Keyboard;

import java.io.File;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;

// 1.8
//import net.minecraftforge.fml.common.Loader;
Expand Down Expand Up @@ -59,6 +64,8 @@ public class Constants
public static String WAYPOINT_ICON_DIR = path.join(ICON_DIR, "waypoint", END);
public static String THEME_ICON_DIR = path.join(ICON_DIR, "theme", END);

public static String WEB_DIR = path.join(JOURNEYMAP_DIR, "web", END);

// Network Channel IDs

/**
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/journeymap/client/JourneymapClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import journeymap.client.network.WorldInfoHandler;
import journeymap.client.properties.*;
import journeymap.client.render.map.TileDrawStepCache;
import journeymap.client.service.WebServer;
import journeymap.client.task.main.IMainThreadTask;
import journeymap.client.task.main.MainTaskController;
import journeymap.client.task.main.MappingMonitorTask;
Expand All @@ -38,6 +37,7 @@
import journeymap.client.ui.UIManager;
import journeymap.client.ui.fullscreen.Fullscreen;
import journeymap.client.waypoint.WaypointStore;
import journeymap.client.webmap.WebMap;
import journeymap.common.CommonProxy;
import journeymap.common.Journeymap;
import journeymap.common.version.VersionCheck;
Expand Down Expand Up @@ -307,7 +307,10 @@ public void postInitialize(FMLPostInitializationEvent event)
ThemeFileHandler.initialize();

// Webserver
WebServer.setEnabled(webMapProperties.enabled.get(), false);
if (webMapProperties.enabled.get())
{
WebMap.getInstance().start();
}
initialized = true;

VersionCheck.getVersionAvailable();
Expand Down Expand Up @@ -384,9 +387,9 @@ public Boolean isThreadLogging()
*
* @return
*/
public WebServer getJmServer()
public WebMap getJmServer()
{
return WebServer.getInstance();
return WebMap.getInstance();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiPlayerInfo;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiScreenRealmsProxy;
import net.minecraft.client.gui.ScaledResolution;
Expand Down Expand Up @@ -50,6 +51,7 @@
import java.net.SocketAddress;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
Expand Down Expand Up @@ -231,6 +233,7 @@ public String getRealmsServerName()
{
try
{

NetHandlerPlayClient netHandler = mc.getNetHandler();
GuiScreen netHandlerGui = ReflectionHelper.getPrivateValue(NetHandlerPlayClient.class, netHandler, "field_147307_j", "guiScreenServer");

Expand Down
27 changes: 22 additions & 5 deletions src/main/java/journeymap/client/io/FileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.google.common.io.ByteSource;
import com.google.common.io.Files;
import com.google.gson.GsonBuilder;
import cpw.mods.fml.client.FMLClientHandler;
import journeymap.client.Constants;
import journeymap.client.JourneymapClient;
import journeymap.client.data.WorldData;
Expand Down Expand Up @@ -39,15 +40,29 @@

public class FileHandler
{
public static final String DEV_MINECRAFT_DIR = "run/";
public static final String ASSETS_JOURNEYMAP = "/assets/journeymap";
public static final String ASSETS_JOURNEYMAP_WEB = "/assets/journeymap/web";

public static final String ASSETS_WEBMAP = "/assets/journeymap/web";
public static final String ASSETS_JOURNEYMAP_UI = "/assets/journeymap/web/img/";
public static final File MinecraftDirectory = ForgeHelper.INSTANCE.getClient().mcDataDir;
public static final File JourneyMapDirectory = new File(MinecraftDirectory, Constants.JOURNEYMAP_DIR);
public static final File StandardConfigDirectory = new File(MinecraftDirectory, Constants.CONFIG_DIR);

private static WorldClient theLastWorld;

public static File getMinecraftDirectory()
{
Minecraft minecraft = FMLClientHandler.instance().getClient();
if (minecraft != null)
{
return minecraft.mcDataDir;
}
else
{
return new File(DEV_MINECRAFT_DIR);
}
}

public static File getMCWorldDir(Minecraft minecraft)
{
if (minecraft.isIntegratedServerRunning())
Expand Down Expand Up @@ -363,7 +378,7 @@ public static BufferedImage getWebImage(String fileName)
{
try
{
String png = FileHandler.ASSETS_JOURNEYMAP_WEB + "/img/" + fileName;//$NON-NLS-1$
String png = FileHandler.ASSETS_WEBMAP + "/img/" + fileName;//$NON-NLS-1$
InputStream is = JourneymapClient.class.getResourceAsStream(png);
if (is == null)
{
Expand Down Expand Up @@ -480,7 +495,7 @@ public static File copyColorPaletteHtmlFile(File toDir, String fileName)
try
{
final File outFile = new File(toDir, fileName);
String htmlPath = FileHandler.ASSETS_JOURNEYMAP_WEB + "/" + fileName;
String htmlPath = FileHandler.ASSETS_WEBMAP + "/" + fileName;
InputStream inputStream = JourneymapClient.class.getResource(htmlPath).openStream();

ByteSink out = new ByteSink()
Expand Down Expand Up @@ -551,7 +566,7 @@ public static void open(File file)
}
}

public static void copyResources(File targetDirectory, String assetsPath, String setName, boolean overwrite)
public static boolean copyResources(File targetDirectory, String assetsPath, String setName, boolean overwrite)
{
String fromPath = null;
File toDir = null;
Expand All @@ -574,11 +589,13 @@ public static void copyResources(File targetDirectory, String assetsPath, String
fromPath = fromDir.getPath();
FileHandler.copyFromDirectory(fromDir, toDir, overwrite);
}
return true;
}
catch (Throwable t)
{
Journeymap.getLogger().error(String.format("Couldn't unzip resource set from %s to %s: %s", fromPath, toDir, t));
}
return false;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/journeymap/client/log/ChatLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import journeymap.client.Constants;
import journeymap.client.JourneymapClient;
import journeymap.client.service.WebServer;
import journeymap.client.webmap.WebMap;
import journeymap.common.Journeymap;
import journeymap.common.version.VersionCheck;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -156,9 +156,9 @@ public static void announceMod(boolean forced)
{
try
{
WebServer webServer = JourneymapClient.getInstance().getJmServer();
WebMap webServer = JourneymapClient.getInstance().getJmServer();
String keyName = Constants.getKeyName(Constants.KB_MAP);
String port = webServer.getPort() == 80 ? "" : ":" + Integer.toString(webServer.getPort()); //$NON-NLS-1$ //$NON-NLS-2$
String port = webServer.getPort() == 80 ? "" : ":" + webServer.getPort();
String message = Constants.getString("jm.common.webserver_and_mapgui_ready", keyName, port); //$NON-NLS-1$
ChatLog.announceURL(message, "http://localhost" + port); //$NON-NLS-1$
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/journeymap/client/model/EntityDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class EntityDTO implements Serializable
public boolean sneaking;
public boolean passiveAnimal;


private EntityDTO(EntityLivingBase entity)
{
this.entityLivingRef = new WeakReference<EntityLivingBase>(entity);
Expand Down Expand Up @@ -109,11 +110,8 @@ else if (entity instanceof IEntityOwnable)
}
else if (entity instanceof EntityHorse)
{
// TODO: Test this with and without owners
// 1.8
String ownerUuidString = ((EntityHorse) entity).func_152119_ch();
// 1.8.8
// String ownerUuidString = ((EntityHorse) entity).getOwnerId();

if (!Strings.isNullOrEmpty(ownerUuidString))
{
try
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/journeymap/client/properties/PropertiesBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ public static <T extends PropertiesBase> T reload(T properties, Class<T> propert
}
}

/**
* Gets a Json representation of this object.
*
* @return json string
*/
public String toJsonString()
{
return gson.toJson(this);
}

/**
* Name used in property file
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import journeymap.client.model.MapType;
import journeymap.client.properties.config.Config;
import journeymap.client.service.MapApiService;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -26,9 +25,6 @@ public class WebMapProperties extends MapProperties
@Config(category = WebMap, key = "jm.advanced.port", minValue = 80, maxValue = 10000, defaultValue = 8080)
public final AtomicInteger port = new AtomicInteger(8080);

@Config(category = WebMap, key = "jm.webmap.google_domain", stringListProvider = MapApiService.TopLevelDomains.class)
public final AtomicReference<String> googleMapApiDomain = new AtomicReference<String>(".com");

public final AtomicReference<MapType.Name> preferredMapType = new AtomicReference<MapType.Name>(MapType.Name.day);
protected transient final String name = "webmap";

Expand Down
Loading

0 comments on commit 5a82f53

Please sign in to comment.