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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 33 additions & 41 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
<configuration>
<source>21</source>
<target>21</target>
<annotationProcessorPaths>
<!--
Automatic execution of annotation processors in the classpath is being deprecated,
and removed in Java 22 (see https://bugs.java.com/bugdatabase/view_bug?bug_id=8321314).
We therefore need to explicitly tell Maven to run Lombok's.
-->
<path>
<groupId>org.projectlombok</groupId> <!-- https://central.sonatype.com/artifact/org.projectlombok/lombok -->
<artifactId>lombok</artifactId>
<version>1.18.42</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin> <!-- https://central.sonatype.com/artifact/org.apache.maven.plugins/maven-shade-plugin -->
Expand All @@ -41,6 +53,21 @@
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<!--
Exclude JAR signature files.
They correspond to the JARs of the libs we shade,
and are invalid for the resulting T+- JAR.
-->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
Expand All @@ -59,22 +86,10 @@
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>OpenCollab Snapshots</id>
<url>https://repo.opencollab.dev/snapshot/</url>
</repository>
<repository>
<id>smyler-releases</id>
<name>Smyler's maven repository</name>
<url>https://maven.smyler.net/releases</url>
</repository>
<repository>
<id>Daporkchop_</id>
<url>https://maven.daporkchop.net/</url>
<url>https://maven.smyler.net/releases/</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
Expand Down Expand Up @@ -112,50 +127,27 @@
<dependency> <!-- https://maven.smyler.net/#/releases/net/buildtheearth/terraminusminus/terraminusminus-bukkit -->
<groupId>net.buildtheearth.terraminusminus</groupId>
<artifactId>terraminusminus-bukkit</artifactId>
<version>2.0.0rc1-1.21.4</version>
<version>2.0.0-1.21.4</version>
</dependency>
<dependency> <!-- https://central.sonatype.com/artifact/com.google.guava/guava -->
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.5.0-jre</version>
</dependency>
<dependency> <!-- https://central.sonatype.com/artifact/org.apache.commons/commons-lang3 -->
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.19.0</version>
</dependency>
<dependency> <!-- https://central.sonatype.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<!--
Terra+- itself doesn't need Jackson, but we are hitting this JDK bug: https://bugs.openjdk.org/browse/JDK-8305250.
Having a direct compile dependency on Jackson gets rid of the unnecessary warning.
-->
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.20.0</version>
</dependency>
<dependency> <!-- https://central.sonatype.com/artifact/io.netty/netty-buffer -->
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
<version>4.2.6.Final</version>
<scope>compile</scope>
</dependency>
<dependency> <!-- https://central.sonatype.com/artifact/org.jetbrains/annotations -->
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>26.0.2-1</version>
<scope>compile</scope>
</dependency>
<dependency> <!-- https://central.sonatype.com/artifact/commons-io/commons-io -->
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.20.0</version>
</dependency>
<dependency> <!-- https://github.com/PorkStudios/PorkLib - needs to be the same as in TerraMinusMinus-->
<groupId>net.daporkchop.lib</groupId>
<artifactId>common</artifactId>
<version>0.5.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.tukaani</groupId>
<artifactId>xz</artifactId>
<version>1.10</version>
</dependency>
<dependency> <!-- https://github.com/dmulloy2/ProtocolLib/releases -->
<groupId>net.dmulloy2</groupId>
<artifactId>ProtocolLib</artifactId>
Expand Down
69 changes: 55 additions & 14 deletions src/main/java/de/btegermany/terraplusminus/Terraplusminus.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.btegermany.terraplusminus;


import com.mojang.brigadier.Command;
import de.btegermany.terraplusminus.commands.OffsetCommand;
import de.btegermany.terraplusminus.commands.TpllCommand;
import de.btegermany.terraplusminus.commands.WhereCommand;
Expand All @@ -14,11 +13,14 @@
import de.btegermany.terraplusminus.utils.LinkedWorld;
import de.btegermany.terraplusminus.utils.PlayerHashMapManagement;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.plugin.configuration.PluginMeta;
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import net.buildtheearth.terraminusminus.TerraConfig;
import net.buildtheearth.terraminusminus.TerraConstants;
import net.buildtheearth.terraminusminus.util.http.Disk;
import net.buildtheearth.terraminusminus.util.http.Http;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
Expand All @@ -33,8 +35,13 @@

import java.io.*;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;

import static java.lang.String.format;
import static java.util.logging.Level.WARNING;
import static net.daporkchop.lib.common.util.PValidation.checkState;

public final class Terraplusminus extends JavaPlugin implements Listener {
public static FileConfiguration config;
public static Terraplusminus instance;
Expand All @@ -60,18 +67,11 @@ public void onEnable() {
this.updateConfig();
// --------------------------

// Copies osm.json5 into terraplusplus/config/
File[] terraPlusPlusDirectories = {new File("terraplusplus"), new File("terraplusplus/config/")};
for (File file : terraPlusPlusDirectories) {
if (!file.exists()) {
file.mkdir();
}
}
File osmJsonFile = new File("terraplusplus" + File.separator + "config" + File.separator + "osm.json5");
if (!osmJsonFile.exists()) {
this.copyFileFromResource("assets/terraplusminus/data/osm.json5", osmJsonFile);
}
// --------------------------
// Set-up Terra-- so it looks for its config files in our plugin dir, and then copy its default files there
this.setupTerraMinusMinus();
this.extractTerraConfigFileToPluginDir("/net/buildtheearth/terraminusminus/dataset/osm/osm.json5", "osm.json5");
this.extractTerraConfigFileToPluginDir("config/readme-heights.md", "heights/README.md");
this.extractTerraConfigFileToPluginDir("config/readme-tree_cover.md", "tree_cover/README.md");

// Register plugin messaging channel
PlayerHashMapManagement playerHashMapManagement = new PlayerHashMapManagement();
Expand Down Expand Up @@ -275,4 +275,45 @@ private void registerCommands() {
commands.register("offset", "Displays the x,y and z offset of your world", new OffsetCommand());
});
}

private void setupTerraMinusMinus() {
Disk.setConfigRoot(this.getDataFolder());
Disk.setCacheRoot(this.getDataPath().resolve("cache").toFile());

String userAgent = this.createHttpUserAgent();
this.getLogger().fine("Terraplusminus HTTP user agent: " + userAgent);
Http.userAgent(userAgent);
}

// This method has to rely on the unstable paper API as we use paper-plugin.yml, which itself is experimental
@SuppressWarnings("UnstableApiUsage")
private String createHttpUserAgent() {
PluginMeta metadata = this.getPluginMeta();
return format(Locale.ENGLISH, "%s/%s (%s/%s; +%s)",
metadata.getName(),
metadata.getVersion(),
TerraConstants.LIB_NAME,
TerraConstants.LIB_VERSION,
metadata.getWebsite()
);
}

private void extractTerraConfigFileToPluginDir(@NotNull String resourcePath, @NotNull String dropPath) {
File droppedFile = this.getDataPath().resolve(dropPath).toFile();
if (droppedFile.exists()) {
this.getLogger().fine("Terra-- config file " + droppedFile.getAbsolutePath() + " is already present in plugin directory");
return;
}
if(droppedFile.getParentFile().mkdirs()) {
this.getLogger().fine("Created parent directory before extracting Terra-- configuration to: " + droppedFile.getAbsolutePath());
}
try (InputStream resourceStream = this.getClass().getResourceAsStream(resourcePath); OutputStream fileStream = new FileOutputStream(droppedFile)) {
checkState(resourceStream != null, "Missing internal resource: %s", resourcePath);
resourceStream.transferTo(fileStream);
} catch (IOException e) {
this.getLogger().log(WARNING, "Failed to drop a Terra configuration file in plugin directory", e);
}
this.getLogger().info("Created default Terra-- configuration at " + droppedFile.getAbsolutePath());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import net.buildtheearth.terraminusminus.dataset.builtin.AbstractBuiltinDataset;
import net.buildtheearth.terraminusminus.util.RLEByteArray;
import net.daporkchop.lib.common.reference.cache.Cached;
import org.tukaani.xz.LZMAInputStream;

import java.io.IOException;
import java.io.InputStream;
import java.util.function.Supplier;
import java.util.zip.GZIPInputStream;

import static net.daporkchop.lib.common.util.PValidation.checkState;

public class KoppenClimateData extends AbstractBuiltinDataset {
protected static final int COLUMNS = 43200;
Expand All @@ -20,22 +23,18 @@ public KoppenClimateData() {
private static final Cached<RLEByteArray> CACHE = Cached.global((Supplier<RLEByteArray>) () -> {
RLEByteArray.Builder builder = RLEByteArray.builder();

try (LZMAInputStream is = new LZMAInputStream(KoppenClimateData.class.getResourceAsStream("/koppen_map.lzma"))) {

try (InputStream compressedStream = KoppenClimateData.class.getResourceAsStream("/koppen_map.gz")) {
checkState(compressedStream != null, "Missing internal resource for Koppen biome dataset");
InputStream is = new GZIPInputStream(compressedStream);
byte[] buffer = new byte[4096];
int readyBytes = 0;
while (true) {
try {
if ((readyBytes = is.read(buffer, 0, 4096)) == -1) break;
} catch (IOException e) {
e.printStackTrace();
}
int readyBytes;
while ((readyBytes = is.read(buffer, 0, buffer.length)) != -1) {
for (int i = 0; i < readyBytes; i++) {
builder.append(buffer[i]);
}
}
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Failed to load internal resource for Koppen dataset", e);
}

return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.buildtheearth.terraminusminus.projection.transform.OffsetProjectionTransform;
import net.buildtheearth.terraminusminus.substitutes.BlockState;
import net.buildtheearth.terraminusminus.substitutes.ChunkPos;
import net.buildtheearth.terraminusminus.substitutes.TerraBukkit;
import net.buildtheearth.terraminusminus.util.http.Http;
import org.bukkit.HeightMap;
import org.bukkit.Location;
Expand All @@ -36,6 +35,7 @@
import static java.lang.Math.min;
import static net.buildtheearth.terraminusminus.substitutes.ChunkPos.blockToCube;
import static net.buildtheearth.terraminusminus.substitutes.ChunkPos.cubeToMinBlock;
import static net.buildtheearth.terraminusminus.substitutes.TerraBukkit.toBukkitBlockData;
import static org.bukkit.Material.BRICKS;
import static org.bukkit.Material.DIRT;
import static org.bukkit.Material.DIRT_PATH;
Expand Down Expand Up @@ -193,7 +193,7 @@ public void generateSurface(@NotNull WorldInfo worldInfo, @NotNull Random random
material = this.materialMapping.get(state.getBlock().toString());
if (material == null) {
// We don't know what material this is, let's respect what the Terra-- configuration says
material = TerraBukkit.toBukkitBlockData(state).getMaterial();
material = toBukkitBlockData(state).getMaterial();
}
} else if (groundY >= startMountainHeight) {
material = STONE; // Mountains stare bare
Expand Down
Loading