Skip to content

Commit

Permalink
Shift old spigot/paper support to dynamic load to handle pedantic Paper
Browse files Browse the repository at this point in the history
loader
  • Loading branch information
mikeprimm committed Aug 20, 2023
1 parent 105d4f1 commit b310a57
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 35 deletions.
2 changes: 2 additions & 0 deletions DynmapCore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ eclipse {
}
}

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

dependencies {
implementation project(':DynmapCoreAPI')
implementation 'javax.servlet:javax.servlet-api:3.1'
Expand Down
2 changes: 2 additions & 0 deletions bukkit-helper-113-2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ eclipse {

description = 'bukkit-helper-1.13.2'

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

dependencies {
implementation project(':bukkit-helper')
implementation project(':dynmap-api')
Expand Down
2 changes: 2 additions & 0 deletions bukkit-helper-114-1/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ eclipse {

description = 'bukkit-helper-1.14.1'

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

dependencies {
implementation project(':bukkit-helper')
implementation project(':dynmap-api')
Expand Down
2 changes: 2 additions & 0 deletions bukkit-helper-115/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ eclipse {

description = 'bukkit-helper-1.15'

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

dependencies {
implementation project(':bukkit-helper')
implementation project(':dynmap-api')
Expand Down
2 changes: 2 additions & 0 deletions bukkit-helper-116-2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ eclipse {

description = 'bukkit-helper-1.16.2'

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

dependencies {
implementation project(':bukkit-helper')
implementation project(':dynmap-api')
Expand Down
2 changes: 2 additions & 0 deletions bukkit-helper-116-3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ eclipse {

description = 'bukkit-helper-1.16.3'

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

dependencies {
implementation project(':bukkit-helper')
implementation project(':dynmap-api')
Expand Down
2 changes: 2 additions & 0 deletions bukkit-helper-116-4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ eclipse {

description = 'bukkit-helper-1.16.4'

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

dependencies {
implementation project(':bukkit-helper')
implementation project(':dynmap-api')
Expand Down
2 changes: 2 additions & 0 deletions bukkit-helper-116/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ eclipse {

description = 'bukkit-helper-1.16'

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

dependencies {
implementation project(':bukkit-helper')
implementation project(':dynmap-api')
Expand Down
2 changes: 1 addition & 1 deletion bukkit-helper/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3))
connection.project.dir=..
connection.project.dir=../bukkit-helper-119-4
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home
Expand Down
2 changes: 1 addition & 1 deletion bukkit-helper/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
#Tue Jun 20 20:08:06 CDT 2023
#Sat Aug 19 16:59:43 CDT 2023
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.nullReference=warning
eclipse.preferences.version=1
Expand Down
2 changes: 2 additions & 0 deletions bukkit-helper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ eclipse {

description = 'bukkit-helper'

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

dependencies {
implementation project(':dynmap-api')
implementation project(path: ':DynmapCore', configuration: 'shadow')
Expand Down
2 changes: 2 additions & 0 deletions dynmap-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ eclipse {

description = "dynmap-api"

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

dependencies {
compileOnly group: 'org.bukkit', name: 'bukkit', version:'1.7.10-R0.1-SNAPSHOT'
compileOnly project(":DynmapCoreAPI")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dynmap.forge_1_18_2;

import java.util.HashMap;
import java.util.List;

import net.minecraft.world.level.biome.Biome;
Expand All @@ -10,6 +11,7 @@
import org.dynmap.common.chunk.GenericChunk;
import org.dynmap.common.chunk.GenericChunkCache;
import org.dynmap.common.chunk.GenericMapChunkCache;
import org.dynmap.utils.TileFlags;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerChunkCache;
Expand Down Expand Up @@ -65,6 +67,8 @@ public void setChunks(ForgeWorld dw, List<DynmapChunk> chunks) {
super.setChunks(dw, chunks);
}

private static HashMap<String, TileFlags> tmap = new HashMap<String, TileFlags>();

private CompoundTag readChunk(int x, int z) {
try {
CompoundTag rslt = cps.chunkMap.read(new ChunkPos(x, z));
Expand All @@ -82,6 +86,30 @@ private CompoundTag readChunk(int x, int z) {
rslt = null;
}
}
if (rslt != null) {
int version = rslt.getInt("DataVersion");
if (version < 2975) {
boolean doIt = false;
synchronized(tmap) {
TileFlags tf = tmap.get(dw.getName());
if (tf == null) {
tf = new TileFlags();
tmap.put(dw.getName(), tf);
}
if (!tf.getFlag(x, z)) {
tf.setFlag(x, z, true);
doIt = true;
}
}
if (doIt) {
ChunkPos pos = new ChunkPos(x, z);
CompoundTag newrec = cps.chunkMap.readChunk(pos);
if (rslt != null) {
cps.chunkMap.write(pos, newrec.copy());
}
}
}
}
// Log.info(String.format("loadChunk(%d,%d)=%s", x, z, (rslt != null) ?
// rslt.toString() : "null"));
return rslt;
Expand Down
2 changes: 2 additions & 0 deletions spigot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ repositories {
}
}

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

dependencies {
implementation('org.bukkit:bukkit:1.10.2-R0.1-SNAPSHOT') { transitive = false }
compileOnly('com.nijikokun.bukkit:Permissions:3.1.6') { transitive = false }
Expand Down
62 changes: 29 additions & 33 deletions spigot/src/main/java/org/dynmap/bukkit/Helper.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
package org.dynmap.bukkit;

import java.lang.reflect.Constructor;

import org.bukkit.Bukkit;
import org.dynmap.Log;
import org.dynmap.bukkit.helper.BukkitVersionHelper;
import org.dynmap.bukkit.helper.BukkitVersionHelperCB;
import org.dynmap.bukkit.helper.BukkitVersionHelperGlowstone;
import org.dynmap.bukkit.helper.v113_2.BukkitVersionHelperSpigot113_2;
import org.dynmap.bukkit.helper.v114_1.BukkitVersionHelperSpigot114_1;
import org.dynmap.bukkit.helper.v115.BukkitVersionHelperSpigot115;
import org.dynmap.bukkit.helper.v116.BukkitVersionHelperSpigot116;
import org.dynmap.bukkit.helper.v116_2.BukkitVersionHelperSpigot116_2;
import org.dynmap.bukkit.helper.v116_3.BukkitVersionHelperSpigot116_3;
import org.dynmap.bukkit.helper.v116_4.BukkitVersionHelperSpigot116_4;
import org.dynmap.bukkit.helper.v117.BukkitVersionHelperSpigot117;
import org.dynmap.bukkit.helper.v118.BukkitVersionHelperSpigot118;
import org.dynmap.bukkit.helper.v118_2.BukkitVersionHelperSpigot118_2;
import org.dynmap.bukkit.helper.v119.BukkitVersionHelperSpigot119;
import org.dynmap.bukkit.helper.v119_3.BukkitVersionHelperSpigot119_3;
import org.dynmap.bukkit.helper.v119_4.BukkitVersionHelperSpigot119_4;
import org.dynmap.bukkit.helper.v120.BukkitVersionHelperSpigot120;

public class Helper {

private static BukkitVersionHelper loadVersionHelper(String classname) {
try {
Class<?> c = Class.forName(classname);
Constructor<?> cons = c.getConstructor();
return (BukkitVersionHelper) cons.newInstance();
} catch (Exception x) {
Log.severe("Error loading " + classname, x);
return null;
}
}
public static final BukkitVersionHelper getHelper() {
if (BukkitVersionHelper.helper == null) {
String v = Bukkit.getServer().getVersion();
Expand All @@ -42,57 +38,57 @@ else if(v.contains("BukkitForge")) {
}
else if(Bukkit.getServer().getClass().getName().contains("GlowServer")) {
Log.info("Loading Glowstone support");
BukkitVersionHelper.helper = new BukkitVersionHelperGlowstone();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.BukkitVersionHelperGlowstone");
}
else if (v.contains("(MC: 1.20")) {
BukkitVersionHelper.helper = new BukkitVersionHelperSpigot120();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v120.BukkitVersionHelperSpigot120");
}
else if (v.contains("(MC: 1.19)") || v.contains("(MC: 1.19.1)") || v.contains("(MC: 1.19.2)")) {
BukkitVersionHelper.helper = new BukkitVersionHelperSpigot119();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v119.BukkitVersionHelperSpigot119");
}
else if (v.contains("(MC: 1.19.3)")) {
BukkitVersionHelper.helper = new BukkitVersionHelperSpigot119_3();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v119_3.BukkitVersionHelperSpigot119_3");
}
else if (v.contains("(MC: 1.19.")) {
BukkitVersionHelper.helper = new BukkitVersionHelperSpigot119_4();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v119_4.BukkitVersionHelperSpigot119_4");
}
else if (v.contains("(MC: 1.18)") || (v.contains("(MC: 1.18.1)"))) {
BukkitVersionHelper.helper = new BukkitVersionHelperSpigot118();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v118.BukkitVersionHelperSpigot118");
}
else if (v.contains("(MC: 1.18")) {
BukkitVersionHelper.helper = new BukkitVersionHelperSpigot118_2();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v118_2.BukkitVersionHelperSpigot118_2");
}
else if (v.contains("(MC: 1.17")) {
BukkitVersionHelper.helper = new BukkitVersionHelperSpigot117();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v117.BukkitVersionHelperSpigot117");
}
else if (v.contains("(MC: 1.16.1")) {
BukkitVersionHelper.helper = new BukkitVersionHelperSpigot116();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v116.BukkitVersionHelperSpigot116");
}
else if (v.contains("(MC: 1.16.2)")) {
BukkitVersionHelper.helper = new BukkitVersionHelperSpigot116_2();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v116_2.BukkitVersionHelperSpigot116_2");
}
else if (v.contains("(MC: 1.16.3)")) {
BukkitVersionHelper.helper = new BukkitVersionHelperSpigot116_3();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v116_3.BukkitVersionHelperSpigot116_3");
}
else if (v.contains("(MC: 1.16.")) {
BukkitVersionHelper.helper = new BukkitVersionHelperSpigot116_4();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v116_4.BukkitVersionHelperSpigot116_4");
}
// Loading last to prevent the 1.16 contains to match all newer versions and load older helper incorrectly.
else if (v.contains("(MC: 1.16")) {
BukkitVersionHelper.helper = new BukkitVersionHelperSpigot116();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v116.BukkitVersionHelperSpigot116");
}
else if (v.contains("(MC: 1.15)") || v.contains("(MC: 1.15.")) {
BukkitVersionHelper.helper = new BukkitVersionHelperSpigot115();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v115.BukkitVersionHelperSpigot115");
}
else if (v.contains("(MC: 1.14)") || v.contains("(MC: 1.14.1)") || v.contains("(MC: 1.14.2)") ||
v.contains("(MC: 1.14.3)") || v.contains("(MC: 1.14.4)")) {
BukkitVersionHelper.helper = new BukkitVersionHelperSpigot114_1();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v114_1.BukkitVersionHelperSpigot114_1");
}
else if (v.contains("(MC: 1.13.2)")) {
BukkitVersionHelper.helper = new BukkitVersionHelperSpigot113_2();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v113_2.BukkitVersionHelperSpigot113_2");
}
else {
BukkitVersionHelper.helper = new BukkitVersionHelperCB();
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.BukkitVersionHelperCB");
}
}
return BukkitVersionHelper.helper;
Expand Down

0 comments on commit b310a57

Please sign in to comment.