Skip to content

Commit

Permalink
Remove method reflection for getMinHeight in BukkitWorld. (#1796)
Browse files Browse the repository at this point in the history
* Remove reflective use of the getMinHeight method in BukkitWorld.

Which requires dep updates to 1.17, which may currently break this build?

* Tell Gradle we can read Java 16 JARs

Co-authored-by: Octavia Togami <octavia.togami@gmail.com>
  • Loading branch information
wizjany and octylFractal committed Jun 22, 2021
1 parent eb7b79c commit 43da91a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
8 changes: 6 additions & 2 deletions worldedit-bukkit/build.gradle.kts
Expand Up @@ -26,12 +26,16 @@ val localImplementation = configurations.create("localImplementation") {
configurations["compileOnly"].extendsFrom(localImplementation)
configurations["testImplementation"].extendsFrom(localImplementation)

configurations.all {
attributes.attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 16)
}

dependencies {
"api"(project(":worldedit-core"))
"api"(project(":worldedit-libs:bukkit"))
// Technically this is api, but everyone should already have some form of the bukkit API
// Avoid pulling in another one, especially one so outdated.
"localImplementation"("org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT") {
"localImplementation"("org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT") {
exclude("junit", "junit")
}

Expand All @@ -41,7 +45,7 @@ dependencies {
"localImplementation"("org.apache.logging.log4j:log4j-api")

"compileOnly"("org.jetbrains:annotations:20.1.0")
"compileOnly"("com.destroystokyo.paper:paper-api:1.16.1-R0.1-SNAPSHOT") {
"compileOnly"("io.papermc.paper:paper-api:1.17-R0.1-SNAPSHOT") {
exclude(group = "org.slf4j", module = "slf4j-api")
}
"implementation"("io.papermc:paperlib:1.0.6")
Expand Down
Expand Up @@ -59,8 +59,6 @@
import org.bukkit.inventory.InventoryHolder;

import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.EnumMap;
Expand All @@ -79,8 +77,6 @@ public class BukkitWorld extends AbstractWorld {

private static final boolean HAS_3D_BIOMES;
private static final boolean HAS_MIN_Y;
private static final Method GET_MIN_Y;
private int minY;

private static final Map<Integer, Effect> effects = new HashMap<>();

Expand All @@ -99,15 +95,12 @@ public class BukkitWorld extends AbstractWorld {
temp = false;
}
HAS_3D_BIOMES = temp;
Method tempGetMinY;
try {
tempGetMinY = World.class.getMethod("getMinHeight");
World.class.getMethod("getMinHeight");
temp = true;
} catch (NoSuchMethodException e) {
tempGetMinY = null;
temp = false;
}
GET_MIN_Y = tempGetMinY;
HAS_MIN_Y = temp;
}

Expand All @@ -127,13 +120,6 @@ public BukkitWorld(World world) {
} else {
this.worldNativeAccess = null;
}
if (HAS_MIN_Y) {
try {
minY = (int) GET_MIN_Y.invoke(world);
} catch (IllegalAccessException | InvocationTargetException e) {
minY = super.getMinY();
}
}
}

@Override
Expand Down Expand Up @@ -374,11 +360,10 @@ public int getMaxY() {

@Override
public int getMinY() {
/*if (HAS_MIN_Y) {
if (HAS_MIN_Y) {
return getWorld().getMinHeight();
}
return super.getMinY();*/
return minY;
return super.getMinY();
}

@SuppressWarnings("deprecation")
Expand Down

0 comments on commit 43da91a

Please sign in to comment.