From 9eb8f4e9182523f88b0479076cf99d5667b68126 Mon Sep 17 00:00:00 2001 From: TechnicallyCoded Date: Sun, 8 Jun 2025 20:24:43 +0200 Subject: [PATCH] Less hacky performance improvements (#5187) --- pom.xml | 10 ++++-- src/main/java/com/gmail/nossr50/mcMMO.java | 38 +++------------------- 2 files changed, 12 insertions(+), 36 deletions(-) diff --git a/pom.xml b/pom.xml index da5354c7d..2b4596d6f 100644 --- a/pom.xml +++ b/pom.xml @@ -171,7 +171,7 @@ net.kyori:option net.kyori:adventure-text-serializer-craftbukkit co.aikar:acf-bukkit - com.github.technicallycoded:FoliaLib + com.tcoded:FoliaLib @@ -277,6 +277,10 @@ jitpack https://jitpack.io + + tcoded-releases + https://repo.tcoded.com/releases/ + @@ -462,9 +466,9 @@ compile - com.github.technicallycoded + com.tcoded FoliaLib - main-SNAPSHOT + 0.5.1 compile diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index c474c4e38..44dd5f9b6 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -162,8 +162,11 @@ public class mcMMO extends JavaPlugin { //Folia lib plugin instance foliaLib = new FoliaLib(this); - InvalidTickDelayNotifier.disableNotifications = true; - foliaPerformanceHack(); + foliaLib.getOptions().disableNotifications(); + // Performance optimization + // This makes the scheduler behave differently between Spigot/Legacy-Paper & Folia/Modern-Paper + foliaLib.getOptions().disableIsValidOnNonFolia(); + setupFilePaths(); generalConfig = new GeneralConfig(getDataFolder()); //Load before skillTools @@ -317,37 +320,6 @@ public class mcMMO extends JavaPlugin { } } - private void foliaPerformanceHack() { - // Spigot can't use this optimization - if (!hasGlobalRegionScheduler()) { - return; - } - - // Thanks SirSalad - // https://github.com/CraftYourTown/mcMMO/commit/2cffd64b127678411e20f0b8f9a3e3b87a649ee8 - try { - final FoliaImplementation setScheduler = new FoliaImplementation(foliaLib); - final java.lang.reflect.Field scheduler = FoliaLib.class.getDeclaredField("scheduler"); - scheduler.setAccessible(true); - scheduler.set(foliaLib, setScheduler); - scheduler.setAccessible(false); - } catch (NoSuchFieldException | IllegalAccessException e) { - getLogger().warning("Unexpected exception when attempting to apply performance tweaks to FoliaLib"); - } - } - - private static boolean hasGlobalRegionScheduler() { - try { - // No parameters → empty Class array - Bukkit.getServer() - .getClass() - .getMethod("getGlobalRegionScheduler"); - return true; // Method is present - } catch (NoSuchMethodException ignored) { - return false; // Not running on Paper/Folia - } - } - public static PlayerLevelUtils getPlayerLevelUtils() { return playerLevelUtils; }