Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MC 1.20.6 support #50

Merged
merged 1 commit into from
May 25, 2024
Merged
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
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