mirror of https://github.com/MilkBowl/Vault.git
Compare commits
2 Commits
64e9fa23fe
...
2c12cec858
Author | SHA1 | Date |
---|---|---|
leonardo-dgs | 2c12cec858 | |
leonardo-dgs | 198812cebb |
|
@ -20,7 +20,6 @@ import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.milkbowl.vault.chat.Chat;
|
import net.milkbowl.vault.chat.Chat;
|
||||||
|
@ -84,8 +83,8 @@ public class Vault extends JavaPlugin {
|
||||||
private static Logger log;
|
private static Logger log;
|
||||||
private Permission perms;
|
private Permission perms;
|
||||||
private String newVersionTitle = "";
|
private String newVersionTitle = "";
|
||||||
private double newVersion = 0;
|
private double newVersion;
|
||||||
private double currentVersion = 0;
|
private double currentVersion;
|
||||||
private String currentVersionTitle = "";
|
private String currentVersionTitle = "";
|
||||||
private ServicesManager sm;
|
private ServicesManager sm;
|
||||||
private Vault plugin;
|
private Vault plugin;
|
||||||
|
@ -102,7 +101,7 @@ public class Vault extends JavaPlugin {
|
||||||
plugin = this;
|
plugin = this;
|
||||||
log = this.getLogger();
|
log = this.getLogger();
|
||||||
currentVersionTitle = getDescription().getVersion().split("-")[0];
|
currentVersionTitle = getDescription().getVersion().split("-")[0];
|
||||||
currentVersion = Double.valueOf(currentVersionTitle.replaceFirst("\\.", ""));
|
currentVersion = Double.parseDouble(currentVersionTitle.replaceFirst("\\.", ""));
|
||||||
sm = getServer().getServicesManager();
|
sm = getServer().getServicesManager();
|
||||||
// set defaults
|
// set defaults
|
||||||
getConfig().addDefault("update-check", true);
|
getConfig().addDefault("update-check", true);
|
||||||
|
@ -115,44 +114,32 @@ public class Vault extends JavaPlugin {
|
||||||
getCommand("vault-info").setExecutor(this);
|
getCommand("vault-info").setExecutor(this);
|
||||||
getCommand("vault-convert").setExecutor(this);
|
getCommand("vault-convert").setExecutor(this);
|
||||||
getServer().getPluginManager().registerEvents(new VaultListener(), this);
|
getServer().getPluginManager().registerEvents(new VaultListener(), this);
|
||||||
// Schedule to check the version every 30 minutes for an update. This is to update the most recent
|
// 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.
|
// version so if an admin reconnects they will be warned about newer versions.
|
||||||
this.getServer().getScheduler().runTask(this, new Runnable() {
|
this.getServer().getScheduler().runTask(this, () -> {
|
||||||
|
// Programmatically set the default permission value cause Bukkit doesn't handle plugin.yml properly for Load order STARTUP plugins
|
||||||
@Override
|
org.bukkit.permissions.Permission perm = getServer().getPluginManager().getPermission("vault.update");
|
||||||
public void run() {
|
if (perm == null)
|
||||||
// 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");
|
perm = new org.bukkit.permissions.Permission("vault.update");
|
||||||
if (perm == null)
|
perm.setDefault(PermissionDefault.OP);
|
||||||
{
|
plugin.getServer().getPluginManager().addPermission(perm);
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 0, 432000);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
perm.setDescription("Allows a user or the console to check for vault updates");
|
||||||
|
|
||||||
|
getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> {
|
||||||
|
if (getServer().getConsoleSender().hasPermission("vault.update") && getConfig().getBoolean("update-check", true)) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 432000);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Load up the Plugin metrics
|
// Load up the Plugin metrics
|
||||||
|
@ -257,7 +244,7 @@ public class Vault extends JavaPlugin {
|
||||||
|
|
||||||
Permission perms = new Permission_SuperPerms(this);
|
Permission perms = new Permission_SuperPerms(this);
|
||||||
sm.register(Permission.class, perms, this, ServicePriority.Lowest);
|
sm.register(Permission.class, perms, this, ServicePriority.Lowest);
|
||||||
log.info(String.format("[Permission] SuperPermissions loaded as backup permission system."));
|
log.info("[Permission] SuperPermissions loaded as backup permission system.");
|
||||||
|
|
||||||
this.perms = sm.getRegistration(Permission.class).getProvider();
|
this.perms = sm.getRegistration(Permission.class).getProvider();
|
||||||
}
|
}
|
||||||
|
@ -319,7 +306,7 @@ public class Vault extends JavaPlugin {
|
||||||
}
|
}
|
||||||
Economy econ1 = null;
|
Economy econ1 = null;
|
||||||
Economy econ2 = null;
|
Economy econ2 = null;
|
||||||
String economies = "";
|
StringBuilder economies = new StringBuilder();
|
||||||
for (RegisteredServiceProvider<Economy> econ : econs) {
|
for (RegisteredServiceProvider<Economy> econ : econs) {
|
||||||
String econName = econ.getProvider().getName().replace(" ", "");
|
String econName = econ.getProvider().getName().replace(" ", "");
|
||||||
if (econName.equalsIgnoreCase(args[0])) {
|
if (econName.equalsIgnoreCase(args[0])) {
|
||||||
|
@ -328,9 +315,9 @@ public class Vault extends JavaPlugin {
|
||||||
econ2 = econ.getProvider();
|
econ2 = econ.getProvider();
|
||||||
}
|
}
|
||||||
if (economies.length() > 0) {
|
if (economies.length() > 0) {
|
||||||
economies += ", ";
|
economies.append(", ");
|
||||||
}
|
}
|
||||||
economies += econName;
|
economies.append(econName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (econ1 == null) {
|
if (econ1 == null) {
|
||||||
|
@ -352,11 +339,11 @@ public class Vault extends JavaPlugin {
|
||||||
econ2.createPlayerAccount(op);
|
econ2.createPlayerAccount(op);
|
||||||
double diff = econ1.getBalance(op) - econ2.getBalance(op);
|
double diff = econ1.getBalance(op) - econ2.getBalance(op);
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
econ2.depositPlayer(op, diff);
|
econ2.depositPlayer(op, diff);
|
||||||
} else if (diff < 0) {
|
} else if (diff < 0) {
|
||||||
econ2.withdrawPlayer(op, -diff);
|
econ2.withdrawPlayer(op, -diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage("Converson complete, please verify the data before using it.");
|
sender.sendMessage("Converson complete, please verify the data before using it.");
|
||||||
|
@ -364,37 +351,37 @@ public class Vault extends JavaPlugin {
|
||||||
|
|
||||||
private void infoCommand(CommandSender sender) {
|
private void infoCommand(CommandSender sender) {
|
||||||
// Get String of Registered Economy Services
|
// Get String of Registered Economy Services
|
||||||
String registeredEcons = null;
|
StringBuilder registeredEcons = null;
|
||||||
Collection<RegisteredServiceProvider<Economy>> econs = this.getServer().getServicesManager().getRegistrations(Economy.class);
|
Collection<RegisteredServiceProvider<Economy>> econs = this.getServer().getServicesManager().getRegistrations(Economy.class);
|
||||||
for (RegisteredServiceProvider<Economy> econ : econs) {
|
for (RegisteredServiceProvider<Economy> econ : econs) {
|
||||||
Economy e = econ.getProvider();
|
Economy e = econ.getProvider();
|
||||||
if (registeredEcons == null) {
|
if (registeredEcons == null) {
|
||||||
registeredEcons = e.getName();
|
registeredEcons = new StringBuilder(e.getName());
|
||||||
} else {
|
} else {
|
||||||
registeredEcons += ", " + e.getName();
|
registeredEcons.append(", ").append(e.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get String of Registered Permission Services
|
// Get String of Registered Permission Services
|
||||||
String registeredPerms = null;
|
StringBuilder registeredPerms = null;
|
||||||
Collection<RegisteredServiceProvider<Permission>> perms = this.getServer().getServicesManager().getRegistrations(Permission.class);
|
Collection<RegisteredServiceProvider<Permission>> perms = this.getServer().getServicesManager().getRegistrations(Permission.class);
|
||||||
for (RegisteredServiceProvider<Permission> perm : perms) {
|
for (RegisteredServiceProvider<Permission> perm : perms) {
|
||||||
Permission p = perm.getProvider();
|
Permission p = perm.getProvider();
|
||||||
if (registeredPerms == null) {
|
if (registeredPerms == null) {
|
||||||
registeredPerms = p.getName();
|
registeredPerms = new StringBuilder(p.getName());
|
||||||
} else {
|
} else {
|
||||||
registeredPerms += ", " + p.getName();
|
registeredPerms.append(", ").append(p.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String registeredChats = null;
|
StringBuilder registeredChats = null;
|
||||||
Collection<RegisteredServiceProvider<Chat>> chats = this.getServer().getServicesManager().getRegistrations(Chat.class);
|
Collection<RegisteredServiceProvider<Chat>> chats = this.getServer().getServicesManager().getRegistrations(Chat.class);
|
||||||
for (RegisteredServiceProvider<Chat> chat : chats) {
|
for (RegisteredServiceProvider<Chat> chat : chats) {
|
||||||
Chat c = chat.getProvider();
|
Chat c = chat.getProvider();
|
||||||
if (registeredChats == null) {
|
if (registeredChats == null) {
|
||||||
registeredChats = c.getName();
|
registeredChats = new StringBuilder(c.getName());
|
||||||
} else {
|
} else {
|
||||||
registeredChats += ", " + c.getName();
|
registeredChats.append(", ").append(c.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,13 +438,13 @@ public class Vault extends JavaPlugin {
|
||||||
final String response = reader.readLine();
|
final String response = reader.readLine();
|
||||||
final JSONArray array = (JSONArray) JSONValue.parse(response);
|
final JSONArray array = (JSONArray) JSONValue.parse(response);
|
||||||
|
|
||||||
if (array.size() == 0) {
|
if (array.isEmpty()) {
|
||||||
this.getLogger().warning("No files found, or Feed URL is bad.");
|
this.getLogger().warning("No files found, or Feed URL is bad.");
|
||||||
return currentVersion;
|
return currentVersion;
|
||||||
}
|
}
|
||||||
// Pull the last version from the JSON
|
// Pull the last version from the JSON
|
||||||
newVersionTitle = ((String) ((JSONObject) array.get(array.size() - 1)).get("name")).replace("Vault", "").trim();
|
newVersionTitle = ((String) ((JSONObject) array.get(array.size() - 1)).get("name")).replace("Vault", "").trim();
|
||||||
return Double.valueOf(newVersionTitle.replaceFirst("\\.", "").trim());
|
return Double.parseDouble(newVersionTitle.replaceFirst("\\.", "").trim());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("There was an issue attempting to check for the latest version.");
|
log.info("There was an issue attempting to check for the latest version.");
|
||||||
}
|
}
|
||||||
|
@ -472,21 +459,11 @@ public class Vault extends JavaPlugin {
|
||||||
econ = rspEcon.getProvider();
|
econ = rspEcon.getProvider();
|
||||||
}
|
}
|
||||||
final String econName = econ != null ? econ.getName() : "No Economy";
|
final String econName = econ != null ? econ.getName() : "No Economy";
|
||||||
metrics.addCustomChart(new SimplePie("economy", new Callable<String>() {
|
metrics.addCustomChart(new SimplePie("economy", () -> econName));
|
||||||
@Override
|
|
||||||
public String call() {
|
|
||||||
return econName;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Create our Permission Graph and Add our permission Plotters
|
// Create our Permission Graph and Add our permission Plotters
|
||||||
final String permName = Bukkit.getServer().getServicesManager().getRegistration(Permission.class).getProvider().getName();
|
final String permName = Bukkit.getServer().getServicesManager().getRegistration(Permission.class).getProvider().getName();
|
||||||
metrics.addCustomChart(new SimplePie("permission", new Callable<String>() {
|
metrics.addCustomChart(new SimplePie("permission", () -> permName));
|
||||||
@Override
|
|
||||||
public String call() {
|
|
||||||
return permName;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Create our Chat Graph and Add our chat Plotters
|
// Create our Chat Graph and Add our chat Plotters
|
||||||
RegisteredServiceProvider<Chat> rspChat = Bukkit.getServer().getServicesManager().getRegistration(Chat.class);
|
RegisteredServiceProvider<Chat> rspChat = Bukkit.getServer().getServicesManager().getRegistration(Chat.class);
|
||||||
|
@ -495,12 +472,7 @@ public class Vault extends JavaPlugin {
|
||||||
chat = rspChat.getProvider();
|
chat = rspChat.getProvider();
|
||||||
}
|
}
|
||||||
final String chatName = chat != null ? chat.getName() : "No Chat";
|
final String chatName = chat != null ? chat.getName() : "No Chat";
|
||||||
metrics.addCustomChart(new SimplePie("chat", new Callable<String>() {
|
metrics.addCustomChart(new SimplePie("chat", () -> chatName));
|
||||||
@Override
|
|
||||||
public String call() {
|
|
||||||
return chatName;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class VaultListener implements Listener {
|
public class VaultListener implements Listener {
|
||||||
|
@ -509,13 +481,9 @@ public class Vault extends JavaPlugin {
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (perms.has(player, "vault.update")) {
|
if (perms.has(player, "vault.update")) {
|
||||||
try {
|
if (newVersion > currentVersion) {
|
||||||
if (newVersion > currentVersion) {
|
player.sendMessage("Vault " + newVersionTitle + " is out! You are running " + currentVersionTitle);
|
||||||
player.sendMessage("Vault " + newVersionTitle + " is out! You are running " + currentVersionTitle);
|
player.sendMessage("Update Vault at: " + VAULT_BUKKIT_URL);
|
||||||
player.sendMessage("Update Vault at: " + VAULT_BUKKIT_URL);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Ignore exceptions
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue