Overall organize imports and format

This commit is contained in:
gomeow
2013-08-20 16:26:34 -07:00
parent 66604da618
commit ce91614d0f
14 changed files with 183 additions and 185 deletions
@@ -1,5 +1,11 @@
package com.drtshock.playervaults; package com.drtshock.playervaults;
import com.drtshock.playervaults.commands.VaultOperations;
import com.drtshock.playervaults.commands.VaultViewInfo;
import com.drtshock.playervaults.util.DropOnDeath;
import com.drtshock.playervaults.util.Lang;
import com.drtshock.playervaults.util.VaultManager;
import java.io.IOException; import java.io.IOException;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@@ -25,12 +31,6 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import com.drtshock.playervaults.commands.VaultOperations;
import com.drtshock.playervaults.commands.VaultViewInfo;
import com.drtshock.playervaults.util.DropOnDeath;
import com.drtshock.playervaults.util.Lang;
import com.drtshock.playervaults.util.VaultManager;
public class Listeners implements Listener { public class Listeners implements Listener {
public PlayerVaults plugin; public PlayerVaults plugin;
@@ -53,7 +53,7 @@ public class Listeners implements Listener {
VaultViewInfo info = PlayerVaults.IN_VAULT.get(p.getName()); VaultViewInfo info = PlayerVaults.IN_VAULT.get(p.getName());
try { try {
vm.saveVault(inv, info.getHolder(), info.getNumber()); vm.saveVault(inv, info.getHolder(), info.getNumber());
} catch(IOException e) { } catch (IOException e) {
} }
PlayerVaults.OPENINVENTORIES.remove(info.toString()); PlayerVaults.OPENINVENTORIES.remove(info.toString());
} }
@@ -1,5 +1,13 @@
package com.drtshock.playervaults; package com.drtshock.playervaults;
import com.drtshock.playervaults.commands.Commands;
import com.drtshock.playervaults.commands.SignSetInfo;
import com.drtshock.playervaults.commands.VaultViewInfo;
import com.drtshock.playervaults.util.Lang;
import com.drtshock.playervaults.util.Metrics;
import com.drtshock.playervaults.util.Updater;
import com.drtshock.playervaults.util.VaultManager;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@@ -19,14 +27,6 @@ import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.drtshock.playervaults.commands.Commands;
import com.drtshock.playervaults.commands.SignSetInfo;
import com.drtshock.playervaults.commands.VaultViewInfo;
import com.drtshock.playervaults.util.Lang;
import com.drtshock.playervaults.util.Metrics;
import com.drtshock.playervaults.util.Updater;
import com.drtshock.playervaults.util.VaultManager;
public class PlayerVaults extends JavaPlugin { public class PlayerVaults extends JavaPlugin {
public static PlayerVaults PLUGIN; public static PlayerVaults PLUGIN;
@@ -77,7 +77,7 @@ public class PlayerVaults extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
for(Player p:Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
if (IN_VAULT.containsKey(p.getName())) { if (IN_VAULT.containsKey(p.getName())) {
p.closeInventory(); p.closeInventory();
} }
@@ -91,7 +91,7 @@ public class PlayerVaults extends JavaPlugin {
try { try {
Metrics metrics = new Metrics(this); Metrics metrics = new Metrics(this);
metrics.start(); metrics.start();
} catch(IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@@ -111,7 +111,7 @@ public class PlayerVaults extends JavaPlugin {
LINK = u.getLink(); LINK = u.getLink();
NEWVERSION = u.getNewVersion(); NEWVERSION = u.getNewVersion();
} }
} catch(Exception e) { } catch (Exception e) {
getLogger().log(Level.WARNING, "Failed to check for updates."); getLogger().log(Level.WARNING, "Failed to check for updates.");
getLogger().log(Level.WARNING, "Report this stack trace to gomeow."); getLogger().log(Level.WARNING, "Report this stack trace to gomeow.");
e.printStackTrace(); e.printStackTrace();
@@ -160,7 +160,7 @@ public class PlayerVaults extends JavaPlugin {
if (!signs.exists()) { if (!signs.exists()) {
try { try {
signs.createNewFile(); signs.createNewFile();
} catch(IOException e) { } catch (IOException e) {
log.severe("PlayerVaults has encountered a fatal error trying to load the signs file."); log.severe("PlayerVaults has encountered a fatal error trying to load the signs file.");
log.severe("Please report this error to drtshock and gomeow."); log.severe("Please report this error to drtshock and gomeow.");
e.printStackTrace(); e.printStackTrace();
@@ -185,7 +185,7 @@ public class PlayerVaults extends JavaPlugin {
public void saveSigns() { public void saveSigns() {
try { try {
PlayerVaults.SIGNS.save(PlayerVaults.SIGNS_FILE); PlayerVaults.SIGNS.save(PlayerVaults.SIGNS_FILE);
} catch(IOException e) { } catch (IOException e) {
log.severe("PlayerVaults has encountered an error trying to save the signs file."); log.severe("PlayerVaults has encountered an error trying to save the signs file.");
log.severe("Please report this error to drtshock and gomeow."); log.severe("Please report this error to drtshock and gomeow.");
e.printStackTrace(); e.printStackTrace();
@@ -215,7 +215,7 @@ public class PlayerVaults extends JavaPlugin {
setInConfig("drop-on-death.inventories", dropInvs, conf); setInConfig("drop-on-death.inventories", dropInvs, conf);
try { try {
conf.save(configFile); conf.save(configFile);
} catch(IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@@ -246,14 +246,14 @@ public class PlayerVaults extends JavaPlugin {
int read = 0; int read = 0;
byte[] bytes = new byte[1024]; byte[] bytes = new byte[1024];
while((read = defLangStream.read(bytes)) != -1) { while ((read = defLangStream.read(bytes)) != -1) {
out.write(bytes, 0, read); out.write(bytes, 0, read);
} }
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defLangStream); YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defLangStream);
Lang.setFile(defConfig); Lang.setFile(defConfig);
return; return;
} }
} catch(IOException e) { } catch (IOException e) {
e.printStackTrace(); // So they notice e.printStackTrace(); // So they notice
log.severe("[PlayerVaults] Couldn't create language file."); log.severe("[PlayerVaults] Couldn't create language file.");
log.severe("[PlayerVaults] This is a fatal error. Now disabling"); log.severe("[PlayerVaults] This is a fatal error. Now disabling");
@@ -262,14 +262,14 @@ public class PlayerVaults extends JavaPlugin {
if (defLangStream != null) { if (defLangStream != null) {
try { try {
defLangStream.close(); defLangStream.close();
} catch(IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
if (out != null) { if (out != null) {
try { try {
out.close(); out.close();
} catch(IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -277,7 +277,7 @@ public class PlayerVaults extends JavaPlugin {
} }
} }
YamlConfiguration conf = YamlConfiguration.loadConfiguration(lang); YamlConfiguration conf = YamlConfiguration.loadConfiguration(lang);
for(Lang item:Lang.values()) { for (Lang item : Lang.values()) {
if (conf.getString(item.getPath()) == null) { if (conf.getString(item.getPath()) == null) {
conf.set(item.getPath(), item.getDefault()); conf.set(item.getPath(), item.getDefault());
} }
@@ -287,7 +287,7 @@ public class PlayerVaults extends JavaPlugin {
PlayerVaults.LANG_FILE = lang; PlayerVaults.LANG_FILE = lang;
try { try {
conf.save(getLangFile()); conf.save(getLangFile());
} catch(IOException e) { } catch (IOException e) {
log.log(Level.WARNING, "PlayerVaults: Failed to save lang.yml."); log.log(Level.WARNING, "PlayerVaults: Failed to save lang.yml.");
log.log(Level.WARNING, "PlayerVaults: Report this stack trace to drtshock and gomeow."); log.log(Level.WARNING, "PlayerVaults: Report this stack trace to drtshock and gomeow.");
e.printStackTrace(); e.printStackTrace();
@@ -1,14 +1,14 @@
package com.drtshock.playervaults.commands; package com.drtshock.playervaults.commands;
import com.drtshock.playervaults.PlayerVaults;
import com.drtshock.playervaults.util.Lang;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.drtshock.playervaults.PlayerVaults;
import com.drtshock.playervaults.util.Lang;
public class Commands implements CommandExecutor { public class Commands implements CommandExecutor {
@Override @Override
@@ -68,7 +68,7 @@ public class Commands implements CommandExecutor {
int i = 0; int i = 0;
try { try {
i = Integer.parseInt(args[0]); i = Integer.parseInt(args[0]);
} catch(NumberFormatException nfe) { } catch (NumberFormatException nfe) {
sender.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER); sender.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER);
sender.sendMessage(Lang.TITLE.toString() + "Usage: /" + label + " <owner> <#>"); sender.sendMessage(Lang.TITLE.toString() + "Usage: /" + label + " <owner> <#>");
return true; return true;
@@ -80,7 +80,7 @@ public class Commands implements CommandExecutor {
int i = 0; int i = 0;
try { try {
i = Integer.parseInt(args[1]); i = Integer.parseInt(args[1]);
} catch(NumberFormatException nfe) { } catch (NumberFormatException nfe) {
sender.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER); sender.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER);
sender.sendMessage(Lang.TITLE.toString() + "Usage: /" + label + " <owner> <#>"); sender.sendMessage(Lang.TITLE.toString() + "Usage: /" + label + " <owner> <#>");
return true; return true;
@@ -1,5 +1,9 @@
package com.drtshock.playervaults.commands; package com.drtshock.playervaults.commands;
import com.drtshock.playervaults.PlayerVaults;
import com.drtshock.playervaults.util.EconomyOperations;
import com.drtshock.playervaults.util.Lang;
import java.io.IOException; import java.io.IOException;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@@ -7,10 +11,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import com.drtshock.playervaults.PlayerVaults;
import com.drtshock.playervaults.util.EconomyOperations;
import com.drtshock.playervaults.util.Lang;
public class VaultOperations { public class VaultOperations {
/** /**
@@ -21,7 +21,7 @@ public class VaultOperations {
*/ */
public static boolean checkPerms(CommandSender sender, int number) { public static boolean checkPerms(CommandSender sender, int number) {
if (sender.hasPermission("playervaults.amount." + String.valueOf(number))) return true; if (sender.hasPermission("playervaults.amount." + String.valueOf(number))) return true;
for(int x = number; x <= 99; x++) { for (int x = number; x <= 99; x++) {
if (sender.hasPermission("playervaults.amount." + String.valueOf(x))) return true; if (sender.hasPermission("playervaults.amount." + String.valueOf(x))) return true;
} }
return false; return false;
@@ -40,7 +40,7 @@ public class VaultOperations {
number = Integer.parseInt(arg); number = Integer.parseInt(arg);
if (number == 0) if (number == 0)
return false; return false;
} catch(NumberFormatException nfe) { } catch (NumberFormatException nfe) {
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER); player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
return false; return false;
} }
@@ -79,7 +79,7 @@ public class VaultOperations {
number = Integer.parseInt(arg); number = Integer.parseInt(arg);
if (number == 0) if (number == 0)
return false; return false;
} catch(NumberFormatException nfe) { } catch (NumberFormatException nfe) {
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER); player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
} }
Inventory inv = PlayerVaults.VM.loadVault(holder, number, true); Inventory inv = PlayerVaults.VM.loadVault(holder, number, true);
@@ -109,7 +109,7 @@ public class VaultOperations {
if (number == 0) if (number == 0)
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER); player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
return; return;
} catch(NumberFormatException nfe) { } catch (NumberFormatException nfe) {
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER); player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
} }
try { try {
@@ -117,7 +117,7 @@ public class VaultOperations {
PlayerVaults.VM.deleteVault(player, player.getName(), number); PlayerVaults.VM.deleteVault(player, player.getName(), number);
return; return;
} }
} catch(IOException e) { } catch (IOException e) {
player.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT_ERROR); player.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT_ERROR);
} }
} else { } else {
@@ -141,12 +141,12 @@ public class VaultOperations {
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER); sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
return; return;
} }
} catch(NumberFormatException nfe) { } catch (NumberFormatException nfe) {
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER); sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
} }
try { try {
PlayerVaults.VM.deleteVault(sender, holder, number); PlayerVaults.VM.deleteVault(sender, holder, number);
} catch(IOException e) { } catch (IOException e) {
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT_ERROR); sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT_ERROR);
} }
} else { } else {
@@ -1,12 +1,12 @@
package com.drtshock.playervaults.util; package com.drtshock.playervaults.util;
import com.drtshock.playervaults.PlayerVaults;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.drtshock.playervaults.PlayerVaults;
/** /**
* A class that contains a method to drop the contents of a player's vault when they die. * A class that contains a method to drop the contents of a player's vault when they die.
*/ */
@@ -18,10 +18,10 @@ public class DropOnDeath {
*/ */
public static void drop(Player player) { public static void drop(Player player) {
Location loc = player.getLocation(); Location loc = player.getLocation();
for(int count = 1; count <= PlayerVaults.INVENTORIES_TO_DROP; count++) { for (int count = 1; count <= PlayerVaults.INVENTORIES_TO_DROP; count++) {
Inventory inv = PlayerVaults.VM.getVault(player.getName(), count); Inventory inv = PlayerVaults.VM.getVault(player.getName(), count);
ItemStack[] stack = inv.getContents(); ItemStack[] stack = inv.getContents();
for(ItemStack is:stack) { for (ItemStack is : stack) {
loc.getWorld().dropItemNaturally(loc, is); loc.getWorld().dropItemNaturally(loc, is);
} }
} }
@@ -1,5 +1,7 @@
package com.drtshock.playervaults.util; package com.drtshock.playervaults.util;
import com.drtshock.playervaults.PlayerVaults;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
@@ -11,8 +13,6 @@ import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.drtshock.playervaults.PlayerVaults;
/** /**
* A class that handles all economy operations. * A class that handles all economy operations.
*/ */
@@ -28,12 +28,6 @@ package com.drtshock.playervaults.util;
* either expressed or implied, of anybody else. * either expressed or implied, of anybody else.
*/ */
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -52,6 +46,12 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
/** /**
* <p> * <p>
* The metrics class obtains data about a plugin and submits statistics about it to the metrics backend. * The metrics class obtains data about a plugin and submits statistics about it to the metrics backend.
@@ -219,7 +219,7 @@ public class Metrics {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public boolean start() { public boolean start() {
synchronized(optOutLock) { synchronized (optOutLock) {
// Did we opt out? // Did we opt out?
if (isOptOut()) { if (isOptOut()) {
return false; return false;
@@ -238,14 +238,14 @@ public class Metrics {
public void run() { public void run() {
try { try {
// This has to be synchronized or it can collide with the disable method. // This has to be synchronized or it can collide with the disable method.
synchronized(optOutLock) { synchronized (optOutLock) {
// Disable Task, if it is running and the server owner decided to // Disable Task, if it is running and the server owner decided to
// opt-out // opt-out
if (isOptOut() && taskId > 0) { if (isOptOut() && taskId > 0) {
plugin.getServer().getScheduler().cancelTask(taskId); plugin.getServer().getScheduler().cancelTask(taskId);
taskId = -1; taskId = -1;
// Tell all plotters to stop gathering information. // Tell all plotters to stop gathering information.
for(Graph graph:graphs) { for (Graph graph : graphs) {
graph.onOptOut(); graph.onOptOut();
} }
} }
@@ -260,7 +260,7 @@ public class Metrics {
// After the first post we set firstPost to false // After the first post we set firstPost to false
// Each post thereafter will be a ping // Each post thereafter will be a ping
firstPost = false; firstPost = false;
} catch(IOException e) { } catch (IOException e) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage()); Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
} }
} }
@@ -276,14 +276,14 @@ public class Metrics {
* @return true if metrics should be opted out of it * @return true if metrics should be opted out of it
*/ */
public boolean isOptOut() { public boolean isOptOut() {
synchronized(optOutLock) { synchronized (optOutLock) {
try { try {
// Reload the metrics file // Reload the metrics file
configuration.load(getConfigFile()); configuration.load(getConfigFile());
} catch(IOException ex) { } catch (IOException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
return true; return true;
} catch(InvalidConfigurationException ex) { } catch (InvalidConfigurationException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
return true; return true;
} }
@@ -298,7 +298,7 @@ public class Metrics {
*/ */
public void enable() throws IOException { public void enable() throws IOException {
// This has to be synchronized or it can collide with the check in the task. // This has to be synchronized or it can collide with the check in the task.
synchronized(optOutLock) { synchronized (optOutLock) {
// Check if the server owner has already set opt-out, if not, set it. // Check if the server owner has already set opt-out, if not, set it.
if (isOptOut()) { if (isOptOut()) {
configuration.set("opt-out", false); configuration.set("opt-out", false);
@@ -319,7 +319,7 @@ public class Metrics {
*/ */
public void disable() throws IOException { public void disable() throws IOException {
// This has to be synchronized or it can collide with the check in the task. // This has to be synchronized or it can collide with the check in the task.
synchronized(optOutLock) { synchronized (optOutLock) {
// Check if the server owner has already set opt-out, if not, set it. // Check if the server owner has already set opt-out, if not, set it.
if (!isOptOut()) { if (!isOptOut()) {
configuration.set("opt-out", true); configuration.set("opt-out", true);
@@ -375,13 +375,13 @@ public class Metrics {
// Acquire a lock on the graphs, which lets us make the assumption we also lock everything // Acquire a lock on the graphs, which lets us make the assumption we also lock everything
// inside of the graph (e.g plotters) // inside of the graph (e.g plotters)
synchronized(graphs) { synchronized (graphs) {
final Iterator<Graph> iter = graphs.iterator(); final Iterator<Graph> iter = graphs.iterator();
while(iter.hasNext()) { while (iter.hasNext()) {
final Graph graph = iter.next(); 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 key name to send to the metrics server
// The format is C-GRAPHNAME-PLOTTERNAME where separator - is defined at the top // The format is C-GRAPHNAME-PLOTTERNAME where separator - is defined at the top
// Legacy (R4) submitters use the format Custom%s, or CustomPLOTTERNAME // Legacy (R4) submitters use the format Custom%s, or CustomPLOTTERNAME
@@ -431,13 +431,13 @@ public class Metrics {
} else { } else {
// Is this the first update this hour? // 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) { synchronized (graphs) {
final Iterator<Graph> iter = graphs.iterator(); final Iterator<Graph> iter = graphs.iterator();
while(iter.hasNext()) { while (iter.hasNext()) {
final Graph graph = iter.next(); final Graph graph = iter.next();
for(Plotter plotter:graph.getPlotters()) { for (Plotter plotter : graph.getPlotters()) {
plotter.reset(); plotter.reset();
} }
} }
@@ -455,7 +455,7 @@ public class Metrics {
try { try {
Class.forName("mineshafter.MineServer"); Class.forName("mineshafter.MineServer");
return true; return true;
} catch(Exception e) { } catch (Exception e) {
return false; return false;
} }
} }
@@ -561,8 +561,7 @@ public class Metrics {
/** /**
* Called when the server owner decides to opt-out of Metrics while the server is running. * Called when the server owner decides to opt-out of Metrics while the server is running.
*/ */
protected void onOptOut() { protected void onOptOut() {}
}
} }
@@ -614,8 +613,7 @@ public class Metrics {
/** /**
* Called after the website graphs have been updated * Called after the website graphs have been updated
*/ */
public void reset() { public void reset() {}
}
@Override @Override
public int hashCode() { public int hashCode() {
@@ -28,7 +28,7 @@ public class Serialization {
public static Map<String, Object> toMap(JSONObject object) throws JSONException { public static Map<String, Object> toMap(JSONObject object) throws JSONException {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
Iterator<String> keys = object.keys(); Iterator<String> keys = object.keys();
while(keys.hasNext()) { while (keys.hasNext()) {
String key = (String) keys.next(); String key = (String) keys.next();
map.put(key, fromJson(object.get(key))); map.put(key, fromJson(object.get(key)));
} }
@@ -49,7 +49,7 @@ public class Serialization {
public static List<Object> toList(JSONArray array) throws JSONException { public static List<Object> toList(JSONArray array) throws JSONException {
List<Object> list = new ArrayList<Object>(); 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))); list.add(fromJson(array.get(i)));
} }
return list; return list;
@@ -58,10 +58,10 @@ public class Serialization {
public static List<String> toString(Inventory inv) { public static List<String> toString(Inventory inv) {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<String>();
List<ConfigurationSerializable> items = new ArrayList<ConfigurationSerializable>(); List<ConfigurationSerializable> items = new ArrayList<ConfigurationSerializable>();
for(ItemStack is:inv.getContents()) { for (ItemStack is : inv.getContents()) {
items.add(is); items.add(is);
} }
for(ConfigurationSerializable cs:items) { for (ConfigurationSerializable cs : items) {
if (cs == null) { if (cs == null) {
result.add("null"); result.add("null");
} }
@@ -77,7 +77,7 @@ public class Serialization {
Inventory inv = Bukkit.createInventory(holder, (large) ? 54 : 27, ChatColor.RED + "Vault #" + number); Inventory inv = Bukkit.createInventory(holder, (large) ? 54 : 27, ChatColor.RED + "Vault #" + number);
holder.setInventory(inv); holder.setInventory(inv);
List<ItemStack> contents = new ArrayList<ItemStack>(); List<ItemStack> contents = new ArrayList<ItemStack>();
for(String piece:stringItems) { for (String piece : stringItems) {
if (piece.equalsIgnoreCase("null")) { if (piece.equalsIgnoreCase("null")) {
contents.add(null); contents.add(null);
} }
@@ -85,13 +85,13 @@ public class Serialization {
try { try {
ItemStack item = (ItemStack) deserialize(toMap(new JSONObject(piece))); ItemStack item = (ItemStack) deserialize(toMap(new JSONObject(piece)));
contents.add(item); contents.add(item);
} catch(JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
ItemStack[] items = new ItemStack[contents.size()]; ItemStack[] items = new ItemStack[contents.size()];
for(int x = 0; x < contents.size(); x++) for (int x = 0; x < contents.size(); x++)
items[x] = contents.get(x); items[x] = contents.get(x);
inv.setContents(items); inv.setContents(items);
return inv; return inv;
@@ -99,7 +99,7 @@ public class Serialization {
public static Map<String, Object> serialize(ConfigurationSerializable cs) { public static Map<String, Object> serialize(ConfigurationSerializable cs) {
Map<String, Object> serialized = recreateMap(cs.serialize()); Map<String, Object> serialized = recreateMap(cs.serialize());
for(Entry<String, Object> entry:serialized.entrySet()) { for (Entry<String, Object> entry : serialized.entrySet()) {
if (entry.getValue() instanceof ConfigurationSerializable) { if (entry.getValue() instanceof ConfigurationSerializable) {
entry.setValue(serialize((ConfigurationSerializable) entry.getValue())); entry.setValue(serialize((ConfigurationSerializable) entry.getValue()));
} }
@@ -110,7 +110,7 @@ public class Serialization {
public static Map<String, Object> recreateMap(Map<String, Object> original) { public static Map<String, Object> recreateMap(Map<String, Object> original) {
Map<String, Object> map = new HashMap<String, Object>(); 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()); map.put(entry.getKey(), entry.getValue());
} }
return map; return map;
@@ -118,7 +118,7 @@ public class Serialization {
@SuppressWarnings({"unchecked", "rawtypes"}) @SuppressWarnings({"unchecked", "rawtypes"})
public static ConfigurationSerializable deserialize(Map<String, Object> map) { public static ConfigurationSerializable deserialize(Map<String, Object> map) {
for(Entry<String, Object> entry:map.entrySet()) { for (Entry<String, Object> entry : map.entrySet()) {
if (entry.getValue() instanceof Map && ((Map) entry.getValue()).containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) { if (entry.getValue() instanceof Map && ((Map) entry.getValue()).containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
entry.setValue(deserialize((Map) entry.getValue())); entry.setValue(deserialize((Map) entry.getValue()));
} }
@@ -24,7 +24,7 @@ public class Updater {
newVersion = feed.getElementsByTagName("title").item(1).getTextContent().substring(1); newVersion = feed.getElementsByTagName("title").item(1).getTextContent().substring(1);
String link = feed.getElementsByTagName("link").item(1).getTextContent(); String link = feed.getElementsByTagName("link").item(1).getTextContent();
this.link = new BufferedReader(new InputStreamReader(new URL("http://is.gd/create.php?format=simple&url=" + link).openStream())).readLine(); this.link = new BufferedReader(new InputStreamReader(new URL("http://is.gd/create.php?format=simple&url=" + link).openStream())).readLine();
if(v.contains("SNAPSHOT") && !newVersion.equals(oldVersion)) { if (v.contains("SNAPSHOT") && !newVersion.equals(oldVersion)) {
update = false; update = false;
return; return;
} }
@@ -7,7 +7,7 @@ import org.bukkit.inventory.InventoryHolder;
* Represents a VaultHolder to assist in detection of Player Vaults from * Represents a VaultHolder to assist in detection of Player Vaults from
* other plugins. * other plugins.
*/ */
public class VaultHolder implements InventoryHolder{ public class VaultHolder implements InventoryHolder {
private Inventory inventory; private Inventory inventory;
private int vaultNumber = 0; private int vaultNumber = 0;
@@ -17,7 +17,7 @@ public class VaultHolder implements InventoryHolder{
* *
* @param vaultNumber the vault number this holder is using * @param vaultNumber the vault number this holder is using
*/ */
public VaultHolder(int vaultNumber){ public VaultHolder(int vaultNumber) {
this.vaultNumber = vaultNumber; this.vaultNumber = vaultNumber;
} }
@@ -26,7 +26,7 @@ public class VaultHolder implements InventoryHolder{
* *
* @return the vault number * @return the vault number
*/ */
public int getVaultNumber(){ public int getVaultNumber() {
return vaultNumber; return vaultNumber;
} }
@@ -35,12 +35,12 @@ public class VaultHolder implements InventoryHolder{
* *
* @param inventory the inventory, may be null * @param inventory the inventory, may be null
*/ */
public void setInventory(Inventory inventory){ public void setInventory(Inventory inventory) {
this.inventory = inventory; this.inventory = inventory;
} }
@Override @Override
public Inventory getInventory(){ public Inventory getInventory() {
return inventory; return inventory;
} }
@@ -1,5 +1,8 @@
package com.drtshock.playervaults.util; package com.drtshock.playervaults.util;
import com.drtshock.playervaults.PlayerVaults;
import com.drtshock.playervaults.commands.VaultViewInfo;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@@ -12,9 +15,6 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import com.drtshock.playervaults.PlayerVaults;
import com.drtshock.playervaults.commands.VaultViewInfo;
/** /**
* A class for managing actual IO to the files, loading inventories, and saving them. * A class for managing actual IO to the files, loading inventories, and saving them.
*/ */
@@ -41,13 +41,13 @@ public class VaultManager {
if (size == 54) { if (size == 54) {
yaml.set("vault" + number, null); yaml.set("vault" + number, null);
} else { } else {
for(int x = 0; x < 27; x++) { for (int x = 0; x < 27; x++) {
yaml.set("vault" + number + "." + x, null); yaml.set("vault" + number + "." + x, null);
} }
} }
List<String> list = Serialization.toString(inventory); List<String> list = Serialization.toString(inventory);
String[] ser = list.toArray(new String[list.size()]); String[] ser = list.toArray(new String[list.size()]);
for(int x = 0; x < ser.length; x++) { for (int x = 0; x < ser.length; x++) {
if (!ser[x].equalsIgnoreCase("null")) { if (!ser[x].equalsIgnoreCase("null")) {
yaml.set("vault" + number + "." + x, ser[x]); yaml.set("vault" + number + "." + x, ser[x]);
} }
@@ -73,7 +73,7 @@ public class VaultManager {
vaultHolder.setInventory(inv); vaultHolder.setInventory(inv);
} else { } else {
List<String> data = new ArrayList<String>(); List<String> data = new ArrayList<String>();
for(int x = 0; x < ((large) ? 54 : 27); x++) { for (int x = 0; x < ((large) ? 54 : 27); x++) {
String line = playerFile.getString("vault" + number + "." + x); String line = playerFile.getString("vault" + number + "." + x);
if (line != null) { if (line != null) {
data.add(line); data.add(line);
@@ -144,7 +144,7 @@ public class VaultManager {
if (!file.exists()) { if (!file.exists()) {
try { try {
file.createNewFile(); file.createNewFile();
} catch(IOException e) { } catch (IOException e) {
// Who cares? // Who cares?
} }
} }
+17 -17
View File
@@ -105,7 +105,7 @@ public class JSONArray {
} }
if (x.nextClean() != ']') { if (x.nextClean() != ']') {
x.back(); x.back();
for(;;) { for (;;) {
if (x.nextClean() == ',') { if (x.nextClean() == ',') {
x.back(); x.back();
this.myArrayList.add(JSONObject.NULL); this.myArrayList.add(JSONObject.NULL);
@@ -149,7 +149,7 @@ public class JSONArray {
this.myArrayList = new ArrayList<Object>(); this.myArrayList = new ArrayList<Object>();
if (collection != null) { if (collection != null) {
Iterator<?> iter = collection.iterator(); Iterator<?> iter = collection.iterator();
while(iter.hasNext()) { while (iter.hasNext()) {
this.myArrayList.add(JSONObject.wrap(iter.next())); this.myArrayList.add(JSONObject.wrap(iter.next()));
} }
} }
@@ -163,7 +163,7 @@ public class JSONArray {
this(); this();
if (array.getClass().isArray()) { if (array.getClass().isArray()) {
int length = Array.getLength(array); int length = Array.getLength(array);
for(int i = 0; i < length; i += 1) { for (int i = 0; i < length; i += 1) {
this.put(JSONObject.wrap(Array.get(array, i))); this.put(JSONObject.wrap(Array.get(array, i)));
} }
} else { } else {
@@ -224,7 +224,7 @@ public class JSONArray {
return object instanceof Number return object instanceof Number
? ((Number) object).doubleValue() ? ((Number) object).doubleValue()
: Double.parseDouble((String) object); : Double.parseDouble((String) object);
} catch(Exception e) { } catch (Exception e) {
throw new JSONException("JSONArray[" + index + throw new JSONException("JSONArray[" + index +
"] is not a number."); "] is not a number.");
} }
@@ -243,7 +243,7 @@ public class JSONArray {
return object instanceof Number return object instanceof Number
? ((Number) object).intValue() ? ((Number) object).intValue()
: Integer.parseInt((String) object); : Integer.parseInt((String) object);
} catch(Exception e) { } catch (Exception e) {
throw new JSONException("JSONArray[" + index + throw new JSONException("JSONArray[" + index +
"] is not a number."); "] is not a number.");
} }
@@ -295,7 +295,7 @@ public class JSONArray {
return object instanceof Number return object instanceof Number
? ((Number) object).longValue() ? ((Number) object).longValue()
: Long.parseLong((String) object); : Long.parseLong((String) object);
} catch(Exception e) { } catch (Exception e) {
throw new JSONException("JSONArray[" + index + throw new JSONException("JSONArray[" + index +
"] is not a number."); "] is not a number.");
} }
@@ -336,7 +336,7 @@ public class JSONArray {
int len = this.length(); int len = this.length();
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for(int i = 0; i < len; i += 1) { for (int i = 0; i < len; i += 1) {
if (i > 0) { if (i > 0) {
sb.append(separator); sb.append(separator);
} }
@@ -390,7 +390,7 @@ public class JSONArray {
public boolean optBoolean(int index, boolean defaultValue) { public boolean optBoolean(int index, boolean defaultValue) {
try { try {
return this.getBoolean(index); return this.getBoolean(index);
} catch(Exception e) { } catch (Exception e) {
return defaultValue; return defaultValue;
} }
} }
@@ -419,7 +419,7 @@ public class JSONArray {
public double optDouble(int index, double defaultValue) { public double optDouble(int index, double defaultValue) {
try { try {
return this.getDouble(index); return this.getDouble(index);
} catch(Exception e) { } catch (Exception e) {
return defaultValue; return defaultValue;
} }
} }
@@ -447,7 +447,7 @@ public class JSONArray {
public int optInt(int index, int defaultValue) { public int optInt(int index, int defaultValue) {
try { try {
return this.getInt(index); return this.getInt(index);
} catch(Exception e) { } catch (Exception e) {
return defaultValue; return defaultValue;
} }
} }
@@ -499,7 +499,7 @@ public class JSONArray {
public long optLong(int index, long defaultValue) { public long optLong(int index, long defaultValue) {
try { try {
return this.getLong(index); return this.getLong(index);
} catch(Exception e) { } catch (Exception e) {
return defaultValue; return defaultValue;
} }
} }
@@ -717,7 +717,7 @@ public class JSONArray {
if (index < this.length()) { if (index < this.length()) {
this.myArrayList.set(index, value); this.myArrayList.set(index, value);
} else { } else {
while(index != this.length()) { while (index != this.length()) {
this.put(JSONObject.NULL); this.put(JSONObject.NULL);
} }
this.put(value); this.put(value);
@@ -751,7 +751,7 @@ public class JSONArray {
return null; return null;
} }
JSONObject jo = new JSONObject(); JSONObject jo = new JSONObject();
for(int i = 0; i < names.length(); i += 1) { for (int i = 0; i < names.length(); i += 1) {
jo.put(names.getString(i), this.opt(i)); jo.put(names.getString(i), this.opt(i));
} }
return jo; return jo;
@@ -771,7 +771,7 @@ public class JSONArray {
public String toString() { public String toString() {
try { try {
return this.toString(0); return this.toString(0);
} catch(Exception e) { } catch (Exception e) {
return null; return null;
} }
} }
@@ -789,7 +789,7 @@ public class JSONArray {
*/ */
public String toString(int indentFactor) throws JSONException { public String toString(int indentFactor) throws JSONException {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
synchronized(sw.getBuffer()) { synchronized (sw.getBuffer()) {
return this.write(sw, indentFactor, 0).toString(); return this.write(sw, indentFactor, 0).toString();
} }
} }
@@ -833,7 +833,7 @@ public class JSONArray {
} else if (length != 0) { } else if (length != 0) {
final int newindent = indent + indentFactor; final int newindent = indent + indentFactor;
for(int i = 0; i < length; i += 1) { for (int i = 0; i < length; i += 1) {
if (commanate) { if (commanate) {
writer.write(','); writer.write(',');
} }
@@ -852,7 +852,7 @@ public class JSONArray {
} }
writer.write(']'); writer.write(']');
return writer; return writer;
} catch(IOException e) { } catch (IOException e) {
throw new JSONException(e); throw new JSONException(e);
} }
} }
+35 -35
View File
@@ -174,10 +174,10 @@ public class JSONObject {
*/ */
public JSONObject(JSONObject jo, String[] names) { public JSONObject(JSONObject jo, String[] names) {
this(); this();
for(int i = 0; i < names.length; i += 1) { for (int i = 0; i < names.length; i += 1) {
try { try {
this.putOnce(names[i], jo.opt(names[i])); this.putOnce(names[i], jo.opt(names[i]));
} catch(Exception ignore) { } catch (Exception ignore) {
} }
} }
} }
@@ -196,7 +196,7 @@ public class JSONObject {
if (x.nextClean() != '{') { if (x.nextClean() != '{') {
throw x.syntaxError("A JSONObject text must begin with '{'"); throw x.syntaxError("A JSONObject text must begin with '{'");
} }
for(;;) { for (;;) {
c = x.nextClean(); c = x.nextClean();
switch (c) { switch (c) {
case 0: case 0:
@@ -249,7 +249,7 @@ public class JSONObject {
this.map = new HashMap(); this.map = new HashMap();
if (map != null) { if (map != null) {
Iterator i = map.entrySet().iterator(); Iterator i = map.entrySet().iterator();
while(i.hasNext()) { while (i.hasNext()) {
Map.Entry e = (Map.Entry) i.next(); Map.Entry e = (Map.Entry) i.next();
Object value = e.getValue(); Object value = e.getValue();
if (value != null) { if (value != null) {
@@ -297,11 +297,11 @@ public class JSONObject {
public JSONObject(Object object, String names[]) { public JSONObject(Object object, String names[]) {
this(); this();
Class c = object.getClass(); Class c = object.getClass();
for(int i = 0; i < names.length; i += 1) { for (int i = 0; i < names.length; i += 1) {
String name = names[i]; String name = names[i];
try { try {
this.putOpt(name, c.getField(name).get(object)); this.putOpt(name, c.getField(name).get(object));
} catch(Exception ignore) { } catch (Exception ignore) {
} }
} }
} }
@@ -333,7 +333,7 @@ public class JSONObject {
// Iterate through the keys in the bundle. // Iterate through the keys in the bundle.
Enumeration keys = bundle.getKeys(); Enumeration keys = bundle.getKeys();
while(keys.hasMoreElements()) { while (keys.hasMoreElements()) {
Object key = keys.nextElement(); Object key = keys.nextElement();
if (key instanceof String) { if (key instanceof String) {
@@ -344,7 +344,7 @@ public class JSONObject {
String[] path = ((String) key).split("\\."); String[] path = ((String) key).split("\\.");
int last = path.length - 1; int last = path.length - 1;
JSONObject target = this; JSONObject target = this;
for(int i = 0; i < last; i += 1) { for (int i = 0; i < last; i += 1) {
String segment = path[i]; String segment = path[i];
JSONObject nextTarget = target.optJSONObject(segment); JSONObject nextTarget = target.optJSONObject(segment);
if (nextTarget == null) { if (nextTarget == null) {
@@ -433,7 +433,7 @@ public class JSONObject {
String string = Double.toString(d); String string = Double.toString(d);
if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && if (string.indexOf('.') > 0 && string.indexOf('e') < 0 &&
string.indexOf('E') < 0) { string.indexOf('E') < 0) {
while(string.endsWith("0")) { while (string.endsWith("0")) {
string = string.substring(0, string.length() - 1); string = string.substring(0, string.length() - 1);
} }
if (string.endsWith(".")) { if (string.endsWith(".")) {
@@ -498,7 +498,7 @@ public class JSONObject {
return object instanceof Number return object instanceof Number
? ((Number) object).doubleValue() ? ((Number) object).doubleValue()
: Double.parseDouble((String) object); : Double.parseDouble((String) object);
} catch(Exception e) { } catch (Exception e) {
throw new JSONException("JSONObject[" + quote(key) + throw new JSONException("JSONObject[" + quote(key) +
"] is not a number."); "] is not a number.");
} }
@@ -518,7 +518,7 @@ public class JSONObject {
return object instanceof Number return object instanceof Number
? ((Number) object).intValue() ? ((Number) object).intValue()
: Integer.parseInt((String) object); : Integer.parseInt((String) object);
} catch(Exception e) { } catch (Exception e) {
throw new JSONException("JSONObject[" + quote(key) + throw new JSONException("JSONObject[" + quote(key) +
"] is not an int."); "] is not an int.");
} }
@@ -572,7 +572,7 @@ public class JSONObject {
return object instanceof Number return object instanceof Number
? ((Number) object).longValue() ? ((Number) object).longValue()
: Long.parseLong((String) object); : Long.parseLong((String) object);
} catch(Exception e) { } catch (Exception e) {
throw new JSONException("JSONObject[" + quote(key) + throw new JSONException("JSONObject[" + quote(key) +
"] is not a long."); "] is not a long.");
} }
@@ -591,7 +591,7 @@ public class JSONObject {
Iterator iterator = jo.keys(); Iterator iterator = jo.keys();
String[] names = new String[length]; String[] names = new String[length];
int i = 0; int i = 0;
while(iterator.hasNext()) { while (iterator.hasNext()) {
names[i] = (String) iterator.next(); names[i] = (String) iterator.next();
i += 1; i += 1;
} }
@@ -614,7 +614,7 @@ public class JSONObject {
return null; return null;
} }
String[] names = new String[length]; String[] names = new String[length];
for(int i = 0; i < length; i += 1) { for (int i = 0; i < length; i += 1) {
names[i] = fields[i].getName(); names[i] = fields[i].getName();
} }
return names; return names;
@@ -719,7 +719,7 @@ public class JSONObject {
public JSONArray names() { public JSONArray names() {
JSONArray ja = new JSONArray(); JSONArray ja = new JSONArray();
Iterator keys = this.keys(); Iterator keys = this.keys();
while(keys.hasNext()) { while (keys.hasNext()) {
ja.put(keys.next()); ja.put(keys.next());
} }
return ja.length() == 0 ? null : ja; return ja.length() == 0 ? null : ja;
@@ -743,7 +743,7 @@ public class JSONObject {
String string = number.toString(); String string = number.toString();
if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && if (string.indexOf('.') > 0 && string.indexOf('e') < 0 &&
string.indexOf('E') < 0) { string.indexOf('E') < 0) {
while(string.endsWith("0")) { while (string.endsWith("0")) {
string = string.substring(0, string.length() - 1); string = string.substring(0, string.length() - 1);
} }
if (string.endsWith(".")) { if (string.endsWith(".")) {
@@ -786,7 +786,7 @@ public class JSONObject {
public boolean optBoolean(String key, boolean defaultValue) { public boolean optBoolean(String key, boolean defaultValue) {
try { try {
return this.getBoolean(key); return this.getBoolean(key);
} catch(Exception e) { } catch (Exception e) {
return defaultValue; return defaultValue;
} }
} }
@@ -817,7 +817,7 @@ public class JSONObject {
public double optDouble(String key, double defaultValue) { public double optDouble(String key, double defaultValue) {
try { try {
return this.getDouble(key); return this.getDouble(key);
} catch(Exception e) { } catch (Exception e) {
return defaultValue; return defaultValue;
} }
} }
@@ -848,7 +848,7 @@ public class JSONObject {
public int optInt(String key, int defaultValue) { public int optInt(String key, int defaultValue) {
try { try {
return this.getInt(key); return this.getInt(key);
} catch(Exception e) { } catch (Exception e) {
return defaultValue; return defaultValue;
} }
} }
@@ -905,7 +905,7 @@ public class JSONObject {
public long optLong(String key, long defaultValue) { public long optLong(String key, long defaultValue) {
try { try {
return this.getLong(key); return this.getLong(key);
} catch(Exception e) { } catch (Exception e) {
return defaultValue; return defaultValue;
} }
} }
@@ -945,7 +945,7 @@ public class JSONObject {
Method[] methods = includeSuperClass Method[] methods = includeSuperClass
? klass.getMethods() ? klass.getMethods()
: klass.getDeclaredMethods(); : klass.getDeclaredMethods();
for(int i = 0; i < methods.length; i += 1) { for (int i = 0; i < methods.length; i += 1) {
try { try {
Method method = methods[i]; Method method = methods[i];
if (Modifier.isPublic(method.getModifiers())) { if (Modifier.isPublic(method.getModifiers())) {
@@ -977,7 +977,7 @@ public class JSONObject {
} }
} }
} }
} catch(Exception ignore) { } catch (Exception ignore) {
} }
} }
} }
@@ -1140,10 +1140,10 @@ public class JSONObject {
*/ */
public static String quote(String string) { public static String quote(String string) {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
synchronized(sw.getBuffer()) { synchronized (sw.getBuffer()) {
try { try {
return quote(string, sw).toString(); return quote(string, sw).toString();
} catch(IOException ignored) { } catch (IOException ignored) {
// will never happen - we are writing to a string writer // will never happen - we are writing to a string writer
return ""; return "";
} }
@@ -1163,7 +1163,7 @@ public class JSONObject {
int len = string.length(); int len = string.length();
w.write('"'); w.write('"');
for(i = 0; i < len; i += 1) { for (i = 0; i < len; i += 1) {
b = c; b = c;
c = string.charAt(i); c = string.charAt(i);
switch (c) { switch (c) {
@@ -1265,7 +1265,7 @@ public class JSONObject {
return myLong; return myLong;
} }
} }
} catch(Exception ignore) { } catch (Exception ignore) {
} }
} }
return string; return string;
@@ -1305,7 +1305,7 @@ public class JSONObject {
return null; return null;
} }
JSONArray ja = new JSONArray(); JSONArray ja = new JSONArray();
for(int i = 0; i < names.length(); i += 1) { for (int i = 0; i < names.length(); i += 1) {
ja.put(this.opt(names.getString(i))); ja.put(this.opt(names.getString(i)));
} }
return ja; return ja;
@@ -1326,7 +1326,7 @@ public class JSONObject {
public String toString() { public String toString() {
try { try {
return this.toString(0); return this.toString(0);
} catch(Exception e) { } catch (Exception e) {
return null; return null;
} }
} }
@@ -1345,7 +1345,7 @@ public class JSONObject {
*/ */
public String toString(int indentFactor) throws JSONException { public String toString(int indentFactor) throws JSONException {
StringWriter w = new StringWriter(); StringWriter w = new StringWriter();
synchronized(w.getBuffer()) { synchronized (w.getBuffer()) {
return this.write(w, indentFactor, 0).toString(); return this.write(w, indentFactor, 0).toString();
} }
} }
@@ -1379,7 +1379,7 @@ public class JSONObject {
Object object; Object object;
try { try {
object = ((JSONString) value).toJSONString(); object = ((JSONString) value).toJSONString();
} catch(Exception e) { } catch (Exception e) {
throw new JSONException(e); throw new JSONException(e);
} }
if (object instanceof String) { if (object instanceof String) {
@@ -1452,7 +1452,7 @@ public class JSONObject {
return object.toString(); return object.toString();
} }
return new JSONObject(object); return new JSONObject(object);
} catch(Exception exception) { } catch (Exception exception) {
return null; return null;
} }
} }
@@ -1493,7 +1493,7 @@ public class JSONObject {
Object o; Object o;
try { try {
o = ((JSONString) value).toJSONString(); o = ((JSONString) value).toJSONString();
} catch(Exception e) { } catch (Exception e) {
throw new JSONException(e); throw new JSONException(e);
} }
writer.write(o != null ? o.toString() : quote(value.toString())); writer.write(o != null ? o.toString() : quote(value.toString()));
@@ -1504,7 +1504,7 @@ public class JSONObject {
} }
static final void indent(Writer writer, int indent) throws IOException { static final void indent(Writer writer, int indent) throws IOException {
for(int i = 0; i < indent; i += 1) { for (int i = 0; i < indent; i += 1) {
writer.write(' '); writer.write(' ');
} }
} }
@@ -1536,7 +1536,7 @@ public class JSONObject {
writeValue(writer, this.map.get(key), indentFactor, indent); writeValue(writer, this.map.get(key), indentFactor, indent);
} else if (length != 0) { } else if (length != 0) {
final int newindent = indent + indentFactor; final int newindent = indent + indentFactor;
while(keys.hasNext()) { while (keys.hasNext()) {
Object key = keys.next(); Object key = keys.next();
if (commanate) { if (commanate) {
writer.write(','); writer.write(',');
@@ -1561,7 +1561,7 @@ public class JSONObject {
} }
writer.write('}'); writer.write('}');
return writer; return writer;
} catch(IOException exception) { } catch (IOException exception) {
throw new JSONException(exception); throw new JSONException(exception);
} }
} }
+9 -9
View File
@@ -146,7 +146,7 @@ public class JSONTokener {
} else { } else {
try { try {
c = this.reader.read(); c = this.reader.read();
} catch(IOException exception) { } catch (IOException exception) {
throw new JSONException(exception); throw new JSONException(exception);
} }
@@ -202,7 +202,7 @@ public class JSONTokener {
char[] chars = new char[n]; char[] chars = new char[n];
int pos = 0; int pos = 0;
while(pos < n) { while (pos < n) {
chars[pos] = this.next(); chars[pos] = this.next();
if (this.end()) { if (this.end()) {
throw this.syntaxError("Substring bounds error"); throw this.syntaxError("Substring bounds error");
@@ -218,7 +218,7 @@ public class JSONTokener {
* @return A character, or 0 if there are no more characters. * @return A character, or 0 if there are no more characters.
*/ */
public char nextClean() throws JSONException { public char nextClean() throws JSONException {
for(;;) { for (;;) {
char c = this.next(); char c = this.next();
if (c == 0 || c > ' ') { if (c == 0 || c > ' ') {
return c; return c;
@@ -240,7 +240,7 @@ public class JSONTokener {
public String nextString(char quote) throws JSONException { public String nextString(char quote) throws JSONException {
char c; char c;
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for(;;) { for (;;) {
c = this.next(); c = this.next();
switch (c) { switch (c) {
case 0: case 0:
@@ -295,7 +295,7 @@ public class JSONTokener {
*/ */
public String nextTo(char delimiter) throws JSONException { public String nextTo(char delimiter) throws JSONException {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for(;;) { for (;;) {
char c = this.next(); char c = this.next();
if (c == delimiter || c == 0 || c == '\n' || c == '\r') { if (c == delimiter || c == 0 || c == '\n' || c == '\r') {
if (c != 0) { if (c != 0) {
@@ -316,7 +316,7 @@ public class JSONTokener {
public String nextTo(String delimiters) throws JSONException { public String nextTo(String delimiters) throws JSONException {
char c; char c;
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for(;;) { for (;;) {
c = this.next(); c = this.next();
if (delimiters.indexOf(c) >= 0 || c == 0 || if (delimiters.indexOf(c) >= 0 || c == 0 ||
c == '\n' || c == '\r') { c == '\n' || c == '\r') {
@@ -362,7 +362,7 @@ public class JSONTokener {
*/ */
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
while(c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) { while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
sb.append(c); sb.append(c);
c = this.next(); c = this.next();
} }
@@ -398,8 +398,8 @@ public class JSONTokener {
this.line = startLine; this.line = startLine;
return c; return c;
} }
} while(c != to); } while (c != to);
} catch(IOException exc) { } catch (IOException exc) {
throw new JSONException(exc); throw new JSONException(exc);
} }