Skip to content

Commit

Permalink
added tab completion
Browse files Browse the repository at this point in the history
  • Loading branch information
NonSwag committed Sep 23, 2023
1 parent 44eeaa4 commit 45970f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies {
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")

implementation("net.thenextlvl.core:api:4.0.1")
implementation("net.thenextlvl.core:i18n:1.0.4")
implementation("net.thenextlvl.core:i18n:1.0.6")
implementation("org.bstats:bstats-bukkit:3.0.2")

annotationProcessor("org.projectlombok:lombok:1.18.26")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import net.thenextlvl.tweaks.command.api.CommandInfo;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@CommandInfo(
name = "broadcast",
Expand All @@ -19,7 +21,7 @@
aliases = {"bc"}
)
@RequiredArgsConstructor
public class BroadcastCommand implements CommandExecutor {
public class BroadcastCommand implements TabExecutor {
private final TweaksPlugin plugin;

@Override
Expand All @@ -30,14 +32,14 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
var tweaksConfig = plugin.config();

var message = String.join(" ", args).replace("\\t", " ");
var format = format(plugin.bundle().format(sender, "broadcast.format"), message);

var receivers = new ArrayList<Audience>(Bukkit.getOnlinePlayers());
receivers.add(Bukkit.getConsoleSender());

receivers.forEach(audience -> {
plugin.bundle().sendMessage(audience, "broadcast.header");
plugin.bundle().sendMessage(audience, format);
var format = format(plugin.bundle().format(audience, "broadcast.format"), message);
plugin.bundle().sendRawMessage(audience, format);
plugin.bundle().sendMessage(audience, "broadcast.footer");
});

Expand All @@ -53,4 +55,9 @@ private String format(String format, String message) {

return String.join("\n", split);
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
return Arrays.asList(args[args.length - 1] + "\\n", args[args.length - 1] + "\\t");
}
}

0 comments on commit 45970f5

Please sign in to comment.