General cleanup of everything I can see right now
This commit is contained in:
@@ -38,10 +38,10 @@ public class Serialization {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, Object> toMap(JSONObject object) throws JSONException {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
Iterator<String> keys = object.keys();
|
||||
while (keys.hasNext()) {
|
||||
String key = (String) keys.next();
|
||||
String key = keys.next();
|
||||
map.put(key, fromJson(object.get(key)));
|
||||
}
|
||||
return map;
|
||||
@@ -60,7 +60,7 @@ public class Serialization {
|
||||
}
|
||||
|
||||
public static List<Object> toList(JSONArray array) throws JSONException {
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
List<Object> list = new ArrayList<>();
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
list.add(fromJson(array.get(i)));
|
||||
}
|
||||
@@ -68,11 +68,9 @@ 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()) {
|
||||
items.add(is);
|
||||
}
|
||||
List<String> result = new ArrayList<>();
|
||||
List<ConfigurationSerializable> items = new ArrayList<>();
|
||||
Collections.addAll(items, inv.getContents());
|
||||
for (ConfigurationSerializable cs : items) {
|
||||
if (cs == null) {
|
||||
result.add("null");
|
||||
@@ -87,7 +85,7 @@ public class Serialization {
|
||||
VaultHolder holder = new VaultHolder(number);
|
||||
Inventory inv = Bukkit.createInventory(holder, size, ChatColor.RED + "Vault #" + number);
|
||||
holder.setInventory(inv);
|
||||
List<ItemStack> contents = new ArrayList<ItemStack>();
|
||||
List<ItemStack> contents = new ArrayList<>();
|
||||
for (String piece : stringItems) {
|
||||
if (piece.equalsIgnoreCase("null")) {
|
||||
contents.add(null);
|
||||
@@ -137,7 +135,7 @@ public class Serialization {
|
||||
return serialized;
|
||||
}
|
||||
public static Map<String, Object> recreateMap(Map<String, Object> original) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.putAll(original);
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class UUIDVaultManager {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
private final String directory = "plugins" + File.separator + "PlayerVaults" + File.separator + "uuidvaults";
|
||||
private final File directory = PlayerVaults.getInstance().getVaultData();
|
||||
|
||||
/**
|
||||
* Saves the inventory to the specified player and vault number.
|
||||
@@ -108,7 +108,7 @@ public class UUIDVaultManager {
|
||||
size = 54;
|
||||
}
|
||||
VaultViewInfo info = new VaultViewInfo(holder.toString(), number);
|
||||
Inventory inv = null;
|
||||
Inventory inv;
|
||||
if (PlayerVaults.getInstance().getOpenInventories().containsKey(info.toString())) {
|
||||
inv = PlayerVaults.getInstance().getOpenInventories().get(info.toString());
|
||||
} else {
|
||||
@@ -168,8 +168,7 @@ public class UUIDVaultManager {
|
||||
vaultHolder.setInventory(inv);
|
||||
return inv;
|
||||
} else {
|
||||
Inventory inv = Serialization.toInventory(data, number, VaultOperations.getMaxVaultSize(player));
|
||||
return inv;
|
||||
return Serialization.toInventory(data, number, VaultOperations.getMaxVaultSize(player));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +187,7 @@ public class UUIDVaultManager {
|
||||
*/
|
||||
public void deleteVault(CommandSender sender, UUID holder, int number) throws IOException {
|
||||
String name = holder.toString();
|
||||
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
|
||||
File file = new File(directory, name.toLowerCase() + ".yml");
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
@@ -217,11 +216,10 @@ public class UUIDVaultManager {
|
||||
* @return The holder's vault config file.
|
||||
*/
|
||||
public YamlConfiguration getPlayerVaultFile(UUID holder) {
|
||||
File folder = new File(directory);
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
if (!directory.exists()) {
|
||||
directory.mkdir();
|
||||
}
|
||||
File file = new File(directory + File.separator + holder.toString() + ".yml");
|
||||
File file = new File(directory, holder.toString() + ".yml");
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
@@ -229,8 +227,7 @@ public class UUIDVaultManager {
|
||||
// Who cares?
|
||||
}
|
||||
}
|
||||
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||
return playerFile;
|
||||
return YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,9 +239,9 @@ public class UUIDVaultManager {
|
||||
* @throws IOException Uh oh!
|
||||
*/
|
||||
public void saveFile(UUID holder, YamlConfiguration yaml) throws IOException {
|
||||
File file = new File(directory + File.separator + holder.toString() + ".yml");
|
||||
File file = new File(directory, holder.toString() + ".yml");
|
||||
if (file.exists()) {
|
||||
file.renameTo(new File(directory + File.separator + "backups" + File.separator + holder.toString() + ".yml"));
|
||||
file.renameTo(new File(directory, "backups" + File.separator + holder.toString() + ".yml"));
|
||||
}
|
||||
yaml.save(file);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class VaultManager {
|
||||
size = 54;
|
||||
}
|
||||
VaultViewInfo info = new VaultViewInfo(holder, number);
|
||||
Inventory inv = null;
|
||||
Inventory inv;
|
||||
if (PlayerVaults.getInstance().getOpenInventories().containsKey(info.toString())) {
|
||||
inv = PlayerVaults.getInstance().getOpenInventories().get(info.toString());
|
||||
} else {
|
||||
@@ -127,7 +127,7 @@ public class VaultManager {
|
||||
size = 54;
|
||||
}
|
||||
VaultViewInfo info = new VaultViewInfo(holder, number);
|
||||
Inventory inv = null;
|
||||
Inventory inv;
|
||||
if (PlayerVaults.getInstance().getOpenInventories().containsKey(info.toString())) {
|
||||
inv = PlayerVaults.getInstance().getOpenInventories().get(info.toString());
|
||||
} else {
|
||||
@@ -157,7 +157,7 @@ public class VaultManager {
|
||||
*/
|
||||
@Deprecated
|
||||
private Inventory getInventory(YamlConfiguration playerFile, int size, int number) {
|
||||
List<String> data = new ArrayList<String>();
|
||||
List<String> data = new ArrayList<>();
|
||||
for (int x = 0; x < size; x++) {
|
||||
String line = playerFile.getString("vault" + number + "." + x);
|
||||
if (line != null) {
|
||||
@@ -187,8 +187,7 @@ public class VaultManager {
|
||||
vaultHolder.setInventory(inv);
|
||||
return inv;
|
||||
} else {
|
||||
Inventory inv = Serialization.toInventory(data, number, VaultOperations.getMaxVaultSize(Bukkit.getPlayerExact(holder)));
|
||||
return inv;
|
||||
return Serialization.toInventory(data, number, VaultOperations.getMaxVaultSize(Bukkit.getPlayerExact(holder)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,8 +246,7 @@ public class VaultManager {
|
||||
// Who cares?
|
||||
}
|
||||
}
|
||||
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||
return playerFile;
|
||||
return YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -148,7 +148,7 @@ public class VaultOperations {
|
||||
number = Integer.parseInt(arg);
|
||||
if (number == 0) {
|
||||
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
||||
return;
|
||||
return;
|
||||
}
|
||||
} catch (NumberFormatException nfe) {
|
||||
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
||||
|
||||
Reference in New Issue
Block a user