2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.util;
|
2011-10-13 23:07:52 +00:00
|
|
|
|
2014-08-23 18:19:25 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileFilter;
|
2013-04-10 02:05:24 +00:00
|
|
|
import java.lang.reflect.Field;
|
2012-11-13 01:42:30 +00:00
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.SimpleDateFormat;
|
2018-07-31 07:05:28 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.GregorianCalendar;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Random;
|
|
|
|
import java.util.Set;
|
2012-09-16 21:18:30 +00:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
2014-11-29 19:16:00 +00:00
|
|
|
import org.apache.commons.io.FileUtils;
|
2019-07-28 06:04:16 +00:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2013-11-30 15:32:00 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.OfflinePlayer;
|
2011-10-13 23:07:52 +00:00
|
|
|
import org.bukkit.command.CommandSender;
|
2013-11-30 15:32:00 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2015-11-15 23:32:04 +00:00
|
|
|
import org.bukkit.scheduler.BukkitTask;
|
2019-01-29 04:57:41 +00:00
|
|
|
import org.bukkit.Material;
|
2011-10-13 23:07:52 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public class FUtil
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
2017-11-27 07:04:53 +00:00
|
|
|
|
|
|
|
private static final Random RANDOM = new Random();
|
|
|
|
//
|
2016-03-02 19:28:01 +00:00
|
|
|
public static final String SAVED_FLAGS_FILENAME = "savedflags.dat";
|
2017-11-27 07:04:53 +00:00
|
|
|
// See https://github.com/TotalFreedom/License - None of the listed names may be removed.
|
2019-07-28 06:04:16 +00:00
|
|
|
public static final List<String> DEVELOPERS = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "OxLemonxO", "Wild1145", "Catholic_Mario", "Arcaknight", "AwesomePinch");
|
2017-11-27 07:04:53 +00:00
|
|
|
public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
|
|
|
|
public static final Map<String, ChatColor> CHAT_COLOR_NAMES = new HashMap<>();
|
|
|
|
public static final List<ChatColor> CHAT_COLOR_POOL = Arrays.asList(
|
|
|
|
ChatColor.DARK_RED,
|
|
|
|
ChatColor.RED,
|
|
|
|
ChatColor.GOLD,
|
|
|
|
ChatColor.YELLOW,
|
|
|
|
ChatColor.GREEN,
|
|
|
|
ChatColor.DARK_GREEN,
|
|
|
|
ChatColor.AQUA,
|
|
|
|
ChatColor.DARK_AQUA,
|
|
|
|
ChatColor.BLUE,
|
|
|
|
ChatColor.DARK_BLUE,
|
|
|
|
ChatColor.DARK_PURPLE,
|
|
|
|
ChatColor.LIGHT_PURPLE);
|
|
|
|
private static Iterator<ChatColor> CHAT_COLOR_ITERATOR;
|
|
|
|
|
|
|
|
static
|
|
|
|
{
|
|
|
|
for (ChatColor chatColor : CHAT_COLOR_POOL)
|
|
|
|
{
|
|
|
|
CHAT_COLOR_NAMES.put(chatColor.name().toLowerCase().replace("_", ""), chatColor);
|
2017-10-13 18:38:05 +00:00
|
|
|
}
|
2011-11-08 00:29:33 +00:00
|
|
|
}
|
2011-10-24 02:43:52 +00:00
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
public static void cancel(BukkitTask task)
|
|
|
|
{
|
|
|
|
if (task == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
task.cancel();
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-13 19:49:13 +00:00
|
|
|
public static boolean isExecutive(String name)
|
|
|
|
{
|
2018-05-15 06:11:24 +00:00
|
|
|
return ConfigEntry.SERVER_OWNERS.getStringList().contains(name) || ConfigEntry.SERVER_EXECUTIVES.getStringList().contains(name);
|
2018-05-13 19:49:13 +00:00
|
|
|
}
|
|
|
|
|
2019-04-23 07:36:51 +00:00
|
|
|
public static boolean canManageMasterBuilders(String name)
|
|
|
|
{
|
|
|
|
return ConfigEntry.SERVER_OWNERS.getStringList().contains(name) || ConfigEntry.SERVER_EXECUTIVES.getStringList().contains(name) || ConfigEntry.SERVER_MASTER_BUILDER_MANAGEMENT.getStringList().contains(name);
|
|
|
|
}
|
|
|
|
|
2019-01-29 04:57:41 +00:00
|
|
|
public static List<String> getPlayerList()
|
|
|
|
{
|
|
|
|
List<String> names = new ArrayList<>();
|
|
|
|
for (Player player : Bukkit.getOnlinePlayers())
|
|
|
|
{
|
|
|
|
names.add(player.getName());
|
|
|
|
}
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<String> getAllMaterialNames()
|
|
|
|
{
|
|
|
|
List<String> names = new ArrayList<>();
|
|
|
|
for (Material material : Material.values())
|
|
|
|
{
|
|
|
|
names.add(material.name());
|
|
|
|
}
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
2011-10-24 02:43:52 +00:00
|
|
|
public static void bcastMsg(String message, ChatColor color)
|
2011-10-13 23:07:52 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.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
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FUtil.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)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FUtil.playerMsg(sender, message, ChatColor.GRAY);
|
2012-09-14 22:49:44 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 12:52:01 +00:00
|
|
|
public static void setFlying(Player player, boolean flying)
|
|
|
|
{
|
2015-05-12 18:17:38 +00:00
|
|
|
player.setAllowFlight(true);
|
|
|
|
player.setFlying(flying);
|
|
|
|
}
|
|
|
|
|
2012-09-14 22:49:44 +00:00
|
|
|
public static void adminAction(String adminName, String action, boolean isRed)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FUtil.bcastMsg(adminName + " - " + action, (isRed ? ChatColor.RED : ChatColor.AQUA));
|
2015-02-16 16:00:38 +00:00
|
|
|
}
|
2014-04-21 15:45:32 +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
|
|
|
}
|
|
|
|
|
2018-01-01 03:43:10 +00:00
|
|
|
public static boolean deleteFolder(File file)
|
2011-10-14 05:31:21 +00:00
|
|
|
{
|
2013-09-24 12:05:48 +00:00
|
|
|
if (file.exists() && file.isDirectory())
|
2011-10-14 05:31:21 +00:00
|
|
|
{
|
2013-09-24 12:05:48 +00:00
|
|
|
return FileUtils.deleteQuietly(file);
|
2011-10-14 05:31:21 +00:00
|
|
|
}
|
2013-09-24 12:05:48 +00:00
|
|
|
return false;
|
2011-10-14 05:31:21 +00:00
|
|
|
}
|
2011-10-24 02:43:52 +00:00
|
|
|
|
2014-05-04 22:01:57 +00:00
|
|
|
public static void deleteCoreDumps()
|
|
|
|
{
|
|
|
|
final File[] coreDumps = new File(".").listFiles(new FileFilter()
|
|
|
|
{
|
|
|
|
@Override
|
2017-11-27 07:04:53 +00:00
|
|
|
public boolean accept(File file)
|
2014-05-04 22:01:57 +00:00
|
|
|
{
|
|
|
|
return file.getName().startsWith("java.core");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
for (File dump : coreDumps)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.info("Removing core dump file: " + dump.getName());
|
2014-05-04 22:01:57 +00:00
|
|
|
dump.delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]*)?"
|
2018-07-31 06:41:56 +00:00
|
|
|
+ "(?:([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);
|
2012-09-16 21:18:30 +00:00
|
|
|
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
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
List<String> names = new ArrayList<>();
|
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
|
|
|
|
2012-11-13 01:42:30 +00:00
|
|
|
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-25 16:32:01 +00:00
|
|
|
public static boolean isFromHostConsole(String senderName)
|
2012-11-18 03:57:24 +00:00
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
return ConfigEntry.HOST_SENDER_NAMES.getList().contains(senderName.toLowerCase());
|
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
|
|
|
|
2014-05-16 13:39:40 +00:00
|
|
|
public static String getFuzzyIp(String ip)
|
|
|
|
{
|
|
|
|
final String[] ipParts = ip.split("\\.");
|
|
|
|
if (ipParts.length == 4)
|
|
|
|
{
|
|
|
|
return String.format("%s.%s.*.*", ipParts[0], ipParts[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ip;
|
|
|
|
}
|
|
|
|
|
2013-04-10 02:05:24 +00:00
|
|
|
//getField: Borrowed from WorldEdit
|
|
|
|
@SuppressWarnings("unchecked")
|
2017-11-27 07:04:53 +00:00
|
|
|
public static <T> T getField(Object from, String name)
|
2013-04-10 02:05:24 +00:00
|
|
|
{
|
|
|
|
Class<?> checkClass = from.getClass();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Field field = checkClass.getDeclaredField(name);
|
|
|
|
field.setAccessible(true);
|
2018-07-31 07:01:29 +00:00
|
|
|
return (T)field.get(from);
|
2014-05-11 16:41:58 +00:00
|
|
|
|
2017-11-27 07:04:53 +00:00
|
|
|
}
|
2016-05-12 19:40:39 +00:00
|
|
|
catch (NoSuchFieldException | IllegalAccessException ex)
|
2013-04-10 02:05:24 +00:00
|
|
|
{
|
|
|
|
}
|
2018-07-31 06:41:56 +00:00
|
|
|
}
|
|
|
|
while (checkClass.getSuperclass() != Object.class
|
2017-11-27 07:04:53 +00:00
|
|
|
&& ((checkClass = checkClass.getSuperclass()) != null));
|
2014-05-11 16:41:58 +00:00
|
|
|
|
2013-04-10 02:05:24 +00:00
|
|
|
return null;
|
|
|
|
}
|
2013-07-11 01:46:29 +00:00
|
|
|
|
2017-11-27 07:04:53 +00:00
|
|
|
public static ChatColor randomChatColor()
|
|
|
|
{
|
|
|
|
return CHAT_COLOR_POOL.get(RANDOM.nextInt(CHAT_COLOR_POOL.size()));
|
2017-10-13 18:38:05 +00:00
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
|
2017-11-27 07:04:53 +00:00
|
|
|
public static String rainbowify(String string)
|
|
|
|
{
|
|
|
|
CHAT_COLOR_ITERATOR = CHAT_COLOR_POOL.iterator();
|
2017-12-23 04:07:36 +00:00
|
|
|
|
2018-01-01 03:43:10 +00:00
|
|
|
StringBuilder newString = new StringBuilder();
|
|
|
|
char[] chars = string.toCharArray();
|
2017-12-23 04:07:36 +00:00
|
|
|
|
2017-11-27 07:04:53 +00:00
|
|
|
for (char c : chars)
|
|
|
|
{
|
|
|
|
if (!CHAT_COLOR_ITERATOR.hasNext())
|
|
|
|
{
|
|
|
|
CHAT_COLOR_ITERATOR = CHAT_COLOR_POOL.iterator(); //Restart from first colour if there are no more colours in iterator.
|
|
|
|
}
|
|
|
|
newString.append(CHAT_COLOR_ITERATOR.next()).append(c);
|
2017-10-13 18:38:05 +00:00
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
|
2017-11-27 07:04:53 +00:00
|
|
|
return newString.toString();
|
2013-07-04 16:10:08 +00:00
|
|
|
}
|
2013-08-12 10:26:49 +00:00
|
|
|
|
2013-09-21 17:58:16 +00:00
|
|
|
public static String colorize(String string)
|
2013-08-12 10:26:49 +00:00
|
|
|
{
|
|
|
|
return ChatColor.translateAlternateColorCodes('&', string);
|
|
|
|
}
|
2013-09-24 12:05:48 +00:00
|
|
|
|
2015-11-22 18:26:47 +00:00
|
|
|
public static Date getUnixDate(long unix)
|
2014-04-04 14:48:39 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
return new Date(unix * 1000);
|
2014-04-04 14:48:39 +00:00
|
|
|
}
|
|
|
|
|
2015-11-22 18:26:47 +00:00
|
|
|
public static long getUnixTime()
|
2014-04-14 19:11:41 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
return System.currentTimeMillis() / 1000L;
|
2014-04-14 19:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static long getUnixTime(Date date)
|
|
|
|
{
|
|
|
|
if (date == null)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return date.getTime() / 1000L;
|
|
|
|
}
|
|
|
|
|
2017-12-28 05:50:39 +00:00
|
|
|
public static String getNMSVersion()
|
2014-05-04 22:01:57 +00:00
|
|
|
{
|
|
|
|
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
|
|
|
return packageName.substring(packageName.lastIndexOf('.') + 1);
|
2014-07-30 02:38:08 +00:00
|
|
|
}
|
2018-01-14 21:53:05 +00:00
|
|
|
|
|
|
|
public static int random(int min, int max)
|
|
|
|
{
|
|
|
|
int range = max - min + 1;
|
2018-07-31 07:01:29 +00:00
|
|
|
int value = (int)(Math.random() * range) + min;
|
2018-01-14 21:53:05 +00:00
|
|
|
return value;
|
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
}
|