diff --git a/src/main/java/com/artemis/the/gr8/playerstats/commands/TabCompleter.java b/src/main/java/com/artemis/the/gr8/playerstats/commands/TabCompleter.java deleted file mode 100644 index deab6a8..0000000 --- a/src/main/java/com/artemis/the/gr8/playerstats/commands/TabCompleter.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.artemis.the.gr8.playerstats.commands; - -import com.artemis.the.gr8.playerstats.utils.EnumHandler; -import com.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler; -import com.artemis.the.gr8.playerstats.commands.cmdutils.TabCompleteHelper; -import org.bukkit.Statistic; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.stream.Collectors; - -public final class TabCompleter implements org.bukkit.command.TabCompleter { - - private final EnumHandler enumHandler; - private final OfflinePlayerHandler offlinePlayerHandler; - private final TabCompleteHelper tabCompleteHelper; - - private final List commandOptions; - - public TabCompleter(EnumHandler enumHandler, OfflinePlayerHandler offlinePlayerHandler) { - this.enumHandler = enumHandler; - this.offlinePlayerHandler = offlinePlayerHandler; - tabCompleteHelper = new TabCompleteHelper(enumHandler); - - commandOptions = new ArrayList<>(); - commandOptions.add("top"); - commandOptions.add("player"); - commandOptions.add("server"); - commandOptions.add("me"); - - } - - //args[0] = statistic (length = 1) - //args[1] = commandOption (top/player/me) OR substatistic (block/item/entitytype) (length = 2) - //args[2] = executorName OR commandOption (top/player/me) (length = 3) - //args[3] = executorName (length = 4) - - @Override - public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { - List tabSuggestions = new ArrayList<>(); - - if (args.length >= 1) { - String currentArg = args[args.length -1]; - - if (args.length == 1) { //after typing "stat", suggest a list of viable statistics - tabSuggestions = getFirstArgSuggestions(args[0]); - } - - else { //after checking if args[0] is a viable statistic, suggest substatistic OR commandOptions - String previousArg = args[args.length -2]; - - if (enumHandler.isStatistic(previousArg)) { - Statistic stat = EnumHandler.getStatEnum(previousArg); - if (stat != null) { - tabSuggestions = getTabSuggestions(getRelevantList(stat), currentArg); - } - } - - //if previous arg = "player" - else if (previousArg.equalsIgnoreCase("player")) { - - if (args.length >= 3 && enumHandler.isEntityStatistic(args[args.length-3])) { - tabSuggestions = commandOptions; //if arg before "player" was entity-stat, suggest commandOptions - } - else { //otherwise "player" is target-flag: suggest playerNames - tabSuggestions = getTabSuggestions(offlinePlayerHandler.getOfflinePlayerNames(), currentArg); - } - } - - //after a substatistic, suggest commandOptions - else if (enumHandler.isSubStatEntry(previousArg)) { - tabSuggestions = commandOptions; - } - } - } - return tabSuggestions; - } - - private List getFirstArgSuggestions(String currentArg) { - List suggestions = enumHandler.getStatNames(); - suggestions.add("examples"); - suggestions.add("help"); - return getTabSuggestions(suggestions, currentArg); - } - - private List getTabSuggestions(List completeList, String currentArg) { - return completeList.stream() - .filter(item -> item.toLowerCase(Locale.ENGLISH).contains(currentArg.toLowerCase(Locale.ENGLISH))) - .collect(Collectors.toList()); - } - - private List getRelevantList(Statistic stat) { - switch (stat.getType()) { - case BLOCK -> { - return tabCompleteHelper.getAllBlockNames(); - } - case ITEM -> { - if (stat == Statistic.BREAK_ITEM) { - return tabCompleteHelper.getItemBrokenSuggestions(); - } else { - return tabCompleteHelper.getAllItemNames(); - } - } - case ENTITY -> { - return tabCompleteHelper.getEntitySuggestions(); - } - default -> { - return commandOptions; - } - } - } -} \ No newline at end of file diff --git a/src/main/java/com/artemis/the/gr8/playerstats/commands/cmdutils/TabCompleteHelper.java b/src/main/java/com/artemis/the/gr8/playerstats/commands/cmdutils/TabCompleteHelper.java deleted file mode 100644 index ab4f00a..0000000 --- a/src/main/java/com/artemis/the/gr8/playerstats/commands/cmdutils/TabCompleteHelper.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.artemis.the.gr8.playerstats.commands.cmdutils; - -import com.artemis.the.gr8.playerstats.utils.EnumHandler; -import org.bukkit.Material; -import org.bukkit.entity.EntityType; - -import java.util.Arrays; -import java.util.List; -import java.util.Locale; -import java.util.stream.Collectors; - -public final class TabCompleteHelper { - - private final EnumHandler enumHandler; - private static List itemBrokenSuggestions; - private static List entitySuggestions; - - public TabCompleteHelper(EnumHandler enumHandler) { - this.enumHandler = enumHandler; - prepareLists(); - } - - public List getAllItemNames() { - return enumHandler.getItemNames(); - } - - public List getItemBrokenSuggestions() { - return itemBrokenSuggestions; - } - - public List getAllBlockNames() { - return enumHandler.getBlockNames(); - } - - public List getEntitySuggestions() { - return entitySuggestions; - } - - - private static void prepareLists() { - //breaking an item means running its durability negative - itemBrokenSuggestions = Arrays.stream(Material.values()) - .parallel() - .filter(Material::isItem) - .filter(item -> item.getMaxDurability() != 0) - .map(Material::toString) - .map(string -> string.toLowerCase(Locale.ENGLISH)) - .collect(Collectors.toList()); - - //the only statistics dealing with entities are killed_entity and entity_killed_by - entitySuggestions = Arrays.stream(EntityType.values()) - .parallel() - .filter(EntityType::isAlive) - .map(EntityType::toString) - .map(string -> string.toLowerCase(Locale.ENGLISH)) - .collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/src/main/java/com/artemis/the/gr8/playerstats/core/commands/TabCompleter.java b/src/main/java/com/artemis/the/gr8/playerstats/core/commands/TabCompleter.java index ffb0ff4..4d5f9d0 100644 --- a/src/main/java/com/artemis/the/gr8/playerstats/core/commands/TabCompleter.java +++ b/src/main/java/com/artemis/the/gr8/playerstats/core/commands/TabCompleter.java @@ -13,6 +13,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.stream.Collectors; public final class TabCompleter implements org.bukkit.command.TabCompleter { @@ -104,7 +105,7 @@ public final class TabCompleter implements org.bukkit.command.TabCompleter { */ private List getDynamicTabSuggestions(@NotNull List completeList, String currentArg) { return completeList.stream() - .filter(item -> item.toLowerCase().contains(currentArg.toLowerCase())) + .filter(item -> item.toLowerCase(Locale.ENGLISH).contains(currentArg.toLowerCase(Locale.ENGLISH))) .collect(Collectors.toList()); } @@ -147,7 +148,7 @@ public final class TabCompleter implements org.bukkit.command.TabCompleter { .filter(Material::isItem) .filter(item -> item.getMaxDurability() != 0) .map(Material::toString) - .map(String::toLowerCase) + .map(string -> string.toLowerCase(Locale.ENGLISH)) .collect(Collectors.toList()); //the only statistics dealing with entities are killed_entity and entity_killed_by @@ -155,7 +156,7 @@ public final class TabCompleter implements org.bukkit.command.TabCompleter { .parallel() .filter(EntityType::isAlive) .map(EntityType::toString) - .map(String::toLowerCase) + .map(string -> string.toLowerCase(Locale.ENGLISH)) .collect(Collectors.toList()); } } \ No newline at end of file diff --git a/src/main/java/com/artemis/the/gr8/playerstats/core/msg/msgutils/StringUtils.java b/src/main/java/com/artemis/the/gr8/playerstats/core/msg/msgutils/StringUtils.java index e4f2223..017385d 100644 --- a/src/main/java/com/artemis/the/gr8/playerstats/core/msg/msgutils/StringUtils.java +++ b/src/main/java/com/artemis/the/gr8/playerstats/core/msg/msgutils/StringUtils.java @@ -2,6 +2,7 @@ package com.artemis.the.gr8.playerstats.core.msg.msgutils; import com.artemis.the.gr8.playerstats.core.utils.MyLogger; +import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -29,7 +30,7 @@ public final class StringUtils { if (input == null) return null; MyLogger.logHighLevelMsg("Prettifying [" + input + "]"); - StringBuilder capitals = new StringBuilder(input.toLowerCase()); + StringBuilder capitals = new StringBuilder(input.toLowerCase(Locale.ENGLISH)); capitals.setCharAt(0, Character.toUpperCase(capitals.charAt(0))); while (capitals.indexOf("_") != -1) { diff --git a/src/main/java/com/artemis/the/gr8/playerstats/msg/msgutils/StringUtils.java b/src/main/java/com/artemis/the/gr8/playerstats/msg/msgutils/StringUtils.java deleted file mode 100644 index 79cc7cf..0000000 --- a/src/main/java/com/artemis/the/gr8/playerstats/msg/msgutils/StringUtils.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.artemis.the.gr8.playerstats.msg.msgutils; - -import com.artemis.the.gr8.playerstats.utils.MyLogger; - -import java.util.Locale; - -/** - * A small utility class that helps make enum constant - * names prettier for output in stat-messages. - */ -public final class StringUtils { - - private StringUtils() { - } - - /** - * Replace "_" with " " and capitalize each first letter of the input. - * - * @param input String to prettify, case-insensitive - */ - public static String prettify(String input) { - if (input == null) return null; - StringBuilder capitals = new StringBuilder(input.toLowerCase(Locale.ENGLISH)); - capitals.setCharAt(0, Character.toUpperCase(capitals.charAt(0))); - while (capitals.indexOf("_") != -1) { - MyLogger.logHighLevelMsg("Replacing underscores and capitalizing names..."); - - int index = capitals.indexOf("_"); - capitals.setCharAt(index + 1, Character.toUpperCase(capitals.charAt(index + 1))); - capitals.setCharAt(index, ' '); - } - return capitals.toString(); - } -} \ No newline at end of file