Skip to content

Commit 284baa3

Browse files
authored
Merge pull request #72 from yL3oft/feature/folia-support-isolated
Add folia support
2 parents 70d99a2 + bbacb4a commit 284baa3

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
@@ -35,6 +35,7 @@ public final class AutoPickup extends JavaPlugin {
3535
public boolean UP2Date = true;
3636
public TallCrops crops;
3737

38+
public static boolean usingFolia = false; // Folia Support
3839
public static boolean usingUpgradableHoppers = false; // UpgradableHoppers Patch
3940
public static boolean usingLocketteProByBrunyman = false; // LockettePro Patch
4041
public static boolean usingBentoBox = false; // BentoBox - AOneBlock Patch
@@ -62,6 +63,16 @@ public final class AutoPickup extends JavaPlugin {
6263

6364
private static AutoPickup instance;
6465

66+
@Override
67+
public void onLoad() {
68+
try {
69+
Class.forName("io.papermc.paper.threadedregions.scheduler.RegionScheduler");
70+
usingFolia = true;
71+
} catch (ClassNotFoundException e) {
72+
usingFolia = false;
73+
}
74+
}
75+
6576
@Override
6677
public void onEnable() {
6778
// Plugin startup logic
@@ -177,15 +188,15 @@ public void run() {
177188
}
178189

179190
// Pickup Objective Cleaner
180-
new BukkitRunnable() {
191+
SchedulerUtils.runTaskTimerAsynchronously(new FoliaRunnable() {
181192
@Override
182193
public void run() {
183194
customItemPatch.keySet().removeIf(key -> (Duration.between(Instant.now(), customItemPatch.get(key).getCreatedAt()).getSeconds() < -15));
184195
}
185-
}.runTaskTimerAsynchronously(this, 300L, 300L); // 15 sec
196+
}, 300L, 300L); // 15 sec
186197

187198
// Dropped items cleaner ****
188-
new BukkitRunnable() {
199+
SchedulerUtils.runTaskTimer(null, new FoliaRunnable() {
189200
@Override
190201
public void run() {
191202
try {
@@ -195,7 +206,7 @@ public void run() {
195206
});
196207
} catch (NullPointerException ignored) {}
197208
}
198-
}.runTaskTimer(this, 6000L, 6000L); // 5 min
209+
}, 6000L, 6000L); // 5 min
199210

200211
// Load auto smelt cache
201212
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,7 +87,7 @@ 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 setEnabledFishing(boolean e) {
@@ -111,7 +111,7 @@ public void run() {
111111
}
112112

113113
public void setEnabledAutoSmelt(boolean e) {
114-
new BukkitRunnable() {
114+
SchedulerUtils.runTaskLater(player.getLocation(), new FoliaRunnable() {
115115
@Override
116116
public void run() {
117117
if (!fileExists()) {createFile();}
@@ -127,7 +127,7 @@ public void run() {
127127
log.warning("[AutoPickup] Unable to update "+uuid+"'s data file.");
128128
}
129129
}
130-
}.runTaskLater(plugin, 1);
130+
}, 1);
131131
}
132132

133133
public boolean getToggle(){

0 commit comments

Comments
 (0)