From 550ff492ee7c0c1befdc92750b3e4d6d1de4e505 Mon Sep 17 00:00:00 2001 From: Video Date: Mon, 14 Nov 2022 10:54:59 -0700 Subject: [PATCH] Resolves FS-339 by aggressively rewriting /list and removing ancient unused code --- .../totalfreedommod/banning/BanManager.java | 9 -- .../totalfreedommod/command/Command_list.java | 122 ++++----------- .../totalfreedommod/config/ConfigEntry.java | 1 - src/main/resources/config.yml | 145 ------------------ 4 files changed, 30 insertions(+), 247 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java b/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java index 03b6465a..23e60e58 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java @@ -1,6 +1,5 @@ package me.totalfreedom.totalfreedommod.banning; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import java.sql.ResultSet; @@ -14,7 +13,6 @@ import java.util.Map; import java.util.Set; import java.util.UUID; import me.totalfreedom.totalfreedommod.FreedomService; -import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.entity.Player; @@ -30,8 +28,6 @@ public class BanManager extends FreedomService private final Map nameBans = Maps.newHashMap(); private final Map uuidBans = Maps.newHashMap(); private final Map ipBans = Maps.newHashMap(); - private final List unbannableUsernames = Lists.newArrayList(); - // @Override @@ -70,11 +66,6 @@ public class BanManager extends FreedomService updateViews(); FLog.info("Loaded " + ipBans.size() + " IP bans and " + nameBans.size() + " username bans."); - - // Load unbannable usernames - unbannableUsernames.clear(); - unbannableUsernames.addAll(ConfigEntry.FAMOUS_PLAYERS.getStringList()); - FLog.info("Loaded " + unbannableUsernames.size() + " unbannable usernames."); } @Override diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java index fc592793..2ebf25e2 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java @@ -1,9 +1,6 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.admin.Admin; -import me.totalfreedom.totalfreedommod.admin.AdminList; -import me.totalfreedom.totalfreedommod.config.ConfigEntry; -import me.totalfreedom.totalfreedommod.rank.Displayable; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; import net.md_5.bungee.api.ChatColor; @@ -12,63 +9,37 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.util.ArrayList; import java.util.List; @CommandPermissions(level = Rank.NON_OP, source = SourceType.BOTH) -@CommandParameters(description = "Lists the real names of all online players.", usage = "/ [-s | -f | -v]", aliases = "who,lsit") +@CommandParameters(description = "Lists the real names of all online players.", usage = "/ [-a | -v]", aliases = "who,lsit") public class Command_list extends FreedomCommand { - + @Override public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole) { if (args.length > 1) { return false; } - if (FUtil.isFromHostConsole(sender.getName())) - { - List names = new ArrayList<>(); - for (Player player : server.getOnlinePlayers()) - { - if (!plugin.al.isVanished(player.getName())) - { - names.add(player.getName()); - } - } - msg("There are " + names.size() + "/" + server.getMaxPlayers() + " players online:\n" + StringUtils.join(names, ", "), ChatColor.WHITE); - return true; - } + ListFilter listFilter; if (args.length == 1) { - String s = args[0]; - switch (s) + switch (args[0].toLowerCase()) { - case "-s": - case "-a": - { - listFilter = ListFilter.ADMINS; - break; - } - case "-v": + case "-s", "-a" -> listFilter = ListFilter.ADMINS; + case "-v" -> { checkRank(Rank.ADMIN); listFilter = ListFilter.VANISHED_ADMINS; - break; } - case "-t": + case "-t" -> { checkRank(Rank.ADMIN); listFilter = ListFilter.TELNET_SESSIONS; - break; } - case "-f": - { - listFilter = ListFilter.FAMOUS_PLAYERS; - break; - } - default: + default -> { return false; } @@ -78,74 +49,42 @@ public class Command_list extends FreedomCommand { listFilter = ListFilter.PLAYERS; } - StringBuilder onlineStats = new StringBuilder(); - StringBuilder onlineUsers = new StringBuilder(); - List n = new ArrayList<>(); + String onlineStats; + List players; if (listFilter == ListFilter.TELNET_SESSIONS && plugin.al.isAdmin(sender)) { - List connectedAdmins = plugin.btb.getConnectedAdmins(); - onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(connectedAdmins.size()) - .append(ChatColor.BLUE) - .append(" admins connected to telnet."); - for (Admin admin : connectedAdmins) - { - n.add(admin.getName()); - } + players = plugin.btb.getConnectedAdmins().stream().map(Admin::getName).toList(); + onlineStats = ChatColor.BLUE + "There are " + ChatColor.RED + players.size() + ChatColor.BLUE + + " admins connected to telnet."; } else { - onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(FUtil.getFakePlayerCount()) - .append(ChatColor.BLUE) - .append(" out of a maximum ") - .append(ChatColor.RED) - .append(server.getMaxPlayers()) - .append(ChatColor.BLUE) - .append(" players online."); - for (Player p : server.getOnlinePlayers()) - { - if (listFilter == ListFilter.ADMINS && !plugin.al.isAdmin(p)) - { - continue; - } - if (listFilter == ListFilter.ADMINS && plugin.al.isVanished(p.getName())) - { - continue; - } - if (listFilter == ListFilter.VANISHED_ADMINS && !plugin.al.isVanished(p.getName())) - { - continue; - } - if (listFilter == ListFilter.FAMOUS_PLAYERS && !ConfigEntry.FAMOUS_PLAYERS.getList().contains(p.getName().toLowerCase())) - { - continue; - } - if (listFilter == ListFilter.PLAYERS && plugin.al.isVanished(p.getName())) - { - continue; - } + onlineStats = ChatColor.BLUE + "There are " + ChatColor.RED + FUtil.getFakePlayerCount() + ChatColor.BLUE + + " out of a maximum " + ChatColor.RED + server.getMaxPlayers() + ChatColor.BLUE + " players online."; - final Displayable display = plugin.rm.getDisplay(p); - n.add(display.getColoredTag() + p.getName()); - } + players = server.getOnlinePlayers().stream().filter(pl -> + (listFilter == ListFilter.ADMINS && plugin.al.isAdmin(pl) && !plugin.al.isVanished(pl.getName())) + || (listFilter == ListFilter.VANISHED_ADMINS && plugin.al.isVanished(pl.getName())) + || (listFilter == ListFilter.PLAYERS && !plugin.al.isVanished(pl.getName()))).map(player -> + plugin.rm.getDisplay(player).getColoredTag() + player.getName()).toList(); } - String playerType = listFilter.toString().toLowerCase().replace('_', ' '); - onlineUsers.append("Connected ") - .append(playerType) - .append(": ") - .append(StringUtils.join(n, ChatColor.WHITE + ", ")); + + String onlineUsers = "Connected " + listFilter.name().toLowerCase().replace('_', ' ') + ": " + ChatColor.WHITE + + StringUtils.join(players, ChatColor.WHITE + ", " + ChatColor.WHITE); + if (senderIsConsole) { - msg(ChatColor.stripColor(onlineStats.toString())); - msg(ChatColor.stripColor(onlineUsers.toString())); + msg(ChatColor.stripColor(onlineStats)); + msg(ChatColor.stripColor(onlineUsers)); } else { - msg(onlineStats.toString()); - msg(onlineUsers.toString()); + msg(onlineStats); + msg(onlineUsers); } - n.clear(); + return true; } @@ -154,7 +93,6 @@ public class Command_list extends FreedomCommand PLAYERS, ADMINS, VANISHED_ADMINS, - TELNET_SESSIONS, - FAMOUS_PLAYERS + TELNET_SESSIONS } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java index 6a00aa17..de498522 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java @@ -164,7 +164,6 @@ public enum ConfigEntry WILDCARD_BLOCKED_COMMANDS(List.class, "blocked_commands.wildcard"), FORBIDDEN_WORDS(List.class, "forbidden_words"), HOST_SENDER_NAMES(List.class, "host_sender_names"), - FAMOUS_PLAYERS(List.class, "famous_players"), ADMIN_ONLY_MODE(Boolean.class, "admin_only_mode"), ADMIN_INFO(List.class, "admininfo"), VOTING_INFO(List.class, "votinginfo"), diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2aa7a488..f2e3b822 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -606,151 +606,6 @@ first_join_info: - "&eThe server's name doesn't mean we have no rules. Do &6/rules &efor a list of them." - "&aNeed help getting started? Do &2/help &aor a list of commands!" -# Famous players - cannot be banned by username -famous_players: - - honeydew - - xephos - - captainsparklez - - truemu - - kiershar - - fvdisco - - sethbling - - gamechap - - bertiechap - - vechs - - antvenom - - chimneyswift - - deadmau5 - - etho - - ethoslab - - skydoesminecraft - - skythekidrs - - tobyturner - - xxslyfoxhoundxx - - paulsoaresjr - - sips_ - - deadlox - - xxslyxx - - jeromeasf - - grum - - evilseph - - cavemanfilms - - herobrine - - whiteboy7thst - - stampylonghead - - stampylongnose - - dantdm - - gizzy14gazza - - furiousdestroyer - - pewdie - - thecampingrusher - - logdotzip - - ssundee - - mrcrainer - - achileis - - donibobes - - itsjerry - - itsharry - - bebopvox - - clankstar - - jollyajax - - b0xx3r - - vareide - - defek7 - - strutt20 - - appleg - - sterling_ - - hypixel - - huskymudkipz - - setosorcerer - - slamacow - - mrcrayfish - - zexyzek - - synhd - - syndicate - - bajancanadian - - actennisac - - bodil40 - - trumu - - huskymudkipz - - dantdm - - skeppy - - badboyhalo - # Mojang staff below this line - - aeplh - - amir343 - - angryem - - ashrafi - - binni - - blurpi - - bopogamel - - boq - - c418 - - carlmanneh - - carnalizer - - carramel - - darngeek - - dinnerbone - - eldrone - - elevenen - - el_hefe_ - - engst - - excitedze - - frukthamster - - fry_ - - grumm - - hampus - - helloiammarsh - - hey - - hoodad - - ianna_na_na - - jeb_ - - jonkagstrom - - kappe - - klumpig - - krisjelbring - - ladyagnes - - lisa - - mahuldur - - mansolson - - marc - - marc_irl - - masseffect - - midnightenforcer - - minecraftchick - - modhelius - - moesh - - mojangjonas - - mojangsta - - mollstam - - neonmaster - - olle - - olofcarlson - - phreakholm - - poipoichen - - pretto - - profmobius - - razzleberryfox - - searge - - searge_dp - - shoghicp - - slicedlime - - sockerpappan - - themogminer - - theopard - - theputtman - - tom__m - - vaktis - - volgar - - vubui - - xlson - - xsson - - yoloswag4lyfe - - zeeraw - - _alcatras - - _tommo_ - - ____fox____ - # Pet Protect - Prevent tamed pets from being killed. petprotect: enabled: true