mirror of
https://github.com/TotalFreedomMC/BukkitTelnet.git
synced 2024-05-18 10:31:20 +00:00
Batch format
This commit is contained in:
parent
a8a429817c
commit
b90f0fbd9f
|
@ -17,8 +17,8 @@ import org.bukkit.plugin.Plugin;
|
|||
/**
|
||||
* Represents all File-related utilities.
|
||||
*/
|
||||
public class FileUtils {
|
||||
|
||||
public class FileUtils
|
||||
{
|
||||
/**
|
||||
* Downloads a file from the specified URIL and saves it at the specified location.
|
||||
*
|
||||
|
@ -27,7 +27,8 @@ public class FileUtils {
|
|||
* @throws MalformedURLException
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void downloadFile(String url, File output) throws MalformedURLException, IOException {
|
||||
public static void downloadFile(String url, File output) throws MalformedURLException, IOException
|
||||
{
|
||||
final URL website = new URL(url);
|
||||
final ReadableByteChannel rbc = Channels.newChannel(website.openStream());
|
||||
final FileOutputStream fos = new FileOutputStream(output);
|
||||
|
@ -42,8 +43,10 @@ public class FileUtils {
|
|||
* @param file The file where the object will be stored.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void saveObject(Object object, File file) throws IOException {
|
||||
if (!file.exists()) {
|
||||
public static void saveObject(Object object, File file) throws IOException
|
||||
{
|
||||
if (!file.exists())
|
||||
{
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
|
@ -58,8 +61,10 @@ public class FileUtils {
|
|||
* @param file The file where the object is stored.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static Object loadObject(File file) throws IOException, ClassNotFoundException {
|
||||
if (!file.exists()) {
|
||||
public static Object loadObject(File file) throws IOException, ClassNotFoundException
|
||||
{
|
||||
if (!file.exists())
|
||||
{
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
|
@ -77,7 +82,8 @@ public class FileUtils {
|
|||
* @param name The name of the file.
|
||||
* @return The requested file.
|
||||
*/
|
||||
public static File getPluginFile(Plugin plugin, String name) {
|
||||
public static File getPluginFile(Plugin plugin, String name)
|
||||
{
|
||||
return new File(plugin.getDataFolder(), name);
|
||||
}
|
||||
|
||||
|
@ -86,7 +92,8 @@ public class FileUtils {
|
|||
*
|
||||
* @return The current working directory.
|
||||
*/
|
||||
public static File getRoot() {
|
||||
public static File getRoot()
|
||||
{
|
||||
return new File(".");
|
||||
}
|
||||
|
||||
|
@ -95,7 +102,8 @@ public class FileUtils {
|
|||
*
|
||||
* @return The plugins folder.
|
||||
*/
|
||||
public static File getPluginsFolder() {
|
||||
public static File getPluginsFolder()
|
||||
{
|
||||
return new File(getRoot(), "plugins");
|
||||
}
|
||||
|
||||
|
@ -105,7 +113,8 @@ public class FileUtils {
|
|||
* @param name The name of the file.
|
||||
* @return The requested file.
|
||||
*/
|
||||
public static File getRootFile(String name) {
|
||||
public static File getRootFile(String name)
|
||||
{
|
||||
return new File(getRoot(), name);
|
||||
}
|
||||
|
||||
|
@ -118,8 +127,10 @@ public class FileUtils {
|
|||
* @return true if the delete was successful.
|
||||
* @deprecated Not in use; Relies on CraftBukkit source
|
||||
*/
|
||||
public static boolean deleteFolder(File file) {
|
||||
if (file.exists() && file.isDirectory()) {
|
||||
public static boolean deleteFolder(File file)
|
||||
{
|
||||
if (file.exists() && file.isDirectory())
|
||||
{
|
||||
//return net.minecraft.util.org.apache.commons.io.FileUtils.deleteQuietly(file);
|
||||
}
|
||||
return false;
|
||||
|
@ -132,15 +143,18 @@ public class FileUtils {
|
|||
* @param file The File to write to.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void copy(InputStream in, File file) throws IOException {
|
||||
if (!file.exists()) {
|
||||
public static void copy(InputStream in, File file) throws IOException
|
||||
{
|
||||
if (!file.exists())
|
||||
{
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
OutputStream out = new FileOutputStream(file);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
while ((len = in.read(buf)) > 0)
|
||||
{
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
out.close();
|
||||
|
|
|
@ -11,8 +11,8 @@ import org.bukkit.plugin.Plugin;
|
|||
*
|
||||
* @see YamlConfiguration
|
||||
*/
|
||||
public class YamlConfig extends YamlConfiguration {
|
||||
|
||||
public class YamlConfig extends YamlConfiguration
|
||||
{
|
||||
private final Plugin PLUGIN;
|
||||
private final File CONFIG_FILE;
|
||||
private final boolean COPY_DEFAULTS;
|
||||
|
@ -30,7 +30,8 @@ public class YamlConfig extends YamlConfiguration {
|
|||
* @param fileName The filename of the config file.
|
||||
* @param copyDefaults If the defaults should be copied and/loaded from a config in the plugin jar-file.
|
||||
*/
|
||||
public YamlConfig(Plugin plugin, String fileName, boolean copyDefaults) {
|
||||
public YamlConfig(Plugin plugin, String fileName, boolean copyDefaults)
|
||||
{
|
||||
this(plugin, FileUtils.getPluginFile(plugin, fileName), copyDefaults);
|
||||
}
|
||||
|
||||
|
@ -47,7 +48,8 @@ public class YamlConfig extends YamlConfiguration {
|
|||
* @param file The file of the config file.
|
||||
* @param copyDefaults If the defaults should be copied and/loaded from a config in the plugin jar-file.
|
||||
*/
|
||||
public YamlConfig(Plugin plugin, File file, boolean copyDefaults) {
|
||||
public YamlConfig(Plugin plugin, File file, boolean copyDefaults)
|
||||
{
|
||||
this.PLUGIN = plugin;
|
||||
this.CONFIG_FILE = file;
|
||||
this.COPY_DEFAULTS = copyDefaults;
|
||||
|
@ -58,10 +60,14 @@ public class YamlConfig extends YamlConfiguration {
|
|||
*
|
||||
* @see #YamlConfig(Plugin, String, boolean)
|
||||
*/
|
||||
public void save() {
|
||||
try {
|
||||
public void save()
|
||||
{
|
||||
try
|
||||
{
|
||||
super.save(CONFIG_FILE);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
PLUGIN.getLogger().severe("Could not save configuration file: " + CONFIG_FILE.getName());
|
||||
PLUGIN.getLogger().severe(ExceptionUtils.getStackTrace(ex));
|
||||
}
|
||||
|
@ -74,14 +80,21 @@ public class YamlConfig extends YamlConfiguration {
|
|||
*
|
||||
* @see #YamlConfig(Plugin, String, boolean)
|
||||
*/
|
||||
public void load() {
|
||||
try {
|
||||
if (COPY_DEFAULTS) {
|
||||
if (!CONFIG_FILE.exists()) {
|
||||
public void load()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (COPY_DEFAULTS)
|
||||
{
|
||||
if (!CONFIG_FILE.exists())
|
||||
{
|
||||
CONFIG_FILE.getParentFile().mkdirs();
|
||||
try {
|
||||
try
|
||||
{
|
||||
FileUtils.copy(PLUGIN.getResource(CONFIG_FILE.getName()), CONFIG_FILE);
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
PLUGIN.getLogger().severe("Could not write default configuration file: " + CONFIG_FILE.getName());
|
||||
PLUGIN.getLogger().severe(ExceptionUtils.getStackTrace(ex));
|
||||
}
|
||||
|
@ -92,7 +105,9 @@ public class YamlConfig extends YamlConfiguration {
|
|||
}
|
||||
|
||||
super.load(CONFIG_FILE);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
PLUGIN.getLogger().severe("Could not load configuration file: " + CONFIG_FILE.getName());
|
||||
PLUGIN.getLogger().severe(ExceptionUtils.getStackTrace(ex));
|
||||
}
|
||||
|
@ -104,7 +119,8 @@ public class YamlConfig extends YamlConfiguration {
|
|||
* @return The YamlConfiguration.
|
||||
* @see YamlConfiguration
|
||||
*/
|
||||
public YamlConfiguration getConfig() {
|
||||
public YamlConfiguration getConfig()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -112,11 +128,15 @@ public class YamlConfig extends YamlConfiguration {
|
|||
* Returns the default configuration as been stored in the jar-file of the owning plugin.
|
||||
* @return The default configuration.
|
||||
*/
|
||||
public YamlConfiguration getDefaultConfig() {
|
||||
public YamlConfiguration getDefaultConfig()
|
||||
{
|
||||
final YamlConfiguration DEFAULT_CONFIG = new YamlConfiguration();
|
||||
try {
|
||||
try
|
||||
{
|
||||
DEFAULT_CONFIG.load(PLUGIN.getResource(CONFIG_FILE.getName()));
|
||||
} catch (Throwable ex) {
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
PLUGIN.getLogger().severe("Could not load default configuration: " + CONFIG_FILE.getName());
|
||||
PLUGIN.getLogger().severe(ExceptionUtils.getStackTrace(ex));
|
||||
return null;
|
||||
|
|
Loading…
Reference in a new issue