diff options
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | src/main/java/eu/olli/cowmoonication/Cowmoonication.java | 4 | ||||
-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 | ||||
-rw-r--r-- | src/main/java/eu/olli/cowmoonication/listener/ChatListener.java | 4 | ||||
-rw-r--r-- | src/main/java/eu/olli/cowmoonication/util/PlayerCache.java | 7 |
7 files changed, 25 insertions, 47 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index c3ed334..e12270c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [1.8.9-0.5.0] - unreleased ### Added - Added Tab-completable usernames for several commands (e.g. party, msg, boop, ...) - - use command `/tabcompletablecommand` for a full list of commands that support Tab-completion - - the list of supported commands can be modified via `/moo config` + - the list of supported commands can be modified via `/moo config` → `Commands with Tab-completable usernames` - Tab-completable usernames consist of: the last 50 players that typed in private/friends, Guild or Party chat; up to 50 best friends that are currently logged in ### Changed @@ -8,7 +8,7 @@ A client-side only Forge mod by [Cow](https://namemc.com/profile/Cow) providing | Toggle join/leave notifications for friends, guild members or best friends separately | `/moo toggle` | | Stalk a player (check online status, current game, ...) | `/moo stalk` | | Change guiScale to any value | `/moo guiscale [newValue]` | -| Tab-completable usernames for several commands (e.g. `/party`, `/invite`, ...) | `/tabcompletablecommand` for full list of commands | +| Tab-completable usernames for several commands (e.g. `/party`, `/invite`, ...) | `/moo config` → `Commands with Tab-completable usernames` for full list of commands | | Auto-replace `/r` with `/w <latest username>` | `/r ` | | Copy chat component | <kbd>ALT</kbd> + <kbd>right click</kbd><br>Hold <kbd>shift</kbd> to copy full component | | Check for mod updates on server login and via command | `/moo update` | diff --git a/src/main/java/eu/olli/cowmoonication/Cowmoonication.java b/src/main/java/eu/olli/cowmoonication/Cowmoonication.java index 30ac662..e106fcd 100644 --- a/src/main/java/eu/olli/cowmoonication/Cowmoonication.java +++ b/src/main/java/eu/olli/cowmoonication/Cowmoonication.java @@ -60,7 +60,9 @@ public class Cowmoonication { MinecraftForge.EVENT_BUS.register(new PlayerListener(this)); ClientCommandHandler.instance.registerCommand(new MooCommand(this)); ClientCommandHandler.instance.registerCommand(new ShrugCommand(this)); - ClientCommandHandler.instance.registerCommand(new TabCompletableCommand(this)); + for (String tabCompletableNamesCommand : MooConfig.tabCompletableNamesCommands) { + ClientCommandHandler.instance.registerCommand(new TabCompletableCommand(this, tabCompletableNamesCommand)); + } } @EventHandler 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; diff --git a/src/main/java/eu/olli/cowmoonication/listener/ChatListener.java b/src/main/java/eu/olli/cowmoonication/listener/ChatListener.java index 3c8847b..855166a 100644 --- a/src/main/java/eu/olli/cowmoonication/listener/ChatListener.java +++ b/src/main/java/eu/olli/cowmoonication/listener/ChatListener.java @@ -92,6 +92,10 @@ public class ChatListener { @SubscribeEvent public void onClickOnChat(GuiScreenEvent.MouseInputEvent.Pre e) { + if (Mouse.getEventButton() < 0) { + // no button press, just mouse-hover + return; + } if (e.gui instanceof GuiChat) { if (!Mouse.getEventButtonState() && Mouse.getEventButton() == 1 && Keyboard.isKeyDown(Keyboard.KEY_LMENU)) { // alt key pressed and right mouse button being released IChatComponent chatComponent = Minecraft.getMinecraft().ingameGUI.getChatGUI().getChatComponent(Mouse.getX(), Mouse.getY()); diff --git a/src/main/java/eu/olli/cowmoonication/util/PlayerCache.java b/src/main/java/eu/olli/cowmoonication/util/PlayerCache.java index 1b5251a..383ca03 100644 --- a/src/main/java/eu/olli/cowmoonication/util/PlayerCache.java +++ b/src/main/java/eu/olli/cowmoonication/util/PlayerCache.java @@ -3,7 +3,7 @@ package eu.olli.cowmoonication.util; import com.google.common.collect.EvictingQueue; import eu.olli.cowmoonication.Cowmoonication; -import java.util.Set; +import java.util.SortedSet; import java.util.TreeSet; public class PlayerCache { @@ -33,8 +33,9 @@ public class PlayerCache { bestFriendCache.remove(name); } - public Set<String> getAllNamesSorted() { - Set<String> nameList = new TreeSet<>(bestFriendCache); + public SortedSet<String> getAllNamesSorted() { + SortedSet<String> nameList = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); + nameList.addAll(bestFriendCache); nameList.addAll(nameCache); return nameList; } |