Skip to content

Commit

Permalink
I added Folia support without breaking previous versions for Spigot.
Browse files Browse the repository at this point in the history
I removed the Bukkit Scheduler implementation to use the Concurrent Executors implementation which is much more maintainable than using an implementation that requires to use another package for Folia like here MilkBowl#915
  • Loading branch information
Euphillya committed Apr 15, 2023
1 parent 460cb21 commit 2b189bf
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
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
67 changes: 32 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,34 @@ 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(() -> {
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

0 comments on commit 2b189bf

Please sign in to comment.