mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-22 00:17:37 +01:00
Use global region scheduler in runSync methods on Folia (#4292)
This commit is contained in:
parent
1653de70c8
commit
96c12ef483
@ -33,6 +33,7 @@ import com.viaversion.viaversion.bukkit.platform.BukkitViaInjector;
|
||||
import com.viaversion.viaversion.bukkit.platform.BukkitViaLoader;
|
||||
import com.viaversion.viaversion.bukkit.platform.BukkitViaTask;
|
||||
import com.viaversion.viaversion.bukkit.platform.BukkitViaTaskTask;
|
||||
import com.viaversion.viaversion.bukkit.platform.FoliaViaTask;
|
||||
import com.viaversion.viaversion.bukkit.platform.PaperViaInjector;
|
||||
import com.viaversion.viaversion.dump.PluginInfo;
|
||||
import com.viaversion.viaversion.unsupported.UnsupportedPlugin;
|
||||
@ -171,11 +172,18 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
|
||||
|
||||
@Override
|
||||
public PlatformTask runSync(Runnable runnable, long delay) {
|
||||
if (FOLIA) {
|
||||
// Set the delayed tick to at least 1, as Folia requires this.
|
||||
return new FoliaViaTask(getServer().getGlobalRegionScheduler().runDelayed(this, (e) -> runnable.run(), delay <= 0L ? 1L : delay));
|
||||
}
|
||||
return new BukkitViaTask(getServer().getScheduler().runTaskLater(this, runnable, delay));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformTask runRepeatingSync(Runnable runnable, long period) {
|
||||
if (FOLIA) {
|
||||
return new FoliaViaTask(getServer().getGlobalRegionScheduler().runAtFixedRate(this, (e) -> runnable.run(), 1, period));
|
||||
}
|
||||
return new BukkitViaTask(getServer().getScheduler().runTaskTimer(this, runnable, 0, period));
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viaversion.bukkit.platform;
|
||||
|
||||
import com.viaversion.viaversion.api.platform.PlatformTask;
|
||||
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||
|
||||
public record FoliaViaTask(ScheduledTask task) implements PlatformTask<ScheduledTask> {
|
||||
@Override
|
||||
public void cancel() {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user