From 8f4cde7c7e8c706b1f379e5b0f420a9e352b3fa3 Mon Sep 17 00:00:00 2001 From: JsNcAr Date: Wed, 11 Nov 2026 10:23:37 -0500 Subject: [PATCH 1/2] Fix datapack location on 26.x Since 26.1, World#getWorldFolder() returns the dimension folder, so the datapack was saved into world/dimensions/minecraft//datapacks, where the server never loads it. Use Server#getLevelDirectory() when it exists and fall back to the main world's folder on older versions. Fixes #776 Co-Authored-By: Claude Opus 5.5 --- .../net/countercraft/movecraft/Movecraft.java | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java b/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java index fe69859c1..6e9074128 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java @@ -39,12 +39,15 @@ import net.countercraft.movecraft.util.Tags; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.Server; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.file.Path; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -253,12 +256,7 @@ public void onLoad() { } private boolean initializeDatapack() { - File datapackDirectory = null; - for(var world : getServer().getWorlds()) { - datapackDirectory = new File(world.getWorldFolder(), "datapacks"); - if(datapackDirectory.exists()) - break; - } + File datapackDirectory = getDatapackDirectory(); if(datapackDirectory == null) { logger.severe("Failed to initialize Movecraft data pack due to first time world initialization."); return false; @@ -313,6 +311,25 @@ else if(new File(datapackDirectory, "movecraft-data.zip").exists()) { return true; } + private @Nullable File getDatapackDirectory() { + // Since 26.1, World#getWorldFolder() is the dimension folder, so ask for the level directory instead + try { + Path levelDirectory = (Path) Server.class.getMethod("getLevelDirectory").invoke(getServer()); + return levelDirectory.resolve("datapacks").toFile(); + } + catch (final NoSuchMethodException e) { + // Before 26.1, the main world's folder is the level directory + } + catch (final ReflectiveOperationException e) { + e.printStackTrace(); + return null; + } + var worlds = getServer().getWorlds(); + if(worlds.isEmpty()) + return null; + return new File(worlds.get(0).getWorldFolder(), "datapacks"); + } + private boolean isDatapackEnabled() { getServer().dispatchCommand(getServer().createCommandSender(response -> {}), "datapack list"); // list datapacks to trigger the server to check for (Datapack datapack : getServer().getDatapackManager().getPacks()) { From 50f762db1480fe0fcd375b1b238312e9cc45abce Mon Sep 17 00:00:00 2001 From: JsNcAr Date: Wed, 11 Nov 2026 10:23:37 -0500 Subject: [PATCH 2/2] Stop onEnable after the plugin disables itself initializeDatapack() calls setEnabled(false) when the datapack cannot be loaded, but onEnable() kept going and scheduled tasks on the disabled plugin, causing an IllegalPluginAccessException. Co-Authored-By: Claude Opus 5.5 --- .../src/main/java/net/countercraft/movecraft/Movecraft.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java b/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java index 6e9074128..f52ce401b 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java @@ -190,6 +190,8 @@ public void onEnable() { // Startup procedure boolean datapackInitialized = isDatapackEnabled() || initializeDatapack(); + if(!isEnabled()) + return; asyncManager = new AsyncManager(); asyncManager.runTaskTimer(this, 0, 1); MapUpdateManager.getInstance().runTaskTimer(this, 0, 1);