aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/eu/olli/cowmoonication/Cowmoonication.java4
-rw-r--r--src/main/java/eu/olli/cowmoonication/command/MooCommand.java2
-rw-r--r--src/main/java/eu/olli/cowmoonication/command/TabCompletableCommand.java50
-rw-r--r--src/main/java/eu/olli/cowmoonication/listener/ChatListener.java4
-rw-r--r--src/main/java/eu/olli/cowmoonication/util/PlayerCache.java7
5 files changed, 23 insertions, 44 deletions
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;
}