Skip to content

Commit

Permalink
Add tab complete
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Nov 20, 2024
1 parent ae7c9fc commit 9edb36c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/io/wdsj/imagepreviewer/ImagePreviewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.Anon8281.universalScheduler.UniversalScheduler;
import com.github.Anon8281.universalScheduler.scheduling.schedulers.TaskScheduler;
import io.wdsj.imagepreviewer.command.ConstructCommandExecutor;
import io.wdsj.imagepreviewer.command.ConstructTabCompleter;
import io.wdsj.imagepreviewer.config.Config;
import io.wdsj.imagepreviewer.image.ImageLoader;
import io.wdsj.imagepreviewer.listener.ChatListener;
Expand Down Expand Up @@ -53,6 +54,7 @@ public void onEnable() {
permTool = CachingPermTool.enable(this);
ImageLoader.init();
Objects.requireNonNull(getCommand("imagepreviewer")).setExecutor(new ConstructCommandExecutor());
Objects.requireNonNull(getCommand("imagepreviewer")).setTabCompleter(new ConstructTabCompleter());
getServer().getPluginManager().registerEvents(new ChatListener(), this);
Metrics metrics = new Metrics(this, 23927);
LOGGER.info("ImagePreviewer is enabled!");
Expand All @@ -77,6 +79,7 @@ public void onEnable() {
public void onDisable() {
permTool.disable();
Objects.requireNonNull(getCommand("imagepreviewer")).setExecutor(null);
Objects.requireNonNull(getCommand("imagepreviewer")).setTabCompleter(null);
mapManager.close();
HandlerList.unregisterAll(this);
if (audiences != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.wdsj.imagepreviewer.command;

import io.wdsj.imagepreviewer.permission.PermissionsEnum;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ConstructTabCompleter implements TabCompleter {
@Nullable
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String s, @NotNull String[] args) {
if (args.length == 1) {
List<String> tabComplete = new ArrayList<>();
if (sender.hasPermission(PermissionsEnum.RELOAD.getPermission()) && args[0].startsWith("r")) {
tabComplete.add("reload");
} else if (sender.hasPermission(PermissionsEnum.HELP.getPermission()) && args[0].startsWith("h")) {
tabComplete.add("help");
} else if (sender.hasPermission(PermissionsEnum.CANCEL_PREVIEW.getPermission()) && args[0].startsWith("i")) {
tabComplete.add("cancel");
} else if (sender.hasPermission(PermissionsEnum.PREVIEW.getPermission()) && args[0].startsWith("p")) {
tabComplete.add("preview");
} else if (sender.hasPermission(PermissionsEnum.HISTORY.getPermission()) && args[0].startsWith("hi")) {
tabComplete.add("history");
} else if (sender.hasPermission(PermissionsEnum.RELOAD.getPermission()) ||
sender.hasPermission(PermissionsEnum.HELP.getPermission()) || sender.hasPermission(PermissionsEnum.PREVIEW.getPermission()) ||
sender.hasPermission(PermissionsEnum.HISTORY.getPermission())) {
tabComplete.add("help");
tabComplete.add("reload");
tabComplete.add("preview");
tabComplete.add("cancel");
tabComplete.add("history");
}
return tabComplete;
}
return Collections.emptyList(); // Must return empty list, if null paper will supply player names
}
}

0 comments on commit 9edb36c

Please sign in to comment.