Aggressive debloat

- Removes unused Logviewer functionality
- Removes several unused bits of code from FPlayer
- Changes the build configuration to not shade in org.apache.commons:commons-lang3, commons-io.commons-io,
  jetbrains.annotation, and org.javassist:javassist, opting instead to load them in on runtime using a
  little-known Spigot trick
This commit is contained in:
Video 2022-11-21 07:09:59 -07:00
parent 99a5897d44
commit b3e1a8b528
11 changed files with 6 additions and 519 deletions

View File

@ -410,14 +410,10 @@
</relocations>
<artifactSet>
<includes>
<include>commons-io:commons-io</include>
<include>org.apache.commons:commons-lang3</include>
<include>org.reflections:reflections</include>
<include>org.javassist:javassist</include>
<include>io.papermc:paperlib</include>
<include>org.bstats:bstats-bukkit</include>
<include>org.bstats:bstats-base</include>
<include>org.jetbrains:annotations</include>
</includes>
</artifactSet>
</configuration>

View File

@ -1,201 +0,0 @@
package me.totalfreedom.totalfreedommod;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FLog;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class LogViewer extends FreedomService
{
@Override
public void onStart()
{
}
@Override
public void onStop()
{
}
public void updateLogsRegistration(final CommandSender sender, final Player target, final LogsRegistrationMode mode)
{
updateLogsRegistration(sender, target.getName(), mode);
}
public void updateLogsRegistration(final CommandSender sender, final String targetName, final LogsRegistrationMode mode)
{
final String logsRegisterUrl = ConfigEntry.LOGS_URL.getString();
final String logsRegisterPassword = ConfigEntry.LOGS_SECRET.getString();
if (logsRegisterUrl == null || logsRegisterPassword == null || logsRegisterUrl.isEmpty() || logsRegisterPassword.isEmpty())
{
return;
}
new BukkitRunnable()
{
@Override
public void run()
{
try
{
if (sender != null)
{
sender.sendMessage(ChatColor.YELLOW + "Connecting...");
}
final String key = SecureCodeGenerator.generateCode(20);
final URL urlAdd = new URLBuilder(logsRegisterUrl)
.addQueryParameter("mode", mode.name())
.addQueryParameter("password", logsRegisterPassword)
.addQueryParameter("name", targetName)
.addQueryParameter("key", key)
.getURL();
final HttpURLConnection connection = (HttpURLConnection)urlAdd.openConnection();
connection.setConnectTimeout(1000 * 5);
connection.setReadTimeout(1000 * 5);
connection.setUseCaches(false);
connection.setRequestMethod("HEAD");
final int responseCode = connection.getResponseCode();
if (sender != null)
{
if (!plugin.isEnabled())
{
return;
}
new BukkitRunnable()
{
@Override
public void run()
{
if (responseCode == 200)
{
if (mode == LogsRegistrationMode.ADD)
{
String link = null;
try
{
final URL urlVerify = new URLBuilder(logsRegisterUrl)
.addQueryParameter("mode", LogsRegistrationMode.VERIFY.name())
.addQueryParameter("name", targetName)
.addQueryParameter("key", key)
.getURL();
link = urlVerify.toString();
}
catch (Exception ex)
{
FLog.severe(ex);
}
sender.sendMessage(ChatColor.GREEN + "Open this link to verify your logviewer registration:\n" + ChatColor.DARK_GREEN + link);
}
else
{
sender.sendMessage(ChatColor.GREEN + "Logviewer access revoked successfully.");
}
}
else
{
sender.sendMessage(ChatColor.RED + "Error contacting logs registration server.");
}
}
}.runTask(plugin);
}
}
catch (Exception ex)
{
FLog.severe(ex);
}
}
}.runTaskAsynchronously(plugin);
}
public enum LogsRegistrationMode
{
ADD, DELETE, VERIFY
}
private static class URLBuilder
{
private final String requestPath;
private final Map<String, String> queryStringMap = new HashMap<>();
private URLBuilder(String requestPath)
{
this.requestPath = requestPath;
}
public URLBuilder addQueryParameter(String key, String value)
{
queryStringMap.put(key, value);
return this;
}
public URL getURL() throws MalformedURLException
{
List<String> pairs = new ArrayList<>();
for (Map.Entry<String, String> pair : queryStringMap.entrySet())
{
try
{
pairs.add(URLEncoder.encode(pair.getKey(), "UTF-8") + "=" + URLEncoder.encode(pair.getValue(), "UTF-8"));
}
catch (UnsupportedEncodingException ex)
{
FLog.severe(ex);
}
}
return new URL(requestPath + "?" + StringUtils.join(pairs, "&"));
}
}
private static class SecureCodeGenerator
{
private static final String CHARACTER_SET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
public static String generateCode(final int length)
{
SecureRandom random;
try
{
random = SecureRandom.getInstance("SHA1PRNG", "SUN");
}
catch (NoSuchAlgorithmException | NoSuchProviderException ex)
{
random = new SecureRandom();
FLog.severe(ex);
}
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++)
{
sb.append(CHARACTER_SET.charAt(random.nextInt(CHARACTER_SET.length())));
}
return sb.toString();
}
}
}

View File

@ -72,7 +72,6 @@ public class TotalFreedomMod extends JavaPlugin
public CommandLoader cl;
// Services
public WorldManager wm;
public LogViewer lv;
public AdminList al;
public ActivityLog acl;
public RankManager rm;
@ -283,7 +282,6 @@ public class TotalFreedomMod extends JavaPlugin
{
// Start services
wm = new WorldManager();
lv = new LogViewer();
sql = new SQLite();
al = new AdminList();
acl = new ActivityLog();

View File

@ -4,7 +4,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import me.totalfreedom.totalfreedommod.LogViewer.LogsRegistrationMode;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank;
@ -184,8 +183,6 @@ public class Admin
}
}
plugin.lv.updateLogsRegistration(null, getName(), LogsRegistrationMode.DELETE);
}
}

View File

@ -1,26 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.LogViewer.LogsRegistrationMode;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Register your connection with the TFM logviewer.", usage = "/<command> [off]")
public class Command_logs extends FreedomCommand
{
@Override
public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
LogsRegistrationMode mode = LogsRegistrationMode.ADD;
if (args.length == 1 && "off".equalsIgnoreCase(args[0]))
{
mode = LogsRegistrationMode.DELETE;
}
plugin.lv.updateLogsRegistration(sender, playerSender, mode);
return true;
}
}

View File

@ -139,9 +139,6 @@ public enum ConfigEntry
AUTOKICK_THRESHOLD(Double.class, "autokick.threshold"),
AUTOKICK_TIME(Integer.class, "autokick.time"),
//
LOGS_SECRET(String.class, "logs.secret"),
LOGS_URL(String.class, "logs.url"),
//
FLATLANDS_GENERATE(Boolean.class, "flatlands.generate"),
FLATLANDS_GENERATE_PARAMS(String.class, "flatlands.generate_params"),
//

View File

@ -20,7 +20,6 @@ import me.totalfreedom.totalfreedommod.httpd.module.Module_indefbans;
import me.totalfreedom.totalfreedommod.httpd.module.Module_index;
import me.totalfreedom.totalfreedommod.httpd.module.Module_list;
import me.totalfreedom.totalfreedommod.httpd.module.Module_logfile;
import me.totalfreedom.totalfreedommod.httpd.module.Module_logs;
import me.totalfreedom.totalfreedommod.httpd.module.Module_players;
import me.totalfreedom.totalfreedommod.httpd.module.Module_punishments;
import me.totalfreedom.totalfreedommod.httpd.module.Module_schematic;
@ -96,7 +95,6 @@ public class HTTPDaemon extends FreedomService
module("help", Module_help.class, false);
module("list", Module_list.class, false);
module("logfile", Module_logfile.class, true);
module("logs", Module_logs.class, true);
module("indefbans", Module_indefbans.class, true);
module("players", Module_players.class, false);
module("punishments", Module_punishments.class, true);

View File

@ -1,29 +0,0 @@
package me.totalfreedom.totalfreedommod.httpd.module;
import java.io.File;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
import me.totalfreedom.totalfreedommod.util.FLog;
public class Module_logs extends Module_file
{
public Module_logs(NanoHTTPD.HTTPSession session)
{
super(session);
}
@Override
public NanoHTTPD.Response getResponse()
{
if (ConfigEntry.LOGS_SECRET.getString().equals(params.get("password")) && !ConfigEntry.LOGS_SECRET.getString().isEmpty())
{
FLog.info(session.getSocket().getInetAddress() + " is downloading latest.log.");
return serveFile("latest.log", params, new File("./logs"));
}
else
{
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.FORBIDDEN, NanoHTTPD.MIME_PLAINTEXT, "Incorrect password.");
}
}
}

View File

@ -20,10 +20,8 @@ import java.util.UUID;
public class FPlayer
{
public static final long AUTO_PURGE_TICKS = 5L * 60L * 20L;
private final TotalFreedomMod plugin;
private final String name;
@ -40,8 +38,6 @@ public class FPlayer
private int messageCount = 0;
private int totalBlockDestroy = 0;
private int totalBlockPlace = 0;
private int freecamDestroyCount = 0;
private int freecamPlaceCount = 0;
private boolean isOrbiting = false;
private double orbitStrength = 10.0;
private boolean mobThrowerEnabled = false;
@ -52,11 +48,9 @@ public class FPlayer
private boolean mp44Firing = false;
private BukkitTask lockupScheduleTask = null;
private boolean lockedUp = false;
private String lastMessage = "";
private boolean inAdminchat = false;
private boolean allCommandsBlocked = false;
private String lastCommand = "";
private boolean cmdspyEnabled = false;
private String tag = null;
private int warningCount = 0;
@ -82,11 +76,6 @@ public class FPlayer
this.ip = ip;
}
public static long getAutoPurgeTicks()
{
return AUTO_PURGE_TICKS;
}
public Player getPlayer()
{
if (player != null && !player.isOnline())
@ -110,7 +99,6 @@ public class FPlayer
// Ensure admins don't have admin functionality when removed (FS-222)
public void removeAdminFunctionality()
{
this.setCommandSpy(false);
this.setAdminChat(false);
this.setFuckoffRadius(0);
}
@ -120,11 +108,6 @@ public class FPlayer
return isOrbiting;
}
public void setOrbiting(boolean orbiting)
{
isOrbiting = orbiting;
}
public void startOrbiting(double strength)
{
this.isOrbiting = true;
@ -186,26 +169,6 @@ public class FPlayer
this.totalBlockPlace = 0;
}
public int incrementAndGetFreecamDestroyCount()
{
return this.freecamDestroyCount++;
}
public void resetFreecamDestroyCount()
{
this.freecamDestroyCount = 0;
}
public int incrementAndGetFreecamPlaceCount()
{
return this.freecamPlaceCount++;
}
public void resetFreecamPlaceCount()
{
this.freecamPlaceCount = 0;
}
public void enableMobThrower(EntityType mobThrowerCreature, double mobThrowerSpeed)
{
this.mobThrowerEnabled = true;
@ -350,16 +313,6 @@ public class FPlayer
this.lockedUp = lockedUp;
}
public String getLastMessage()
{
return lastMessage;
}
public void setLastMessage(String message)
{
this.lastMessage = message;
}
public void setAdminChat(boolean inAdminchat)
{
this.inAdminchat = inAdminchat;
@ -390,16 +343,6 @@ public class FPlayer
this.lastCommand = lastCommand;
}
public void setCommandSpy(boolean enabled)
{
this.cmdspyEnabled = enabled;
}
public boolean cmdspyEnabled()
{
return cmdspyEnabled;
}
public String getTag()
{
return this.tag;
@ -417,16 +360,6 @@ public class FPlayer
}
}
public int getWarningCount()
{
return this.warningCount;
}
public void setWarningCount(int warningCount)
{
this.warningCount = warningCount;
}
public void incrementWarnings(boolean quiet)
{
this.warningCount++;
@ -459,16 +392,6 @@ public class FPlayer
return ip;
}
public BukkitTask getUnmuteTask()
{
return unmuteTask;
}
public void setUnmuteTask(BukkitTask unmuteTask)
{
this.unmuteTask = unmuteTask;
}
public FreezeData getFreezeData()
{
return freezeData;
@ -484,176 +407,11 @@ public class FPlayer
this.fuckoffRadius = fuckoffRadius;
}
public int getMessageCount()
{
return messageCount;
}
public void setMessageCount(int messageCount)
{
this.messageCount = messageCount;
}
public int getTotalBlockDestroy()
{
return totalBlockDestroy;
}
public void setTotalBlockDestroy(int totalBlockDestroy)
{
this.totalBlockDestroy = totalBlockDestroy;
}
public int getTotalBlockPlace()
{
return totalBlockPlace;
}
public void setTotalBlockPlace(int totalBlockPlace)
{
this.totalBlockPlace = totalBlockPlace;
}
public int getFreecamDestroyCount()
{
return freecamDestroyCount;
}
public void setFreecamDestroyCount(int freecamDestroyCount)
{
this.freecamDestroyCount = freecamDestroyCount;
}
public int getFreecamPlaceCount()
{
return freecamPlaceCount;
}
public void setFreecamPlaceCount(int freecamPlaceCount)
{
this.freecamPlaceCount = freecamPlaceCount;
}
public CageData getCageData()
{
return cageData;
}
public double getOrbitStrength()
{
return orbitStrength;
}
public void setOrbitStrength(double orbitStrength)
{
this.orbitStrength = orbitStrength;
}
public boolean isMobThrowerEnabled()
{
return mobThrowerEnabled;
}
public void setMobThrowerEnabled(boolean mobThrowerEnabled)
{
this.mobThrowerEnabled = mobThrowerEnabled;
}
public EntityType getMobThrowerEntity()
{
return mobThrowerEntity;
}
public void setMobThrowerEntity(EntityType mobThrowerEntity)
{
this.mobThrowerEntity = mobThrowerEntity;
}
public double getMobThrowerSpeed()
{
return mobThrowerSpeed;
}
public void setMobThrowerSpeed(double mobThrowerSpeed)
{
this.mobThrowerSpeed = mobThrowerSpeed;
}
public List<LivingEntity> getMobThrowerQueue()
{
return mobThrowerQueue;
}
public BukkitTask getMp44ScheduleTask()
{
return mp44ScheduleTask;
}
public void setMp44ScheduleTask(BukkitTask mp44ScheduleTask)
{
this.mp44ScheduleTask = mp44ScheduleTask;
}
public boolean isMp44Armed()
{
return mp44Armed;
}
public void setMp44Armed(boolean mp44Armed)
{
this.mp44Armed = mp44Armed;
}
public boolean isMp44Firing()
{
return mp44Firing;
}
public void setMp44Firing(boolean mp44Firing)
{
this.mp44Firing = mp44Firing;
}
public BukkitTask getLockupScheduleTask()
{
return lockupScheduleTask;
}
public void setLockupScheduleTask(BukkitTask lockupScheduleTask)
{
this.lockupScheduleTask = lockupScheduleTask;
}
public boolean isInAdminchat()
{
return inAdminchat;
}
public void setInAdminchat(boolean inAdminchat)
{
this.inAdminchat = inAdminchat;
}
public boolean isAllCommandsBlocked()
{
return allCommandsBlocked;
}
public void setAllCommandsBlocked(boolean allCommandsBlocked)
{
this.allCommandsBlocked = allCommandsBlocked;
}
public boolean isCmdspyEnabled()
{
return cmdspyEnabled;
}
public void setCmdspyEnabled(boolean cmdspyEnabled)
{
this.cmdspyEnabled = cmdspyEnabled;
}
public boolean isEditBlocked()
{
return editBlocked;

View File

@ -597,11 +597,6 @@ first_join_info:
petprotect:
enabled: true
# Logviewer
logs:
url: ''
secret: ''
# Mojang service checker
service_checker_url: http://status.mojang.com/check

View File

@ -10,8 +10,12 @@ softdepend:
- WorldEdit
- WorldGuard
- WorldGuardExtraFlags
- TFGuilds
- JDA
- Votifier
authors: [Madgeek1450, Prozza]
api-version: "1.17"
libraries:
- org.apache.commons:commons-lang3:3.12.0
- commons-io:commons-io:2.11.0
- org.jetbrains:annotations:23.0.0
- org.javassist:javassist:3.29.1-GA