mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-11 21:43:54 +00:00
TotalFreedomMod Electrum
Version 5.0 This TotalFreedomMod release implements many changes. Most notably, the internals have been completely revamped. TotalFreedomMod now relies on the Aero library for core mechanics such as command handling and services. Another important change is the UUID system. In TotalFreedomMod Electrum, it has been completely removed. The core reason for this is that the system as a whole was very bugged. Additionally, it did not solve the primary reason for its conception: preserving player data when the player changes their username. This is because TotalFreedomMod servers usually run in offline-mode. This meaning that some of the players joining do not have a registerd Mojang UUID whatsoever. All in all, the UUID system was buggy, and it did not fix the reason it was implemented, so it has been completely removed. The admin list and the ban list now use usernames and IPs again. Lastly, many smaller changes have been implemented. Due to the amount of changes, they have not been named individualy. Please refer to the issues below for more details. Fixes #342 Fixes #350 Fixes #380 Fixes #684 Fixes #704 Fixes #716 Fixes #735 Fixes #745 Fixes #784 Fixes #765 Fixes #791 Fixes #805 Fixes #826 Fixes #883 Fixes #1524 Fixes #1534 Fixes #1536 Fixes #1538 Fixes #1545 Fixes #1546 Fixes #1568 Fixes #1627 Resolves #403 Resolves #435 Resolves #597 Resolves #603 Resolves #628 Resolves #690 Resolves #708 Resolves #747 Resolves #748 Resolves #749 Resolves #764 Resolves #767 Resolves #782 Resolves #809 Resolves #803 Resolves #811 Resolves #813 Resolves #830 Resolves #848 Resolves #856 Resolves #876 Resolves #908 Resolves #992 Resolves #1018 Resolves #1432 Resolves #1446 Resolves #1494 Resolves #1501 Resolves #1526 Resolves #1540 Resolves #1550 Resolves #1560 Resolves #1561 Resolves #1578 Resolves #1613
This commit is contained in:
@ -12,7 +12,6 @@ public class FLog
|
||||
|
||||
private FLog()
|
||||
{
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
// Level.INFO:
|
||||
|
@ -11,6 +11,7 @@ public class FSync
|
||||
|
||||
public static void playerMsg(final Player player, final String message)
|
||||
{
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@ -20,11 +21,12 @@ public class FSync
|
||||
FUtil.playerMsg(player, message);
|
||||
}
|
||||
|
||||
}.runTask(TotalFreedomMod.plugin);
|
||||
}.runTask(plugin);
|
||||
}
|
||||
|
||||
public static void playerKick(final Player player, final String reason)
|
||||
{
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@ -34,39 +36,42 @@ public class FSync
|
||||
player.kickPlayer(reason);
|
||||
}
|
||||
|
||||
}.runTask(TotalFreedomMod.plugin);
|
||||
}.runTask(plugin);
|
||||
}
|
||||
|
||||
public static void adminChatMessage(final CommandSender sender, final String message)
|
||||
{
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
FUtil.adminChatMessage(sender, message);
|
||||
plugin.cm.adminChat(sender, message);
|
||||
}
|
||||
|
||||
}.runTask(TotalFreedomMod.plugin);
|
||||
}.runTask(plugin);
|
||||
}
|
||||
|
||||
public static void autoEject(final Player player, final String kickMessage)
|
||||
{
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
FUtil.autoEject(player, kickMessage);
|
||||
plugin.ae.autoEject(player, kickMessage);
|
||||
}
|
||||
|
||||
}.runTask(TotalFreedomMod.plugin);
|
||||
}.runTask(plugin);
|
||||
}
|
||||
|
||||
public static void bcastMsg(final String message, final ChatColor color)
|
||||
{
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@ -76,6 +81,6 @@ public class FSync
|
||||
FUtil.bcastMsg(message, color);
|
||||
}
|
||||
|
||||
}.runTask(TotalFreedomMod.plugin);
|
||||
}.runTask(plugin);
|
||||
}
|
||||
}
|
||||
|
@ -2,17 +2,7 @@ package me.totalfreedom.totalfreedommod.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
@ -26,40 +16,25 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.banning.Ban;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import net.pravian.aero.config.YamlConfig;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.FileUtil;
|
||||
|
||||
public class FUtil
|
||||
{
|
||||
|
||||
private static final Map<String, Integer> EJECT_TRACKER = new HashMap<>();
|
||||
private static final Random RANDOM = new Random();
|
||||
//
|
||||
public static final String SAVED_FLAGS_FILENAME = "savedflags.dat";
|
||||
public static final Map<String, EntityType> MOB_TYPES = new HashMap<>();
|
||||
// See https://github.com/TotalFreedom/License - None of the listed names may be removed.
|
||||
public static final List<String> DEVELOPERS = Arrays.asList("Madgeek1450", "Prozza", "Wild1145", "WickedGamingUK");
|
||||
public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
|
||||
@ -80,23 +55,6 @@ public class FUtil
|
||||
|
||||
static
|
||||
{
|
||||
for (EntityType type : EntityType.values())
|
||||
{
|
||||
try
|
||||
{
|
||||
if (DepreciationAggregator.getName_EntityType(type) != null)
|
||||
{
|
||||
if (Creature.class.isAssignableFrom(type.getEntityClass()))
|
||||
{
|
||||
MOB_TYPES.put(DepreciationAggregator.getName_EntityType(type).toLowerCase(), type);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
for (ChatColor chatColor : CHAT_COLOR_POOL)
|
||||
{
|
||||
CHAT_COLOR_NAMES.put(chatColor.name().toLowerCase().replace("_", ""), chatColor);
|
||||
@ -105,7 +63,6 @@ public class FUtil
|
||||
|
||||
private FUtil()
|
||||
{
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static void cancel(BukkitTask task)
|
||||
@ -162,19 +119,6 @@ public class FUtil
|
||||
FUtil.bcastMsg(adminName + " - " + action, (isRed ? ChatColor.RED : ChatColor.AQUA));
|
||||
}
|
||||
|
||||
public static boolean isUniqueId(String uuid)
|
||||
{
|
||||
try
|
||||
{
|
||||
UUID.fromString(uuid);
|
||||
return true;
|
||||
}
|
||||
catch (IllegalArgumentException ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatLocation(Location location)
|
||||
{
|
||||
return String.format("%s: (%d, %d, %d)",
|
||||
@ -184,109 +128,6 @@ public class FUtil
|
||||
Math.round(location.getZ()));
|
||||
}
|
||||
|
||||
public static String formatPlayer(Player player)
|
||||
{
|
||||
return player.getName() + " (" + Ips.getIp(player) + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes an IP-address to a config-friendly version.
|
||||
*
|
||||
* <p>
|
||||
* Example:
|
||||
* <pre>
|
||||
* IpUtils.toEscapedString("192.168.1.192"); // 192_168_1_192
|
||||
* </pre></p>
|
||||
*
|
||||
* @param ip The IP-address to escape.
|
||||
* @return The config-friendly IP address.
|
||||
* @see #fromEscapedString(String)
|
||||
*/
|
||||
public static String toEscapedString(String ip) // BukkitLib @ https://github.com/Pravian/BukkitLib
|
||||
{
|
||||
return ip.trim().replaceAll("\\.", "_");
|
||||
}
|
||||
|
||||
/**
|
||||
* Un-escapes a config-friendly Ipv4-address.
|
||||
*
|
||||
* <p>
|
||||
* Example:
|
||||
* <pre>
|
||||
* IpUtils.fromEscapedString("192_168_1_192"); // 192.168.1.192
|
||||
* </pre></p>
|
||||
*
|
||||
* @param escapedIp The IP-address to un-escape.
|
||||
* @return The config-friendly IP address.
|
||||
* @see #toEscapedString(String)
|
||||
*/
|
||||
public static String fromEscapedString(String escapedIp) // BukkitLib @ https://github.com/Pravian/BukkitLib
|
||||
{
|
||||
return escapedIp.trim().replaceAll("_", "\\.");
|
||||
}
|
||||
|
||||
public static void gotoWorld(Player player, String targetWorld)
|
||||
{
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getWorld().getName().equalsIgnoreCase(targetWorld))
|
||||
{
|
||||
playerMsg(player, "Going to main world.", ChatColor.GRAY);
|
||||
player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation());
|
||||
return;
|
||||
}
|
||||
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
if (world.getName().equalsIgnoreCase(targetWorld))
|
||||
{
|
||||
playerMsg(player, "Going to world: " + targetWorld, ChatColor.GRAY);
|
||||
player.teleport(world.getSpawnLocation());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
playerMsg(player, "World " + targetWorld + " not found.", ChatColor.GRAY);
|
||||
}
|
||||
|
||||
public static String decolorize(String string)
|
||||
{
|
||||
return string.replaceAll("\\u00A7(?=[0-9a-fk-or])", "&");
|
||||
}
|
||||
|
||||
public static void setWorldTime(World world, long ticks)
|
||||
{
|
||||
long time = world.getTime();
|
||||
time -= time % 24000;
|
||||
world.setTime(time + 24000 + ticks);
|
||||
}
|
||||
|
||||
public static void createDefaultConfiguration(final String configFileName)
|
||||
{
|
||||
final File targetFile = new File(TotalFreedomMod.plugin.getDataFolder(), configFileName);
|
||||
|
||||
if (targetFile.exists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FLog.info("Installing default configuration file template: " + targetFile.getPath());
|
||||
|
||||
try
|
||||
{
|
||||
final InputStream configFileStream = TotalFreedomMod.plugin.getResource(configFileName);
|
||||
FileUtils.copyInputStreamToFile(configFileStream, targetFile);
|
||||
configFileStream.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean deleteFolder(final File file)
|
||||
{
|
||||
if (file.exists() && file.isDirectory())
|
||||
@ -314,128 +155,6 @@ public class FUtil
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityType getEntityType(String mobname) throws Exception
|
||||
{
|
||||
mobname = mobname.toLowerCase().trim();
|
||||
|
||||
if (!FUtil.MOB_TYPES.containsKey(mobname))
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
return FUtil.MOB_TYPES.get(mobname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the specified InputStream to a file.
|
||||
*
|
||||
* @param in The InputStream from which to read.
|
||||
* @param file The File to write to.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void copy(InputStream in, File file) throws IOException // BukkitLib @ https://github.com/Pravian/BukkitLib
|
||||
{
|
||||
if (!file.exists())
|
||||
{
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
final OutputStream out = new FileOutputStream(file);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0)
|
||||
{
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a file at located at the Plugins Data folder.
|
||||
*
|
||||
* @param plugin The plugin to use
|
||||
* @param name The name of the file.
|
||||
* @return The requested file.
|
||||
*/
|
||||
public static File getPluginFile(Plugin plugin, String name) // BukkitLib @ https://github.com/Pravian/BukkitLib
|
||||
{
|
||||
return new File(plugin.getDataFolder(), name);
|
||||
}
|
||||
|
||||
public static void autoEject(Player player, String kickMessage)
|
||||
{
|
||||
EjectMethod method = EjectMethod.STRIKE_ONE;
|
||||
final String ip = Ips.getIp(player);
|
||||
|
||||
if (!FUtil.EJECT_TRACKER.containsKey(ip))
|
||||
{
|
||||
FUtil.EJECT_TRACKER.put(ip, 0);
|
||||
}
|
||||
|
||||
int kicks = FUtil.EJECT_TRACKER.get(ip);
|
||||
kicks += 1;
|
||||
|
||||
FUtil.EJECT_TRACKER.put(ip, kicks);
|
||||
|
||||
if (kicks <= 1)
|
||||
{
|
||||
method = EjectMethod.STRIKE_ONE;
|
||||
}
|
||||
else if (kicks == 2)
|
||||
{
|
||||
method = EjectMethod.STRIKE_TWO;
|
||||
}
|
||||
else if (kicks >= 3)
|
||||
{
|
||||
method = EjectMethod.STRIKE_THREE;
|
||||
}
|
||||
|
||||
FLog.info("AutoEject -> name: " + player.getName() + " - player ip: " + ip + " - method: " + method.toString());
|
||||
|
||||
player.setOp(false);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.getInventory().clear();
|
||||
|
||||
switch (method)
|
||||
{
|
||||
case STRIKE_ONE:
|
||||
{
|
||||
final Calendar cal = new GregorianCalendar();
|
||||
cal.add(Calendar.MINUTE, 1);
|
||||
final Date expires = cal.getTime();
|
||||
|
||||
FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 1 minute.");
|
||||
|
||||
TotalFreedomMod.plugin.bm.addBan(Ban.forPlayer(player, Bukkit.getConsoleSender(), expires, kickMessage));
|
||||
player.kickPlayer(kickMessage);
|
||||
|
||||
break;
|
||||
}
|
||||
case STRIKE_TWO:
|
||||
{
|
||||
final Calendar c = new GregorianCalendar();
|
||||
c.add(Calendar.MINUTE, 3);
|
||||
final Date expires = c.getTime();
|
||||
|
||||
FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 3 minutes.");
|
||||
|
||||
TotalFreedomMod.plugin.bm.addBan(Ban.forPlayer(player, Bukkit.getConsoleSender(), expires, kickMessage));
|
||||
player.kickPlayer(kickMessage);
|
||||
break;
|
||||
}
|
||||
case STRIKE_THREE:
|
||||
{
|
||||
TotalFreedomMod.plugin.bm.addBan(Ban.forPlayerFuzzy(player, Bukkit.getConsoleSender(), null, kickMessage));
|
||||
|
||||
FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned.");
|
||||
|
||||
player.kickPlayer(kickMessage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Date parseDateOffset(String time)
|
||||
{
|
||||
Pattern timePattern = Pattern.compile(
|
||||
@ -551,149 +270,6 @@ public class FUtil
|
||||
return StringUtils.join(names, ", ");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, Boolean> getSavedFlags()
|
||||
{
|
||||
Map<String, Boolean> flags = null;
|
||||
|
||||
File input = new File(TotalFreedomMod.plugin.getDataFolder(), SAVED_FLAGS_FILENAME);
|
||||
if (input.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
FileInputStream fis = new FileInputStream(input);
|
||||
ObjectInputStream ois = new ObjectInputStream(fis);
|
||||
flags = (HashMap<String, Boolean>) ois.readObject();
|
||||
ois.close();
|
||||
fis.close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
public static boolean getSavedFlag(String flag) throws Exception
|
||||
{
|
||||
Boolean flagValue = null;
|
||||
|
||||
Map<String, Boolean> flags = FUtil.getSavedFlags();
|
||||
|
||||
if (flags != null)
|
||||
{
|
||||
if (flags.containsKey(flag))
|
||||
{
|
||||
flagValue = flags.get(flag);
|
||||
}
|
||||
}
|
||||
|
||||
if (flagValue != null)
|
||||
{
|
||||
return flagValue.booleanValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setSavedFlag(String flag, boolean value)
|
||||
{
|
||||
Map<String, Boolean> flags = FUtil.getSavedFlags();
|
||||
|
||||
if (flags == null)
|
||||
{
|
||||
flags = new HashMap<>();
|
||||
}
|
||||
|
||||
flags.put(flag, value);
|
||||
|
||||
try
|
||||
{
|
||||
final FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), SAVED_FLAGS_FILENAME));
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||
oos.writeObject(flags);
|
||||
oos.close();
|
||||
fos.close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void createBackups(String file)
|
||||
{
|
||||
createBackups(file, false);
|
||||
}
|
||||
|
||||
public static void createBackups(String file, boolean onlyWeekly)
|
||||
{
|
||||
final String save = file.split("\\.")[0];
|
||||
final YamlConfig config = new YamlConfig(TotalFreedomMod.plugin, "backup/backup.yml", false);
|
||||
config.load();
|
||||
|
||||
// Weekly
|
||||
if (!config.isInt(save + ".weekly"))
|
||||
{
|
||||
performBackup(file, "weekly");
|
||||
config.set(save + ".weekly", FUtil.getUnixTime());
|
||||
}
|
||||
else
|
||||
{
|
||||
int lastBackupWeekly = config.getInt(save + ".weekly");
|
||||
|
||||
if (lastBackupWeekly + 3600 * 24 * 7 < FUtil.getUnixTime())
|
||||
{
|
||||
performBackup(file, "weekly");
|
||||
config.set(save + ".weekly", FUtil.getUnixTime());
|
||||
}
|
||||
}
|
||||
|
||||
if (onlyWeekly)
|
||||
{
|
||||
config.save();
|
||||
return;
|
||||
}
|
||||
|
||||
// Daily
|
||||
if (!config.isInt(save + ".daily"))
|
||||
{
|
||||
performBackup(file, "daily");
|
||||
config.set(save + ".daily", FUtil.getUnixTime());
|
||||
}
|
||||
else
|
||||
{
|
||||
int lastBackupDaily = config.getInt(save + ".daily");
|
||||
|
||||
if (lastBackupDaily + 3600 * 24 < FUtil.getUnixTime())
|
||||
{
|
||||
performBackup(file, "daily");
|
||||
config.set(save + ".daily", FUtil.getUnixTime());
|
||||
}
|
||||
}
|
||||
|
||||
config.save();
|
||||
}
|
||||
|
||||
private static void performBackup(String file, String type)
|
||||
{
|
||||
FLog.info("Backing up " + file + " to " + file + "." + type + ".bak");
|
||||
final File backupFolder = new File(TotalFreedomMod.plugin.getDataFolder(), "backup");
|
||||
|
||||
if (!backupFolder.exists())
|
||||
{
|
||||
backupFolder.mkdirs();
|
||||
}
|
||||
|
||||
final File oldYaml = new File(TotalFreedomMod.plugin.getDataFolder(), file);
|
||||
final File newYaml = new File(backupFolder, file + "." + type + ".bak");
|
||||
FileUtil.copy(oldYaml, newYaml);
|
||||
}
|
||||
|
||||
public static String dateToString(Date date)
|
||||
{
|
||||
return new SimpleDateFormat(DATE_STORAGE_FORMAT, Locale.ENGLISH).format(date);
|
||||
@ -711,23 +287,9 @@ public class FUtil
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static boolean isFromHostConsole(String senderName)
|
||||
{
|
||||
return ((List<String>) ConfigEntry.HOST_SENDER_NAMES.getList()).contains(senderName.toLowerCase());
|
||||
}
|
||||
|
||||
public static List<String> removeDuplicates(List<String> oldList)
|
||||
{
|
||||
List<String> newList = new ArrayList<>();
|
||||
for (String entry : oldList)
|
||||
{
|
||||
if (!newList.contains(entry))
|
||||
{
|
||||
newList.add(entry);
|
||||
}
|
||||
}
|
||||
return newList;
|
||||
return ConfigEntry.HOST_SENDER_NAMES.getList().contains(senderName.toLowerCase());
|
||||
}
|
||||
|
||||
public static boolean fuzzyIpMatch(String a, String b, int octets)
|
||||
@ -779,67 +341,6 @@ public class FUtil
|
||||
return ip;
|
||||
}
|
||||
|
||||
public static int replaceBlocks(Location center, Material fromMaterial, Material toMaterial, int radius)
|
||||
{
|
||||
int affected = 0;
|
||||
|
||||
Block centerBlock = center.getBlock();
|
||||
for (int xOffset = -radius; xOffset <= radius; xOffset++)
|
||||
{
|
||||
for (int yOffset = -radius; yOffset <= radius; yOffset++)
|
||||
{
|
||||
for (int zOffset = -radius; zOffset <= radius; zOffset++)
|
||||
{
|
||||
Block block = centerBlock.getRelative(xOffset, yOffset, zOffset);
|
||||
|
||||
if (block.getType().equals(fromMaterial))
|
||||
{
|
||||
if (block.getLocation().distanceSquared(center) < (radius * radius))
|
||||
{
|
||||
block.setType(toMaterial);
|
||||
affected++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return affected;
|
||||
}
|
||||
|
||||
public static void downloadFile(String url, File output) throws java.lang.Exception
|
||||
{
|
||||
downloadFile(url, output, false);
|
||||
}
|
||||
|
||||
public static void downloadFile(String url, File output, boolean verbose) throws java.lang.Exception
|
||||
{
|
||||
final URL website = new URL(url);
|
||||
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(output);
|
||||
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
|
||||
fos.close();
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
FLog.info("Downloaded " + url + " to " + output.toString() + ".");
|
||||
}
|
||||
}
|
||||
|
||||
public static void adminChatMessage(CommandSender sender, String message)
|
||||
{
|
||||
String name = sender.getName() + " " + TotalFreedomMod.plugin.rm.getDisplay(sender).getColoredTag() + ChatColor.WHITE;
|
||||
FLog.info("[ADMIN] " + name + ": " + message);
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (TotalFreedomMod.plugin.al.isAdmin(player))
|
||||
{
|
||||
player.sendMessage("[" + ChatColor.AQUA + "ADMIN" + ChatColor.WHITE + "] " + ChatColor.DARK_RED + name + ": " + ChatColor.AQUA + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//getField: Borrowed from WorldEdit
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getField(Object from, String name)
|
||||
@ -854,10 +355,7 @@ public class FUtil
|
||||
return (T) field.get(from);
|
||||
|
||||
}
|
||||
catch (NoSuchFieldException ex)
|
||||
{
|
||||
}
|
||||
catch (IllegalAccessException ex)
|
||||
catch (NoSuchFieldException | IllegalAccessException ex)
|
||||
{
|
||||
}
|
||||
} while (checkClass.getSuperclass() != Object.class
|
||||
@ -900,55 +398,6 @@ public class FUtil
|
||||
{
|
||||
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||
return packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||
|
||||
}
|
||||
|
||||
public static void reportAction(Player reporter, Player reported, String report)
|
||||
{
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (TotalFreedomMod.plugin.al.isAdmin(player))
|
||||
{
|
||||
playerMsg(player, ChatColor.RED + "[REPORTS] " + ChatColor.GOLD + reporter.getName() + " has reported " + reported.getName() + " for " + report);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static enum EjectMethod
|
||||
{
|
||||
|
||||
STRIKE_ONE, STRIKE_TWO, STRIKE_THREE;
|
||||
}
|
||||
|
||||
public static class MethodTimer
|
||||
{
|
||||
|
||||
private long lastStart;
|
||||
private long total = 0;
|
||||
|
||||
public MethodTimer()
|
||||
{
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
this.lastStart = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
this.total += (System.currentTimeMillis() - this.lastStart);
|
||||
}
|
||||
|
||||
public long getTotal()
|
||||
{
|
||||
return this.total;
|
||||
}
|
||||
|
||||
public void printTotalToLog(String timerName)
|
||||
{
|
||||
FLog.info("DEBUG: " + timerName + " used " + this.getTotal() + " ms.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package me.totalfreedom.totalfreedommod.util;
|
||||
|
||||
public class MethodTimer
|
||||
{
|
||||
|
||||
private long lastStart;
|
||||
private long total = 0;
|
||||
|
||||
public MethodTimer()
|
||||
{
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
this.lastStart = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
this.total += (System.currentTimeMillis() - this.lastStart);
|
||||
}
|
||||
|
||||
public long getTotal()
|
||||
{
|
||||
return this.total;
|
||||
}
|
||||
|
||||
public void printTotalToLog(String timerName)
|
||||
{
|
||||
FLog.info("DEBUG: " + timerName + " used " + this.getTotal() + " ms.");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user