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

Add Support Folia without Bukkit Scheduler or GlobalScheduler #916

Open
wants to merge 4 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
68 changes: 33 additions & 35 deletions src/net/milkbowl/vault/Vault.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.net.URLConnection;
import java.util.Collection;
import java.util.concurrent.Callable;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

import net.milkbowl.vault.chat.Chat;
Expand Down Expand Up @@ -76,6 +78,8 @@
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

import java.util.concurrent.Executors;

import net.milkbowl.vault.chat.plugins.Chat_TotalPermissions;

public class Vault extends JavaPlugin {
Expand All @@ -89,12 +93,15 @@ public class Vault extends JavaPlugin {
private String currentVersionTitle = "";
private ServicesManager sm;
private Vault plugin;
private ScheduledExecutorService asyncTaskTimer;

@Override
public void onDisable() {
// Remove all Service Registrations
getServer().getServicesManager().unregisterAll(this);
Bukkit.getScheduler().cancelTasks(this);
if (asyncTaskTimer != null) {
asyncTaskTimer.shutdownNow();
}
}

@Override
Expand All @@ -115,44 +122,35 @@ public void onEnable() {
getCommand("vault-info").setExecutor(this);
getCommand("vault-convert").setExecutor(this);
getServer().getPluginManager().registerEvents(new VaultListener(), this);
asyncTaskTimer = Executors.newScheduledThreadPool(1);
// 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() {

@Override
public void run() {
// Programmatically set the default permission value cause Bukkit doesn't handle plugin.yml properly for Load order STARTUP plugins
org.bukkit.permissions.Permission perm = getServer().getPluginManager().getPermission("vault.update");
if (perm == null)
{
perm = new org.bukkit.permissions.Permission("vault.update");
perm.setDefault(PermissionDefault.OP);
plugin.getServer().getPluginManager().addPermission(perm);
}
perm.setDescription("Allows a user or the console to check for vault updates");

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

@Override
public void run() {
if (getServer().getConsoleSender().hasPermission("vault.update") && getConfig().getBoolean("update-check", true)) {
try {
log.info("Checking for Updates ... ");
newVersion = updateCheck(currentVersion);
if (newVersion > currentVersion) {
log.warning("Stable Version: " + newVersionTitle + " is out!" + " You are still running version: " + currentVersionTitle);
log.warning("Update at: https://dev.bukkit.org/projects/vault");
} else if (currentVersion > newVersion) {
log.info("Stable Version: " + newVersionTitle + " | Current Version: " + currentVersionTitle);
}
} catch (Exception e) {
// ignore exceptions
}
Executors.newSingleThreadExecutor().execute(() -> {
// Programmatically set the default permission value cause Bukkit doesn't handle plugin.yml properly for Load order STARTUP plugins
org.bukkit.permissions.Permission perm = getServer().getPluginManager().getPermission("vault.update");
if (perm == null)
{
perm = new org.bukkit.permissions.Permission("vault.update");
perm.setDefault(PermissionDefault.OP);
plugin.getServer().getPluginManager().addPermission(perm);
}
perm.setDescription("Allows a user or the console to check for vault updates");
asyncTaskTimer.scheduleAtFixedRate(() -> {
if (getServer().getConsoleSender().hasPermission("vault.update") && getConfig().getBoolean("update-check", true)) {
try {
log.info("Checking for Updates ... ");
newVersion = updateCheck(currentVersion);
if (newVersion > currentVersion) {
log.warning("Stable Version: " + newVersionTitle + " is out!" + " You are still running version: " + currentVersionTitle);
log.warning("Update at: https://dev.bukkit.org/projects/vault");
} else if (currentVersion > newVersion) {
log.info("Stable Version: " + newVersionTitle + " | Current Version: " + currentVersionTitle);
}
} catch (Exception e) {
// ignore exceptions
}
}, 0, 432000);

}
}
}, 0, 21600, TimeUnit.SECONDS);
});

// Load up the Plugin metrics
Expand Down