Skip to content

Commit

Permalink
Removido ImmutableList e StringUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock committed Feb 21, 2024
1 parent f725217 commit 5028f43
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 166 deletions.
27 changes: 14 additions & 13 deletions src/main/java/com/gmail/nossr50/commands/McconvertCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +19,7 @@
public class McconvertCommand implements TabExecutor {
private static final List<String> FORMULA_TYPES;
private static final List<String> DATABASE_TYPES;
private static final List<String> SUBCOMMANDS = ImmutableList.of("database", "experience");
private static final List<String> SUBCOMMANDS = List.of("database", "experience");

private final CommandExecutor databaseConvertCommand = new ConvertDatabaseCommand();
private final CommandExecutor experienceConvertCommand = new ConvertExperienceCommand();
Expand All @@ -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);

}

Expand All @@ -70,20 +68,23 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
@Override
public List<String> 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();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -39,6 +37,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command

@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
return ImmutableList.of();
return List.of();
}
}
18 changes: 10 additions & 8 deletions src/main/java/com/gmail/nossr50/commands/ToggleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -66,10 +69,9 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
if (args.length == 1) {
List<String> 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);
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/com/gmail/nossr50/commands/XprateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -26,15 +24,14 @@ 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)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (mcMMO.p.isXPEventEnabled()) {

if (mcMMO.p.getAdvancedConfig().useTitlesForXPEvent()) {
NotificationManager.broadcastTitle(mcMMO.p.getServer(),
LocaleLoader.getString("Commands.Event.Stop"),
Expand Down Expand Up @@ -102,15 +99,15 @@ public List<String> 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();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +27,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command

@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
return ImmutableList.of();
return List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -46,9 +43,8 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
if (args.length == 1) {
List<String> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +29,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command

@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
return ImmutableList.of();
return List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
}
Expand All @@ -137,13 +133,15 @@ private boolean isSilent(String[] args) {
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
switch (args.length) {
case 1:
List<String> 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();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -111,12 +108,11 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
switch (args.length) {
case 1:
List<String> 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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@
// public List<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

public class PartyCommand implements TabExecutor {
private static final List<String> PARTY_SUBCOMMANDS = PartySubcommandType.getSubcommands();
private static final List<String> XPSHARE_COMPLETIONS = List.of("none", "equal");
private static final List<String> ITEMSHARE_COMPLETIONS = List.of("none", "equal", "random", "loot", "mining", "herbalism", "woodcutting", "misc");
private static final List<String> ITEMSHARE_CATEGORY = List.of("loot", "mining", "herbalism", "woodcutting", "misc");
private static final List<String> XPSHARE_COMPLETIONS = List.of("nenhum", "igual");
private static final List<String> ITEMSHARE_COMPLETIONS = List.of("nenhum", "igual", "aleatorio", "saque", "mineracao", "herbalismo", "lenhador", "outros");
private static final List<String> ITEMSHARE_CATEGORY = List.of("saque", "mineracao", "herbalismo", "lenhador", "outros");
private final CommandExecutor partyJoinCommand;
private final CommandExecutor partyAcceptCommand;
private final CommandExecutor partyCreateCommand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -110,8 +109,7 @@ public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull
List<String> matches = ALLIANCE_SUBCOMMANDS.stream().filter(s -> s.startsWith(args[0])).toList();

if (matches.isEmpty()) {
List<String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -135,8 +133,7 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
if (!mcMMOPlayer.inParty()) return List.of();
Party party = mcMMOPlayer.getParty();
if (party == null) return List.of();
List<String> 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;
Expand Down
Loading

0 comments on commit 5028f43

Please sign in to comment.