From 2d8cc827b9f3046cc4ef2f50032cffbcc96c7a9a Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Thu, 30 Mar 2023 13:31:16 -0400 Subject: [PATCH] Add method for checking the global thread --- .../src/main/java/com/earth2me/essentials/Essentials.java | 5 +++++ .../src/main/java/com/earth2me/essentials/IEssentials.java | 2 ++ .../src/main/java/net/ess3/provider/SchedulingProvider.java | 2 ++ .../ess3/provider/providers/BukkitSchedulingProvider.java | 6 ++++++ .../ess3/provider/providers/FoliaSchedulingProvider.java | 5 +++++ 5 files changed, 20 insertions(+) diff --git a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java index f7bac6ea2..1a3dcae41 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java @@ -1239,6 +1239,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials { return schedulingProvider.isRegionThread(location); } + @Override + public boolean isGlobalThread() { + return schedulingProvider.isGlobalThread(); + } + @Override public PermissionsHandler getPermissionsHandler() { return permissionsHandler; diff --git a/Essentials/src/main/java/com/earth2me/essentials/IEssentials.java b/Essentials/src/main/java/com/earth2me/essentials/IEssentials.java index 0f0c51a2d..375aa77a1 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IEssentials.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IEssentials.java @@ -129,6 +129,8 @@ public interface IEssentials extends Plugin { boolean isRegionThread(Location location); + boolean isGlobalThread(); + PermissionsHandler getPermissionsHandler(); AlternativeCommandsHandler getAlternativeCommandsHandler(); diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/SchedulingProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/SchedulingProvider.java index 0b4ca9c63..8206a16f2 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/SchedulingProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/SchedulingProvider.java @@ -10,6 +10,8 @@ public interface SchedulingProvider extends Provider { boolean isRegionThread(Location location); + boolean isGlobalThread(); + void runEntityTask(Entity entity, Runnable runnable); EssentialsTask runEntityTask(Entity entity, Runnable runnable, long delay); diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BukkitSchedulingProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BukkitSchedulingProvider.java index 94433986d..ac21c0040 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BukkitSchedulingProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BukkitSchedulingProvider.java @@ -1,6 +1,7 @@ package net.ess3.provider.providers; import net.ess3.provider.SchedulingProvider; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.plugin.Plugin; @@ -28,6 +29,11 @@ public class BukkitSchedulingProvider implements SchedulingProvider { return plugin.getServer().isPrimaryThread(); } + @Override + public boolean isGlobalThread() { + return Bukkit.isPrimaryThread(); + } + @Override public void runEntityTask(Entity entity, Runnable runnable) { runEntityTask(entity, runnable, 1); diff --git a/providers/FoliaProvider/src/main/java/net/ess3/provider/providers/FoliaSchedulingProvider.java b/providers/FoliaProvider/src/main/java/net/ess3/provider/providers/FoliaSchedulingProvider.java index 4ffdf8e93..0cc884506 100644 --- a/providers/FoliaProvider/src/main/java/net/ess3/provider/providers/FoliaSchedulingProvider.java +++ b/providers/FoliaProvider/src/main/java/net/ess3/provider/providers/FoliaSchedulingProvider.java @@ -48,6 +48,11 @@ public class FoliaSchedulingProvider implements SchedulingProvider, Listener { return plugin.getServer().isOwnedByCurrentRegion(location); } + @Override + public boolean isGlobalThread() { + return plugin.getServer().isGlobalTickThread(); + } + @Override public void runEntityTask(Entity entity, Runnable runnable) { runEntityTask(entity, runnable, 1);