diff --git a/appinfo.properties b/appinfo.properties index 42a4d5c3..afb1971d 100644 --- a/appinfo.properties +++ b/appinfo.properties @@ -1,5 +1,5 @@ -#Sat, 21 Sep 2013 13:56:10 -0400 +#Tue, 24 Sep 2013 07:27:17 -0400 program.VERSION=3.2 -program.BUILDNUM=600 -program.BUILDDATE=09/21/2013 01\:56 PM +program.BUILDNUM=602 +program.BUILDDATE=09/24/2013 07\:27 AM diff --git a/buildnumber.properties b/buildnumber.properties index 2080d35c..4e9fd80d 100644 --- a/buildnumber.properties +++ b/buildnumber.properties @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Sat Sep 21 13:56:10 EDT 2013 -build.number=601 +#Tue Sep 24 07:27:17 EDT 2013 +build.number=603 diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_SuperadminList.java b/src/me/StevenLawson/TotalFreedomMod/TFM_SuperadminList.java index e46b7cef..7d8fcfb8 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_SuperadminList.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_SuperadminList.java @@ -48,7 +48,7 @@ public class TFM_SuperadminList { superadminList.clear(); - TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE, TotalFreedomMod.plugin_file); + TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE); FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE)); cleanThreshold = config.getInt("clean_threshold_hours", cleanThreshold); diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java index 769b31c7..45356d39 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java @@ -8,12 +8,10 @@ import java.nio.channels.ReadableByteChannel; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; -import java.util.jar.JarFile; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.zip.ZipEntry; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.exception.ExceptionUtils; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.Skull; @@ -27,6 +25,21 @@ public class TFM_Util public static final List STOP_COMMANDS = Arrays.asList("stop", "off", "end", "halt", "die"); public static final List REMOVE_COMMANDS = Arrays.asList("del", "delete", "rem", "remove"); public static final List DEVELOPERS = Arrays.asList("Madgeek1450", "DarthSalamon", "AcidicCyanide", "wild1145", "HeXeRei452"); + private static final Random RANDOM = new Random(); + public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z"; + public static final List COLOR_POOL = Arrays.asList( + ChatColor.DARK_BLUE, + ChatColor.DARK_GREEN, + ChatColor.DARK_AQUA, + ChatColor.DARK_RED, + ChatColor.DARK_PURPLE, + ChatColor.GOLD, + ChatColor.BLUE, + ChatColor.GREEN, + ChatColor.AQUA, + ChatColor.RED, + ChatColor.LIGHT_PURPLE, + ChatColor.YELLOW); static { @@ -214,177 +227,36 @@ public class TFM_Util world.setTime(time + 24000 + ticks); } - public static void createDefaultConfiguration(String name, File pluginFile) + public static void createDefaultConfiguration(final String configFileName) { - TotalFreedomMod tfm = TotalFreedomMod.plugin; + final File targetFile = new File(TotalFreedomMod.plugin.getDataFolder(), configFileName); - File actual = new File(tfm.getDataFolder(), name); - if (!actual.exists()) + if (targetFile.exists()) { - TFM_Log.info("Installing default configuration file template: " + actual.getPath()); - InputStream input = null; - try - { - JarFile file = new JarFile(pluginFile); - ZipEntry copy = file.getEntry(name); - if (copy == null) - { - TFM_Log.severe("Unable to read default configuration: " + actual.getPath()); - return; - } - input = file.getInputStream(copy); - } - catch (IOException ioex) - { - TFM_Log.severe("Unable to read default configuration: " + actual.getPath()); - } - if (input != null) - { - FileOutputStream output = null; + return; + } - try - { - tfm.getDataFolder().mkdirs(); - output = new FileOutputStream(actual); - byte[] buf = new byte[8192]; - int length; - while ((length = input.read(buf)) > 0) - { - output.write(buf, 0, length); - } + TFM_Log.info("Installing default configuration file template: " + targetFile.getPath()); - TFM_Log.info("Default configuration file written: " + actual.getPath()); - } - catch (IOException ioex) - { - TFM_Log.severe("Unable to write default configuration: " + actual.getPath() + "\n" + ExceptionUtils.getStackTrace(ioex)); - } - finally - { - try - { - if (input != null) - { - input.close(); - } - } - catch (IOException ioex) - { - } - - try - { - if (output != null) - { - output.close(); - } - } - catch (IOException ioex) - { - } - } - } + try + { + final InputStream configFileStream = TotalFreedomMod.plugin.getResource(configFileName); + FileUtils.copyInputStreamToFile(configFileStream, targetFile); + configFileStream.close(); + } + catch (IOException ex) + { + TFM_Log.severe(ex); } } - public static class TFM_EntityWiper + public static boolean deleteFolder(final File file) { - private static final List> WIPEABLES = new ArrayList>(); - - static + if (file.exists() && file.isDirectory()) { - WIPEABLES.add(EnderCrystal.class); - WIPEABLES.add(EnderSignal.class); - WIPEABLES.add(ExperienceOrb.class); - WIPEABLES.add(Projectile.class); - WIPEABLES.add(FallingBlock.class); - WIPEABLES.add(Firework.class); - WIPEABLES.add(Item.class); - } - - private TFM_EntityWiper() - { - throw new AssertionError(); - } - - private static boolean canWipe(Entity entity, boolean wipeExplosives, boolean wipeVehicles) - { - if (wipeExplosives) - { - if (Explosive.class.isAssignableFrom(entity.getClass())) - { - return true; - } - } - - if (wipeVehicles) - { - if (Boat.class.isAssignableFrom(entity.getClass())) - { - return true; - } - else if (Minecart.class.isAssignableFrom(entity.getClass())) - { - return true; - } - } - - Iterator> it = WIPEABLES.iterator(); - while (it.hasNext()) - { - if (it.next().isAssignableFrom(entity.getClass())) - { - return true; - } - } - - return false; - } - - public static int wipeEntities(boolean wipeExplosives, boolean wipeVehicles) - { - int removed = 0; - - Iterator worlds = Bukkit.getWorlds().iterator(); - while (worlds.hasNext()) - { - Iterator entities = worlds.next().getEntities().iterator(); - while (entities.hasNext()) - { - Entity entity = entities.next(); - if (canWipe(entity, wipeExplosives, wipeVehicles)) - { - entity.remove(); - removed++; - } - } - } - - return removed; - } - } - - public static boolean deleteFolder(File file) - { - if (file.exists()) - { - if (file.isDirectory()) - { - for (File f : file.listFiles()) - { - if (!TFM_Util.deleteFolder(f)) - { - return false; - } - } - } - file.delete(); - return !file.exists(); - } - else - { - return false; + return FileUtils.deleteQuietly(file); } + return false; } public static EntityType getEntityType(String mobname) throws Exception @@ -413,32 +285,6 @@ public class TFM_Util } } - private static void copy(File file, OutputStream out) throws IOException - { - InputStream in = new FileInputStream(file); - try - { - copy(in, out); - } - finally - { - in.close(); - } - } - - private static void copy(InputStream in, File file) throws IOException - { - OutputStream out = new FileOutputStream(file); - try - { - copy(in, out); - } - finally - { - out.close(); - } - } - public static boolean isStopCommand(String command) { return STOP_COMMANDS.contains(command.toLowerCase()); @@ -449,11 +295,6 @@ public class TFM_Util return REMOVE_COMMANDS.contains(command.toLowerCase()); } - enum EjectMethod - { - STRIKE_ONE, STRIKE_TWO, STRIKE_THREE; - } - public static void autoEject(Player player, String kickMessage) { EjectMethod method = EjectMethod.STRIKE_ONE; @@ -776,7 +617,6 @@ public class TFM_Util TFM_Log.severe(ex); } } - public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z"; public static String dateToString(Date date) { @@ -938,18 +778,6 @@ public class TFM_Util return prefix + ChatColor.WHITE; } - public static String inputStreamToString(InputStream is, boolean preserveNewlines) throws IOException - { - BufferedReader br = new BufferedReader(new InputStreamReader(is)); - StringBuilder sb = new StringBuilder(); - String line; - while ((line = br.readLine()) != null) - { - sb.append(line).append(preserveNewlines ? System.getProperty("line.separator") : ""); - } - return sb.toString(); - } - //getField: Borrowed from WorldEdit @SuppressWarnings("unchecked") public static T getField(Object from, String name) @@ -973,20 +801,6 @@ public class TFM_Util while (checkClass.getSuperclass() != Object.class && ((checkClass = checkClass.getSuperclass()) != null)); return null; } - public static final List COLOR_POOL = Arrays.asList( - ChatColor.DARK_BLUE, - ChatColor.DARK_GREEN, - ChatColor.DARK_AQUA, - ChatColor.DARK_RED, - ChatColor.DARK_PURPLE, - ChatColor.GOLD, - ChatColor.BLUE, - ChatColor.GREEN, - ChatColor.AQUA, - ChatColor.RED, - ChatColor.LIGHT_PURPLE, - ChatColor.YELLOW); - private static final Random RANDOM = new Random(); public static ChatColor randomChatColor() { @@ -997,4 +811,86 @@ public class TFM_Util { return ChatColor.translateAlternateColorCodes('&', string); } + + public static class TFM_EntityWiper + { + private static final List> WIPEABLES = new ArrayList>(); + + static + { + WIPEABLES.add(EnderCrystal.class); + WIPEABLES.add(EnderSignal.class); + WIPEABLES.add(ExperienceOrb.class); + WIPEABLES.add(Projectile.class); + WIPEABLES.add(FallingBlock.class); + WIPEABLES.add(Firework.class); + WIPEABLES.add(Item.class); + } + + private TFM_EntityWiper() + { + throw new AssertionError(); + } + + private static boolean canWipe(Entity entity, boolean wipeExplosives, boolean wipeVehicles) + { + if (wipeExplosives) + { + if (Explosive.class.isAssignableFrom(entity.getClass())) + { + return true; + } + } + + if (wipeVehicles) + { + if (Boat.class.isAssignableFrom(entity.getClass())) + { + return true; + } + else if (Minecart.class.isAssignableFrom(entity.getClass())) + { + return true; + } + } + + Iterator> it = WIPEABLES.iterator(); + while (it.hasNext()) + { + if (it.next().isAssignableFrom(entity.getClass())) + { + return true; + } + } + + return false; + } + + public static int wipeEntities(boolean wipeExplosives, boolean wipeVehicles) + { + int removed = 0; + + Iterator worlds = Bukkit.getWorlds().iterator(); + while (worlds.hasNext()) + { + Iterator entities = worlds.next().getEntities().iterator(); + while (entities.hasNext()) + { + Entity entity = entities.next(); + if (canWipe(entity, wipeExplosives, wipeVehicles)) + { + entity.remove(); + removed++; + } + } + } + + return removed; + } + } + + enum EjectMethod + { + STRIKE_ONE, STRIKE_TWO, STRIKE_THREE; + } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java index 50e30cb2..88b7475d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java +++ b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java @@ -46,7 +46,6 @@ public class TotalFreedomMod extends JavaPlugin // public static final Server server = Bukkit.getServer(); public static TotalFreedomMod plugin = null; - public static File plugin_file = null; // public static String pluginName = ""; public static String pluginVersion = ""; @@ -66,7 +65,6 @@ public class TotalFreedomMod extends JavaPlugin public void onLoad() { TotalFreedomMod.plugin = this; - TotalFreedomMod.plugin_file = plugin.getFile(); TotalFreedomMod.pluginName = plugin.getDescription().getName(); TFM_Log.setPluginLogger(this.getLogger()); @@ -273,7 +271,7 @@ public class TotalFreedomMod extends JavaPlugin { try { - TFM_Util.createDefaultConfiguration(PERMBAN_FILE, plugin_file); + TFM_Util.createDefaultConfiguration(PERMBAN_FILE); FileConfiguration config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), PERMBAN_FILE)); permbanned_players = new ArrayList();