From 5028f43b971b08219ef01b155109acd4ee8f22d2 Mon Sep 17 00:00:00 2001 From: ThiagoROX <51332006+SrBedrock@users.noreply.github.com> Date: Tue, 20 Feb 2024 23:07:55 -0300 Subject: [PATCH] Removido ImmutableList e StringUtil --- .../nossr50/commands/McconvertCommand.java | 27 ++-- .../nossr50/commands/McnotifyCommand.java | 4 +- .../gmail/nossr50/commands/ToggleCommand.java | 18 +-- .../gmail/nossr50/commands/XprateCommand.java | 15 +-- .../commands/database/McpurgeCommand.java | 3 +- .../commands/database/McremoveCommand.java | 8 +- .../commands/database/MmoshowdbCommand.java | 3 +- .../experience/ExperienceCommand.java | 22 ++-- .../experience/SkillresetCommand.java | 10 +- .../hardcore/HardcoreModeCommand.java | 4 +- .../nossr50/commands/party/PartyCommand.java | 6 +- .../party/alliance/PartyAllianceCommand.java | 4 +- .../commands/party/teleport/PtpCommand.java | 5 +- .../commands/player/InspectCommand.java | 8 +- .../commands/player/McstatsCommand.java | 3 +- .../nossr50/commands/player/MctopCommand.java | 6 +- .../nossr50/commands/player/XPBarCommand.java | 117 ++++++++++-------- .../nossr50/commands/skills/AprilCommand.java | 2 +- .../commands/skills/MmoInfoCommand.java | 32 ++--- .../nossr50/commands/skills/SkillCommand.java | 6 +- 20 files changed, 137 insertions(+), 166 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/McconvertCommand.java b/src/main/java/com/gmail/nossr50/commands/McconvertCommand.java index e00510078d..bd9f75985d 100644 --- a/src/main/java/com/gmail/nossr50/commands/McconvertCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/McconvertCommand.java @@ -6,12 +6,10 @@ import com.gmail.nossr50.datatypes.database.DatabaseType; import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.mcMMO; -import com.google.common.collect.ImmutableList; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; -import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -21,7 +19,7 @@ public class McconvertCommand implements TabExecutor { private static final List FORMULA_TYPES; private static final List DATABASE_TYPES; - private static final List SUBCOMMANDS = ImmutableList.of("database", "experience"); + private static final List SUBCOMMANDS = List.of("database", "experience"); private final CommandExecutor databaseConvertCommand = new ConvertDatabaseCommand(); private final CommandExecutor experienceConvertCommand = new ConvertExperienceCommand(); @@ -48,8 +46,8 @@ public class McconvertCommand implements TabExecutor { Collections.sort(formulaTypes); Collections.sort(databaseTypes); - FORMULA_TYPES = ImmutableList.copyOf(formulaTypes); - DATABASE_TYPES = ImmutableList.copyOf(databaseTypes); + FORMULA_TYPES = List.copyOf(formulaTypes); + DATABASE_TYPES = List.copyOf(databaseTypes); } @@ -70,20 +68,23 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { switch (args.length) { - case 1: - return StringUtil.copyPartialMatches(args[0], SUBCOMMANDS, new ArrayList<>(SUBCOMMANDS.size())); - case 2: + case 1 -> { + return SUBCOMMANDS.stream().filter(s -> s.startsWith(args[0])).toList(); + } + case 2 -> { if (args[0].equalsIgnoreCase("database") || args[0].equalsIgnoreCase("db")) { - return StringUtil.copyPartialMatches(args[0], DATABASE_TYPES, new ArrayList<>(DATABASE_TYPES.size())); + return DATABASE_TYPES.stream().filter(s -> s.startsWith(args[1])).toList(); } if (args[0].equalsIgnoreCase("experience") || args[0].equalsIgnoreCase("xp") || args[0].equalsIgnoreCase("exp")) { - return StringUtil.copyPartialMatches(args[0], FORMULA_TYPES, new ArrayList<>(FORMULA_TYPES.size())); + return FORMULA_TYPES.stream().filter(s -> s.startsWith(args[1])).toList(); } - return ImmutableList.of(); - default: - return ImmutableList.of(); + return List.of(); + } + default -> { + return List.of(); + } } } } diff --git a/src/main/java/com/gmail/nossr50/commands/McnotifyCommand.java b/src/main/java/com/gmail/nossr50/commands/McnotifyCommand.java index a57b7f221e..fe03ca1e84 100644 --- a/src/main/java/com/gmail/nossr50/commands/McnotifyCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/McnotifyCommand.java @@ -2,9 +2,7 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; -import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; -import com.google.common.collect.ImmutableList; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; @@ -39,6 +37,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { - return ImmutableList.of(); + return List.of(); } } diff --git a/src/main/java/com/gmail/nossr50/commands/ToggleCommand.java b/src/main/java/com/gmail/nossr50/commands/ToggleCommand.java index 85985edc73..5e02351a32 100644 --- a/src/main/java/com/gmail/nossr50/commands/ToggleCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/ToggleCommand.java @@ -4,15 +4,12 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; -import com.google.common.collect.ImmutableList; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; -import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; public abstract class ToggleCommand implements TabExecutor { @@ -26,7 +23,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } if (!hasSelfPermission(sender)) { - sender.sendMessage(command.getPermissionMessage()); + String commandPermissionMessage = command.getPermissionMessage(); + if (commandPermissionMessage != null) { + sender.sendMessage(commandPermissionMessage); + } return true; } @@ -39,7 +39,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command case 1: if (!hasOtherPermission(sender)) { - sender.sendMessage(command.getPermissionMessage()); + String commandPermissionMessage = command.getPermissionMessage(); + if (commandPermissionMessage != null) { + sender.sendMessage(commandPermissionMessage); + } return true; } @@ -66,10 +69,9 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { if (args.length == 1) { - List playerNames = CommandUtils.getOnlinePlayerNames(sender); - return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size())); + return CommandUtils.getOnlinePlayerNames(sender).stream().filter(s -> s.startsWith(args[0])).toList(); } - return ImmutableList.of(); + return List.of(); } protected abstract boolean hasOtherPermission(CommandSender sender); diff --git a/src/main/java/com/gmail/nossr50/commands/XprateCommand.java b/src/main/java/com/gmail/nossr50/commands/XprateCommand.java index d982b0a833..787867821a 100644 --- a/src/main/java/com/gmail/nossr50/commands/XprateCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/XprateCommand.java @@ -8,15 +8,13 @@ import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.NotificationManager; import com.gmail.nossr50.util.text.StringUtils; -import com.google.common.collect.ImmutableList; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; -import org.bukkit.util.StringUtil; + import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; public class XprateCommand implements TabExecutor { @@ -26,7 +24,7 @@ public class XprateCommand implements TabExecutor { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { switch (args.length) { case 1 -> { - if (!args[0].equalsIgnoreCase("reset") && !args[0].equalsIgnoreCase("clear")) { + if (!args[0].equalsIgnoreCase("resetar") && !args[0].equalsIgnoreCase("limpar")) { return false; } if (!Permissions.xprateReset(sender)) { @@ -34,7 +32,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command return true; } if (mcMMO.p.isXPEventEnabled()) { - if (mcMMO.p.getAdvancedConfig().useTitlesForXPEvent()) { NotificationManager.broadcastTitle(mcMMO.p.getServer(), LocaleLoader.getString("Commands.Event.Stop"), @@ -102,15 +99,15 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman switch (args.length) { case 1 -> { if (StringUtils.isInt(args[0])) { - return java.util.List.of(); + return List.of(); } - return StringUtil.copyPartialMatches(args[0], CommandUtils.RESET_OPTIONS, new ArrayList<>(CommandUtils.RESET_OPTIONS.size())); + return CommandUtils.RESET_OPTIONS.stream().filter(s -> s.startsWith(args[0])).toList(); } case 2 -> { - return StringUtil.copyPartialMatches(args[1], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList<>(CommandUtils.TRUE_FALSE_OPTIONS.size())); + return CommandUtils.TRUE_FALSE_OPTIONS.stream().filter(s -> s.startsWith(args[1])).toList(); } default -> { - return java.util.List.of(); + return List.of(); } } } diff --git a/src/main/java/com/gmail/nossr50/commands/database/McpurgeCommand.java b/src/main/java/com/gmail/nossr50/commands/database/McpurgeCommand.java index 6f192510f6..c81bb83489 100644 --- a/src/main/java/com/gmail/nossr50/commands/database/McpurgeCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/database/McpurgeCommand.java @@ -2,7 +2,6 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; -import com.google.common.collect.ImmutableList; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; @@ -28,6 +27,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { - return ImmutableList.of(); + return List.of(); } } diff --git a/src/main/java/com/gmail/nossr50/commands/database/McremoveCommand.java b/src/main/java/com/gmail/nossr50/commands/database/McremoveCommand.java index 56b8173379..90ec69834c 100644 --- a/src/main/java/com/gmail/nossr50/commands/database/McremoveCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/database/McremoveCommand.java @@ -4,15 +4,12 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; -import com.google.common.collect.ImmutableList; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; -import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -46,9 +43,8 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { if (args.length == 1) { - List playerNames = CommandUtils.getOnlinePlayerNames(sender); - return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size())); + return CommandUtils.getOnlinePlayerNames(sender).stream().filter(s -> s.startsWith(args[0])).toList(); } - return ImmutableList.of(); + return List.of(); } } diff --git a/src/main/java/com/gmail/nossr50/commands/database/MmoshowdbCommand.java b/src/main/java/com/gmail/nossr50/commands/database/MmoshowdbCommand.java index bcb07312dc..90b3667e0f 100644 --- a/src/main/java/com/gmail/nossr50/commands/database/MmoshowdbCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/database/MmoshowdbCommand.java @@ -3,7 +3,6 @@ import com.gmail.nossr50.database.DatabaseManagerFactory; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; -import com.google.common.collect.ImmutableList; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; @@ -30,6 +29,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { - return ImmutableList.of(); + return List.of(); } } diff --git a/src/main/java/com/gmail/nossr50/commands/experience/ExperienceCommand.java b/src/main/java/com/gmail/nossr50/commands/experience/ExperienceCommand.java index bb6a83b6ff..c9f1de6488 100644 --- a/src/main/java/com/gmail/nossr50/commands/experience/ExperienceCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/experience/ExperienceCommand.java @@ -8,15 +8,12 @@ import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.SkillTools; -import com.google.common.collect.ImmutableList; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; -import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; public abstract class ExperienceCommand implements TabExecutor { @@ -127,8 +124,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command private boolean isSilent(String[] args) { int length = args.length; - if(length == 0) - return false; + if (length == 0) return false; return args[length-1].equalsIgnoreCase("-s"); } @@ -137,13 +133,15 @@ private boolean isSilent(String[] args) { @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { switch (args.length) { - case 1: - List playerNames = CommandUtils.getOnlinePlayerNames(sender); - return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size())); - case 2: - return StringUtil.copyPartialMatches(args[1], mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES, new ArrayList<>(mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.size())); - default: - return ImmutableList.of(); + case 1 -> { + return CommandUtils.getOnlinePlayerNames(sender).stream().filter(s -> s.startsWith(args[0])).toList(); + } + case 2 -> { + return mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.stream().filter(s -> s.startsWith(args[1])).toList(); + } + default -> { + return List.of(); + } } } diff --git a/src/main/java/com/gmail/nossr50/commands/experience/SkillresetCommand.java b/src/main/java/com/gmail/nossr50/commands/experience/SkillresetCommand.java index 343e3da75f..2c74db7028 100644 --- a/src/main/java/com/gmail/nossr50/commands/experience/SkillresetCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/experience/SkillresetCommand.java @@ -11,16 +11,13 @@ import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.SkillTools; -import com.google.common.collect.ImmutableList; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; -import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; /** @@ -111,12 +108,11 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { switch (args.length) { case 1: - List playerNames = CommandUtils.getOnlinePlayerNames(sender); - return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size())); + return CommandUtils.getOnlinePlayerNames(sender).stream().filter(s -> s.startsWith(args[0])).toList(); case 2: - return StringUtil.copyPartialMatches(args[1], mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES, new ArrayList<>(mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.size())); + return mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.stream().filter(s -> s.startsWith(args[1])).toList(); default: - return ImmutableList.of(); + return List.of(); } } diff --git a/src/main/java/com/gmail/nossr50/commands/hardcore/HardcoreModeCommand.java b/src/main/java/com/gmail/nossr50/commands/hardcore/HardcoreModeCommand.java index 1bffa7a65e..6bb76ad3d0 100644 --- a/src/main/java/com/gmail/nossr50/commands/hardcore/HardcoreModeCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/hardcore/HardcoreModeCommand.java @@ -112,12 +112,12 @@ // public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { // if (args.length == 1) { // if (StringUtils.isDouble(args[0])) { -// return ImmutableList.of(); +// return List.of(); // } // // return StringUtil.copyPartialMatches(args[0], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList<>(CommandUtils.TRUE_FALSE_OPTIONS.size())); // } -// return ImmutableList.of(); +// return List.of(); // } // // protected abstract boolean checkTogglePermissions(CommandSender sender); diff --git a/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java b/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java index a4384c1e10..174c0a6b8a 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java @@ -20,9 +20,9 @@ public class PartyCommand implements TabExecutor { private static final List PARTY_SUBCOMMANDS = PartySubcommandType.getSubcommands(); - private static final List XPSHARE_COMPLETIONS = List.of("none", "equal"); - private static final List ITEMSHARE_COMPLETIONS = List.of("none", "equal", "random", "loot", "mining", "herbalism", "woodcutting", "misc"); - private static final List ITEMSHARE_CATEGORY = List.of("loot", "mining", "herbalism", "woodcutting", "misc"); + private static final List XPSHARE_COMPLETIONS = List.of("nenhum", "igual"); + private static final List ITEMSHARE_COMPLETIONS = List.of("nenhum", "igual", "aleatorio", "saque", "mineracao", "herbalismo", "lenhador", "outros"); + private static final List ITEMSHARE_CATEGORY = List.of("saque", "mineracao", "herbalismo", "lenhador", "outros"); private final CommandExecutor partyJoinCommand; private final CommandExecutor partyAcceptCommand; private final CommandExecutor partyCreateCommand; diff --git a/src/main/java/com/gmail/nossr50/commands/party/alliance/PartyAllianceCommand.java b/src/main/java/com/gmail/nossr50/commands/party/alliance/PartyAllianceCommand.java index e6ba92b902..aed140281e 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/alliance/PartyAllianceCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/alliance/PartyAllianceCommand.java @@ -13,7 +13,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; -import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -110,8 +109,7 @@ public List onTabComplete(@NotNull CommandSender commandSender, @NotNull List matches = ALLIANCE_SUBCOMMANDS.stream().filter(s -> s.startsWith(args[0])).toList(); if (matches.isEmpty()) { - List playerNames = CommandUtils.getOnlinePlayerNames(commandSender); - return playerNames.stream().filter(s -> StringUtil.startsWithIgnoreCase(s, args[0])).toList(); + return CommandUtils.getOnlinePlayerNames(commandSender).stream().filter(s -> s.startsWith(args[0])).toList(); } return matches; diff --git a/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpCommand.java b/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpCommand.java index 69bb92fe70..27fce1f6f0 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpCommand.java @@ -22,10 +22,8 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; -import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; public class PtpCommand implements TabExecutor { @@ -135,8 +133,7 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman if (!mcMMOPlayer.inParty()) return List.of(); Party party = mcMMOPlayer.getParty(); if (party == null) return List.of(); - List playerNames = mcMMOPlayer.getParty().getOnlinePlayerNames(player); - return playerNames.stream().filter(s -> StringUtil.startsWithIgnoreCase(s, args[0])).toList(); + return mcMMOPlayer.getParty().getOnlinePlayerNames(player).stream().filter(s -> s.startsWith(args[0])).toList(); } return matches; diff --git a/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java b/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java index ab10473879..846852bfa8 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java @@ -10,15 +10,12 @@ import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.scoreboards.ScoreboardManager; import com.gmail.nossr50.util.skills.SkillTools; -import com.google.common.collect.ImmutableList; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; -import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; public class InspectCommand implements TabExecutor { @@ -113,9 +110,8 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { if (args.length == 1) { - List playerNames = CommandUtils.getOnlinePlayerNames(sender); - return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size())); + return CommandUtils.getOnlinePlayerNames(sender).stream().filter(s -> s.startsWith(args[0])).toList(); } - return ImmutableList.of(); + return List.of(); } } diff --git a/src/main/java/com/gmail/nossr50/commands/player/McstatsCommand.java b/src/main/java/com/gmail/nossr50/commands/player/McstatsCommand.java index ef8ba3d029..b2e9b0b182 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/McstatsCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/McstatsCommand.java @@ -6,7 +6,6 @@ import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.scoreboards.ScoreboardManager; -import com.google.common.collect.ImmutableList; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; @@ -64,6 +63,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { - return ImmutableList.of(); + return List.of(); } } diff --git a/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java b/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java index 86b1757e9b..1df80b0495 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java @@ -10,13 +10,11 @@ import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.text.StringUtils; -import com.google.common.collect.ImmutableList; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; import org.bukkit.metadata.FixedMetadataValue; -import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -69,9 +67,9 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { if (args.length == 1) { - return StringUtil.copyPartialMatches(args[0], mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES, new ArrayList<>(mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.size())); + return mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.stream().filter(s -> s.startsWith(args[0])).toList(); } - return ImmutableList.of(); + return List.of(); } private void display(int page, PrimarySkillType skill, CommandSender sender, Command command) { diff --git a/src/main/java/com/gmail/nossr50/commands/player/XPBarCommand.java b/src/main/java/com/gmail/nossr50/commands/player/XPBarCommand.java index e780fa19d9..ef125cd243 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/XPBarCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/XPBarCommand.java @@ -2,21 +2,21 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; +import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.experience.ExperienceBarManager; import com.gmail.nossr50.util.player.NotificationManager; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.text.StringUtils; -import com.google.common.collect.ImmutableList; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; -import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; + import java.util.ArrayList; import java.util.List; @@ -24,56 +24,57 @@ public class XPBarCommand implements TabExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if(sender instanceof Player) { - McMMOPlayer mmoPlayer = UserManager.getPlayer((Player) sender); - if(mmoPlayer == null) { - NotificationManager.sendPlayerInformationChatOnlyPrefixed(mmoPlayer.getPlayer(), "Profile.PendingLoad"); - return false; + if (!(sender instanceof Player player)) { + sender.sendMessage(LocaleLoader.getString("Commands.NoConsole")); + return false; + } + + McMMOPlayer mmoPlayer = UserManager.getPlayer(player); + if (mmoPlayer == null) { + NotificationManager.sendPlayerInformationChatOnlyPrefixed(player, "Profile.PendingLoad"); + return false; + } + + if (args.length == 0) { + return false; + } + + if (args.length < 2) { + String option = args[0]; + if (option.equalsIgnoreCase(ExperienceBarManager.XPBarSettingTarget.RESET.toString())) { + mmoPlayer.getExperienceBarManager().xpBarSettingToggle(ExperienceBarManager.XPBarSettingTarget.RESET, null); + return true; } - if(args.length == 0) { - return false; - } else if(args.length < 2) { - String option = args[0]; - - if(option.equalsIgnoreCase(ExperienceBarManager.XPBarSettingTarget.RESET.toString())) { - mmoPlayer.getExperienceBarManager().xpBarSettingToggle(ExperienceBarManager.XPBarSettingTarget.RESET, null); - return true; - } else if(option.equalsIgnoreCase(ExperienceBarManager.XPBarSettingTarget.DISABLE.toString())) { - mmoPlayer.getExperienceBarManager().disableAllBars(); - return true; - } else { - return false; - } - - //Per skill Settings path - } else if (args.length == 2) { - String skillName = args[1]; - - if(SkillUtils.isSkill(skillName)) { - - PrimarySkillType targetSkill = mcMMO.p.getSkillTools().matchSkill(skillName); - - //Target setting - String option = args[0].toLowerCase(); - - ExperienceBarManager.XPBarSettingTarget settingTarget = getSettingTarget(option); - if(settingTarget != null && settingTarget != ExperienceBarManager.XPBarSettingTarget.RESET) { - //Change setting - mmoPlayer.getExperienceBarManager().xpBarSettingToggle(settingTarget, targetSkill); - return true; - } else { - return false; - } - } else { - return false; - } - } else { - return false; + if (option.equalsIgnoreCase(ExperienceBarManager.XPBarSettingTarget.DISABLE.toString())) { + mmoPlayer.getExperienceBarManager().disableAllBars(); + return true; } - } else { + return false; } + + //Per skill Settings path + if (args.length == 2) { + String skillName = args[1]; + if (!SkillUtils.isSkill(skillName)) { + return false; + } + + PrimarySkillType targetSkill = mcMMO.p.getSkillTools().matchSkill(skillName); + + //Target setting + String option = args[0].toLowerCase(); + + ExperienceBarManager.XPBarSettingTarget settingTarget = getSettingTarget(option); + if (settingTarget != null && settingTarget != ExperienceBarManager.XPBarSettingTarget.RESET) { + //Change setting + mmoPlayer.getExperienceBarManager().xpBarSettingToggle(settingTarget, targetSkill); + return true; + } + } + + return false; } private @Nullable ExperienceBarManager.XPBarSettingTarget getSettingTarget(String string) { @@ -94,19 +95,25 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { switch (args.length) { - case 1: + case 1 -> { List options = new ArrayList<>(); - for(ExperienceBarManager.XPBarSettingTarget settingTarget : ExperienceBarManager.XPBarSettingTarget.values()) { + for (ExperienceBarManager.XPBarSettingTarget settingTarget : ExperienceBarManager.XPBarSettingTarget.values()) { options.add(StringUtils.getCapitalized(settingTarget.toString())); } - return StringUtil.copyPartialMatches(args[0], options, new ArrayList<>(ExperienceBarManager.XPBarSettingTarget.values().length)); - case 2: - if(!args[0].equalsIgnoreCase(ExperienceBarManager.XPBarSettingTarget.RESET.toString())) - return StringUtil.copyPartialMatches(args[1], mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES, new ArrayList<>(mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.size())); - default: - return ImmutableList.of(); + return options.stream().filter(s -> s.startsWith(args[0])).toList(); + } + case 2 -> { + if (!args[0].equalsIgnoreCase(ExperienceBarManager.XPBarSettingTarget.RESET.toString())) { + mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.stream().filter(s -> s.startsWith(args[1])).toList(); + } + } + default -> { + return List.of(); + } } + + return List.of(); } } diff --git a/src/main/java/com/gmail/nossr50/commands/skills/AprilCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/AprilCommand.java index 5364918ffe..5b97aa9922 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/AprilCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/AprilCommand.java @@ -103,7 +103,7 @@ // if (args.length == 1) { // return ImmutableList.of("?"); // } -// return ImmutableList.of(); +// return List.of(); // } // // private List effectsDisplay(FakeSkillType fakeSkillType) { diff --git a/src/main/java/com/gmail/nossr50/commands/skills/MmoInfoCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/MmoInfoCommand.java index 0f0a4a710d..171ac009c7 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/MmoInfoCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/MmoInfoCommand.java @@ -6,15 +6,12 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.text.TextComponentFactory; -import com.google.common.collect.ImmutableList; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; -import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; /** @@ -27,25 +24,20 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command /* * Only allow players to use this command */ - if(commandSender instanceof Player player) - { - if(args.length < 1) + if (commandSender instanceof Player player) { + if (args.length < 1) return false; - if(Permissions.mmoinfo(player)) - { - if(args == null || args[0] == null) - return false; + if (Permissions.mmoinfo(player)) { + if (args == null || args[0] == null) return false; - if(args[0].equalsIgnoreCase( "???")) - { + if (args[0].equalsIgnoreCase("???")) { player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.Header")); player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.SubSkillHeader", "???")); player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.DetailsHeader")); player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.Mystery")); return true; - } else if(InteractionManager.getAbstractByName(args[0]) != null || mcMMO.p.getSkillTools().EXACT_SUBSKILL_NAMES.contains(args[0])) - { + } else if (InteractionManager.getAbstractByName(args[0]) != null || mcMMO.p.getSkillTools().EXACT_SUBSKILL_NAMES.contains(args[0])) { displayInfo(player, args[0]); return true; } @@ -62,21 +54,19 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { if (args.length == 1) { - return StringUtil.copyPartialMatches(args[0], mcMMO.p.getSkillTools().EXACT_SUBSKILL_NAMES, new ArrayList<>(mcMMO.p.getSkillTools().EXACT_SUBSKILL_NAMES.size())); + return mcMMO.p.getSkillTools().EXACT_SUBSKILL_NAMES.stream().filter(s -> s.startsWith(args[0])).toList(); } - return ImmutableList.of(); + return List.of(); } - private void displayInfo(Player player, String subSkillName) - { + private void displayInfo(Player player, String subSkillName) { player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.Header")); player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.SubSkillHeader", subSkillName)); player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.DetailsHeader")); player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.OldSkill")); - for(SubSkillType subSkillType : SubSkillType.values()) - { - if(subSkillType.getNiceNameNoSpaces(subSkillType).equalsIgnoreCase(subSkillName)) + for (SubSkillType subSkillType : SubSkillType.values()) { + if (subSkillType.getNiceNameNoSpaces(subSkillType).equalsIgnoreCase(subSkillName)) subSkillName = subSkillType.getWikiName(subSkillType.toString()); } diff --git a/src/main/java/com/gmail/nossr50/commands/skills/SkillCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/SkillCommand.java index 70b88d7717..b571c079b6 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/SkillCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/SkillCommand.java @@ -18,7 +18,6 @@ import com.gmail.nossr50.util.skills.SkillTools; import com.gmail.nossr50.util.text.StringUtils; import com.gmail.nossr50.util.text.TextComponentFactory; -import com.google.common.collect.ImmutableList; import net.kyori.adventure.text.Component; import net.md_5.bungee.api.ChatColor; import org.bukkit.command.Command; @@ -33,6 +32,7 @@ import java.util.List; import java.util.Locale; import java.util.Set; +import java.util.stream.Stream; public abstract class SkillCommand implements TabExecutor { protected PrimarySkillType skill; @@ -223,9 +223,9 @@ private void sendSkillCommandHeader(Player player, McMMOPlayer mcMMOPlayer, int @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { if (args.length == 1) { - return ImmutableList.of("?", "keep"); + return Stream.of("?", "keep").filter(s -> s.startsWith(args[0])).toList(); } - return ImmutableList.of(); + return List.of(); } protected int calculateRank(float skillValue, int maxLevel, int rankChangeLevel) {