Less hacky performance improvements (#5187)

This commit is contained in:
TechnicallyCoded
2025-06-08 20:24:43 +02:00
committed by GitHub
parent 4def2be918
commit 9eb8f4e918
2 changed files with 12 additions and 36 deletions

View File

@ -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;
}