drtshock loves formatting, so I may as well

This commit is contained in:
gomeow
2013-04-12 10:54:25 -07:00
parent 678f61127e
commit 03a7b52a8e
22 changed files with 677 additions and 793 deletions
@@ -10,6 +10,7 @@ import com.drtshock.playervaults.Main;
public class DropOnDeath {
public static Main plugin;
public DropOnDeath(Main instance) {
DropOnDeath.plugin = instance;
}
@@ -26,7 +27,7 @@ public class DropOnDeath {
for(int count = 1; count <= Main.inventoriesToDrop; count++) {
Inventory inv = vm.getVault(player, count);
ItemStack[] stack = inv.getContents();
for(ItemStack is : stack) {
for(ItemStack is:stack) {
loc.getWorld().dropItemNaturally(loc, is);
}
}
@@ -25,6 +25,7 @@ public class EconomyOperations {
configFile = new File(plugin.getDataFolder(), "config.yml");
bukkitConfig.load(configFile);
}
/**
* Have a player pay to open a vault.
* Returns true if successful. Otherwise false.
@@ -32,7 +33,7 @@ public class EconomyOperations {
* @return transaction success
*/
public static boolean payToOpen(Player player) {
if(!bukkitConfig.getBoolean("economy.enabled") || /*player.hasPermission("playervaults.free") || */!Main.useVault)
if(!bukkitConfig.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !Main.useVault)
return true;
double cost = bukkitConfig.getDouble("economy.cost-to-open", 10);
@@ -44,6 +45,7 @@ public class EconomyOperations {
return false;
}
/**
* Have a player pay to create a vault.
* Returns true if successful. Otherwise false.
@@ -51,7 +53,7 @@ public class EconomyOperations {
* @return transaction success
*/
public static boolean payToCreate(Player player) {
if(!bukkitConfig.getBoolean("economy.enabled") || /*player.hasPermission("playervaults.free") || */!Main.useVault)
if(!bukkitConfig.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !Main.useVault)
return true;
double cost = bukkitConfig.getDouble("economy.cost-to-create", 100);
@@ -79,7 +81,7 @@ public class EconomyOperations {
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
if(file.exists()) {
if(playerFile.getString("vault"+number) == null) {
if(playerFile.getString("vault" + number) == null) {
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
return false;
}
@@ -2,17 +2,17 @@ package com.drtshock.playervaults.util;
/*
* Copyright 2011 Tyler Blair. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
@@ -22,7 +22,7 @@ package com.drtshock.playervaults.util;
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* The views and conclusions contained in the software and documentation are those of the
* authors and contributors and should not be interpreted as representing official policies,
* either expressed or implied, of anybody else.
@@ -134,7 +134,7 @@ public class Metrics {
private volatile int taskId = -1;
public Metrics(final Plugin plugin) throws IOException {
if (plugin == null) {
if(plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null");
}
@@ -149,7 +149,7 @@ public class Metrics {
configuration.addDefault("guid", UUID.randomUUID().toString());
// Do we need to create the file?
if (configuration.get("guid", null) == null) {
if(configuration.get("guid", null) == null) {
configuration.options().header("http://mcstats.org").copyDefaults(true);
configuration.save(configurationFile);
}
@@ -166,7 +166,7 @@ public class Metrics {
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
*/
public Graph createGraph(final String name) {
if (name == null) {
if(name == null) {
throw new IllegalArgumentException("Graph name cannot be null");
}
@@ -186,7 +186,7 @@ public class Metrics {
* @param graph The name of the graph
*/
public void addGraph(final Graph graph) {
if (graph == null) {
if(graph == null) {
throw new IllegalArgumentException("Graph cannot be null");
}
@@ -199,7 +199,7 @@ public class Metrics {
* @param plotter The plotter to use to plot custom data
*/
public void addCustomData(final Plotter plotter) {
if (plotter == null) {
if(plotter == null) {
throw new IllegalArgumentException("Plotter cannot be null");
}
@@ -221,12 +221,12 @@ public class Metrics {
public boolean start() {
synchronized (optOutLock) {
// Did we opt out?
if (isOptOut()) {
if(isOptOut()) {
return false;
}
// Is metrics already running?
if (taskId >= 0) {
if(taskId >= 0) {
return true;
}
@@ -239,18 +239,20 @@ public class Metrics {
try {
// This has to be synchronized or it can collide with the disable method.
synchronized (optOutLock) {
// Disable Task, if it is running and the server owner decided to opt-out
if (isOptOut() && taskId > 0) {
// Disable Task, if it is running and the server owner decided to
// opt-out
if(isOptOut() && taskId > 0) {
plugin.getServer().getScheduler().cancelTask(taskId);
taskId = -1;
// Tell all plotters to stop gathering information.
for (Graph graph : graphs){
for(Graph graph:graphs) {
graph.onOptOut();
}
}
}
// We use the inverse of firstPost because if it is the first time we are posting,
// We use the inverse of firstPost because if it is the first time we are
// posting,
// it is not a interval ping, so it evaluates to FALSE
// Each time thereafter it will evaluate to TRUE, i.e PING!
postPlugin(!firstPost);
@@ -258,7 +260,7 @@ public class Metrics {
// After the first post we set firstPost to false
// Each post thereafter will be a ping
firstPost = false;
} catch (IOException e) {
} catch(IOException e) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
}
}
@@ -274,14 +276,14 @@ public class Metrics {
* @return true if metrics should be opted out of it
*/
public boolean isOptOut() {
synchronized(optOutLock) {
synchronized (optOutLock) {
try {
// Reload the metrics file
configuration.load(getConfigFile());
} catch (IOException ex) {
} catch(IOException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
return true;
} catch (InvalidConfigurationException ex) {
} catch(InvalidConfigurationException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
return true;
}
@@ -298,13 +300,13 @@ public class Metrics {
// This has to be synchronized or it can collide with the check in the task.
synchronized (optOutLock) {
// Check if the server owner has already set opt-out, if not, set it.
if (isOptOut()) {
if(isOptOut()) {
configuration.set("opt-out", false);
configuration.save(configurationFile);
}
// Enable Task, if it is not running
if (taskId < 0) {
if(taskId < 0) {
start();
}
}
@@ -319,13 +321,13 @@ public class Metrics {
// This has to be synchronized or it can collide with the check in the task.
synchronized (optOutLock) {
// Check if the server owner has already set opt-out, if not, set it.
if (!isOptOut()) {
if(!isOptOut()) {
configuration.set("opt-out", true);
configuration.save(configurationFile);
}
// Disable Task, if it is running
if (taskId > 0) {
if(taskId > 0) {
this.plugin.getServer().getScheduler().cancelTask(taskId);
taskId = -1;
}
@@ -338,7 +340,8 @@ public class Metrics {
* @return the File object for the config file
*/
public File getConfigFile() {
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins
// to use
// is to abuse the plugin object we already have
// plugin.getDataFolder() => base/plugins/PluginA/
// pluginsFolder => base/plugins/
@@ -353,7 +356,8 @@ public class Metrics {
* Generic method that posts a plugin to the metrics website
*/
private void postPlugin(final boolean isPing) throws IOException {
// The plugin's description file containg all of the plugin data such as name, version, author, etc
// The plugin's description file containg all of the plugin data such as name, version,
// author, etc
final PluginDescriptionFile description = plugin.getDescription();
// Construct the post data
@@ -365,7 +369,7 @@ public class Metrics {
encodeDataPair(data, "revision", String.valueOf(REVISION));
// If we're pinging, append it
if (isPing) {
if(isPing) {
encodeDataPair(data, "ping", "true");
}
@@ -377,7 +381,7 @@ public class Metrics {
while (iter.hasNext()) {
final Graph graph = iter.next();
for (Plotter plotter : graph.getPlotters()) {
for(Plotter plotter:graph.getPlotters()) {
// The key name to send to the metrics server
// The format is C-GRAPHNAME-PLOTTERNAME where separator - is defined at the top
// Legacy (R4) submitters use the format Custom%s, or CustomPLOTTERNAME
@@ -401,7 +405,7 @@ public class Metrics {
// Mineshafter creates a socks proxy, so we can safely bypass it
// It does not reroute POST requests so we need to go around it
if (isMineshafterPresent()) {
if(isMineshafterPresent()) {
connection = url.openConnection(Proxy.NO_PROXY);
} else {
connection = url.openConnection();
@@ -422,18 +426,18 @@ public class Metrics {
writer.close();
reader.close();
if (response == null || response.startsWith("ERR")) {
throw new IOException(response); //Throw the exception
if(response == null || response.startsWith("ERR")) {
throw new IOException(response); // Throw the exception
} else {
// Is this the first update this hour?
if (response.contains("OK This is your first update this hour")) {
if(response.contains("OK This is your first update this hour")) {
synchronized (graphs) {
final Iterator<Graph> iter = graphs.iterator();
while (iter.hasNext()) {
final Graph graph = iter.next();
for (Plotter plotter : graph.getPlotters()) {
for(Plotter plotter:graph.getPlotters()) {
plotter.reset();
}
}
@@ -451,7 +455,7 @@ public class Metrics {
try {
Class.forName("mineshafter.MineServer");
return true;
} catch (Exception e) {
} catch(Exception e) {
return false;
}
}
@@ -546,7 +550,7 @@ public class Metrics {
@Override
public boolean equals(final Object object) {
if (!(object instanceof Graph)) {
if(!(object instanceof Graph)) {
return false;
}
@@ -620,7 +624,7 @@ public class Metrics {
@Override
public boolean equals(final Object object) {
if (!(object instanceof Plotter)) {
if(!(object instanceof Plotter)) {
return false;
}
@@ -631,4 +635,3 @@ public class Metrics {
}
}
@@ -33,12 +33,13 @@ public class Serialization {
}
return map;
}
private static Object fromJson(Object json) throws JSONException {
if (json == JSONObject.NULL) {
if(json == JSONObject.NULL) {
return null;
} else if (json instanceof JSONObject) {
} else if(json instanceof JSONObject) {
return toMap((JSONObject) json);
} else if (json instanceof JSONArray) {
} else if(json instanceof JSONArray) {
return toList((JSONArray) json);
} else {
return json;
@@ -47,7 +48,7 @@ public class Serialization {
public static List<Object> toList(JSONArray array) throws JSONException {
List<Object> list = new ArrayList<Object>();
for (int i = 0; i < array.length(); i++) {
for(int i = 0; i < array.length(); i++) {
list.add(fromJson(array.get(i)));
}
return list;
@@ -81,7 +82,7 @@ public class Serialization {
try {
ItemStack item = (ItemStack) deserialize(toMap(new JSONObject(piece)));
contents.add(item);
} catch (JSONException e) {
} catch(JSONException e) {
e.printStackTrace();
}
}
@@ -95,17 +96,18 @@ public class Serialization {
public static Map<String, Object> serialize(ConfigurationSerializable cs) {
Map<String, Object> serialized = recreateMap(cs.serialize());
for (Entry<String, Object> entry : serialized.entrySet()) {
if (entry.getValue() instanceof ConfigurationSerializable) {
entry.setValue(serialize((ConfigurationSerializable)entry.getValue()));
for(Entry<String, Object> entry:serialized.entrySet()) {
if(entry.getValue() instanceof ConfigurationSerializable) {
entry.setValue(serialize((ConfigurationSerializable) entry.getValue()));
}
}
serialized.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(cs.getClass()));
return serialized;
}
public static Map<String, Object> recreateMap(Map<String, Object> original) {
Map<String, Object> map = new HashMap<String, Object>();
for (Entry<String, Object> entry : original.entrySet()) {
for(Entry<String, Object> entry:original.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
return map;
@@ -113,10 +115,11 @@ public class Serialization {
@SuppressWarnings({ "unchecked", "rawtypes" })
public static ConfigurationSerializable deserialize(Map<String, Object> map) {
for (Entry<String, Object> entry : map.entrySet()) {
// Check if any of its sub-maps are ConfigurationSerializable. They need to be done first.
if (entry.getValue() instanceof Map && ((Map)entry.getValue()).containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
entry.setValue(deserialize((Map)entry.getValue()));
for(Entry<String, Object> entry:map.entrySet()) {
// Check if any of its sub-maps are ConfigurationSerializable. They need to be done
// first.
if(entry.getValue() instanceof Map && ((Map) entry.getValue()).containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
entry.setValue(deserialize((Map) entry.getValue()));
}
}
return ConfigurationSerialization.deserializeObject(map);
@@ -28,7 +28,7 @@ public class Updater extends Main {
}
try {
langConf.save(super.getLangFile());
} catch (IOException e) {
} catch(IOException e) {
log.log(Level.WARNING, "PlayerVaults: Failed to save lang.yml.");
log.log(Level.WARNING, "PlayerVaults: Report this stack trace to drtshock and gomeow.");
e.printStackTrace();
@@ -40,34 +40,47 @@ public class Updater extends Main {
public String getNewVersion() {
return this.newVersion;
}
public boolean getUpdate() throws Exception {
String version = this.version;
URL url = new URL("http://dev.bukkit.org/server-mods/playervaults/files.rss");
InputStreamReader isr = null;
try {
isr = new InputStreamReader(url.openStream());
}
catch(UnknownHostException e) {
return false; //Cannot connect
} catch(UnknownHostException e) {
return false; // Cannot connect
}
BufferedReader in = new BufferedReader(isr);
String line;
int lineNum = 0;
while((line = in.readLine()) != null) {
while ((line = in.readLine()) != null) {
if(line.length() != line.replace("<title>", "").length()) {
line = line.replaceAll("<title>", "").replaceAll("</title>", "").replaceAll(" ", "").substring(1); //Substring 1 for me, takes off the beginning v on my file name "v1.3.2"
line = line.replaceAll("<title>", "").replaceAll("</title>", "").replaceAll(" ", "").substring(1); // Substring
// 1
// for
// me,
// takes
// off
// the
// beginning
// v
// on
// my
// file
// name
// "v1.3.2"
if(lineNum == 1) {
this.newVersion = line;
Integer newVer = Integer.parseInt(line.replace(".", ""));
Integer oldVer = Integer.parseInt(version.replace(".", ""));
if(oldVer < newVer) {
return true; //They are using an old version
return true; // They are using an old version
}
else if(oldVer > newVer) {
return false; //They are using a FUTURE version!
return false; // They are using a FUTURE version!
}
else {
return false; //They are up to date!
return false; // They are up to date!
}
}
lineNum = lineNum + 1;
@@ -18,6 +18,7 @@ import com.drtshock.playervaults.Main;
public class VaultManager {
public Main plugin;
public VaultManager(Main instance) {
this.plugin = instance;
}
@@ -128,7 +129,7 @@ public class VaultManager {
if(!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
} catch(IOException e) {
e.printStackTrace();
}
}
@@ -144,7 +145,7 @@ public class VaultManager {
*/
public void saveFile(String name, YamlConfiguration yaml) throws IOException {
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
if (file.exists()) {
if(file.exists()) {
file.renameTo(new File(directory + File.separator + "backups" + File.separator + name.toLowerCase() + ".yml"));
}
yaml.save(file);