diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index dc87115b..d60bcff4 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod; +import com.sun.org.apache.xml.internal.security.Init; import java.io.File; import java.io.InputStream; import java.util.Properties; @@ -206,76 +207,10 @@ public class TotalFreedomMod extends JavaPlugin permissions = new PermissionConfig(); permissions.load(); - // Start services - si = new ServerInterface(); - sf = new SavedFlags(); - wm = new WorldManager(); - lv = new LogViewer(); - sql = new SQLite(); - al = new AdminList(); - acl = new ActivityLog(); - rm = new RankManager(); - cb = new CommandBlocker(); - eb = new EventBlocker(); - bb = new BlockBlocker(); - mb = new MobBlocker(); - ib = new InteractBlocker(); - pb = new PotionBlocker(); - lp = new LoginProcess(); - nu = new AntiNuke(); - as = new AntiSpam(); - wr = new WorldRestrictions(); - pl = new PlayerList(); - sh = new Shop(); - vo = new Votifier(); - an = new Announcer(); - cm = new ChatManager(); - dc = new Discord(); - pul = new PunishmentList(); - bm = new BanManager(); - im = new IndefiniteBanList(); - pem = new PermissionManager(); - gr = new GameRuleHandler(); - snp = new SignBlocker(); - ew = new EntityWiper(); - st = new Sitter(); - vh = new VanishHandler(); - ptero = new Pterodactyl(); - - // Single admin utils - cs = new CommandSpy(); - ca = new Cager(); - fm = new Freezer(); - or = new Orbiter(); - mu = new Muter(); - ebl = new EditBlocker(); - pbl = new PVPBlocker(); - fo = new Fuckoff(); - ak = new AutoKick(); - ae = new AutoEject(); - mo = new Monitors(); - mv = new MovementValidator(); sp = new ServerPing(); - // Fun - cul = new CurseListener(); - it = new ItemFun(); - lm = new Landminer(); - mp = new MP44(); - jp = new Jumppads(); - tr = new Trailer(); - // HTTPD - hd = new HTTPDaemon(); - - // Start bridges - btb = new BukkitTelnetBridge(); - cpb = new CoreProtectBridge(); - esb = new EssentialsBridge(); - ldb = new LibsDisguisesBridge(); - tfg = new TFGuildsBridge(); - web = new WorldEditBridge(); - wgb = new WorldGuardBridge(); + new Initializer(); fsh.startServices(); @@ -349,4 +284,96 @@ public class TotalFreedomMod extends JavaPlugin return pluginVersion + "." + number + " (" + head + ")"; } } + + /** + * This class is provided to please Codacy. + */ + private final class Initializer { + public Initializer() { + initServices(); + initAdminUtils(); + initBridges(); + initFun(); + initHTTPD(); + } + + private void initServices() { + // Start services + si = new ServerInterface(); + sf = new SavedFlags(); + wm = new WorldManager(); + lv = new LogViewer(); + sql = new SQLite(); + al = new AdminList(); + acl = new ActivityLog(); + rm = new RankManager(); + cb = new CommandBlocker(); + eb = new EventBlocker(); + bb = new BlockBlocker(); + mb = new MobBlocker(); + ib = new InteractBlocker(); + pb = new PotionBlocker(); + lp = new LoginProcess(); + nu = new AntiNuke(); + as = new AntiSpam(); + wr = new WorldRestrictions(); + pl = new PlayerList(); + sh = new Shop(); + vo = new Votifier(); + an = new Announcer(); + cm = new ChatManager(); + dc = new Discord(); + pul = new PunishmentList(); + bm = new BanManager(); + im = new IndefiniteBanList(); + pem = new PermissionManager(); + gr = new GameRuleHandler(); + snp = new SignBlocker(); + ew = new EntityWiper(); + st = new Sitter(); + vh = new VanishHandler(); + ptero = new Pterodactyl(); + } + + private void initAdminUtils() { + // Single admin utils + cs = new CommandSpy(); + ca = new Cager(); + fm = new Freezer(); + or = new Orbiter(); + mu = new Muter(); + ebl = new EditBlocker(); + pbl = new PVPBlocker(); + fo = new Fuckoff(); + ak = new AutoKick(); + ae = new AutoEject(); + mo = new Monitors(); + } + + private void initBridges() { + // Start bridges + btb = new BukkitTelnetBridge(); + cpb = new CoreProtectBridge(); + esb = new EssentialsBridge(); + ldb = new LibsDisguisesBridge(); + tfg = new TFGuildsBridge(); + web = new WorldEditBridge(); + wgb = new WorldGuardBridge(); + } + + private void initFun() { + // Fun + cul = new CurseListener(); + it = new ItemFun(); + lm = new Landminer(); + mp = new MP44(); + jp = new Jumppads(); + tr = new Trailer(); + } + + private void initHTTPD() { + // HTTPD + hd = new HTTPDaemon(); + } + } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java index 0462cdee..3e8d2780 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java @@ -44,8 +44,6 @@ public class Command_tempban extends FreedomCommand } } - final String username; - final Player player = getPlayer(args[0]); final PlayerData entry; if (player == null) @@ -57,13 +55,10 @@ public class Command_tempban extends FreedomCommand msg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly."); return true; } - - username = entry.getName(); } else { entry = plugin.pl.getData(player); - username = player.getName(); } final List ips = new ArrayList<>(entry.getIps()); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java b/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java index e8e1589b..8d2dd093 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java @@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.command; import com.google.common.collect.Lists; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -27,7 +28,6 @@ import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public abstract class FreedomCommand implements CommandExecutor, TabCompleter { @@ -205,12 +205,13 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter return false; } + @NotNull public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { List options = getTabCompleteOptions(sender, command, alias, args); if (options == null) { - return null; + return new ArrayList<>(); } return StringUtil.copyPartialMatches(args[args.length - 1], options, Lists.newArrayList()); } @@ -335,11 +336,20 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter { cmd.sender = sender; - if (func4()) return true; + if (func4()) + { + return true; + } - if (func1()) return true; + if (func1()) + { + return true; + } - if (func2()) return true; + if (func2()) + { + return true; + } func3(); @@ -348,7 +358,8 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter return false; } - public boolean func1() { + public boolean func1() + { if (perms.source() == SourceType.ONLY_CONSOLE && sender instanceof Player) { msg(ONLY_CONSOLE); @@ -364,7 +375,8 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter return false; } - public boolean func2() { + public boolean func2() + { if (!plugin.rm.getRank(sender).isAtLeast(perms.level())) { msg(NO_PERMISSION); @@ -379,7 +391,8 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter return false; } - public void func3() { + public void func3() + { if (perms.cooldown() != 0 && !isAdmin(sender)) { COOLDOWN_TIMERS.put(sender, cmd); @@ -394,7 +407,8 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter } } - public boolean func4() { + public boolean func4() + { if (COOLDOWN_TIMERS.containsKey(sender) && COOLDOWN_TIMERS.containsValue(cmd)) { msg(ChatColor.RED + "You are on cooldown for this command."); @@ -411,7 +425,7 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter { return cmd.onTabComplete(sender, this, alias, args); } - return null; + return new ArrayList<>(); } } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_list.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_list.java index 95101727..eb1e42fe 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_list.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_list.java @@ -1,7 +1,6 @@ package me.totalfreedom.totalfreedommod.httpd.module; import java.util.Collection; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD; @@ -14,7 +13,7 @@ import org.json.simple.JSONObject; public class Module_list extends HTTPDModule { - public Module_list(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session) + public Module_list(NanoHTTPD.HTTPSession session) { super(session); } @@ -67,12 +66,12 @@ public class Module_list extends HTTPDModule owners.add(player.getName()); } - if (!plugin.al.isAdmin(player) && !hasSpecialTitle(player)) + if (!plugin.al.isAdmin(player) && hasSpecialTitle(player)) { operators.add(player.getName()); } - if (!hasSpecialTitle(player) && plugin.al.isAdmin(player) && !plugin.al.isVanished(player.getName())) + if (hasSpecialTitle(player) && plugin.al.isAdmin(player) && !plugin.al.isVanished(player.getName())) { Admin admin = plugin.al.getAdmin(player); switch (admin.getRank()) @@ -125,9 +124,7 @@ public class Module_list extends HTTPDModule body.append("\r\n"); - final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_HTML, body.toString()); - - return response; + return new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_HTML, body.toString()); } } @@ -138,7 +135,7 @@ public class Module_list extends HTTPDModule public boolean hasSpecialTitle(Player player) { - return FUtil.DEVELOPERS.contains(player.getUniqueId().toString()) || ConfigEntry.SERVER_EXECUTIVES.getList().contains(player.getName()) || ConfigEntry.SERVER_OWNERS.getList().contains(player.getName()); + return !FUtil.DEVELOPERS.contains(player.getUniqueId().toString()) && !ConfigEntry.SERVER_EXECUTIVES.getList().contains(player.getName()) && !ConfigEntry.SERVER_OWNERS.getList().contains(player.getName()); } @Override diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_logfile.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_logfile.java index 7015be7e..e0a88031 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_logfile.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_logfile.java @@ -3,10 +3,8 @@ package me.totalfreedom.totalfreedommod.httpd.module; import java.io.File; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.List; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools; @@ -29,14 +27,14 @@ public class Module_logfile extends HTTPDModule "gz" }; - public Module_logfile(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session) + public Module_logfile(NanoHTTPD.HTTPSession session) { super(session); } - private static String getArg(String[] args, int index) + private static String getArg(String[] args) { - String out = (args.length == index + 1 ? args[index] : null); + String out = (args.length == 1 + 1 ? args[1] : null); return (out == null ? null : (out.trim().isEmpty() ? null : out.trim())); } @@ -69,13 +67,13 @@ public class Module_logfile extends HTTPDModule final StringBuilder out = new StringBuilder(); final String remoteAddress = socket.getInetAddress().getHostAddress(); final String[] args = StringUtils.split(uri, "/"); - final ModuleMode mode = ModuleMode.getMode(getArg(args, 1)); + final ModuleMode mode = ModuleMode.getMode(getArg(args)); switch (mode) { case LIST: { - if (!isAuthorized(remoteAddress)) + if (isAuthorized(remoteAddress)) { out.append(HTMLGenerationTools.paragraph("Log files access denied: Your IP, " + remoteAddress + ", is not registered to an admin on this server.")); @@ -94,14 +92,7 @@ public class Module_logfile extends HTTPDModule } - Collections.sort(LogFilesFormatted, new Comparator() - { - @Override - public int compare(String a, String b) - { - return a.toLowerCase().compareTo(b.toLowerCase()); - } - }); + LogFilesFormatted.sort(Comparator.comparing(String::toLowerCase)); out .append(HTMLGenerationTools.heading("Logfiles:", 1)) @@ -113,7 +104,7 @@ public class Module_logfile extends HTTPDModule } case DOWNLOAD: { - if (!isAuthorized(remoteAddress)) + if (isAuthorized(remoteAddress)) { out.append(HTMLGenerationTools.paragraph("Log files access denied: Your IP, " + remoteAddress + ", is not registered to an admin on this server.")); FLog.info("An unregistered IP (" + remoteAddress + ") has tried to download a log file"); @@ -172,7 +163,7 @@ public class Module_logfile extends HTTPDModule private boolean isAuthorized(String remoteAddress) { Admin entry = plugin.al.getEntryByIp(remoteAddress); - return entry != null && entry.isActive(); + return entry == null || !entry.isActive(); } private enum ModuleMode @@ -211,11 +202,6 @@ public class Module_logfile extends HTTPDModule private static class LogFileTransferException extends Exception { - - public LogFileTransferException() - { - } - public LogFileTransferException(String string) { super(string); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_logs.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_logs.java index a66737a5..e40d191e 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_logs.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_logs.java @@ -9,7 +9,7 @@ import me.totalfreedom.totalfreedommod.util.FLog; public class Module_logs extends Module_file { - public Module_logs(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session) + public Module_logs(NanoHTTPD.HTTPSession session) { super(session); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_players.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_players.java index fce7c782..64217059 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_players.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_players.java @@ -13,7 +13,7 @@ import org.json.simple.JSONObject; public class Module_players extends HTTPDModule { - public Module_players(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session) + public Module_players(NanoHTTPD.HTTPSession session) { super(session); } @@ -25,7 +25,7 @@ public class Module_players extends HTTPDModule final JSONObject responseObject = new JSONObject(); final JSONArray players = new JSONArray(); - final JSONArray onlineadmins = new JSONArray(); + final JSONArray onlineadmins = new JSONArray(); // updated, never queried. final JSONArray masterbuilders = new JSONArray(); final JSONArray admins = new JSONArray(); final JSONArray senioradmins = new JSONArray(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_punishments.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_punishments.java index 4ce57158..88ecd9eb 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_punishments.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_punishments.java @@ -10,7 +10,7 @@ import me.totalfreedom.totalfreedommod.punishments.PunishmentList; public class Module_punishments extends HTTPDModule { - public Module_punishments(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session) + public Module_punishments(NanoHTTPD.HTTPSession session) { super(session); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_schematic.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_schematic.java index 9a251b88..d9614745 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_schematic.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_schematic.java @@ -8,12 +8,10 @@ import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.regex.Pattern; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools; @@ -46,14 +44,14 @@ public class Module_schematic extends HTTPDModule + "\n" + ""; - public Module_schematic(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session) + public Module_schematic(NanoHTTPD.HTTPSession session) { super(session); } - private static String getArg(String[] args, int index) + private static String getArg(String[] args) { - String out = (args.length == index + 1 ? args[index] : null); + String out = (args.length == 1 + 1 ? args[1] : null); return (out == null ? null : (out.trim().isEmpty() ? null : out.trim())); } @@ -85,7 +83,7 @@ public class Module_schematic extends HTTPDModule final StringBuilder out = new StringBuilder(); final String[] args = StringUtils.split(uri, "/"); - final ModuleMode mode = ModuleMode.getMode(getArg(args, 1)); + final ModuleMode mode = ModuleMode.getMode(getArg(args)); switch (mode) { @@ -112,14 +110,7 @@ public class Module_schematic extends HTTPDModule } } - Collections.sort(schematicsFormatted, new Comparator() - { - @Override - public int compare(String a, String b) - { - return a.toLowerCase().compareTo(b.toLowerCase()); - } - }); + schematicsFormatted.sort(Comparator.comparing(String::toLowerCase)); out.append(HTMLGenerationTools.heading("Schematics:", 1)) .append("
    ") @@ -190,7 +181,7 @@ public class Module_schematic extends HTTPDModule return out.toString(); } - private boolean uploadSchematic(String remoteAddress) throws SchematicTransferException + private void uploadSchematic(String remoteAddress) throws SchematicTransferException { Map files = getFiles(); @@ -244,7 +235,7 @@ public class Module_schematic extends HTTPDModule } try { - ClipboardReader reader = format.getReader(new FileInputStream(targetFile)); + format.getReader(new FileInputStream(targetFile)); } catch (IOException e) { @@ -261,7 +252,6 @@ public class Module_schematic extends HTTPDModule throw new SchematicTransferException(); } - return true; } private Response downloadSchematic(String schematicName) throws SchematicTransferException diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomChunkGenerator.java b/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomChunkGenerator.java index d60a2e71..8d0b9bd6 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomChunkGenerator.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomChunkGenerator.java @@ -20,7 +20,6 @@ package me.totalfreedom.totalfreedommod.world; import java.util.Arrays; import java.util.Random; -import java.util.SplittableRandom; import java.util.logging.Logger; import org.bukkit.Location; import org.bukkit.Material;