Skip to content

Commit

Permalink
Merge pull request #197 from dniym/fix/1.21-support
Browse files Browse the repository at this point in the history
1.21 support & Bug Fixes
  • Loading branch information
dniym authored Jul 8, 2024
2 parents 8761b9e + 78d5135 commit ecdb5ba
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repositories {
}

dependencies {
compileOnly("dev.folia:folia-api:1.20.2-R0.1-SNAPSHOT")
compileOnly("dev.folia:folia-api:1.20.4-R0.1-SNAPSHOT")
compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0")
compileOnly("com.elmakers.mine.bukkit:MagicAPI:10.2")
compileOnly("de.tr7zw:item-nbt-api-plugin:2.8.0")
Expand Down
28 changes: 25 additions & 3 deletions src/main/java/main/java/me/dniym/IllegalStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class IllegalStack extends JavaPlugin {
private static Plugin ProCosmetics = null;
private static boolean isHybridEnvironment = false;
private static boolean isPaperServer = false;
private static boolean isFoliaServer = false;
private static boolean hasProtocolLib = false;
private static boolean hasAttribAPI = false;
private static boolean nbtAPI = false;
Expand Down Expand Up @@ -99,6 +100,10 @@ public static boolean isSpigot() {
return Spigot;
}

public static boolean isFoliaServer() {
return isFoliaServer;
}

public static boolean isCMI() {
return CMI;
}
Expand Down Expand Up @@ -164,10 +169,22 @@ private static void checkForPaperServer() {
}
}

private static void checkForFoliaServer() {
try {
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
isFoliaServer = true;
LOGGER.info("Server has Folia components, enabling Folia features.");
} catch (ClassNotFoundException e) {
isFoliaServer = false;
LOGGER.info("Server does NOT have Folia components, continuing as normal.");
}
}

private static void StartupPlugin() {

checkForHybridEnvironment();
checkForPaperServer();
checkForFoliaServer();

try {
Class.forName("org.spigotmc.SpigotConfig");
Expand Down Expand Up @@ -424,6 +441,7 @@ public void onEnable() {
loadMsgs();
checkForHybridEnvironment();
checkForPaperServer();
checkForFoliaServer();
IllegalStackCommand illegalStackCommand = new IllegalStackCommand();
this.getCommand("istack").setExecutor(illegalStackCommand);
this.getCommand("istack").setTabCompleter(illegalStackCommand);
Expand Down Expand Up @@ -1018,7 +1036,7 @@ public void onDisable() {
disable = true;
if (hasAsyncScheduler) {
getServer().getAsyncScheduler().cancelTasks(this);
} else {
} else if (!isFoliaServer()){
Bukkit.getScheduler().cancelTasks(this);
}

Expand Down Expand Up @@ -1119,8 +1137,12 @@ private void setVersion() {
} else {
String packageName = Bukkit.getServer().getClass().getPackage().getName();
String bukkitVersion = Bukkit.getServer().getBukkitVersion();
if (bukkitVersion.contains("1.20.5") || bukkitVersion.contains("1.20.6")) {
serverVersion = ServerVersion.v1_20_R4;
if (bukkitVersion.contains("1.20.5")) {
serverVersion = ServerVersion.v1_20_R5;
} else if (bukkitVersion.contains("1.20.6")) {
serverVersion = ServerVersion.v1_20_R5;
} else if (bukkitVersion.contains("1.21")) {
serverVersion = ServerVersion.v1_21_R1;
} else {
serverVersion = ServerVersion.valueOf(packageName.replace("org.bukkit.craftbukkit.", ""));
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/main/java/me/dniym/enums/ServerVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public enum ServerVersion {
v1_20_R1,
v1_20_R2,
v1_20_R3,
v1_20_R4;
v1_20_R4,
v1_20_R5,
v1_21_R1;

public boolean serverVersionEqual(ServerVersion version) {
return this.equals(version);
Expand Down

0 comments on commit ecdb5ba

Please sign in to comment.