diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..e2d0acc
Binary files /dev/null and b/.DS_Store differ
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..5bd3d5d
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+OptimizeCommand.java
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 0723e98..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml
index e4e60fd..1872084 100644
--- a/dependency-reduced-pom.xml
+++ b/dependency-reduced-pom.xml
@@ -1,69 +1,73 @@
-
-
- 4.0.0
- rebelmythik
- antivillagerlag
- antivillagerlag
- 3.0.6
-
- clean package
-
-
- true
- src/main/resources
-
-
-
-
- maven-compiler-plugin
- 3.13.0
-
- ${java.version}
- ${java.version}
-
-
-
- maven-shade-plugin
- 3.5.3
-
-
- package
-
- shade
-
-
-
-
-
-
- org.bstats
- rebelmythik.antivillagerlag.utils
-
-
-
-
-
-
-
-
- spigotmc-repo
- https://hub.spigotmc.org/nexus/content/repositories/snapshots/
-
-
- sonatype
- https://oss.sonatype.org/content/groups/public/
-
-
-
-
- org.spigotmc
- spigot-api
- 1.20.1-R0.1-SNAPSHOT
- provided
-
-
-
- 17
- UTF-8
-
-
+
+
+ 4.0.0
+ rebelmythik
+ antivillagerlag
+ antivillagerlag
+ 3.1.0-FOLIA
+
+ clean package
+
+
+ true
+ src/main/resources
+
+
+
+
+ maven-compiler-plugin
+ 3.13.0
+
+ ${java.version}
+ ${java.version}
+
+
+
+ maven-shade-plugin
+ 3.5.3
+
+
+ package
+
+ shade
+
+
+
+
+
+
+ org.bstats
+ rebelmythik.antivillagerlag.utils
+
+
+
+
+
+
+
+
+ spigotmc-repo
+ https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
+
+ sonatype
+ https://oss.sonatype.org/content/groups/public/
+
+
+ papermc
+ https://repo.papermc.io/repository/maven-public/
+
+
+
+
+ dev.folia
+ folia-api
+ 1.20.1-R0.1-SNAPSHOT
+ provided
+
+
+
+ UTF-8
+ 17
+
+
diff --git a/pom.xml b/pom.xml
index ddc3f12..3348778 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,19 +68,24 @@
sonatype
https://oss.sonatype.org/content/groups/public/
+
+ papermc
+ https://repo.papermc.io/repository/maven-public/
+
- org.spigotmc
- spigot-api
+ dev.folia
+ folia-api
1.20.1-R0.1-SNAPSHOT
provided
-
- org.bstats
- bstats-bukkit
- 3.0.0
- compile
-
+
+
+ org.bstats
+ bstats-bukkit
+ 3.0.0
+ compile
+
diff --git a/src/main/java/rebelmythik/antiVillagerLag/commands/OptimizeCommand.java b/src/main/java/rebelmythik/antiVillagerLag/commands/OptimizeCommand.java
index 48f3dd6..15801a0 100644
--- a/src/main/java/rebelmythik/antiVillagerLag/commands/OptimizeCommand.java
+++ b/src/main/java/rebelmythik/antiVillagerLag/commands/OptimizeCommand.java
@@ -12,6 +12,7 @@
import rebelmythik.antiVillagerLag.events.NameTagAI;
import rebelmythik.antiVillagerLag.events.WorkblockAI;
import rebelmythik.antiVillagerLag.utils.ColorCode;
+import rebelmythik.antiVillagerLag.utils.SchedulerUtils;
import rebelmythik.antiVillagerLag.utils.VillagerUtilities;
public class OptimizeCommand implements CommandExecutor {
@@ -54,19 +55,20 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
player.getNearbyEntities(radius, radius, radius).forEach(entity -> {
if (entity instanceof Villager) {
Villager villager = (Villager) entity;
- // Setup new Villagers
- if (!VillagerUtilities.hasMarker(villager, plugin)) {
- VillagerUtilities.setAiCooldown(villager, plugin, 0);
- VillagerUtilities.setLevelCooldown(villager, plugin, 0);
- VillagerUtilities.setLastRestock(villager, plugin);
- VillagerUtilities.setMarker(villager, plugin, true);
- }
- // Rename villager
- villager.setCustomName(VillagerUtilities.disabling_names.getFirst());
- // Update the marker and AI
- VillagerUtilities.setMarker(villager, plugin, false);
- villager.setAware(false);
-
+ SchedulerUtils.runAtEntity(villager, plugin, () -> {
+ // Setup new Villagers
+ if (!VillagerUtilities.hasMarker(villager, plugin)) {
+ VillagerUtilities.setAiCooldown(villager, plugin, 0);
+ VillagerUtilities.setLevelCooldown(villager, plugin, 0);
+ VillagerUtilities.setLastRestock(villager, plugin);
+ VillagerUtilities.setMarker(villager, plugin, true);
+ }
+ // Rename villager
+ villager.setCustomName(VillagerUtilities.disabling_names.getFirst());
+ // Update the marker and AI
+ VillagerUtilities.setMarker(villager, plugin, false);
+ villager.setAware(false);
+ });
}
});
return true;
diff --git a/src/main/java/rebelmythik/antiVillagerLag/commands/RemoveChangesCommand.java b/src/main/java/rebelmythik/antiVillagerLag/commands/RemoveChangesCommand.java
index 4d3f4f7..662540a 100644
--- a/src/main/java/rebelmythik/antiVillagerLag/commands/RemoveChangesCommand.java
+++ b/src/main/java/rebelmythik/antiVillagerLag/commands/RemoveChangesCommand.java
@@ -11,6 +11,7 @@
import org.bukkit.entity.Villager;
import rebelmythik.antiVillagerLag.AntiVillagerLag;
import rebelmythik.antiVillagerLag.utils.ColorCode;
+import rebelmythik.antiVillagerLag.utils.SchedulerUtils;
import rebelmythik.antiVillagerLag.utils.VillagerUtilities;
public class RemoveChangesCommand implements CommandExecutor {
@@ -73,7 +74,9 @@ private void removeVillagerChanges() {
for (Entity entity : world.getLivingEntities()) {
if (entity.getType() == EntityType.VILLAGER) {
Villager vil = (Villager) entity;
- VillagerUtilities.CleanseTheVillagers(vil, plugin);
+ SchedulerUtils.runAtEntity(vil, plugin, () -> {
+ VillagerUtilities.CleanseTheVillagers(vil, plugin);
+ });
}
}
}
diff --git a/src/main/java/rebelmythik/antiVillagerLag/commands/UnoptimizeCommand.java b/src/main/java/rebelmythik/antiVillagerLag/commands/UnoptimizeCommand.java
index 194163d..1fb2de9 100644
--- a/src/main/java/rebelmythik/antiVillagerLag/commands/UnoptimizeCommand.java
+++ b/src/main/java/rebelmythik/antiVillagerLag/commands/UnoptimizeCommand.java
@@ -6,6 +6,7 @@
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import rebelmythik.antiVillagerLag.AntiVillagerLag;
+import rebelmythik.antiVillagerLag.utils.SchedulerUtils;
import rebelmythik.antiVillagerLag.utils.VillagerUtilities;
public class UnoptimizeCommand implements CommandExecutor {
@@ -48,18 +49,20 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
player.getNearbyEntities(radius, radius, radius).forEach(entity -> {
if (entity instanceof Villager) {
Villager villager = (Villager) entity;
- // Setup new Villagers
- if (!VillagerUtilities.hasMarker(villager, plugin)) {
- VillagerUtilities.setAiCooldown(villager, plugin, 0);
- VillagerUtilities.setLevelCooldown(villager, plugin, 0);
- VillagerUtilities.setLastRestock(villager, plugin);
+ SchedulerUtils.runAtEntity(villager, plugin, () -> {
+ // Setup new Villagers
+ if (!VillagerUtilities.hasMarker(villager, plugin)) {
+ VillagerUtilities.setAiCooldown(villager, plugin, 0);
+ VillagerUtilities.setLevelCooldown(villager, plugin, 0);
+ VillagerUtilities.setLastRestock(villager, plugin);
+ VillagerUtilities.setMarker(villager, plugin, true);
+ }
+ // Rename villager
+ villager.setCustomName("");
+ // Update the marker and AI
VillagerUtilities.setMarker(villager, plugin, true);
- }
- // Rename villager
- villager.setCustomName("");
- // Update the marker and AI
- VillagerUtilities.setMarker(villager, plugin, true);
- villager.setAware(true);
+ villager.setAware(true);
+ });
}
});
return true;
diff --git a/src/main/java/rebelmythik/antiVillagerLag/utils/SchedulerUtils.java b/src/main/java/rebelmythik/antiVillagerLag/utils/SchedulerUtils.java
new file mode 100644
index 0000000..917667d
--- /dev/null
+++ b/src/main/java/rebelmythik/antiVillagerLag/utils/SchedulerUtils.java
@@ -0,0 +1,74 @@
+package rebelmythik.antiVillagerLag.utils;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.entity.Entity;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.util.concurrent.TimeUnit;
+
+public class SchedulerUtils {
+
+ private static boolean isFolia;
+
+ static {
+ try {
+ Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
+ isFolia = true;
+ } catch (ClassNotFoundException e) {
+ isFolia = false;
+ }
+ }
+
+ public static boolean isFolia() {
+ return isFolia;
+ }
+
+ public static void runAsync(JavaPlugin plugin, Runnable runnable) {
+ if (isFolia) {
+ Bukkit.getAsyncScheduler().runNow(plugin, task -> runnable.run());
+ } else {
+ Bukkit.getScheduler().runTaskAsynchronously(plugin, runnable);
+ }
+ }
+
+ public static void runSync(JavaPlugin plugin, Runnable runnable) {
+ if (isFolia) {
+ Bukkit.getGlobalRegionScheduler().run(plugin, task -> runnable.run());
+ } else {
+ Bukkit.getScheduler().runTask(plugin, runnable);
+ }
+ }
+
+ public static void runAtEntity(Entity entity, JavaPlugin plugin, Runnable runnable) {
+ if (isFolia) {
+ entity.getScheduler().run(plugin, task -> runnable.run(), null);
+ } else {
+ Bukkit.getScheduler().runTask(plugin, runnable);
+ }
+ }
+
+ public static void runAtLocation(Location location, JavaPlugin plugin, Runnable runnable) {
+ if (isFolia) {
+ Bukkit.getRegionScheduler().run(plugin, location, task -> runnable.run());
+ } else {
+ Bukkit.getScheduler().runTask(plugin, runnable);
+ }
+ }
+
+ public static void runAtEntityLater(Entity entity, JavaPlugin plugin, Runnable runnable, long delay) {
+ if (isFolia) {
+ entity.getScheduler().runDelayed(plugin, task -> runnable.run(), null, delay);
+ } else {
+ Bukkit.getScheduler().runTaskLater(plugin, runnable, delay);
+ }
+ }
+
+ public static void runAtLocationLater(Location location, JavaPlugin plugin, Runnable runnable, long delay) {
+ if (isFolia) {
+ Bukkit.getRegionScheduler().runDelayed(plugin, location, task -> runnable.run(), delay);
+ } else {
+ Bukkit.getScheduler().runTaskLater(plugin, runnable, delay);
+ }
+ }
+}
diff --git a/src/main/java/rebelmythik/antiVillagerLag/utils/UpdateChecker.java b/src/main/java/rebelmythik/antiVillagerLag/utils/UpdateChecker.java
index e1d0fed..3617318 100644
--- a/src/main/java/rebelmythik/antiVillagerLag/utils/UpdateChecker.java
+++ b/src/main/java/rebelmythik/antiVillagerLag/utils/UpdateChecker.java
@@ -21,7 +21,7 @@ public UpdateChecker(JavaPlugin plugin, int resourceId) {
}
public void getVersion(final Consumer consumer) {
- Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
+ SchedulerUtils.runAsync(this.plugin, () -> {
try (InputStream is = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId + "/~").openStream(); Scanner scann = new Scanner(is)) {
if (scann.hasNext()) {
consumer.accept(scann.next());
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index f48dd29..19b7c6c 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -2,6 +2,7 @@ name: AntiVillagerLag
version: '${project.version}'
main: rebelmythik.antiVillagerLag.AntiVillagerLag
api-version: '1.20'
+folia-supported: true
authors: [ RebelMythik, CaveRaider ]
description: Bonk Villagers