Skip to content
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

Folia Support #915

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ javadoc
Vault.jar
/Vault.iml
/target
.idea

#added by LRFLEW
#feel free to remove
Expand Down
1 change: 1 addition & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ description: ${project.description}
authors: [cereal, Sleaker, mung3r]
website: ${project.url}
api-version: 1.13
folia-supported: true

main: ${mainClass}
load: startup
Expand Down
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<bukkitVersion>1.13.1-R0.1-SNAPSHOT</bukkitVersion>
<foliaVersion>1.19.4-R0.1-SNAPSHOT</foliaVersion>
<mainClass>${project.groupId}.${project.artifactId}</mainClass>
<api.version>1.7</api.version>
</properties>
Expand Down Expand Up @@ -59,6 +60,10 @@
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>escapecraft-repo</id>
<url>http://dev.escapecraft.com/maven</url>
Expand All @@ -70,6 +75,12 @@
</repositories>

<dependencies>
<dependency>
<groupId>dev.folia</groupId>
<artifactId>folia-api</artifactId>
<version>${foliaVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
Expand Down
35 changes: 32 additions & 3 deletions src/net/milkbowl/vault/Vault.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.net.URLConnection;
import java.util.Collection;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

import net.milkbowl.vault.chat.Chat;
Expand Down Expand Up @@ -89,12 +90,13 @@ public class Vault extends JavaPlugin {
private String currentVersionTitle = "";
private ServicesManager sm;
private Vault plugin;
private boolean folia;

@Override
public void onDisable() {
// Remove all Service Registrations
getServer().getServicesManager().unregisterAll(this);
Bukkit.getScheduler().cancelTasks(this);
schedulerCancelTasks(this);
}

@Override
Expand All @@ -104,6 +106,8 @@ public void onEnable() {
currentVersionTitle = getDescription().getVersion().split("-")[0];
currentVersion = Double.valueOf(currentVersionTitle.replaceFirst("\\.", ""));
sm = getServer().getServicesManager();
folia = packagesExists("io.papermc.paper.threadedregions.scheduler.AsyncScheduler");

// set defaults
getConfig().addDefault("update-check", true);
getConfig().options().copyDefaults(true);
Expand All @@ -117,7 +121,7 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new VaultListener(), this);
// Schedule to check the version every 30 minutes for an update. This is to update the most recent
// version so if an admin reconnects they will be warned about newer versions.
this.getServer().getScheduler().runTask(this, new Runnable() {
schedulerRunTask(this, new Runnable() {

@Override
public void run() {
Expand All @@ -131,7 +135,7 @@ public void run() {
}
perm.setDescription("Allows a user or the console to check for vault updates");

getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
schedulerRunTaskTimerAsynchronously(plugin, new Runnable() {

@Override
public void run() {
Expand Down Expand Up @@ -421,6 +425,31 @@ private void infoCommand(CommandSender sender) {
sender.sendMessage(String.format("[%s] Chat: %s [%s]", getDescription().getName(), chat == null ? "None" : chat.getName(), registeredChats));
}

private void schedulerRunTask(Plugin plugin, Runnable runnable) {
if (folia) {
Bukkit.getGlobalRegionScheduler().execute(plugin, runnable);
} else {
Bukkit.getScheduler().runTask(plugin, runnable);
}
}

private void schedulerRunTaskTimerAsynchronously(Plugin plugin, Runnable runnable, long delay, long period) {
if (folia) {
Bukkit.getAsyncScheduler().runAtFixedRate(plugin, st -> runnable.run(), delay, period * 50L, TimeUnit.MILLISECONDS);
} else {
Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, runnable, delay, period);
}
}

private void schedulerCancelTasks(Plugin plugin) {
if (folia) {
Bukkit.getAsyncScheduler().cancelTasks(plugin);
Bukkit.getGlobalRegionScheduler().cancelTasks(plugin);
} else {
Bukkit.getScheduler().cancelTasks(plugin);
}
}

/**
* Determines if all packages in a String array are within the Classpath
* This is the best way to determine if a specific plugin exists and will be
Expand Down