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,12 +1,12 @@
package com.drtshock.playervaults.util;
import com.drtshock.playervaults.PlayerVaults;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
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.
*/
@@ -18,10 +18,10 @@ public class DropOnDeath {
*/
public static void drop(Player player) {
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);
ItemStack[] stack = inv.getContents();
for(ItemStack is:stack) {
for (ItemStack is : stack) {
loc.getWorld().dropItemNaturally(loc, is);
}
}
@@ -1,5 +1,7 @@
package com.drtshock.playervaults.util;
import com.drtshock.playervaults.PlayerVaults;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -11,8 +13,6 @@ import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import com.drtshock.playervaults.PlayerVaults;
/**
* A class that handles all economy operations.
*/
@@ -28,12 +28,6 @@ package com.drtshock.playervaults.util;
* 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.File;
import java.io.IOException;
@@ -52,6 +46,12 @@ import java.util.Set;
import java.util.UUID;
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>
* 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")
public boolean start() {
synchronized(optOutLock) {
synchronized (optOutLock) {
// Did we opt out?
if (isOptOut()) {
return false;
@@ -238,14 +238,14 @@ public class Metrics {
public void run() {
try {
// 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
// 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();
}
}
@@ -260,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());
}
}
@@ -276,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,7 +298,7 @@ public class Metrics {
*/
public void enable() throws IOException {
// 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.
if (isOptOut()) {
configuration.set("opt-out", false);
@@ -319,7 +319,7 @@ public class Metrics {
*/
public void disable() throws IOException {
// 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.
if (!isOptOut()) {
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
// inside of the graph (e.g plotters)
synchronized(graphs) {
synchronized (graphs) {
final Iterator<Graph> iter = graphs.iterator();
while(iter.hasNext()) {
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
@@ -431,13 +431,13 @@ public class Metrics {
} else {
// Is this the 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();
while(iter.hasNext()) {
while (iter.hasNext()) {
final Graph graph = iter.next();
for(Plotter plotter:graph.getPlotters()) {
for (Plotter plotter : graph.getPlotters()) {
plotter.reset();
}
}
@@ -455,7 +455,7 @@ public class Metrics {
try {
Class.forName("mineshafter.MineServer");
return true;
} catch(Exception e) {
} catch (Exception e) {
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.
*/
protected void onOptOut() {
}
protected void onOptOut() {}
}
@@ -614,8 +613,7 @@ public class Metrics {
/**
* Called after the website graphs have been updated
*/
public void reset() {
}
public void reset() {}
@Override
public int hashCode() {
@@ -28,7 +28,7 @@ public class Serialization {
public static Map<String, Object> toMap(JSONObject object) throws JSONException {
Map<String, Object> map = new HashMap<String, Object>();
Iterator<String> keys = object.keys();
while(keys.hasNext()) {
while (keys.hasNext()) {
String key = (String) keys.next();
map.put(key, fromJson(object.get(key)));
}
@@ -49,7 +49,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;
@@ -58,10 +58,10 @@ public class Serialization {
public static List<String> toString(Inventory inv) {
List<String> result = new ArrayList<String>();
List<ConfigurationSerializable> items = new ArrayList<ConfigurationSerializable>();
for(ItemStack is:inv.getContents()) {
for (ItemStack is : inv.getContents()) {
items.add(is);
}
for(ConfigurationSerializable cs:items) {
for (ConfigurationSerializable cs : items) {
if (cs == null) {
result.add("null");
}
@@ -77,7 +77,7 @@ public class Serialization {
Inventory inv = Bukkit.createInventory(holder, (large) ? 54 : 27, ChatColor.RED + "Vault #" + number);
holder.setInventory(inv);
List<ItemStack> contents = new ArrayList<ItemStack>();
for(String piece:stringItems) {
for (String piece : stringItems) {
if (piece.equalsIgnoreCase("null")) {
contents.add(null);
}
@@ -85,13 +85,13 @@ public class Serialization {
try {
ItemStack item = (ItemStack) deserialize(toMap(new JSONObject(piece)));
contents.add(item);
} catch(JSONException e) {
} catch (JSONException e) {
e.printStackTrace();
}
}
}
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);
inv.setContents(items);
return inv;
@@ -99,7 +99,7 @@ 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()) {
for (Entry<String, Object> entry : serialized.entrySet()) {
if (entry.getValue() instanceof ConfigurationSerializable) {
entry.setValue(serialize((ConfigurationSerializable) entry.getValue()));
}
@@ -110,7 +110,7 @@ public class Serialization {
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;
@@ -118,7 +118,7 @@ public class Serialization {
@SuppressWarnings({"unchecked", "rawtypes"})
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)) {
entry.setValue(deserialize((Map) entry.getValue()));
}
@@ -24,7 +24,7 @@ public class Updater {
newVersion = feed.getElementsByTagName("title").item(1).getTextContent().substring(1);
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();
if(v.contains("SNAPSHOT") && !newVersion.equals(oldVersion)) {
if (v.contains("SNAPSHOT") && !newVersion.equals(oldVersion)) {
update = false;
return;
}
@@ -7,41 +7,41 @@ import org.bukkit.inventory.InventoryHolder;
* Represents a VaultHolder to assist in detection of Player Vaults from
* other plugins.
*/
public class VaultHolder implements InventoryHolder{
public class VaultHolder implements InventoryHolder {
private Inventory inventory;
private int vaultNumber = 0;
private Inventory inventory;
private int vaultNumber = 0;
/**
* Creates a new vault holder
*
* @param vaultNumber the vault number this holder is using
*/
public VaultHolder(int vaultNumber){
this.vaultNumber = vaultNumber;
}
/**
* Creates a new vault holder
*
* @param vaultNumber the vault number this holder is using
*/
public VaultHolder(int vaultNumber) {
this.vaultNumber = vaultNumber;
}
/**
* Gets the vault number this holder is currently using
*
* @return the vault number
*/
public int getVaultNumber(){
return vaultNumber;
}
/**
* Gets the vault number this holder is currently using
*
* @return the vault number
*/
public int getVaultNumber() {
return vaultNumber;
}
/**
* Sets the inventory this vault holder holds
*
* @param inventory the inventory, may be null
*/
public void setInventory(Inventory inventory){
this.inventory = inventory;
}
/**
* Sets the inventory this vault holder holds
*
* @param inventory the inventory, may be null
*/
public void setInventory(Inventory inventory) {
this.inventory = inventory;
}
@Override
public Inventory getInventory(){
return inventory;
}
@Override
public Inventory getInventory() {
return inventory;
}
}
@@ -1,5 +1,8 @@
package com.drtshock.playervaults.util;
import com.drtshock.playervaults.PlayerVaults;
import com.drtshock.playervaults.commands.VaultViewInfo;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -12,9 +15,6 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
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.
*/
@@ -41,13 +41,13 @@ public class VaultManager {
if (size == 54) {
yaml.set("vault" + number, null);
} else {
for(int x = 0; x < 27; x++) {
for (int x = 0; x < 27; x++) {
yaml.set("vault" + number + "." + x, null);
}
}
List<String> list = Serialization.toString(inventory);
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")) {
yaml.set("vault" + number + "." + x, ser[x]);
}
@@ -73,7 +73,7 @@ public class VaultManager {
vaultHolder.setInventory(inv);
} else {
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);
if (line != null) {
data.add(line);
@@ -144,7 +144,7 @@ public class VaultManager {
if (!file.exists()) {
try {
file.createNewFile();
} catch(IOException e) {
} catch (IOException e) {
// Who cares?
}
}