Skip to content

Commit d7992ee

Browse files
author
MagicTeaMC
committed
fix folia support
1 parent 63bdda3 commit d7992ee

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

src/main/java/org/milkteamc/autotreechop/AutoTreeChop.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.milkteamc.autotreechop;
22

3+
import com.github.Anon8281.universalScheduler.UniversalScheduler;
34
import java.io.File;
45
import java.util.HashSet;
56
import java.util.Locale;
@@ -158,8 +159,7 @@ public void onEnable() {
158159
config.getPassword());
159160

160161
saveTask = new PlayerDataSaveTask(this, SAVE_THRESHOLD);
161-
saveTask.runTaskTimerAsynchronously(this, SAVE_INTERVAL, SAVE_INTERVAL);
162-
162+
UniversalScheduler.getScheduler(this).runTaskTimerAsynchronously(saveTask, SAVE_INTERVAL, SAVE_INTERVAL);
163163
autoTreeChopAPI = new AutoTreeChopAPI(this);
164164
playerConfigs = new ConcurrentHashMap<>();
165165
initializeHooks();
@@ -268,7 +268,11 @@ public void onDisable() {
268268
getLogger().info("Saving all player data before shutdown...");
269269

270270
if (saveTask != null) {
271-
saveTask.cancel();
271+
try {
272+
saveTask.cancel();
273+
} catch (IllegalStateException ignored) {
274+
// Task was never scheduled or already cancelled (e.g. Folia shutdown)
275+
}
272276
}
273277

274278
for (Map.Entry<UUID, PlayerConfig> entry : playerConfigs.entrySet()) {

src/main/java/org/milkteamc/autotreechop/ModrinthUpdateChecker.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ public ModrinthUpdateChecker startPeriodicCheck() {
177177
checkNow();
178178

179179
long intervalTicks = checkIntervalHours * 60 * 60 * 20L; // hours to ticks
180-
plugin.getServer()
181-
.getScheduler()
182-
.runTaskTimerAsynchronously(plugin, this::performCheck, intervalTicks, intervalTicks);
180+
UniversalScheduler.getScheduler(plugin)
181+
.runTaskTimerAsynchronously(this::performCheck, intervalTicks, intervalTicks);
183182

184183
return this;
185184
}
@@ -322,9 +321,8 @@ public void onPlayerJoin(PlayerJoinEvent event) {
322321
}
323322

324323
if (shouldNotify) {
325-
plugin.getServer()
326-
.getScheduler()
327-
.runTaskLater(plugin, () -> printCheckResultToPlayer(player, false), 40L); // 2s
324+
UniversalScheduler.getScheduler(plugin)
325+
.runTaskLater(() -> printCheckResultToPlayer(player, false), 40L); // 2s
328326
}
329327
}
330328

src/main/java/org/milkteamc/autotreechop/events/BlockBreakListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void onBlockBreak(BlockBreakEvent event) {
132132
Location frozenLocation = location.clone();
133133
ItemStack frozenTool = tool.clone();
134134

135-
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
135+
scheduler.runTaskAsync(() -> {
136136
boolean hasLeaves = hasNearbyLeaves(block, config, snapshots);
137137

138138
// Return to the main/region thread to act on the result.

0 commit comments

Comments
 (0)