diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 05f7da27..9c263404 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -115,3 +115,8 @@ jobs: cd ../ - name: Build with Maven run: mvn -B package --file pom.xml + - name: Artifacts + uses: actions/upload-artifact@v4 + with: + path: | + IF/target/*.jar diff --git a/IF/pom.xml b/IF/pom.xml index 427a3b41..0395b6bb 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -19,8 +19,8 @@ - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://repo.papermc.io/repository/maven-public/ mojang-repo @@ -192,9 +192,9 @@ compile - org.spigotmc - spigot-api - 1.20.3-R0.1-SNAPSHOT + dev.folia + folia-api + 1.20.4-R0.1-SNAPSHOT provided @@ -328,4 +328,4 @@ - \ No newline at end of file + diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index ea100811..df45b936 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -3,6 +3,8 @@ import com.github.stefvanschie.inventoryframework.gui.type.*; import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.util.InventoryViewUtil; +import com.github.stefvanschie.inventoryframework.util.DispatchUtil; + import org.bukkit.Bukkit; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.LivingEntity; @@ -84,7 +86,7 @@ public void onInventoryClick(@NotNull InventoryClickEvent event) { gui.click(event); if (event.isCancelled()) { - Bukkit.getScheduler().runTask(this.plugin, () -> { + DispatchUtil.runTaskFor(event.getWhoClicked(), this.plugin, () -> { PlayerInventory playerInventory = event.getWhoClicked().getInventory(); /* due to a client issue off-hand items appear as ghost items, this updates the off-hand correctly @@ -356,26 +358,31 @@ public void onInventoryClose(@NotNull InventoryCloseEvent event) { playerInventory.setItemInOffHand(playerInventory.getItemInOffHand()); if (!gui.isUpdating()) { - gui.callOnClose(event); - - event.getInventory().clear(); //clear inventory to prevent items being put back - - gui.getHumanEntityCache().restoreAndForget(humanEntity); - - if (gui.getViewerCount() == 1) { - activeGuiInstances.remove(gui); - } - - if (gui instanceof AnvilGui) { - ((AnvilGui) gui).handleClose(humanEntity); - } else if (gui instanceof MerchantGui) { - ((MerchantGui) gui).handleClose(humanEntity); - } else if (gui instanceof ModernSmithingTableGui) { - ((ModernSmithingTableGui) gui).handleClose(humanEntity); - } - - //Bukkit doesn't like it if you open an inventory while the previous one is being closed - Bukkit.getScheduler().runTask(this.plugin, () -> gui.navigateToParent(humanEntity)); + DispatchUtil.runTaskFor(humanEntity, this.plugin, () -> { + gui.callOnClose(event); + + event.getInventory().clear(); //clear inventory to prevent items being put back + + }); + + DispatchUtil.runTaskFor(humanEntity, this.plugin, () -> { + gui.getHumanEntityCache().restoreAndForget(humanEntity); + + if (gui.getViewerCount() == 1) { + activeGuiInstances.remove(gui); + } + + if (gui instanceof AnvilGui) { + ((AnvilGui) gui).handleClose(humanEntity); + } else if (gui instanceof MerchantGui) { + ((MerchantGui) gui).handleClose(humanEntity); + } else if (gui instanceof ModernSmithingTableGui) { + ((ModernSmithingTableGui) gui).handleClose(humanEntity); + } + + //Bukkit doesn't like it if you open an inventory while the previous one is being closed + DispatchUtil.runTaskFor(humanEntity, this.plugin, () -> { gui.navigateToParent(humanEntity); }); + }); } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java index 84c54704..5e3c0f1f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java @@ -7,6 +7,7 @@ import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; +import com.github.stefvanschie.inventoryframework.util.DispatchUtil; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; import org.bukkit.Bukkit; @@ -236,7 +237,7 @@ public void handleClickEvent(@NotNull InventoryClickEvent event) { cartographyTableInventory.sendItems(player, getTopItems()); } else if (slot >= 0 && slot <= 2) { //the client rejects the output item if send immediately - Bukkit.getScheduler().runTask(super.plugin, () -> + DispatchUtil.runTaskFor(player, this.plugin, () -> cartographyTableInventory.sendItems(player, getTopItems())); if (event.isCancelled()) { diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/DispatchUtil.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/DispatchUtil.java new file mode 100644 index 00000000..13594c66 --- /dev/null +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/DispatchUtil.java @@ -0,0 +1,31 @@ +package com.github.stefvanschie.inventoryframework.util; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; +import org.bukkit.plugin.Plugin; + +public class DispatchUtil { + private static boolean isFolia() { + try { + Class.forName("io.papermc.paper.threadedregions.RegionizedServer"); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } + + /* + * Schedules a task to run for a given entity. + * + * For non-Folia servers, runs on Bukkit scheduler. + * For Folia servers, runs on the entity's scheduler. + */ + @SuppressWarnings("deprecation") + public static void runTaskFor(Entity entity, Plugin plugin, Runnable task) { + if (isFolia()) { + entity.getScheduler().run(plugin, e -> task.run(), null); + } else { + Bukkit.getScheduler().runTask(plugin, task); + } + } +}