2011-10-13 23:07:52 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod;
|
|
|
|
|
2012-03-09 19:01:04 +00:00
|
|
|
import java.io.*;
|
2013-04-10 02:05:24 +00:00
|
|
|
import java.lang.reflect.Field;
|
2012-12-02 17:05:54 +00:00
|
|
|
import java.net.URL;
|
|
|
|
import java.nio.channels.Channels;
|
|
|
|
import java.nio.channels.ReadableByteChannel;
|
2012-11-13 01:42:30 +00:00
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.SimpleDateFormat;
|
2012-03-09 19:01:04 +00:00
|
|
|
import java.util.*;
|
2011-10-13 23:07:52 +00:00
|
|
|
import java.util.jar.JarFile;
|
2012-09-16 21:18:30 +00:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
2011-10-13 23:07:52 +00:00
|
|
|
import java.util.zip.ZipEntry;
|
2013-09-04 12:35:12 +00:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
2012-03-09 19:01:04 +00:00
|
|
|
import org.bukkit.*;
|
2011-10-13 23:07:52 +00:00
|
|
|
import org.bukkit.block.Block;
|
2013-08-25 23:08:53 +00:00
|
|
|
import org.bukkit.block.Skull;
|
2011-10-13 23:07:52 +00:00
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.*;
|
|
|
|
|
|
|
|
public class TFM_Util
|
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
private static final Map<String, Integer> ejectTracker = new HashMap<String, Integer>();
|
2012-03-03 04:29:54 +00:00
|
|
|
public static final Map<String, EntityType> mobtypes = new HashMap<String, EntityType>();
|
2012-12-09 03:42:29 +00:00
|
|
|
public static final List<String> STOP_COMMANDS = Arrays.asList("stop", "off", "end", "halt", "die");
|
2013-08-15 21:36:55 +00:00
|
|
|
public static final List<String> REMOVE_COMMANDS = Arrays.asList("del", "delete", "rem", "remove");
|
2013-08-22 19:29:16 +00:00
|
|
|
public static final List<String> DEVELOPERS = Arrays.asList("Madgeek1450", "DarthSalamon", "AcidicCyanide", "wild1145", "HeXeRei452");
|
2011-11-08 00:29:33 +00:00
|
|
|
|
|
|
|
static
|
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
for (EntityType type : EntityType.values())
|
2012-11-18 03:57:24 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
if (type.getName() != null)
|
2012-11-18 03:57:24 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
if (Creature.class.isAssignableFrom(type.getEntityClass()))
|
2012-11-18 03:57:24 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
mobtypes.put(type.getName().toLowerCase(), type);
|
2012-11-18 03:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (Exception ex)
|
2012-11-18 03:57:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2011-11-08 00:29:33 +00:00
|
|
|
}
|
2011-10-24 02:43:52 +00:00
|
|
|
|
|
|
|
private TFM_Util()
|
|
|
|
{
|
|
|
|
throw new AssertionError();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void bcastMsg(String message, ChatColor color)
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
2012-09-23 23:00:45 +00:00
|
|
|
TFM_Log.info(message, true);
|
2011-10-13 23:07:52 +00:00
|
|
|
|
2013-08-14 14:01:42 +00:00
|
|
|
for (Player player : Bukkit.getOnlinePlayers())
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
2013-08-14 14:01:42 +00:00
|
|
|
player.sendMessage((color == null ? "" : color) + message);
|
2011-10-13 23:07:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-24 02:43:52 +00:00
|
|
|
public static void bcastMsg(String message)
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
2012-09-23 23:00:45 +00:00
|
|
|
TFM_Util.bcastMsg(message, null);
|
2011-10-13 23:07:52 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 18:58:42 +00:00
|
|
|
// Still in use by listeners
|
2012-09-14 22:49:44 +00:00
|
|
|
public static void playerMsg(CommandSender sender, String message, ChatColor color)
|
|
|
|
{
|
|
|
|
sender.sendMessage(color + message);
|
|
|
|
}
|
2012-09-16 01:19:55 +00:00
|
|
|
|
2013-01-21 18:58:42 +00:00
|
|
|
// Still in use by listeners
|
2012-09-14 22:49:44 +00:00
|
|
|
public static void playerMsg(CommandSender sender, String message)
|
|
|
|
{
|
|
|
|
TFM_Util.playerMsg(sender, message, ChatColor.GRAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void adminAction(String adminName, String action, boolean isRed)
|
|
|
|
{
|
2012-09-15 18:05:48 +00:00
|
|
|
TFM_Util.bcastMsg(adminName + " - " + action, (isRed ? ChatColor.RED : ChatColor.AQUA));
|
2012-09-14 22:49:44 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
public static String formatLocation(Location location)
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
|
|
|
return String.format("%s: (%d, %d, %d)",
|
2013-08-25 16:32:01 +00:00
|
|
|
location.getWorld().getName(),
|
|
|
|
Math.round(location.getX()),
|
|
|
|
Math.round(location.getY()),
|
|
|
|
Math.round(location.getZ()));
|
2011-10-13 23:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void gotoWorld(CommandSender sender, String targetworld)
|
|
|
|
{
|
|
|
|
if (sender instanceof Player)
|
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
Player player = (Player) sender;
|
2011-10-13 23:07:52 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
if (player.getWorld().getName().equalsIgnoreCase(targetworld))
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
|
|
|
sender.sendMessage(ChatColor.GRAY + "Going to main world.");
|
2013-08-25 16:32:01 +00:00
|
|
|
player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation());
|
2011-10-13 23:07:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (World world : Bukkit.getWorlds())
|
|
|
|
{
|
|
|
|
if (world.getName().equalsIgnoreCase(targetworld))
|
|
|
|
{
|
|
|
|
sender.sendMessage(ChatColor.GRAY + "Going to world: " + targetworld);
|
2013-08-25 16:32:01 +00:00
|
|
|
player.teleport(world.getSpawnLocation());
|
2011-10-13 23:07:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-07-22 18:06:01 +00:00
|
|
|
|
2011-11-28 22:44:51 +00:00
|
|
|
sender.sendMessage(ChatColor.GRAY + "World " + targetworld + " not found.");
|
2011-10-13 23:07:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-16 06:00:37 +00:00
|
|
|
sender.sendMessage(TotalFreedomMod.NOT_FROM_CONSOLE);
|
2011-10-13 23:07:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-21 18:58:42 +00:00
|
|
|
public static void buildHistory(Location location, int length, TFM_PlayerData playerdata)
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
Block center = location.getBlock();
|
|
|
|
for (int xOffset = -length; xOffset <= length; xOffset++)
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
for (int yOffset = -length; yOffset <= length; yOffset++)
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
for (int zOffset = -length; zOffset <= length; zOffset++)
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
Block block = center.getRelative(xOffset, yOffset, zOffset);
|
2011-10-13 23:07:52 +00:00
|
|
|
playerdata.insertHistoryBlock(block.getLocation(), block.getType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void generateCube(Location location, int length, Material material)
|
|
|
|
{
|
2013-08-25 23:08:53 +00:00
|
|
|
Block center = location.getBlock();
|
2013-08-25 16:32:01 +00:00
|
|
|
for (int xOffset = -length; xOffset <= length; xOffset++)
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
for (int yOffset = -length; yOffset <= length; yOffset++)
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
for (int zOffset = -length; zOffset <= length; zOffset++)
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
2013-08-26 13:04:36 +00:00
|
|
|
final Block block = center.getRelative(xOffset, yOffset, zOffset);
|
|
|
|
if (block.getType() != material)
|
|
|
|
{
|
|
|
|
block.setType(material);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void generateHollowCube(Location location, int length, Material material)
|
|
|
|
{
|
|
|
|
Block center = location.getBlock();
|
|
|
|
for (int xOffset = -length; xOffset <= length; xOffset++)
|
|
|
|
{
|
|
|
|
for (int yOffset = -length; yOffset <= length; yOffset++)
|
|
|
|
{
|
|
|
|
for (int zOffset = -length; zOffset <= length; zOffset++)
|
|
|
|
{
|
|
|
|
// Hollow
|
|
|
|
if (Math.abs(xOffset) != length && Math.abs(yOffset) != length && Math.abs(zOffset) != length)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Block block = center.getRelative(xOffset, yOffset, zOffset);
|
|
|
|
|
2013-08-25 23:08:53 +00:00
|
|
|
if (material != Material.SKULL)
|
|
|
|
{
|
2013-08-26 13:04:36 +00:00
|
|
|
// Glowstone light
|
|
|
|
if (material != Material.GLASS && xOffset == 0 && yOffset == 2 && zOffset == 0)
|
|
|
|
{
|
|
|
|
block.setType(Material.GLOWSTONE);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
block.setType(material);
|
2013-08-25 23:08:53 +00:00
|
|
|
}
|
2013-08-26 13:04:36 +00:00
|
|
|
else // Darth mode
|
2013-08-25 23:08:53 +00:00
|
|
|
{
|
2013-08-26 13:04:36 +00:00
|
|
|
if (Math.abs(xOffset) == length && Math.abs(yOffset) == length && Math.abs(zOffset) == length)
|
|
|
|
{
|
|
|
|
block.setType(Material.GLOWSTONE);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-08-25 23:08:53 +00:00
|
|
|
block.setType(Material.SKULL);
|
|
|
|
Skull skull = (Skull) block.getState();
|
|
|
|
skull.setSkullType(SkullType.PLAYER);
|
|
|
|
skull.setOwner("DarthSalamon");
|
|
|
|
skull.update();
|
|
|
|
}
|
2011-10-13 23:07:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-14 05:31:21 +00:00
|
|
|
|
2011-10-13 23:07:52 +00:00
|
|
|
public static void setWorldTime(World world, long ticks)
|
|
|
|
{
|
|
|
|
long time = world.getTime();
|
|
|
|
time -= time % 24000;
|
|
|
|
world.setTime(time + 24000 + ticks);
|
|
|
|
}
|
2011-10-14 05:31:21 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
public static void createDefaultConfiguration(String name, File pluginFile)
|
2012-09-14 22:49:44 +00:00
|
|
|
{
|
|
|
|
TotalFreedomMod tfm = TotalFreedomMod.plugin;
|
|
|
|
|
2011-10-13 23:07:52 +00:00
|
|
|
File actual = new File(tfm.getDataFolder(), name);
|
|
|
|
if (!actual.exists())
|
|
|
|
{
|
2012-09-15 17:01:43 +00:00
|
|
|
TFM_Log.info("Installing default configuration file template: " + actual.getPath());
|
2011-10-13 23:07:52 +00:00
|
|
|
InputStream input = null;
|
|
|
|
try
|
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
JarFile file = new JarFile(pluginFile);
|
2011-10-13 23:07:52 +00:00
|
|
|
ZipEntry copy = file.getEntry(name);
|
|
|
|
if (copy == null)
|
|
|
|
{
|
2012-09-15 17:01:43 +00:00
|
|
|
TFM_Log.severe("Unable to read default configuration: " + actual.getPath());
|
2011-10-13 23:07:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
input = file.getInputStream(copy);
|
|
|
|
}
|
|
|
|
catch (IOException ioex)
|
|
|
|
{
|
2012-09-15 17:01:43 +00:00
|
|
|
TFM_Log.severe("Unable to read default configuration: " + actual.getPath());
|
2011-10-13 23:07:52 +00:00
|
|
|
}
|
|
|
|
if (input != null)
|
|
|
|
{
|
|
|
|
FileOutputStream output = null;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
tfm.getDataFolder().mkdirs();
|
|
|
|
output = new FileOutputStream(actual);
|
|
|
|
byte[] buf = new byte[8192];
|
2012-03-09 19:01:04 +00:00
|
|
|
int length;
|
2011-10-13 23:07:52 +00:00
|
|
|
while ((length = input.read(buf)) > 0)
|
|
|
|
{
|
|
|
|
output.write(buf, 0, length);
|
|
|
|
}
|
|
|
|
|
2012-09-15 17:01:43 +00:00
|
|
|
TFM_Log.info("Default configuration file written: " + actual.getPath());
|
2011-10-13 23:07:52 +00:00
|
|
|
}
|
|
|
|
catch (IOException ioex)
|
|
|
|
{
|
2012-09-15 17:01:43 +00:00
|
|
|
TFM_Log.severe("Unable to write default configuration: " + actual.getPath() + "\n" + ExceptionUtils.getStackTrace(ioex));
|
2011-10-13 23:07:52 +00:00
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (input != null)
|
|
|
|
{
|
|
|
|
input.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (IOException ioex)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (output != null)
|
|
|
|
{
|
|
|
|
output.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (IOException ioex)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-14 05:31:21 +00:00
|
|
|
|
2013-08-12 02:02:18 +00:00
|
|
|
public static class TFM_EntityWiper
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
2013-08-12 02:02:18 +00:00
|
|
|
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()
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
2013-08-12 02:02:18 +00:00
|
|
|
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)
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
2013-08-12 02:02:18 +00:00
|
|
|
if (Boat.class.isAssignableFrom(entity.getClass()))
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
2013-08-12 02:02:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (Minecart.class.isAssignableFrom(entity.getClass()))
|
|
|
|
{
|
|
|
|
return true;
|
2011-10-13 23:07:52 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-12 02:02:18 +00:00
|
|
|
|
|
|
|
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;
|
2011-10-13 23:07:52 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-14 05:31:21 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2011-10-24 02:43:52 +00:00
|
|
|
|
2012-03-03 04:29:54 +00:00
|
|
|
public static EntityType getEntityType(String mobname) throws Exception
|
2011-10-24 02:43:52 +00:00
|
|
|
{
|
2011-11-28 22:44:51 +00:00
|
|
|
mobname = mobname.toLowerCase().trim();
|
2012-07-22 18:06:01 +00:00
|
|
|
|
2011-11-28 22:44:51 +00:00
|
|
|
if (!TFM_Util.mobtypes.containsKey(mobname))
|
|
|
|
{
|
|
|
|
throw new Exception();
|
|
|
|
}
|
2012-07-22 18:06:01 +00:00
|
|
|
|
2011-11-28 22:44:51 +00:00
|
|
|
return TFM_Util.mobtypes.get(mobname);
|
2011-10-24 02:43:52 +00:00
|
|
|
}
|
2011-11-04 23:14:17 +00:00
|
|
|
|
|
|
|
private static void copy(InputStream in, OutputStream out) throws IOException
|
|
|
|
{
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
int readCount = in.read(buffer);
|
|
|
|
if (readCount < 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out.write(buffer, 0, readCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2011-11-08 00:29:33 +00:00
|
|
|
|
|
|
|
public static boolean isStopCommand(String command)
|
2011-11-07 13:11:13 +00:00
|
|
|
{
|
2012-12-09 03:42:29 +00:00
|
|
|
return STOP_COMMANDS.contains(command.toLowerCase());
|
2011-11-07 13:11:13 +00:00
|
|
|
}
|
2011-11-08 00:29:33 +00:00
|
|
|
|
2013-08-15 21:36:55 +00:00
|
|
|
public static boolean isRemoveCommand(String command)
|
|
|
|
{
|
|
|
|
return REMOVE_COMMANDS.contains(command.toLowerCase());
|
|
|
|
}
|
|
|
|
|
2011-11-08 00:29:33 +00:00
|
|
|
enum EjectMethod
|
|
|
|
{
|
|
|
|
STRIKE_ONE, STRIKE_TWO, STRIKE_THREE;
|
|
|
|
}
|
|
|
|
|
2013-08-14 14:01:42 +00:00
|
|
|
public static void autoEject(Player player, String kickMessage)
|
2011-11-07 13:11:13 +00:00
|
|
|
{
|
2011-11-08 00:29:33 +00:00
|
|
|
EjectMethod method = EjectMethod.STRIKE_ONE;
|
2013-08-25 16:32:01 +00:00
|
|
|
String ip = null;
|
2012-07-22 18:06:01 +00:00
|
|
|
|
2011-11-08 00:29:33 +00:00
|
|
|
try
|
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
ip = player.getAddress().getAddress().getHostAddress();
|
2012-07-22 18:06:01 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
Integer kicks = TFM_Util.ejectTracker.get(ip);
|
|
|
|
if (kicks == null)
|
2011-11-08 00:29:33 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
kicks = new Integer(0);
|
2011-11-08 00:29:33 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
kicks = new Integer(kicks.intValue() + 1);
|
2012-07-22 18:06:01 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
TFM_Util.ejectTracker.put(ip, kicks);
|
2011-11-08 00:29:33 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
if (kicks.intValue() <= 1)
|
2011-11-08 00:29:33 +00:00
|
|
|
{
|
|
|
|
method = EjectMethod.STRIKE_ONE;
|
|
|
|
}
|
2013-08-25 16:32:01 +00:00
|
|
|
else if (kicks.intValue() == 2)
|
2011-11-08 00:29:33 +00:00
|
|
|
{
|
|
|
|
method = EjectMethod.STRIKE_TWO;
|
|
|
|
}
|
2013-08-25 16:32:01 +00:00
|
|
|
else if (kicks.intValue() >= 3)
|
2011-11-08 00:29:33 +00:00
|
|
|
{
|
|
|
|
method = EjectMethod.STRIKE_THREE;
|
|
|
|
}
|
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (Exception ex)
|
2011-11-08 00:29:33 +00:00
|
|
|
{
|
|
|
|
}
|
2012-07-22 18:06:01 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
TFM_Log.info("autoEject -> name: " + player.getName() + " - player ip: " + ip + " - method: " + method.toString());
|
2011-11-08 00:29:33 +00:00
|
|
|
|
2013-08-14 14:01:42 +00:00
|
|
|
player.setOp(false);
|
|
|
|
player.setGameMode(GameMode.SURVIVAL);
|
|
|
|
player.getInventory().clear();
|
2011-11-08 00:29:33 +00:00
|
|
|
|
|
|
|
switch (method)
|
|
|
|
{
|
|
|
|
case STRIKE_ONE:
|
|
|
|
{
|
2012-09-16 21:25:34 +00:00
|
|
|
Calendar c = new GregorianCalendar();
|
|
|
|
c.add(Calendar.MINUTE, 1);
|
|
|
|
Date expires = c.getTime();
|
2012-09-16 01:19:55 +00:00
|
|
|
|
2013-08-14 14:01:42 +00:00
|
|
|
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 1 minute.");
|
2012-09-16 01:19:55 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
TFM_ServerInterface.banIP(ip, kickMessage, "AutoEject", expires);
|
2013-08-14 14:01:42 +00:00
|
|
|
TFM_ServerInterface.banUsername(player.getName(), kickMessage, "AutoEject", expires);
|
|
|
|
player.kickPlayer(kickMessage);
|
2012-09-16 01:19:55 +00:00
|
|
|
|
2011-11-08 00:29:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STRIKE_TWO:
|
|
|
|
{
|
2012-09-16 21:25:34 +00:00
|
|
|
Calendar c = new GregorianCalendar();
|
|
|
|
c.add(Calendar.MINUTE, 3);
|
|
|
|
Date expires = c.getTime();
|
2012-09-16 01:19:55 +00:00
|
|
|
|
2013-08-14 14:01:42 +00:00
|
|
|
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 3 minutes.");
|
2012-09-16 01:19:55 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
TFM_ServerInterface.banIP(ip, kickMessage, "AutoEject", expires);
|
2013-08-14 14:01:42 +00:00
|
|
|
TFM_ServerInterface.banUsername(player.getName(), kickMessage, "AutoEject", expires);
|
|
|
|
player.kickPlayer(kickMessage);
|
2012-09-16 01:19:55 +00:00
|
|
|
|
2011-11-08 00:29:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STRIKE_THREE:
|
|
|
|
{
|
2012-09-16 01:19:55 +00:00
|
|
|
//Bukkit.banIP(player_ip);
|
2013-08-25 16:32:01 +00:00
|
|
|
TFM_ServerInterface.banIP(ip, kickMessage, "AutoEject", null);
|
|
|
|
String[] ipAddressParts = ip.split("\\.");
|
2012-09-16 01:19:55 +00:00
|
|
|
//Bukkit.banIP();
|
2013-08-25 16:32:01 +00:00
|
|
|
TFM_ServerInterface.banIP(ipAddressParts[0] + "." + ipAddressParts[1] + ".*.*", kickMessage, "AutoEject", null);
|
2012-09-16 01:19:55 +00:00
|
|
|
|
|
|
|
//p.setBanned(true);
|
2013-08-14 14:01:42 +00:00
|
|
|
TFM_ServerInterface.banUsername(player.getName(), kickMessage, "AutoEject", null);
|
2012-07-22 18:06:01 +00:00
|
|
|
|
2013-08-14 14:01:42 +00:00
|
|
|
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned permanently.");
|
2012-07-22 18:06:01 +00:00
|
|
|
|
2013-08-14 14:01:42 +00:00
|
|
|
player.kickPlayer(kickMessage);
|
2012-07-22 18:06:01 +00:00
|
|
|
|
2011-11-08 00:29:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-11-07 13:11:13 +00:00
|
|
|
}
|
2012-07-22 18:06:01 +00:00
|
|
|
|
2012-09-14 22:49:44 +00:00
|
|
|
public static String getRank(CommandSender sender)
|
|
|
|
{
|
2012-11-19 01:25:47 +00:00
|
|
|
if (TFM_SuperadminList.isSuperadminImpostor(sender))
|
2012-09-14 22:49:44 +00:00
|
|
|
{
|
2012-09-15 18:05:48 +00:00
|
|
|
return "an " + ChatColor.YELLOW + ChatColor.UNDERLINE + "impostor" + ChatColor.RESET + ChatColor.AQUA + "!";
|
2012-09-14 22:49:44 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry(sender.getName());
|
2012-09-18 21:45:10 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
if (entry != null)
|
2012-09-17 16:29:43 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
if (entry.isActivated())
|
2012-11-13 01:42:30 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
String loginMessage = entry.getCustomLoginMessage();
|
2012-11-19 01:25:47 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
if (loginMessage != null)
|
2012-11-13 01:42:30 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
if (!loginMessage.isEmpty())
|
2012-11-19 01:25:47 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
return ChatColor.translateAlternateColorCodes('&', loginMessage);
|
2012-11-19 01:25:47 +00:00
|
|
|
}
|
2012-11-13 01:42:30 +00:00
|
|
|
}
|
2012-09-14 22:49:44 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
if (entry.isSeniorAdmin())
|
2012-11-19 01:25:47 +00:00
|
|
|
{
|
2012-11-28 16:35:31 +00:00
|
|
|
return "a " + ChatColor.LIGHT_PURPLE + "Senior Admin" + ChatColor.AQUA + ".";
|
2012-11-19 01:25:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-28 16:35:31 +00:00
|
|
|
return "a " + ChatColor.GOLD + "Super Admin" + ChatColor.AQUA + ".";
|
2012-11-19 01:25:47 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-14 22:49:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sender.isOp())
|
|
|
|
{
|
|
|
|
return "an " + ChatColor.DARK_GREEN + "OP" + ChatColor.AQUA + ".";
|
|
|
|
}
|
|
|
|
|
2012-09-17 16:29:43 +00:00
|
|
|
return "a " + ChatColor.GREEN + "non-OP" + ChatColor.AQUA + ".";
|
2012-09-14 22:49:44 +00:00
|
|
|
}
|
|
|
|
|
2012-09-16 21:18:30 +00:00
|
|
|
public static Date parseDateOffset(String time)
|
|
|
|
{
|
|
|
|
Pattern timePattern = Pattern.compile(
|
|
|
|
"(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?"
|
|
|
|
+ "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?"
|
|
|
|
+ "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?"
|
|
|
|
+ "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?"
|
|
|
|
+ "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?"
|
|
|
|
+ "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?"
|
|
|
|
+ "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE);
|
|
|
|
Matcher m = timePattern.matcher(time);
|
|
|
|
int years = 0;
|
|
|
|
int months = 0;
|
|
|
|
int weeks = 0;
|
|
|
|
int days = 0;
|
|
|
|
int hours = 0;
|
|
|
|
int minutes = 0;
|
|
|
|
int seconds = 0;
|
|
|
|
boolean found = false;
|
|
|
|
while (m.find())
|
|
|
|
{
|
|
|
|
if (m.group() == null || m.group().isEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < m.groupCount(); i++)
|
|
|
|
{
|
|
|
|
if (m.group(i) != null && !m.group(i).isEmpty())
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
if (m.group(1) != null && !m.group(1).isEmpty())
|
|
|
|
{
|
|
|
|
years = Integer.parseInt(m.group(1));
|
|
|
|
}
|
|
|
|
if (m.group(2) != null && !m.group(2).isEmpty())
|
|
|
|
{
|
|
|
|
months = Integer.parseInt(m.group(2));
|
|
|
|
}
|
|
|
|
if (m.group(3) != null && !m.group(3).isEmpty())
|
|
|
|
{
|
|
|
|
weeks = Integer.parseInt(m.group(3));
|
|
|
|
}
|
|
|
|
if (m.group(4) != null && !m.group(4).isEmpty())
|
|
|
|
{
|
|
|
|
days = Integer.parseInt(m.group(4));
|
|
|
|
}
|
|
|
|
if (m.group(5) != null && !m.group(5).isEmpty())
|
|
|
|
{
|
|
|
|
hours = Integer.parseInt(m.group(5));
|
|
|
|
}
|
|
|
|
if (m.group(6) != null && !m.group(6).isEmpty())
|
|
|
|
{
|
|
|
|
minutes = Integer.parseInt(m.group(6));
|
|
|
|
}
|
|
|
|
if (m.group(7) != null && !m.group(7).isEmpty())
|
|
|
|
{
|
|
|
|
seconds = Integer.parseInt(m.group(7));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
Calendar c = new GregorianCalendar();
|
|
|
|
|
|
|
|
if (years > 0)
|
|
|
|
{
|
|
|
|
c.add(Calendar.YEAR, years);
|
|
|
|
}
|
|
|
|
if (months > 0)
|
|
|
|
{
|
|
|
|
c.add(Calendar.MONTH, months);
|
|
|
|
}
|
|
|
|
if (weeks > 0)
|
|
|
|
{
|
|
|
|
c.add(Calendar.WEEK_OF_YEAR, weeks);
|
|
|
|
}
|
|
|
|
if (days > 0)
|
|
|
|
{
|
|
|
|
c.add(Calendar.DAY_OF_MONTH, days);
|
|
|
|
}
|
|
|
|
if (hours > 0)
|
|
|
|
{
|
|
|
|
c.add(Calendar.HOUR_OF_DAY, hours);
|
|
|
|
}
|
|
|
|
if (minutes > 0)
|
|
|
|
{
|
|
|
|
c.add(Calendar.MINUTE, minutes);
|
|
|
|
}
|
|
|
|
if (seconds > 0)
|
|
|
|
{
|
|
|
|
c.add(Calendar.SECOND, seconds);
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.getTime();
|
|
|
|
}
|
2012-09-17 23:46:59 +00:00
|
|
|
|
2012-09-18 00:13:13 +00:00
|
|
|
public static String playerListToNames(Set<OfflinePlayer> players)
|
2012-09-17 16:29:43 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
List<String> names = new ArrayList<String>();
|
2013-08-14 14:01:42 +00:00
|
|
|
for (OfflinePlayer player : players)
|
2012-09-17 16:29:43 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
names.add(player.getName());
|
2012-09-17 16:29:43 +00:00
|
|
|
}
|
2013-08-25 16:32:01 +00:00
|
|
|
return StringUtils.join(names, ", ");
|
2012-09-17 16:29:43 +00:00
|
|
|
}
|
2012-11-05 03:44:24 +00:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public static Map<String, Boolean> getSavedFlags()
|
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
Map<String, Boolean> flags = null;
|
2012-11-05 03:44:24 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILE);
|
|
|
|
if (input.exists())
|
2012-11-05 03:44:24 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
FileInputStream fis = new FileInputStream(input);
|
2012-11-05 03:44:24 +00:00
|
|
|
ObjectInputStream ois = new ObjectInputStream(fis);
|
2013-08-25 16:32:01 +00:00
|
|
|
flags = (HashMap<String, Boolean>) ois.readObject();
|
2012-11-05 03:44:24 +00:00
|
|
|
ois.close();
|
|
|
|
fis.close();
|
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (Exception ex)
|
2012-11-05 03:44:24 +00:00
|
|
|
{
|
2013-08-14 13:28:19 +00:00
|
|
|
TFM_Log.severe(ex);
|
2012-11-05 03:44:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
return flags;
|
2012-11-05 03:44:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean getSavedFlag(String flag) throws Exception
|
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
Boolean flagValue = null;
|
2012-11-05 03:44:24 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
Map<String, Boolean> flags = TFM_Util.getSavedFlags();
|
2012-11-05 03:44:24 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
if (flags != null)
|
2012-11-05 03:44:24 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
if (flags.containsKey(flag))
|
2012-11-05 03:44:24 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
flagValue = flags.get(flag);
|
2012-11-05 03:44:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
if (flagValue != null)
|
2012-11-05 03:44:24 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
return flagValue.booleanValue();
|
2012-11-05 03:44:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new Exception();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setSavedFlag(String flag, boolean value)
|
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
Map<String, Boolean> flags = TFM_Util.getSavedFlags();
|
2012-11-05 03:44:24 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
if (flags == null)
|
2012-11-05 03:44:24 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
flags = new HashMap<String, Boolean>();
|
2012-11-05 03:44:24 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
flags.put(flag, value);
|
2012-11-05 03:44:24 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILE));
|
|
|
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
2013-08-25 16:32:01 +00:00
|
|
|
oos.writeObject(flags);
|
2012-11-05 03:44:24 +00:00
|
|
|
oos.close();
|
|
|
|
fos.close();
|
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (Exception ex)
|
2012-11-05 03:44:24 +00:00
|
|
|
{
|
2013-08-14 13:28:19 +00:00
|
|
|
TFM_Log.severe(ex);
|
2012-11-05 03:44:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-13 01:42:30 +00:00
|
|
|
public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
|
|
|
|
|
|
|
|
public static String dateToString(Date date)
|
|
|
|
{
|
|
|
|
return new SimpleDateFormat(DATE_STORAGE_FORMAT, Locale.ENGLISH).format(date);
|
|
|
|
}
|
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
public static Date stringToDate(String dateString)
|
2012-11-13 01:42:30 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
return new SimpleDateFormat(DATE_STORAGE_FORMAT, Locale.ENGLISH).parse(dateString);
|
2012-11-13 01:42:30 +00:00
|
|
|
}
|
2013-08-25 16:32:01 +00:00
|
|
|
catch (ParseException pex)
|
2012-11-13 01:42:30 +00:00
|
|
|
{
|
|
|
|
return new Date(0L);
|
|
|
|
}
|
|
|
|
}
|
2012-11-18 03:57:24 +00:00
|
|
|
|
2013-08-28 15:26:08 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2013-08-25 16:32:01 +00:00
|
|
|
public static boolean isFromHostConsole(String senderName)
|
2012-11-18 03:57:24 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
return ((List<String>) TFM_ConfigEntry.HOST_SENDER_NAMES.getList()).contains(senderName.toLowerCase());
|
2012-11-18 03:57:24 +00:00
|
|
|
}
|
2012-11-21 01:29:57 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
public static List<String> removeDuplicates(List<String> oldList)
|
2012-11-21 01:29:57 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
List<String> newList = new ArrayList<String>();
|
|
|
|
for (String entry : oldList)
|
2012-11-23 02:32:55 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
if (!newList.contains(entry))
|
2012-11-23 02:32:55 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
newList.add(entry);
|
2012-11-23 02:32:55 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-25 16:32:01 +00:00
|
|
|
return newList;
|
2012-11-23 02:32:55 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
public static boolean fuzzyIpMatch(String a, String b, int octets)
|
2012-11-23 02:32:55 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
boolean match = true;
|
2012-11-23 02:32:55 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
String[] aParts = a.split("\\.");
|
|
|
|
String[] bParts = b.split("\\.");
|
2012-11-23 02:32:55 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
if (aParts.length != 4 || bParts.length != 4)
|
2012-11-23 02:32:55 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
if (octets > 4)
|
2012-11-23 02:32:55 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
octets = 4;
|
2012-11-23 02:32:55 +00:00
|
|
|
}
|
2013-08-25 16:32:01 +00:00
|
|
|
else if (octets < 1)
|
2012-11-23 02:32:55 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
octets = 1;
|
2012-11-23 02:32:55 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
for (int i = 0; i < octets && i < 4; i++)
|
2012-11-23 02:32:55 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
if (aParts[i].equals("*") || bParts[i].equals("*"))
|
2012-11-23 02:32:55 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
if (!aParts[i].equals(bParts[i]))
|
2012-11-23 02:32:55 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
match = false;
|
2012-11-23 02:32:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
return match;
|
2012-11-21 01:29:57 +00:00
|
|
|
}
|
2012-12-01 20:11:00 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
public static int replaceBlocks(Location center, Material fromMaterial, Material toMaterial, int radius)
|
2012-12-01 20:11:00 +00:00
|
|
|
{
|
|
|
|
int affected = 0;
|
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
Block centerBlock = center.getBlock();
|
|
|
|
for (int xOffset = -radius; xOffset <= radius; xOffset++)
|
2012-12-01 20:11:00 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
for (int yOffset = -radius; yOffset <= radius; yOffset++)
|
2012-12-01 20:11:00 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
for (int zOffset = -radius; zOffset <= radius; zOffset++)
|
2012-12-01 20:11:00 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
Block block = centerBlock.getRelative(xOffset, yOffset, zOffset);
|
2012-12-01 20:11:00 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
if (block.getType().equals(fromMaterial))
|
2012-12-01 20:11:00 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
if (block.getLocation().distanceSquared(center) < (radius * radius))
|
2012-12-01 20:11:00 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
block.setType(toMaterial);
|
2012-12-01 20:11:00 +00:00
|
|
|
affected++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return affected;
|
|
|
|
}
|
2012-12-02 17:05:54 +00:00
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
public static void downloadFile(String url, File output) throws java.lang.Exception
|
2012-12-22 03:22:08 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
downloadFile(url, output, false);
|
2012-12-22 03:22:08 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
public static void downloadFile(String url, File output, boolean verbose) throws java.lang.Exception
|
2012-12-02 17:05:54 +00:00
|
|
|
{
|
|
|
|
URL website = new URL(url);
|
|
|
|
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
|
2013-08-25 16:32:01 +00:00
|
|
|
FileOutputStream fos = new FileOutputStream(output);
|
2012-12-02 17:05:54 +00:00
|
|
|
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
|
|
|
|
fos.close();
|
2012-12-22 03:22:08 +00:00
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
TFM_Log.info("Downloaded " + url + " to " + output.toString() + ".");
|
2012-12-22 03:22:08 +00:00
|
|
|
}
|
2012-12-02 17:05:54 +00:00
|
|
|
}
|
2012-12-02 17:27:10 +00:00
|
|
|
|
|
|
|
public static void adminChatMessage(CommandSender sender, String message, boolean senderIsConsole)
|
2012-11-28 18:31:01 +00:00
|
|
|
{
|
2013-05-06 20:04:10 +00:00
|
|
|
String name = sender.getName() + " " + getPrefix(sender, senderIsConsole);
|
2012-11-28 18:31:01 +00:00
|
|
|
TFM_Log.info("[ADMIN] " + name + ": " + message);
|
2012-12-02 17:27:10 +00:00
|
|
|
|
2013-08-14 14:01:42 +00:00
|
|
|
for (Player player : Bukkit.getOnlinePlayers())
|
2012-11-28 18:31:01 +00:00
|
|
|
{
|
2013-08-14 14:01:42 +00:00
|
|
|
if (TFM_SuperadminList.isUserSuperadmin(player))
|
2012-11-28 18:31:01 +00:00
|
|
|
{
|
2013-08-14 14:01:42 +00:00
|
|
|
player.sendMessage("[" + ChatColor.AQUA + "ADMIN" + ChatColor.WHITE + "] " + ChatColor.DARK_RED + name + ": " + ChatColor.AQUA + message);
|
2012-11-28 18:31:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-02 18:31:22 +00:00
|
|
|
|
2013-05-06 20:04:10 +00:00
|
|
|
public static String getPrefix(CommandSender sender, boolean senderIsConsole)
|
|
|
|
{
|
|
|
|
String prefix;
|
2013-07-02 18:31:22 +00:00
|
|
|
if (senderIsConsole)
|
|
|
|
{
|
|
|
|
prefix = ChatColor.BLUE + "(Console)";
|
2013-06-03 21:06:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-06 20:04:10 +00:00
|
|
|
if (TFM_SuperadminList.isSeniorAdmin(sender))
|
|
|
|
{
|
|
|
|
prefix = ChatColor.LIGHT_PURPLE + "(SrA)";
|
2013-07-02 18:31:22 +00:00
|
|
|
}
|
|
|
|
else
|
2013-05-06 20:04:10 +00:00
|
|
|
{
|
|
|
|
prefix = ChatColor.GOLD + "(SA)";
|
|
|
|
}
|
2013-06-03 21:06:23 +00:00
|
|
|
if (DEVELOPERS.contains(sender.getName()))
|
2013-05-06 20:04:10 +00:00
|
|
|
{
|
|
|
|
prefix = ChatColor.DARK_PURPLE + "(Dev)";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return prefix + ChatColor.WHITE;
|
|
|
|
}
|
2013-03-21 00:19:07 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2013-05-06 20:04:10 +00:00
|
|
|
sb.append(line).append(preserveNewlines ? System.getProperty("line.separator") : "");
|
2013-03-21 00:19:07 +00:00
|
|
|
}
|
|
|
|
return sb.toString();
|
|
|
|
}
|
2013-04-10 02:05:24 +00:00
|
|
|
|
|
|
|
//getField: Borrowed from WorldEdit
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public static <T> T getField(Object from, String name)
|
|
|
|
{
|
|
|
|
Class<?> checkClass = from.getClass();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Field field = checkClass.getDeclaredField(name);
|
|
|
|
field.setAccessible(true);
|
|
|
|
return (T) field.get(from);
|
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (NoSuchFieldException ex)
|
2013-04-10 02:05:24 +00:00
|
|
|
{
|
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (IllegalAccessException ex)
|
2013-04-10 02:05:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (checkClass.getSuperclass() != Object.class && ((checkClass = checkClass.getSuperclass()) != null));
|
|
|
|
return null;
|
|
|
|
}
|
2013-07-04 16:10:08 +00:00
|
|
|
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();
|
2013-07-11 01:46:29 +00:00
|
|
|
|
2013-07-04 16:10:08 +00:00
|
|
|
public static ChatColor randomChatColor()
|
|
|
|
{
|
|
|
|
return COLOR_POOL.get(RANDOM.nextInt(COLOR_POOL.size()));
|
|
|
|
}
|
2013-08-12 10:26:49 +00:00
|
|
|
|
|
|
|
public static String colorise(String string)
|
|
|
|
{
|
|
|
|
return ChatColor.translateAlternateColorCodes('&', string);
|
|
|
|
}
|
2011-10-13 23:07:52 +00:00
|
|
|
}
|