Skip to content

Commit bbacb4a

Browse files
committed
Add folia support
1 parent 442dace commit bbacb4a

File tree

10 files changed

+228
-25
lines changed

10 files changed

+228
-25
lines changed

pom.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
<id>spigotmc-repo</id>
6060
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
6161
</repository>
62+
<repository>
63+
<id>papermc</id>
64+
<url>https://repo.papermc.io/repository/maven-public/</url>
65+
</repository>
6266
<repository>
6367
<id>sonatype</id>
6468
<url>https://oss.sonatype.org/content/groups/public/</url>
@@ -76,7 +80,6 @@
7680
<name>Lumine Releases</name>
7781
<url>https://mvn.lumine.io/repository/maven-public/</url>
7882
</repository>
79-
8083
</repositories>
8184

8285
<dependencies>
@@ -86,6 +89,12 @@
8689
<version>1.21.1-R0.1-SNAPSHOT</version>
8790
<scope>provided</scope>
8891
</dependency>
92+
<dependency>
93+
<groupId>dev.folia</groupId>
94+
<artifactId>folia-api</artifactId>
95+
<version>1.21.4-R0.1-SNAPSHOT</version>
96+
<scope>provided</scope>
97+
</dependency>
8998
<dependency>
9099
<groupId>world.bentobox</groupId>
91100
<artifactId>bentobox</artifactId>
@@ -101,7 +110,7 @@
101110
<dependency>
102111
<groupId>me.clip</groupId>
103112
<artifactId>placeholderapi</artifactId>
104-
<version>2.10.9</version>
113+
<version>2.11.6</version>
105114
<scope>provided</scope>
106115
</dependency>
107116
<dependency>

src/main/java/us/thezircon/play/autopickup/AutoPickup.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public final class AutoPickup extends JavaPlugin {
3333
public boolean UP2Date = true;
3434
public TallCrops crops;
3535

36+
public static boolean usingFolia = false; // Folia Support
3637
public static boolean usingUpgradableHoppers = false; // UpgradableHoppers Patch
3738
public static boolean usingLocketteProByBrunyman = false; // LockettePro Patch
3839
public static boolean usingBentoBox = false; // BentoBox - AOneBlock Patch
@@ -60,6 +61,16 @@ public final class AutoPickup extends JavaPlugin {
6061

6162
private static AutoPickup instance;
6263

64+
@Override
65+
public void onLoad() {
66+
try {
67+
Class.forName("io.papermc.paper.threadedregions.scheduler.RegionScheduler");
68+
usingFolia = true;
69+
} catch (ClassNotFoundException e) {
70+
usingFolia = false;
71+
}
72+
}
73+
6374
@Override
6475
public void onEnable() {
6576
// Plugin startup logic
@@ -173,15 +184,15 @@ public void run() {
173184
}
174185

175186
// Pickup Objective Cleaner
176-
new BukkitRunnable() {
187+
SchedulerUtils.runTaskTimerAsynchronously(new FoliaRunnable() {
177188
@Override
178189
public void run() {
179190
customItemPatch.keySet().removeIf(key -> (Duration.between(Instant.now(), customItemPatch.get(key).getCreatedAt()).getSeconds() < -15));
180191
}
181-
}.runTaskTimerAsynchronously(this, 300L, 300L); // 15 sec
192+
}, 300L, 300L); // 15 sec
182193

183194
// Dropped items cleaner ****
184-
new BukkitRunnable() {
195+
SchedulerUtils.runTaskTimer(null, new FoliaRunnable() {
185196
@Override
186197
public void run() {
187198
try {
@@ -191,7 +202,7 @@ public void run() {
191202
});
192203
} catch (NullPointerException ignored) {}
193204
}
194-
}.runTaskTimer(this, 6000L, 6000L); // 5 min
205+
}, 6000L, 6000L); // 5 min
195206

196207
// Load auto smelt cache
197208
AutoSmeltUtils.loadFurnaceRecipes(smeltRecipeCache);

src/main/java/us/thezircon/play/autopickup/listeners/BlockBreakEventListener.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
import org.bukkit.inventory.meta.ItemMeta;
2020
import org.bukkit.scheduler.BukkitRunnable;
2121
import us.thezircon.play.autopickup.AutoPickup;
22-
import us.thezircon.play.autopickup.utils.HexFormat;
23-
import us.thezircon.play.autopickup.utils.Mendable;
24-
import us.thezircon.play.autopickup.utils.PickupObjective;
25-
import us.thezircon.play.autopickup.utils.TallCrops;
22+
import us.thezircon.play.autopickup.utils.*;
2623
import world.bentobox.bentobox.BentoBox;
2724
import world.bentobox.bentobox.database.objects.Island;
2825

@@ -44,7 +41,7 @@ public void onBreak(BlockBreakEvent e) {
4441
return;
4542
}
4643

47-
Bukkit.getScheduler().runTaskAsynchronously(PLUGIN, new Runnable() {
44+
SchedulerUtils.runTaskAsynchronously(new Runnable() {
4845
@Override
4946
public void run() {
5047
boolean requirePermsAUTO = PLUGIN.getConfig().getBoolean("requirePerms.autopickup");
@@ -92,7 +89,7 @@ public void run() {
9289
// }
9390

9491
// AOneBlock Patch
95-
new BukkitRunnable() {
92+
SchedulerUtils.runTaskLater(player.getLocation(), new FoliaRunnable() {
9693
@Override
9794
public void run() {
9895
if (AutoPickup.usingBentoBox) {
@@ -143,7 +140,7 @@ public void run() {
143140
}
144141
}
145142
}
146-
}.runTaskLater(PLUGIN, 1);
143+
}, 1);
147144

148145
// Mend Items & Give Player XP
149146
boolean usingSilkSpawner = PLUGIN.getConfig().getBoolean("usingSilkSpawnerPlugin");
@@ -494,15 +491,15 @@ public static int mend(ItemStack item, int xp) {
494491
}
495492

496493
private static void fix(ItemStack item) {
497-
new BukkitRunnable() {
494+
SchedulerUtils.runTaskLater(null, new FoliaRunnable() {
498495
@Override
499496
public void run() {
500497
ItemMeta meta = item.getItemMeta();
501498
Damageable damage = (Damageable) meta;
502499
damage.setDamage(0);
503500
item.setItemMeta(meta);
504501
}
505-
}.runTaskLater(PLUGIN, 1);
502+
}, 1);
506503
}
507504

508505
private static int amt = 1;

src/main/java/us/thezircon/play/autopickup/listeners/EntityDeathEventListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.bukkit.event.entity.EntityDeathEvent;
1111
import org.bukkit.inventory.ItemStack;
1212
import us.thezircon.play.autopickup.AutoPickup;
13+
import us.thezircon.play.autopickup.utils.SchedulerUtils;
1314

1415
import java.util.HashMap;
1516
import java.util.Iterator;
@@ -33,7 +34,7 @@ public void onDeath(EntityDeathEvent e) {
3334

3435
if (!PLUGIN.autopickup_list_mobs.contains(player)) return;
3536

36-
Bukkit.getScheduler().runTaskAsynchronously(PLUGIN, new Runnable() {
37+
SchedulerUtils.runTaskAsynchronously(new Runnable() {
3738
@Override
3839
public void run() {
3940
boolean requirePermsAUTO = PLUGIN.getConfig().getBoolean("requirePerms.autopickup");

src/main/java/us/thezircon/play/autopickup/listeners/EntityDropItemEventListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.bukkit.event.player.PlayerShearEntityEvent;
99
import org.bukkit.inventory.ItemStack;
1010
import us.thezircon.play.autopickup.AutoPickup;
11+
import us.thezircon.play.autopickup.utils.SchedulerUtils;
1112

1213
import java.util.HashMap;
1314
import java.util.Iterator;
@@ -67,7 +68,7 @@ public void onDrop(EntityDropItemEvent e) {
6768
}
6869
}
6970

70-
Bukkit.getScheduler().runTaskAsynchronously(PLUGIN, new Runnable() {
71+
SchedulerUtils.runTaskAsynchronously(new Runnable() {
7172
@Override
7273
public void run() {
7374
if (!player.hasPermission("autopickup.pickup.mined")) {

src/main/java/us/thezircon/play/autopickup/listeners/PlayerInteractEventListener.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.bukkit.inventory.ItemStack;
1414
import org.bukkit.scheduler.BukkitRunnable;
1515
import us.thezircon.play.autopickup.AutoPickup;
16+
import us.thezircon.play.autopickup.utils.FoliaRunnable;
17+
import us.thezircon.play.autopickup.utils.SchedulerUtils;
1618

1719
import java.util.HashMap;
1820

@@ -40,7 +42,7 @@ public void onClick(PlayerInteractEvent e) {
4042

4143
if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
4244
if(e.getClickedBlock().getType() == Material.SWEET_BERRY_BUSH) {
43-
new BukkitRunnable() {
45+
SchedulerUtils.runTaskLater(loc, new FoliaRunnable() {
4446
@Override
4547
public void run() {
4648
for (Entity entity : loc.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
@@ -66,7 +68,7 @@ public void run() {
6668
}
6769
}
6870
}
69-
}.runTaskLater(PLUGIN, 1);
71+
}, 1);
7072
}
7173
}
7274
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package us.thezircon.play.autopickup.utils;
2+
3+
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
4+
import org.bukkit.scheduler.BukkitRunnable;
5+
6+
public class FoliaRunnable extends BukkitRunnable {
7+
8+
private ScheduledTask foliaTask;
9+
10+
@Override
11+
public synchronized void cancel() throws IllegalStateException {
12+
if(foliaTask != null) foliaTask.cancel();
13+
}
14+
15+
@Override
16+
public void run() {
17+
}
18+
19+
public void setScheduledTask(ScheduledTask task) {
20+
this.foliaTask = task;
21+
}
22+
}

src/main/java/us/thezircon/play/autopickup/utils/PickupPlayer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public File getPlayerData() {
5151
}
5252

5353
public void setEnabled(boolean e) {
54-
new BukkitRunnable() {
54+
SchedulerUtils.runTaskLater(player.getLocation(), new FoliaRunnable() {
5555
@Override
5656
public void run() {
5757
if (!fileExists()) {createFile();}
@@ -67,11 +67,11 @@ public void run() {
6767
log.warning("[AutoPickup] Unable to update "+uuid+"'s data file.");
6868
}
6969
}
70-
}.runTaskLater(plugin, 1);
70+
}, 1);
7171
}
7272

7373
public void setEnabledEntities(boolean e) {
74-
new BukkitRunnable() {
74+
SchedulerUtils.runTaskLater(player.getLocation(), new FoliaRunnable() {
7575
@Override
7676
public void run() {
7777
if (!fileExists()) {createFile();}
@@ -87,11 +87,11 @@ public void run() {
8787
log.warning("[AutoPickup] Unable to update "+uuid+"'s data file.");
8888
}
8989
}
90-
}.runTaskLater(plugin, 1);
90+
}, 1);
9191
}
9292

9393
public void setEnabledAutoSmelt(boolean e) {
94-
new BukkitRunnable() {
94+
SchedulerUtils.runTaskLater(player.getLocation(), new FoliaRunnable() {
9595
@Override
9696
public void run() {
9797
if (!fileExists()) {createFile();}
@@ -107,7 +107,7 @@ public void run() {
107107
log.warning("[AutoPickup] Unable to update "+uuid+"'s data file.");
108108
}
109109
}
110-
}.runTaskLater(plugin, 1);
110+
}, 1);
111111
}
112112

113113
public boolean getToggle(){

0 commit comments

Comments
 (0)