mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 10:05:59 +00:00
Cleaned up TFM_Util
This commit is contained in:
parent
97b27cd7b4
commit
c5ddc60b97
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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<String> STOP_COMMANDS = Arrays.asList("stop", "off", "end", "halt", "die");
|
||||
public static final List<String> REMOVE_COMMANDS = Arrays.asList("del", "delete", "rem", "remove");
|
||||
public static final List<String> 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<ChatColor> 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,179 +227,38 @@ 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;
|
||||
|
||||
TFM_Log.info("Installing default configuration file template: " + targetFile.getPath());
|
||||
|
||||
try
|
||||
{
|
||||
tfm.getDataFolder().mkdirs();
|
||||
output = new FileOutputStream(actual);
|
||||
byte[] buf = new byte[8192];
|
||||
int length;
|
||||
while ((length = input.read(buf)) > 0)
|
||||
final InputStream configFileStream = TotalFreedomMod.plugin.getResource(configFileName);
|
||||
FileUtils.copyInputStreamToFile(configFileStream, targetFile);
|
||||
configFileStream.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
output.write(buf, 0, length);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
TFM_Log.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TFM_EntityWiper
|
||||
public static boolean deleteFolder(final File file)
|
||||
{
|
||||
private static final List<Class<? extends Entity>> WIPEABLES = new ArrayList<Class<? extends Entity>>();
|
||||
|
||||
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);
|
||||
return FileUtils.deleteQuietly(file);
|
||||
}
|
||||
|
||||
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<Class<? extends Entity>> 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<World> worlds = Bukkit.getWorlds().iterator();
|
||||
while (worlds.hasNext())
|
||||
{
|
||||
Iterator<Entity> 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;
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityType getEntityType(String mobname) throws Exception
|
||||
{
|
||||
mobname = mobname.toLowerCase().trim();
|
||||
@ -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> 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<ChatColor> 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<Class<? extends Entity>> WIPEABLES = new ArrayList<Class<? extends Entity>>();
|
||||
|
||||
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<Class<? extends Entity>> 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<World> worlds = Bukkit.getWorlds().iterator();
|
||||
while (worlds.hasNext())
|
||||
{
|
||||
Iterator<Entity> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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<String>();
|
||||
|
Loading…
Reference in New Issue
Block a user