This commit is contained in:
LOOHP 2023-03-30 14:51:44 +00:00 committed by GitHub
commit 545773f452
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 3 deletions

1
.gitignore vendored
View File

@ -10,6 +10,7 @@ javadoc
Vault.jar
/Vault.iml
/target
.idea
#added by LRFLEW
#feel free to remove

View File

@ -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

11
pom.xml
View File

@ -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>
@ -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>
@ -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>

View File

@ -21,6 +21,7 @@ import java.net.URL;
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;
@ -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
@ -104,6 +106,8 @@ public class Vault extends JavaPlugin {
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);
@ -117,7 +121,7 @@ public class Vault extends JavaPlugin {
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() {
@ -131,7 +135,7 @@ public class Vault extends JavaPlugin {
}
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() {
@ -421,6 +425,31 @@ public class Vault extends JavaPlugin {
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