-
-
Notifications
You must be signed in to change notification settings - Fork 566
Add Folia Support; #2012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
HarvelsX
wants to merge
10
commits into
EngineHub:master
Choose a base branch
from
HarvelsX:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add Folia Support; #2012
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4ad4abb
Add Folia scheduler adapter with folia check support;
HarvelsX 9157100
Add scheduler report only if it is not Folia;
HarvelsX e632541
Add scheduler adapter interface & implementation for: folia, bukkit;
HarvelsX dbe1a4e
Migrate to using scheduler adapter;
HarvelsX ce7b623
Implement synchronous execution for BukkitSchedulerAdapter;
HarvelsX 4b5dc2e
Possible fix duplicate initialization;
HarvelsX 73f116d
Mark plugin as supporting Folia;
HarvelsX e14f4f4
Fix using modified SchedulerAdapter methods;
HarvelsX 80faf9a
Fix implicit session uninitialization;
HarvelsX 41de14c
Migrate to use PaperLib for async entity teleportation;
HarvelsX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...rd-bukkit/src/main/java/com/sk89q/worldguard/bukkit/scheduler/BukkitSchedulerAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* WorldGuard, a suite of tools for Minecraft | ||
* Copyright (C) sk89q <http://www.sk89q.com> | ||
* Copyright (C) WorldGuard team and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser 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 Lesser General Public License | ||
* for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.sk89q.worldguard.bukkit.scheduler; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.plugin.Plugin; | ||
import org.bukkit.scheduler.BukkitScheduler; | ||
|
||
public class BukkitSchedulerAdapter implements SchedulerAdapter { | ||
|
||
private final Plugin plugin; | ||
@SuppressWarnings("deprecation") | ||
private final BukkitScheduler scheduler; | ||
|
||
public BukkitSchedulerAdapter(final Plugin plugin) { | ||
this.plugin = plugin; | ||
this.scheduler = plugin.getServer().getScheduler(); | ||
} | ||
|
||
@Override | ||
public void runAsyncRate(Runnable runnable, long delay, long period) { | ||
scheduler.runTaskTimerAsynchronously(plugin, runnable, delay, period); | ||
} | ||
|
||
@Override | ||
public void executeAtEntity(Entity entity, Runnable runnable) { | ||
scheduler.runTask(plugin, runnable); | ||
} | ||
|
||
@Override | ||
public void runAtEntityDelayed(final Entity entity, final Runnable runnable, final long delay) { | ||
scheduler.runTaskLater(plugin, runnable, delay); | ||
} | ||
|
||
@Override | ||
public void executeAtRegion(Location location, Runnable runnable) { | ||
scheduler.runTask(plugin, runnable); | ||
} | ||
|
||
@Override | ||
public void cancelTasks() { | ||
scheduler.cancelTasks(plugin); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...ard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/scheduler/FoliaSchedulerAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* WorldGuard, a suite of tools for Minecraft | ||
* Copyright (C) sk89q <http://www.sk89q.com> | ||
* Copyright (C) WorldGuard team and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser 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 Lesser General Public License | ||
* for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.sk89q.worldguard.bukkit.scheduler; | ||
|
||
import io.papermc.paper.threadedregions.scheduler.AsyncScheduler; | ||
import io.papermc.paper.threadedregions.scheduler.RegionScheduler; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.plugin.Plugin; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public class FoliaSchedulerAdapter implements SchedulerAdapter { | ||
private static final boolean SUPPORTED = checkSupport(); | ||
|
||
private final Plugin plugin; | ||
private final AsyncScheduler asyncScheduler; | ||
private final RegionScheduler regionScheduler; | ||
|
||
public FoliaSchedulerAdapter(final Plugin plugin) { | ||
this.plugin = plugin; | ||
this.asyncScheduler = plugin.getServer().getAsyncScheduler(); | ||
this.regionScheduler = plugin.getServer().getRegionScheduler(); | ||
} | ||
|
||
public static boolean isSupported() { | ||
return SUPPORTED; | ||
} | ||
|
||
private static boolean checkSupport() { | ||
try { | ||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer"); | ||
return true; | ||
} catch (ClassNotFoundException e) { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public void runAsyncRate(final Runnable runnable, final long delay, final long period) { | ||
asyncScheduler.runAtFixedRate(plugin, task -> runnable.run(), delay * 50, period * 50, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
@Override | ||
public void executeAtEntity(final Entity entity, final Runnable runnable) { | ||
entity.getScheduler().run(plugin, task -> runnable.run(), null); | ||
} | ||
|
||
@Override | ||
public void runAtEntityDelayed(final Entity entity, final Runnable runnable, final long delay) { | ||
entity.getScheduler().execute(plugin, runnable, null, delay); | ||
} | ||
|
||
@Override | ||
public void executeAtRegion(final Location location, final Runnable runnable) { | ||
regionScheduler.execute(plugin, location, runnable); | ||
} | ||
|
||
@Override | ||
public void cancelTasks() { | ||
asyncScheduler.cancelTasks(plugin); | ||
} | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/scheduler/SchedulerAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* WorldGuard, a suite of tools for Minecraft | ||
* Copyright (C) sk89q <http://www.sk89q.com> | ||
* Copyright (C) WorldGuard team and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser 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 Lesser General Public License | ||
* for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.sk89q.worldguard.bukkit.scheduler; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.entity.Entity; | ||
|
||
public interface SchedulerAdapter { | ||
HarvelsX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Schedules the specified task to be executed asynchronously after the delay has passed, | ||
* and then periodically executed with the specified period. | ||
* | ||
* @param runnable The task to execute. | ||
* @param delay The time delay to pass before the task should be executed. | ||
* @param period The time between task executions after the first execution of the task. | ||
*/ | ||
void runAsyncRate(Runnable runnable, long delay, long period); | ||
|
||
/** | ||
* Schedules a task. If the task failed to schedule because the scheduler is retired (entity removed), | ||
* then returns {@code false}. Otherwise, either the run callback will be invoked after the specified delay, | ||
* or the retired callback will be invoked if the scheduler is retired. | ||
* Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity, | ||
* remove other entities, load chunks, load worlds, modify ticket levels, etc. | ||
* | ||
* <p> | ||
* It is guaranteed that the task and retired callback are invoked on the region which owns the entity. | ||
* </p> | ||
* | ||
* @param entity The entity relative to which the scheduler is obtained. | ||
* @param runnable The task to execute. | ||
*/ | ||
void executeAtEntity(Entity entity, Runnable runnable); | ||
|
||
/** | ||
* Schedules a task with the given delay. If the task failed to schedule because the scheduler is retired (entity removed), | ||
* then returns {@code false}. Otherwise, either the run callback will be invoked after the specified delay, | ||
* or the retired callback will be invoked if the scheduler is retired. | ||
* Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity, | ||
* remove other entities, load chunks, load worlds, modify ticket levels, etc. | ||
* | ||
* <p> | ||
* It is guaranteed that the task and retired callback are invoked on the region which owns the entity. | ||
* </p> | ||
* | ||
* @param entity The entity relative to which the scheduler is obtained. | ||
* @param runnable The task to execute. | ||
* @param delay The time delay to pass before the task should be executed, in ticks. | ||
*/ | ||
void runAtEntityDelayed(Entity entity, Runnable runnable, long delay); | ||
|
||
/** | ||
* Schedules a task to be executed on the region which owns the location. | ||
* | ||
* @param location The location at which the region executing should own. | ||
* @param runnable The task to execute. | ||
*/ | ||
void executeAtRegion(Location location, Runnable runnable); | ||
|
||
/** | ||
* Attempts to cancel all tasks scheduled by the plugin. | ||
*/ | ||
void cancelTasks(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.