programmatically set permissions because bukkit doesn't handle load

order startup plugin permissions properly when overriden in
permissions.yml
This commit is contained in:
Nick Minkler 2013-12-24 14:01:04 -08:00
parent 25916757e5
commit 8f408a635b
2 changed files with 45 additions and 28 deletions

View File

@ -20,6 +20,3 @@ permissions:
vault.admin:
description: Notifies the player when vault is in need of an update.
default: op
vault.update:
description: Allows a user or the console to check for updates
default: op

View File

@ -92,6 +92,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicePriority;
@ -115,6 +116,7 @@ public class Vault extends JavaPlugin {
private String currentVersionTitle = "";
private ServicesManager sm;
private Metrics metrics;
private Vault plugin;
@Override
public void onDisable() {
@ -125,7 +127,8 @@ public class Vault extends JavaPlugin {
@Override
public void onEnable() {
currentVersionTitle = getDescription().getVersion().split("-")[0];
plugin = this;
currentVersionTitle = getDescription().getVersion().split("-")[0].replace("Vault", "").trim();
currentVersion = Double.valueOf(currentVersionTitle.replaceFirst("\\.", ""));
sm = getServer().getServicesManager();
// Load Vault Addons
@ -138,7 +141,21 @@ 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().runTaskTimerAsynchronously(this, new Runnable() {
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() {
@ -165,9 +182,12 @@ public class Vault extends JavaPlugin {
}
}
}
}, 0, 432000);
}
});
// Load up the Plugin metrics
try {
metrics = new Metrics(this);