aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/cowtipper/cowlection/command/TabCompletableCommand.java
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2020-07-28 00:12:36 +0200
committerCow <cow@volloeko.de>2020-07-28 00:12:36 +0200
commitb393636cb3f7e05ef8b34804eeb06357f1b9cfbe (patch)
treed754561fd2e2f09ac66f41b2645ac5f351c1cace /src/main/java/de/cowtipper/cowlection/command/TabCompletableCommand.java
parent023589c75ae72ddc5ff75fa7235bce4d102b2ad1 (diff)
downloadCowlection-b393636cb3f7e05ef8b34804eeb06357f1b9cfbe.tar.gz
Cowlection-b393636cb3f7e05ef8b34804eeb06357f1b9cfbe.tar.bz2
Cowlection-b393636cb3f7e05ef8b34804eeb06357f1b9cfbe.zip
Renamed package to match cowtipper.de
Diffstat (limited to 'src/main/java/de/cowtipper/cowlection/command/TabCompletableCommand.java')
-rw-r--r--src/main/java/de/cowtipper/cowlection/command/TabCompletableCommand.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/main/java/de/cowtipper/cowlection/command/TabCompletableCommand.java b/src/main/java/de/cowtipper/cowlection/command/TabCompletableCommand.java
new file mode 100644
index 0000000..5edabe8
--- /dev/null
+++ b/src/main/java/de/cowtipper/cowlection/command/TabCompletableCommand.java
@@ -0,0 +1,53 @@
+package de.cowtipper.cowlection.command;
+
+import de.cowtipper.cowlection.Cowlection;
+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 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 Cowlection main;
+ private final String cmdName;
+
+ public TabCompletableCommand(Cowlection main, String cmdName) {
+ this.main = main;
+ this.cmdName = cmdName;
+ }
+
+ @Override
+ public String getCommandName() {
+ return cmdName;
+ }
+
+ @Override
+ public String getCommandUsage(ICommandSender sender) {
+ return null;
+ }
+
+ @Override
+ public void processCommand(ICommandSender sender, String[] args) throws CommandException {
+ // send client-command to server
+ Minecraft.getMinecraft().thePlayer.sendChatMessage("/" + getCommandName() + " " + CommandBase.buildString(args, 0));
+ }
+
+ @Override
+ public int getRequiredPermissionLevel() {
+ return 0;
+ }
+
+ @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;
+ }
+}