Skip to content

Commit

Permalink
Merge pull request #50 from Xitee1/1.20.6-support
Browse files Browse the repository at this point in the history
MC 1.20.6 support
  • Loading branch information
Xitee1 authored May 25, 2024
2 parents 92d8cc8 + 3f0d3ae commit f266de4
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/main/java/de/xite/scoreboard/versions/VersionSpecific.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.logging.Logger;

public abstract class VersionSpecific {
public static final String NMS_VERSION = Bukkit.getServer().getClass().getPackage().getName().substring(23);
public static String NMS_VERSION;
protected static final Logger logger = PowerBoard.pl.getLogger();

public static VersionSpecific current;
Expand All @@ -28,6 +28,12 @@ public int getPing(Player p) {


public static void init() {
String packageVersion = Bukkit.getServer().getClass().getPackage().getName();
if(!packageVersion.equals("org.bukkit.craftbukkit")) {
// Minecraft 1.20.4 and below
NMS_VERSION = Bukkit.getServer().getClass().getPackage().getName().substring(23);
}

if (Version.CURRENT.isAtLeast(Version.v1_17)) {
current = new version_1_17_later();
} else if (Version.CURRENT.isAtLeast(Version.v1_16)) {
Expand Down Expand Up @@ -63,17 +69,17 @@ public void sendTab(Player p, String header, String footer) {

// ------------------------------ Reflection / NMS stuff ------------------------------

protected final Class<?> craftPlayer;

{
try {
craftPlayer = Class.forName("org.bukkit.craftbukkit." + NMS_VERSION + ".entity.CraftPlayer");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
protected Class<?> craftPlayer = null;

protected final Object nmsPlayer(Player p) {
if(craftPlayer == null) {
try {
craftPlayer = Class.forName("org.bukkit.craftbukkit." + NMS_VERSION + ".entity.CraftPlayer");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

try {
return craftPlayer.getMethod("getHandle").invoke(p);
} catch (ReflectiveOperationException ex) {
Expand Down

0 comments on commit f266de4

Please sign in to comment.