mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-07-01 20:46:41 +00:00
Removal of Lombok
Lombok implementation removal. I have also gone through and replaced things with inline methods and variables, lambdas, and simplified loops down, removed unnecessary guard clauses, and overall cleaned up every single class. This took a long time, please do remember to follow proper naming conventions, don't include unnecessary guard clauses, follow exception rules and comment rules, and please PLEASE remember to use the DIAMOND OPERATOR rather than just inferring RAW TYPES!!! Thank you!!
This commit is contained in:
@ -3,7 +3,6 @@ package me.totalfreedom.totalfreedommod.util;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Field;
|
||||
@ -21,6 +20,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
@ -52,7 +52,6 @@ import static org.bukkit.Bukkit.getServer;
|
||||
public class FUtil
|
||||
{
|
||||
|
||||
private static final Random RANDOM = new Random();
|
||||
public static final String SAVED_FLAGS_FILENAME = "savedflags.dat";
|
||||
/* See https://github.com/TotalFreedom/License - None of the listed names may be removed.
|
||||
Leaving this list here for anyone running TFM on a cracked server:
|
||||
@ -72,7 +71,6 @@ public class FUtil
|
||||
"c8e5af82-6aba-4dd7-83e8-474381380cc9" // Paldiu
|
||||
);
|
||||
public static final List<String> DEVELOPER_NAMES = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "Wild1145", "aggelosQQ", "scripthead", "CoolJWB", "elmon_", "speednt", "SupItsDillon", "Paldiu");
|
||||
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,
|
||||
@ -87,9 +85,10 @@ public class FUtil
|
||||
ChatColor.DARK_BLUE,
|
||||
ChatColor.DARK_PURPLE,
|
||||
ChatColor.LIGHT_PURPLE);
|
||||
private static Iterator<ChatColor> CHAT_COLOR_ITERATOR;
|
||||
private static String CHARACTER_STRING = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
private static Map<Integer, String> TIMEZONE_LOOKUP = new HashMap<>();
|
||||
private static final Random RANDOM = new Random();
|
||||
private static final String CHARACTER_STRING = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
private static final Map<Integer, String> TIMEZONE_LOOKUP = new HashMap<>();
|
||||
public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
|
||||
|
||||
static
|
||||
{
|
||||
@ -128,7 +127,7 @@ public class FUtil
|
||||
{
|
||||
task.cancel();
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -163,7 +162,7 @@ public class FUtil
|
||||
List<String> names = new ArrayList<>();
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (!TotalFreedomMod.plugin().al.isVanished(player.getName()))
|
||||
if (!Objects.requireNonNull(TotalFreedomMod.plugin()).al.isVanished(player.getName()))
|
||||
{
|
||||
names.add(player.getName());
|
||||
}
|
||||
@ -232,6 +231,7 @@ public class FUtil
|
||||
return names;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static UUID nameToUUID(String name)
|
||||
{
|
||||
try
|
||||
@ -288,7 +288,7 @@ public class FUtil
|
||||
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuffer response = new StringBuffer();
|
||||
StringBuilder response = new StringBuilder();
|
||||
|
||||
while ((inputLine = in.readLine()) != null)
|
||||
{
|
||||
@ -354,7 +354,7 @@ public class FUtil
|
||||
public static String formatLocation(Location location)
|
||||
{
|
||||
return String.format("%s: (%d, %d, %d)",
|
||||
location.getWorld().getName(),
|
||||
Objects.requireNonNull(location.getWorld()).getName(),
|
||||
Math.round(location.getX()),
|
||||
Math.round(location.getY()),
|
||||
Math.round(location.getZ()));
|
||||
@ -371,14 +371,7 @@ public class FUtil
|
||||
|
||||
public static void deleteCoreDumps()
|
||||
{
|
||||
final File[] coreDumps = new File(".").listFiles(new FileFilter()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(File file)
|
||||
{
|
||||
return file.getName().startsWith("java.core");
|
||||
}
|
||||
});
|
||||
final File[] coreDumps = new File(".").listFiles(file -> file.getName().startsWith("java.core"));
|
||||
|
||||
for (File dump : coreDumps)
|
||||
{
|
||||
@ -545,7 +538,7 @@ public class FUtil
|
||||
octets = 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < octets && i < 4; i++)
|
||||
for (int i = 0; i < octets; i++)
|
||||
{
|
||||
if (aParts[i].equals("*") || bParts[i].equals("*"))
|
||||
{
|
||||
@ -587,7 +580,7 @@ public class FUtil
|
||||
return (T)field.get(from);
|
||||
|
||||
}
|
||||
catch (NoSuchFieldException | IllegalAccessException ex)
|
||||
catch (NoSuchFieldException | IllegalAccessException ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -604,7 +597,7 @@ public class FUtil
|
||||
|
||||
public static String rainbowify(String string)
|
||||
{
|
||||
CHAT_COLOR_ITERATOR = CHAT_COLOR_POOL.iterator();
|
||||
Iterator<ChatColor> CHAT_COLOR_ITERATOR = CHAT_COLOR_POOL.iterator();
|
||||
|
||||
StringBuilder newString = new StringBuilder();
|
||||
char[] chars = string.toCharArray();
|
||||
@ -666,37 +659,36 @@ public class FUtil
|
||||
public static int randomInteger(int min, int max)
|
||||
{
|
||||
int range = max - min + 1;
|
||||
int value = (int)(Math.random() * range) + min;
|
||||
return value;
|
||||
return (int)(Math.random() * range) + min;
|
||||
}
|
||||
|
||||
public static String randomString(int length)
|
||||
{
|
||||
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz0123456789-_=+[]{};:,.<>~";
|
||||
String randomString = "";
|
||||
StringBuilder randomString = new StringBuilder();
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
int selectedCharacter = randomInteger(1, characters.length()) - 1;
|
||||
|
||||
randomString += characters.charAt(selectedCharacter);
|
||||
randomString.append(characters.charAt(selectedCharacter));
|
||||
}
|
||||
|
||||
return randomString;
|
||||
return randomString.toString();
|
||||
|
||||
}
|
||||
|
||||
public static String randomAlphanumericString(int length)
|
||||
{
|
||||
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz0123456789";
|
||||
String randomString = "";
|
||||
StringBuilder randomString = new StringBuilder();
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
int selectedCharacter = randomInteger(1, characters.length()) - 1;
|
||||
|
||||
randomString += characters.charAt(selectedCharacter);
|
||||
randomString.append(characters.charAt(selectedCharacter));
|
||||
}
|
||||
|
||||
return randomString;
|
||||
return randomString.toString();
|
||||
|
||||
}
|
||||
|
||||
@ -736,6 +728,7 @@ public class FUtil
|
||||
{
|
||||
ItemStack stack = new ItemStack(material, amount);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
assert meta != null;
|
||||
meta.setDisplayName(FUtil.colorize(coloredName));
|
||||
List<String> loreList = new ArrayList<>();
|
||||
for (String entry : lore)
|
||||
@ -788,7 +781,7 @@ public class FUtil
|
||||
|
||||
public static String getIp(Player player)
|
||||
{
|
||||
return player.getAddress().getAddress().getHostAddress().trim();
|
||||
return Objects.requireNonNull(player.getAddress()).getAddress().getHostAddress().trim();
|
||||
}
|
||||
|
||||
public static String getIp(PlayerLoginEvent event)
|
||||
@ -809,12 +802,8 @@ public class FUtil
|
||||
|
||||
public static boolean isValidIPv4(String ip)
|
||||
{
|
||||
if (ip.matches("^([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))$")
|
||||
|| ip.matches("^([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([*])\\.([*])$"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return !ip.matches("^([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))$")
|
||||
&& !ip.matches("^([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([*])\\.([*])$");
|
||||
}
|
||||
|
||||
public static List<Color> createColorGradient(Color c1, Color c2, int steps)
|
||||
@ -868,7 +857,7 @@ public class FUtil
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
location.getWorld().createExplosion(location, power);
|
||||
Objects.requireNonNull(location.getWorld()).createExplosion(location, power);
|
||||
}
|
||||
}.runTaskLater(TotalFreedomMod.getPlugin(), delay);
|
||||
}
|
||||
|
Reference in New Issue
Block a user