Skip to content

Commit

Permalink
Fix for 1.20.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Elikill58 committed Jul 6, 2024
1 parent 45e9551 commit 2c060b4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
12 changes: 11 additions & 1 deletion spigot/src/com/elikill58/negativity/spigot/SpigotAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,17 @@ public void reload() {

@Override
public String getVersion() {
return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
String[] parts = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",");
if(parts.length > 3)
return parts[3];
/*try {
Object mcVersion = Bukkit.class.getDeclaredMethod("getMinecraftVersion").invoke(null);
return mcVersion.toString().replace(".", "_");
} catch (Exception e) {
getLogger().warn("Failed to get minecraft version");
e.printStackTrace();
}*/
return "";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public void onEnable() {
SpigotVersionAdapter versionAdapter = SpigotVersionAdapter.getVersionAdapter();
Version v = versionAdapter.getVersion();
if (v.equals(Version.HIGHER) || v.equals(Version.LOWER))
getLogger().warning("Unknow server version " + Utils.VERSION + " ! Some problems can appears.");
getLogger().warning("Unknow server version " + Adapter.getAdapter().getVersion() + " ! Some problems can appears.");
else {
getLogger().info("Detected server version: " + v.getName().toLowerCase(Locale.ROOT) + " (" + Utils.VERSION + ") using " + getSubPlatform().getName() + " server.");
getLogger().info("Detected server version: " + v.getName().toLowerCase(Locale.ROOT) + " (" + Adapter.getAdapter().getVersion() + ") using " + getSubPlatform().getName() + " server.");
}

Negativity.loadNegativity();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.elikill58.negativity.spigot.nms;

import static com.elikill58.negativity.spigot.utils.Utils.VERSION;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
Expand All @@ -24,6 +22,7 @@
import com.elikill58.negativity.spigot.SpigotNegativity;
import com.elikill58.negativity.spigot.SubPlatform;
import com.elikill58.negativity.spigot.utils.PacketUtils;
import com.elikill58.negativity.universal.Adapter;
import com.elikill58.negativity.universal.Version;
import com.elikill58.negativity.universal.utils.ReflectionUtils;

Expand Down Expand Up @@ -281,7 +280,7 @@ public List<Entity> getEntities(World w) {

public static SpigotVersionAdapter getVersionAdapter() {
if (instance == null) {
switch (VERSION) {
switch (Adapter.getAdapter().getVersion()) {
case "v1_8_R3":
return instance = new Spigot_1_8_R3();
case "v1_9_R1":
Expand Down Expand Up @@ -324,10 +323,10 @@ public static SpigotVersionAdapter getVersionAdapter() {
return instance = new Spigot_1_20_R3();
case "v1_20_R4":
return instance = new Spigot_1_20_R4();
case "v1_21_R1":
case "": // 1.20.6 or upper
return instance = new Spigot_1_21_R1();
default:
return instance = new Spigot_UnknowVersion(VERSION);
return instance = new Spigot_UnknowVersion(Adapter.getAdapter().getVersion());
}
}
return instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

import com.elikill58.negativity.universal.Adapter;
import com.elikill58.negativity.universal.utils.ReflectionUtils;

public class PacketUtils {
Expand All @@ -19,14 +20,12 @@ public class PacketUtils {
*/
private static final HashMap<String, Class<?>> ALL_CLASS = new HashMap<>();

private static final String VERSION = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",")
.split(",")[3];
private static final boolean isNewSystem = isNewSystem();
public static final String NMS_PREFIX = isNewSystem ? "net.minecraft." : "net.minecraft.server." + VERSION + ".";
public static final String NMS_PREFIX = isNewSystem ? "net.minecraft." : "net.minecraft.server." + Adapter.getAdapter().getVersion() + ".";

private static boolean isNewSystem() {
try {
Class.forName("net.minecraft.server." + VERSION + ".MinecraftServer");
Class.forName("net.minecraft.server." + Adapter.getAdapter().getVersion() + ".MinecraftServer");
return false;
} catch (Exception e) {
}
Expand Down Expand Up @@ -85,7 +84,8 @@ public static Class<?> getObcClass(String name) {
synchronized (ALL_CLASS) {
return ALL_CLASS.computeIfAbsent(name, (s) -> {
try {
return Class.forName("org.bukkit.craftbukkit." + VERSION + "." + name);
String version = Adapter.getAdapter().getVersion();
return Class.forName("org.bukkit.craftbukkit." + (version.equalsIgnoreCase("") ? "" : version + ".") + name);
} catch (Exception e) {
e.printStackTrace();
return null;
Expand Down
3 changes: 0 additions & 3 deletions spigot/src/com/elikill58/negativity/spigot/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
@SuppressWarnings("deprecation")
public class Utils {

public static final String VERSION = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",")
.split(",")[3];

public static List<Player> getOnlinePlayers() {
return SpigotVersionAdapter.getVersionAdapter().getOnlinePlayers();
}
Expand Down

0 comments on commit 2c060b4

Please sign in to comment.