Reformat.
This commit is contained in:
@@ -237,9 +237,9 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Set an object in the config.yml
|
* Set an object in the config.yml
|
||||||
*
|
*
|
||||||
* @param path The path in the config.
|
* @param path The path in the config.
|
||||||
* @param object What to be saved.
|
* @param object What to be saved.
|
||||||
* @param conf Where to save the object.
|
* @param conf Where to save the object.
|
||||||
*/
|
*/
|
||||||
public <T> void setInConfig(String path, T object, YamlConfiguration conf) {
|
public <T> void setInConfig(String path, T object, YamlConfiguration conf) {
|
||||||
conf.set(path, object);
|
conf.set(path, object);
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import org.bukkit.entity.Player;
|
|||||||
public class DeleteCommand implements CommandExecutor {
|
public class DeleteCommand implements CommandExecutor {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if(VaultOperations.isLocked()){
|
if (VaultOperations.isLocked()) {
|
||||||
sender.sendMessage(Lang.TITLE+Lang.LOCKED.toString());
|
sender.sendMessage(Lang.TITLE + Lang.LOCKED.toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ import org.bukkit.entity.Player;
|
|||||||
public class VaultCommand implements CommandExecutor {
|
public class VaultCommand implements CommandExecutor {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if(VaultOperations.isLocked()){
|
if (VaultOperations.isLocked()) {
|
||||||
sender.sendMessage(Lang.TITLE+Lang.LOCKED.toString());
|
sender.sendMessage(Lang.TITLE + Lang.LOCKED.toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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());
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public enum Lang {
|
|||||||
/**
|
/**
|
||||||
* Lang enum constructor.
|
* Lang enum constructor.
|
||||||
*
|
*
|
||||||
* @param path The string path.
|
* @param path The string path.
|
||||||
* @param start The default string.
|
* @param start The default string.
|
||||||
*/
|
*/
|
||||||
Lang(String path, String start) {
|
Lang(String path, String start) {
|
||||||
@@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -131,11 +131,11 @@ public class Updater {
|
|||||||
/**
|
/**
|
||||||
* Initialize the updater
|
* Initialize the updater
|
||||||
*
|
*
|
||||||
* @param plugin The plugin that is checking for an update.
|
* @param plugin The plugin that is checking for an update.
|
||||||
* @param id The dev.bukkit.org id of the project
|
* @param id The dev.bukkit.org id of the project
|
||||||
* @param file The file that the plugin is running from, get this by doing this.getFile() from within your main
|
* @param file The file that the plugin is running from, get this by doing this.getFile() from within your main
|
||||||
* class.
|
* class.
|
||||||
* @param type Specify the type of update this will be. See {@link UpdateType}
|
* @param type Specify the type of update this will be. See {@link UpdateType}
|
||||||
* @param announce True if the program should announce the progress of new updates in console
|
* @param announce True if the program should announce the progress of new updates in console
|
||||||
*/
|
*/
|
||||||
public Updater(Plugin plugin, int id, File file, Updater.UpdateType type, boolean announce) {
|
public Updater(Plugin plugin, int id, File file, Updater.UpdateType type, boolean announce) {
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ public class UUIDVaultManager {
|
|||||||
* Saves the inventory to the specified player and vault number.
|
* Saves the inventory to the specified player and vault number.
|
||||||
*
|
*
|
||||||
* @param inventory The inventory to be saved.
|
* @param inventory The inventory to be saved.
|
||||||
* @param player The player of whose file to save to.
|
* @param player The player of whose file to save to.
|
||||||
* @param number The vault number.
|
* @param number The vault number.
|
||||||
*
|
*
|
||||||
* @throws java.io.IOException Uh oh!
|
* @throws java.io.IOException Uh oh!
|
||||||
*/
|
*/
|
||||||
@@ -132,8 +132,8 @@ public class UUIDVaultManager {
|
|||||||
* Get an inventory from file. Returns null if the inventory doesn't exist. SHOULD ONLY BE USED INTERNALLY
|
* Get an inventory from file. Returns null if the inventory doesn't exist. SHOULD ONLY BE USED INTERNALLY
|
||||||
*
|
*
|
||||||
* @param playerFile the YamlConfiguration file.
|
* @param playerFile the YamlConfiguration file.
|
||||||
* @param size the size of the vault.
|
* @param size the size of the vault.
|
||||||
* @param number the vault number.
|
* @param number the vault number.
|
||||||
*
|
*
|
||||||
* @return inventory if exists, otherwise null.
|
* @return inventory if exists, otherwise null.
|
||||||
*/
|
*/
|
||||||
@@ -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()));
|
||||||
@@ -234,7 +236,7 @@ public class UUIDVaultManager {
|
|||||||
* Save the players vault file.
|
* Save the players vault file.
|
||||||
*
|
*
|
||||||
* @param holder The vault holder of whose file to save.
|
* @param holder The vault holder of whose file to save.
|
||||||
* @param yaml The config to save.
|
* @param yaml The config to save.
|
||||||
*
|
*
|
||||||
* @throws IOException Uh oh!
|
* @throws IOException Uh oh!
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
@@ -48,8 +47,8 @@ public class VaultManager {
|
|||||||
* Saves the inventory to the specified player and vault number.
|
* Saves the inventory to the specified player and vault number.
|
||||||
*
|
*
|
||||||
* @param inventory The inventory to be saved.
|
* @param inventory The inventory to be saved.
|
||||||
* @param player The player of whose file to save to.
|
* @param player The player of whose file to save to.
|
||||||
* @param number The vault number.
|
* @param number The vault number.
|
||||||
*
|
*
|
||||||
* @throws IOException Uh oh!
|
* @throws IOException Uh oh!
|
||||||
*/
|
*/
|
||||||
@@ -151,8 +150,8 @@ public class VaultManager {
|
|||||||
* Get an inventory from file. Returns null if the inventory doesn't exist. SHOULD ONLY BE USED INTERNALLY
|
* Get an inventory from file. Returns null if the inventory doesn't exist. SHOULD ONLY BE USED INTERNALLY
|
||||||
*
|
*
|
||||||
* @param playerFile the YamlConfiguration file.
|
* @param playerFile the YamlConfiguration file.
|
||||||
* @param size the size of the vault.
|
* @param size the size of the vault.
|
||||||
* @param number the vault number.
|
* @param number the vault number.
|
||||||
*
|
*
|
||||||
* @return inventory if exists, otherwise null.
|
* @return inventory if exists, otherwise null.
|
||||||
*/
|
*/
|
||||||
@@ -254,7 +253,7 @@ public class VaultManager {
|
|||||||
* Save the players vault file.
|
* Save the players vault file.
|
||||||
*
|
*
|
||||||
* @param holder The vault holder of whose file to save.
|
* @param holder The vault holder of whose file to save.
|
||||||
* @param yaml The config to save.
|
* @param yaml The config to save.
|
||||||
*
|
*
|
||||||
* @throws IOException Uh oh!
|
* @throws IOException Uh oh!
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user