diff options
Diffstat (limited to 'src/main/java/eu/olli/cowmoonication/command')
| -rw-r--r-- | src/main/java/eu/olli/cowmoonication/command/MooCommand.java | 2 | ||||
| -rw-r--r-- | src/main/java/eu/olli/cowmoonication/command/TabCompletableCommand.java | 50 |
2 files changed, 12 insertions, 40 deletions
diff --git a/src/main/java/eu/olli/cowmoonication/command/MooCommand.java b/src/main/java/eu/olli/cowmoonication/command/MooCommand.java index c1a8318..9cf94e1 100644 --- a/src/main/java/eu/olli/cowmoonication/command/MooCommand.java +++ b/src/main/java/eu/olli/cowmoonication/command/MooCommand.java @@ -180,7 +180,7 @@ public class MooCommand extends CommandBase { if (slothStalking == null) { main.getChatHelper().sendMessage(EnumChatFormatting.RED, "Something went wrong contacting the Slothpixel API. Couldn't stalk " + EnumChatFormatting.DARK_RED + stalkedPlayer.getName() + EnumChatFormatting.RED + " but they appear to be offline currently."); } else if (slothStalking.hasNeverJoinedHypixel()) { - main.getChatHelper().sendMessage(EnumChatFormatting.YELLOW, stalkedPlayer.getName() + EnumChatFormatting.YELLOW + " has " + EnumChatFormatting.GOLD + "never " + EnumChatFormatting.YELLOW + "been on Hypixel (or might be nicked)."); + main.getChatHelper().sendMessage(EnumChatFormatting.YELLOW, EnumChatFormatting.GOLD + stalkedPlayer.getName() + EnumChatFormatting.YELLOW + " has " + EnumChatFormatting.GOLD + "never " + EnumChatFormatting.YELLOW + "been on Hypixel (or might be nicked)."); } else if (slothStalking.isHidingOnlineStatus()) { main.getChatHelper().sendMessage(EnumChatFormatting.YELLOW, slothStalking.getPlayerNameFormatted() + EnumChatFormatting.YELLOW + " is hiding their online status."); } else if (slothStalking.hasNeverLoggedOut()) { diff --git a/src/main/java/eu/olli/cowmoonication/command/TabCompletableCommand.java b/src/main/java/eu/olli/cowmoonication/command/TabCompletableCommand.java index b1ffa33..470f93c 100644 --- a/src/main/java/eu/olli/cowmoonication/command/TabCompletableCommand.java +++ b/src/main/java/eu/olli/cowmoonication/command/TabCompletableCommand.java @@ -1,63 +1,40 @@ package eu.olli.cowmoonication.command; -import com.mojang.realmsclient.util.Pair; import eu.olli.cowmoonication.Cowmoonication; -import eu.olli.cowmoonication.config.MooConfig; import net.minecraft.client.Minecraft; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.util.BlockPos; -import net.minecraft.util.EnumChatFormatting; -import org.apache.commons.lang3.StringUtils; -import java.util.Arrays; import java.util.List; +/** + * This is not a real command. Its sole purpose is to add tab completion for usernames to server-side commands that do not provide tab completion for usernames by default. + */ public class TabCompletableCommand extends CommandBase { private final Cowmoonication main; + private final String cmdName; - public TabCompletableCommand(Cowmoonication main) { + public TabCompletableCommand(Cowmoonication main, String cmdName) { this.main = main; + this.cmdName = cmdName; } @Override public String getCommandName() { - return "tabcompletablecommand"; + return cmdName; } @Override public String getCommandUsage(ICommandSender sender) { - return EnumChatFormatting.YELLOW + "Commands where player names can be Tab-completed: " + EnumChatFormatting.GOLD + StringUtils.join(getCommandAliases(), EnumChatFormatting.YELLOW + ", " + EnumChatFormatting.GOLD) - + EnumChatFormatting.YELLOW + ". Use " + EnumChatFormatting.GOLD + "/moo config " + EnumChatFormatting.YELLOW + " to edit the list of commands with tab-completable usernames."; + return null; } @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { - Pair<String, String> lastCommand = getLastCommand(); - if (lastCommand == null) { - main.getChatHelper().sendMessage(EnumChatFormatting.RED, "Something went wrong trying to process this command."); - } else if (lastCommand.first().equalsIgnoreCase(getCommandName())) { - main.getChatHelper().sendMessage(EnumChatFormatting.YELLOW, getCommandUsage(sender)); - } else { - Minecraft.getMinecraft().thePlayer.sendChatMessage(lastCommand.second()); - } - } - - /** - * Work-around to get last used command name or alias (by default it's impossible to detect the used alias) - * - * @return 1st: last command used by thePlayer, 2nd: (full) last message sent thePlayer; or null if no command was sent as the last message - */ - private Pair<String, String> getLastCommand() { - List<String> sentMessages = Minecraft.getMinecraft().ingameGUI.getChatGUI().getSentMessages(); - String lastMessage = sentMessages.get(sentMessages.size() - 1); - if (lastMessage.startsWith("/")) { - int endOfCommandName = lastMessage.indexOf(" "); - return Pair.of(lastMessage.substring(1, endOfCommandName == -1 ? lastMessage.length() : endOfCommandName), - lastMessage); - } - return null; + // send client-command to server + Minecraft.getMinecraft().thePlayer.sendChatMessage("/" + getCommandName() + " " + CommandBase.buildString(args, 0)); } @Override @@ -66,14 +43,9 @@ public class TabCompletableCommand extends CommandBase { } @Override - public List<String> getCommandAliases() { - // list of commands that require a player name as one their 1st or 2nd argument - return Arrays.asList(MooConfig.tabCompletableNamesCommands); - } - - @Override public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { if (args.length == 1 || args.length == 2) { + // suggest recently 'seen' usernames as tab-completion options. return getListOfStringsMatchingLastWord(args, main.getPlayerCache().getAllNamesSorted()); } return null; |
