Reformat.

This commit is contained in:
drtshock
2015-04-27 12:03:11 -05:00
parent d690786803
commit f97ba1e694
12 changed files with 73 additions and 55 deletions
@@ -24,11 +24,15 @@ public class BackpackConverter implements Converter {
@Override @Override
public int run(CommandSender initiator, ServiceProvider uuidProvider) { public int run(CommandSender initiator, ServiceProvider uuidProvider) {
if (uuidProvider == null) throw new IllegalArgumentException(); if (uuidProvider == null) {
throw new IllegalArgumentException();
}
PlayerVaults plugin = PlayerVaults.getInstance(); PlayerVaults plugin = PlayerVaults.getInstance();
File destination = new File(plugin.getDataFolder().getParentFile(), "Backpack" + File.separator + "backpacks"); File destination = new File(plugin.getDataFolder().getParentFile(), "Backpack" + File.separator + "backpacks");
if (!destination.exists()) return -1; if (!destination.exists()) {
return -1;
}
int converted = 0; int converted = 0;
@@ -60,15 +64,20 @@ public class BackpackConverter implements Converter {
UUID uuid = player.getUuid(); UUID uuid = player.getUuid();
FileConfiguration yaml = YamlConfiguration.loadConfiguration(file); FileConfiguration yaml = YamlConfiguration.loadConfiguration(file);
ConfigurationSection section = yaml.getConfigurationSection("backpack"); ConfigurationSection section = yaml.getConfigurationSection("backpack");
if (section.getKeys(false).size() <= 0) continue; // No slots if (section.getKeys(false).size() <= 0) {
continue; // No slots
}
Inventory vault = vaults.getVault(uuid, intoVaultNum); Inventory vault = vaults.getVault(uuid, intoVaultNum);
if (vault == null) if (vault == null) {
vault = plugin.getServer().createInventory(null, section.getKeys(false).size()); vault = plugin.getServer().createInventory(null, section.getKeys(false).size());
}
for (String key : section.getKeys(false)) { for (String key : section.getKeys(false)) {
ConfigurationSection slotSection = section.getConfigurationSection(key); ConfigurationSection slotSection = section.getConfigurationSection(key);
ItemStack item = slotSection.getItemStack("ItemStack"); ItemStack item = slotSection.getItemStack("ItemStack");
if (item == null) continue; if (item == null) {
continue;
}
// Overwrite // Overwrite
vault.setItem(Integer.parseInt(key.split(" ")[1]), item); vault.setItem(Integer.parseInt(key.split(" ")[1]), item);
@@ -99,7 +108,9 @@ public class BackpackConverter implements Converter {
public boolean canConvert() { public boolean canConvert() {
PlayerVaults plugin = PlayerVaults.getInstance(); PlayerVaults plugin = PlayerVaults.getInstance();
File expectedFolder = new File(plugin.getDataFolder().getParentFile(), "Backpack"); File expectedFolder = new File(plugin.getDataFolder().getParentFile(), "Backpack");
if (!expectedFolder.exists()) return false; if (!expectedFolder.exists()) {
return false;
}
File backpackDir = new File(expectedFolder, "backpacks"); File backpackDir = new File(expectedFolder, "backpacks");
return backpackDir.exists(); return backpackDir.exists();
} }
@@ -4,8 +4,7 @@ import com.turt2live.uuid.ServiceProvider;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
/** /**
* Represents a simple converter for converting another plugin's content * Represents a simple converter for converting another plugin's content to PlayerVaults.
* to PlayerVaults.
* *
* @author turt2live * @author turt2live
*/ */
@@ -17,14 +16,13 @@ public interface Converter {
* @param initiator the initiator of the conversion. May be null * @param initiator the initiator of the conversion. May be null
* @param uuidProvider the UUID provider to use, cannot be null * @param uuidProvider the UUID provider to use, cannot be null
* *
* @return the number of vaults converted. Returns 0 on none converted * @return the number of vaults converted. Returns 0 on none converted or -1 if no vaults were converted.
* or -1 if no vaults were converted.
*/ */
public int run(CommandSender initiator, ServiceProvider uuidProvider); public int run(CommandSender initiator, ServiceProvider uuidProvider);
/** /**
* Determines if this converter is applicable for converting to PlayerVaults. * Determines if this converter is applicable for converting to PlayerVaults. This may check for the existance of a
* This may check for the existance of a plugin, plugin folder, or otherwise. * plugin, plugin folder, or otherwise.
* *
* @return true if this converter can convert, false otherwise * @return true if this converter can convert, false otherwise
*/ */
@@ -105,14 +105,7 @@ public class Listeners implements Listener {
if (PlayerVaults.getInstance().getInVault().containsKey(player.getName())) { if (PlayerVaults.getInstance().getInVault().containsKey(player.getName())) {
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
// Different inventories that we don't want the player to open. // Different inventories that we don't want the player to open.
if (block.getType() == Material.CHEST if (block.getType() == Material.CHEST || block.getType() == Material.TRAPPED_CHEST || block.getType() == Material.ENDER_CHEST || block.getType() == Material.FURNACE || block.getType() == Material.BURNING_FURNACE || block.getType() == Material.BREWING_STAND || block.getType() == Material.ENCHANTMENT_TABLE || block.getType() == Material.BEACON) {
|| block.getType() == Material.TRAPPED_CHEST
|| block.getType() == Material.ENDER_CHEST
|| block.getType() == Material.FURNACE
|| block.getType() == Material.BURNING_FURNACE
|| block.getType() == Material.BREWING_STAND
|| block.getType() == Material.ENCHANTMENT_TABLE
|| block.getType() == Material.BEACON) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@@ -33,7 +33,9 @@ public final class UUIDConversion extends BukkitRunnable {
logger.info(oldVaults.toString() + " will remain as a backup."); logger.info(oldVaults.toString() + " will remain as a backup.");
for (File file : oldVaults.listFiles()) { for (File file : oldVaults.listFiles()) {
if (file.isDirectory()) continue; // backups folder. if (file.isDirectory()) {
continue; // backups folder.
}
OfflinePlayer player = Bukkit.getOfflinePlayer(file.getName().replace(".yml", "")); OfflinePlayer player = Bukkit.getOfflinePlayer(file.getName().replace(".yml", ""));
if (player == null) { if (player == null) {
logger.warning("Unable to convert file because player never joined the server: " + file.getName()); logger.warning("Unable to convert file because player never joined the server: " + file.getName());
@@ -77,8 +77,9 @@ public enum Lang {
@Override @Override
public String toString() { public String toString() {
if (this == TITLE) if (this == TITLE) {
return ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, def)) + " "; return ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, def)) + " ";
}
return ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, def)); return ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, def));
} }
@@ -263,7 +263,9 @@ public class Updater {
byte[] data = new byte[BYTE_SIZE]; byte[] data = new byte[BYTE_SIZE];
int count; int count;
if (announce) plugin.getLogger().log(Level.INFO, "About to download a new update: {0}", versionName); if (announce) {
plugin.getLogger().log(Level.INFO, "About to download a new update: {0}", versionName);
}
long downloaded = 0; long downloaded = 0;
while ((count = in.read(data, 0, BYTE_SIZE)) != -1) { while ((count = in.read(data, 0, BYTE_SIZE)) != -1) {
downloaded += count; downloaded += count;
@@ -285,7 +287,9 @@ public class Updater {
// Unzip // Unzip
unzip(dFile.getCanonicalPath()); unzip(dFile.getCanonicalPath());
} }
if (announce) plugin.getLogger().info("Finished updating."); if (announce) {
plugin.getLogger().info("Finished updating.");
}
} catch (Exception ex) { } catch (Exception ex) {
plugin.getLogger().warning("The auto-updater tried to download a new update, but was unsuccessful."); plugin.getLogger().warning("The auto-updater tried to download a new update, but was unsuccessful.");
result = Updater.UpdateResult.FAIL_DOWNLOAD; result = Updater.UpdateResult.FAIL_DOWNLOAD;
@@ -162,7 +162,9 @@ public class UUIDVaultManager {
YamlConfiguration playerFile = getPlayerVaultFile(holder); YamlConfiguration playerFile = getPlayerVaultFile(holder);
List<String> data = playerFile.getStringList("vault" + number); List<String> data = playerFile.getStringList("vault" + number);
OfflinePlayer player = Bukkit.getPlayer(holder); OfflinePlayer player = Bukkit.getPlayer(holder);
if (player == null) return null; if (player == null) {
return null;
}
if (data == null) { if (data == null) {
VaultHolder vaultHolder = new VaultHolder(number); VaultHolder vaultHolder = new VaultHolder(number);
Inventory inv = Bukkit.createInventory(vaultHolder, VaultOperations.getMaxVaultSize(player), Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(number)).replace("%p", player.getName())); Inventory inv = Bukkit.createInventory(vaultHolder, VaultOperations.getMaxVaultSize(player), Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(number)).replace("%p", player.getName()));
@@ -33,8 +33,7 @@ import java.util.List;
/** /**
* 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.
*/ */
@Deprecated @Deprecated public class VaultManager {
public class VaultManager {
public PlayerVaults plugin; public PlayerVaults plugin;
@@ -42,8 +42,8 @@ public class VaultOperations {
} }
/** /**
* Sets whether or not player vaults are locked. If set to true, this * Sets whether or not player vaults are locked. If set to true, this will kick anyone who is currently using their
* will kick anyone who is currently using their vaults out. * vaults out.
* *
* @param locked true for locked, false otherwise * @param locked true for locked, false otherwise
*/ */
@@ -111,7 +111,9 @@ public class VaultOperations {
* @return Whether or not the player was allowed to open it. * @return Whether or not the player was allowed to open it.
*/ */
public static boolean openOwnVault(Player player, String arg) { public static boolean openOwnVault(Player player, String arg) {
if (isLocked()) return false; if (isLocked()) {
return false;
}
int number; int number;
try { try {
number = Integer.parseInt(arg); number = Integer.parseInt(arg);
@@ -149,7 +151,9 @@ public class VaultOperations {
* @return Whether or not the player was allowed to open it. * @return Whether or not the player was allowed to open it.
*/ */
public static boolean openOtherVault(Player player, Player holder, String arg) { public static boolean openOtherVault(Player player, Player holder, String arg) {
if (isLocked()) return false; if (isLocked()) {
return false;
}
if (player.hasPermission("playervaults.admin")) { if (player.hasPermission("playervaults.admin")) {
int number = 0; int number = 0;
try { try {
@@ -181,7 +185,9 @@ public class VaultOperations {
* @param arg The vault number to delete. * @param arg The vault number to delete.
*/ */
public static void deleteOwnVault(Player player, String arg) { public static void deleteOwnVault(Player player, String arg) {
if (isLocked()) return; if (isLocked()) {
return;
}
if (arg.matches("^[0-9]{1,2}$")) { if (arg.matches("^[0-9]{1,2}$")) {
int number = 0; int number = 0;
try { try {
@@ -214,7 +220,9 @@ public class VaultOperations {
* @param arg The vault number to delete. * @param arg The vault number to delete.
*/ */
public static void deleteOtherVault(CommandSender sender, Player holder, String arg) { public static void deleteOtherVault(CommandSender sender, Player holder, String arg) {
if (isLocked()) return; if (isLocked()) {
return;
}
if (sender.hasPermission("playervaults.delete")) { if (sender.hasPermission("playervaults.delete")) {
if (arg.matches("^[0-9]{1,2}$")) { if (arg.matches("^[0-9]{1,2}$")) {
int number = 0; int number = 0;