Skip to content

Commit 4ab4f8c

Browse files
committed
change: make StreamlineSpigotCommand use BOU BetterCommand class
1 parent 4ef4941 commit 4ab4f8c

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.streamline.platform.commands;
22

3+
import host.plas.bou.commands.CommandContext;
4+
import host.plas.bou.commands.SimplifiedCommand;
35
import net.streamline.base.Streamline;
46
import net.streamline.platform.savables.UserManager;
57
import org.bukkit.ChatColor;
@@ -16,33 +18,34 @@
1618
import java.util.ArrayList;
1719
import java.util.List;
1820
import java.util.Objects;
21+
import java.util.concurrent.ConcurrentSkipListSet;
1922
import java.util.stream.Collectors;
2023

21-
public class StreamlineSpigotCommand implements TabExecutor {
24+
public class StreamlineSpigotCommand extends SimplifiedCommand {
2225
public StreamlineSpigotCommand() {
23-
try {
24-
Objects.requireNonNull(Streamline.getInstance().getCommand("streamlinespigot")).setExecutor(this);
25-
} catch (Exception e) {
26-
e.printStackTrace();
27-
}
26+
super("streamlinespigot", Streamline.getInstance());
2827
}
2928

3029
@Override
31-
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
32-
if (args == null) args = new String[] { "" };
33-
String alias = args[0];
30+
public boolean command(CommandContext ctx) {
31+
if (ctx.getArgCount() < 1) {
32+
ctx.sendMessage("&cCommand not found.");
33+
return false;
34+
}
35+
36+
String alias = ctx.getStringArg(0);
3437

3538
CosmicCommand streamlineCommand = CommandHandler.getCommandByAlias(alias);
3639
if (streamlineCommand == null) {
37-
sender.sendMessage(ChatColor.RED + "Command not found.");
38-
return true;
40+
ctx.sendMessage("&cCommand not found.");
41+
return false;
3942
}
4043

41-
String[] newArgs = StringUtils.argsMinus(args, 0);
44+
String[] newArgs = StringUtils.argsMinus(ctx.getArgsAsStringArray(), 0);
4245

43-
CosmicSender s = UserManager.getInstance().getOrCreateSender(sender);
46+
CosmicSender s = UserManager.getInstance().getOrCreateSender(ctx.getCommandSender());
4447
if (s == null) {
45-
sender.sendMessage(ChatColor.RED + "Could not find your user...");
48+
ctx.sendMessage("&cCould not find your user...");
4649
return true;
4750
}
4851

@@ -52,24 +55,21 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
5255

5356
@Nullable
5457
@Override
55-
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
56-
if (args.length == 0) {
57-
return StringUtils.getAsCompletionList("", CommandHandler.getAllAliases());
58-
}
59-
if (args.length == 1) {
60-
return StringUtils.getAsCompletionList(args[0], CommandHandler.getAllAliases());
58+
public ConcurrentSkipListSet<String> tabComplete(CommandContext ctx) {
59+
if (ctx.getArgCount() <= 1) {
60+
return CommandHandler.getAllAliases();
6161
}
6262

63-
String alias = args[0];
63+
String alias = ctx.getStringArg(0);
6464

6565
CosmicCommand streamlineCommand = CommandHandler.getCommandByAlias(alias);
6666
if (streamlineCommand == null) return null;
6767

68-
String[] newArgs = StringUtils.argsMinus(args, 0);
68+
String[] newArgs = StringUtils.argsMinus(ctx.getArgsAsStringArray(), 0);
6969

70-
CosmicSender s = UserManager.getInstance().getOrCreateSender(sender);
70+
CosmicSender s = UserManager.getInstance().getOrCreateSender(ctx.getCommandSender());
7171
if (s == null) return null;
7272

73-
return new ArrayList<>(streamlineCommand.baseTabComplete(s, newArgs));
73+
return streamlineCommand.baseTabComplete(s, newArgs);
7474
}
7575
}

0 commit comments

Comments
 (0)