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:
Paldiu
2020-12-25 14:46:43 -05:00
parent 210b0f8b43
commit 5c0f77c7c5
170 changed files with 3302 additions and 2383 deletions

View File

@ -78,16 +78,6 @@ public class FLog
getLogger(false).log(level, null, throwable);
}
public static void setServerLogger(Logger logger)
{
serverLogger = logger;
}
public static void setPluginLogger(Logger logger)
{
pluginLogger = logger;
}
private static Logger getLogger(boolean raw)
{
if (raw || pluginLogger == null)
@ -105,8 +95,18 @@ public class FLog
return (pluginLogger != null ? pluginLogger : FALLBACK_LOGGER);
}
public static void setPluginLogger(Logger logger)
{
pluginLogger = logger;
}
public static Logger getServerLogger()
{
return (serverLogger != null ? serverLogger : FALLBACK_LOGGER);
}
public static void setServerLogger(Logger logger)
{
serverLogger = logger;
}
}

View File

@ -12,6 +12,7 @@ public class FSync
public static void playerMsg(final Player player, final String message)
{
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
assert plugin != null;
new BukkitRunnable()
{
@ -27,6 +28,7 @@ public class FSync
public static void playerMsg(final CommandSender sender, final String message)
{
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
assert plugin != null;
new BukkitRunnable()
{
@ -42,6 +44,7 @@ public class FSync
public static void playerKick(final Player player, final String reason)
{
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
assert plugin != null;
new BukkitRunnable()
{
@ -57,6 +60,7 @@ public class FSync
public static void adminChatMessage(final CommandSender sender, final String message)
{
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
assert plugin != null;
new BukkitRunnable()
{
@ -72,6 +76,7 @@ public class FSync
public static void autoEject(final Player player, final String kickMessage)
{
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
assert plugin != null;
new BukkitRunnable()
{
@ -87,6 +92,7 @@ public class FSync
public static void bcastMsg(final String message, final ChatColor color)
{
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
assert plugin != null;
new BukkitRunnable()
{

View File

@ -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);
}

View File

@ -10,6 +10,7 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Objects;
import java.util.UUID;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import org.bukkit.ChatColor;
@ -64,7 +65,7 @@ public class History
FSync.playerMsg(sender, ChatColor.RED + "Player not found!");
}
}
}.runTaskAsynchronously(TotalFreedomMod.plugin());
}.runTaskAsynchronously(Objects.requireNonNull(TotalFreedomMod.plugin()));
}
private static void printHistory(CommandSender sender, FName[] oldNames)
@ -85,9 +86,15 @@ public class History
private static class FName implements Comparable<FName>
{
private final String name;
private final long changedToAt;
private String name;
private long changedToAt;
//Added constructor because otherwise there's no way name or changedToAt would have been anything other than null.
public FName(String name, long changedToAt)
{
this.name = name;
this.changedToAt = changedToAt;
}
@Override
public int compareTo(FName other)

View File

@ -1,16 +1,13 @@
package me.totalfreedom.totalfreedommod.util;
import lombok.Getter;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class Response
{
@Getter
private int code;
@Getter
private String message;
private final int code;
private final String message;
public Response(int code, String message)
{
@ -20,6 +17,16 @@ public class Response
public JSONObject getJSONMessage() throws ParseException
{
return (JSONObject) new JSONParser().parse(message);
return (JSONObject)new JSONParser().parse(message);
}
public int getCode()
{
return code;
}
public String getMessage()
{
return message;
}
}

View File

@ -55,7 +55,7 @@ public class UUIDFetcher
return null;
}
private class FetchedUuid
private static class FetchedUuid
{
private String id;