Added tab complete
This commit is contained in:
parent
160adf9a5e
commit
287dffee43
2 changed files with 104 additions and 2 deletions
|
@ -4,6 +4,7 @@ import club.minnced.discord.webhook.WebhookClient;
|
|||
import club.minnced.discord.webhook.WebhookClientBuilder;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import nl.sbdeveloper.themeparkplus.commands.TPPCMD;
|
||||
import nl.sbdeveloper.themeparkplus.commands.TPPTabComplete;
|
||||
import nl.sbdeveloper.themeparkplus.listeners.*;
|
||||
import nl.sbdeveloper.themeparkplus.managers.DBManager;
|
||||
import nl.sbdeveloper.themeparkplus.sbutils.UpdateManager;
|
||||
|
@ -135,7 +136,8 @@ public final class ThemeParkPlus extends JavaPlugin {
|
|||
}
|
||||
|
||||
Bukkit.getLogger().info("[ThemeParkPlus] Loading commands...");
|
||||
Objects.requireNonNull(getCommand("themeparkplus"), "Couldn't read command from plugin.yml!").setExecutor(new TPPCMD());
|
||||
getCommand("themeparkplus").setExecutor(new TPPCMD());
|
||||
getCommand("themeparkplus").setTabCompleter(new TPPTabComplete());
|
||||
|
||||
Bukkit.getLogger().info("[ThemeParkPlus] Loading listeners...");
|
||||
Bukkit.getPluginManager().registerEvents(new DirectionalGateListener(), this);
|
||||
|
@ -155,7 +157,7 @@ public final class ThemeParkPlus extends JavaPlugin {
|
|||
WebhookClientBuilder builder = new WebhookClientBuilder(URL);
|
||||
builder.setThreadFactory((job) -> {
|
||||
Thread thread = new Thread(job);
|
||||
thread.setName("Hello");
|
||||
thread.setName("ThemeParkPlus");
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
});
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
package nl.sbdeveloper.themeparkplus.commands;
|
||||
|
||||
import nl.iobyte.themepark.api.API;
|
||||
import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TPPTabComplete implements TabCompleter {
|
||||
private static final List<String> COMMANDS = Arrays.asList("info", "help", "opengate", "closegate", "lampon", "lampoff", "lampson", "lampsoff", "redstonetimer", "givefpticket");
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, @NotNull String[] args) {
|
||||
//Aliases
|
||||
if (label.equalsIgnoreCase("themeparkplus") || label.equalsIgnoreCase("tpp") || label.equalsIgnoreCase("themeparkp")) {
|
||||
if (args.length == 1) {
|
||||
return StringUtil.copyPartialMatches(args[0], COMMANDS, new ArrayList<>());
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("opengate")
|
||||
|| args[0].equalsIgnoreCase("closegate")
|
||||
|| args[0].equalsIgnoreCase("lampon")
|
||||
|| args[0].equalsIgnoreCase("lampoff")
|
||||
|| args[0].equalsIgnoreCase("redstonetimer")) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
Location targetLoc = getTarget(p).getLocation();
|
||||
return StringUtil.copyPartialMatches(args[1], Collections.singletonList("" + targetLoc.getWorld().getName()), new ArrayList<>());
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("givefpticket")) {
|
||||
return StringUtil.copyPartialMatches(args[1], API.getAttractions().keySet(), new ArrayList<>());
|
||||
}
|
||||
} else if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("opengate")
|
||||
|| args[0].equalsIgnoreCase("closegate")
|
||||
|| args[0].equalsIgnoreCase("lampon")
|
||||
|| args[0].equalsIgnoreCase("lampoff")
|
||||
|| args[0].equalsIgnoreCase("redstonetimer")) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
Location targetLoc = getTarget(p).getLocation();
|
||||
return StringUtil.copyPartialMatches(args[2], Collections.singletonList("" + targetLoc.getBlockX()), new ArrayList<>());
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("givefpticket")) {
|
||||
return StringUtil.copyPartialMatches(args[1], Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()), new ArrayList<>());
|
||||
}
|
||||
} else if (args.length == 4) {
|
||||
if (args[0].equalsIgnoreCase("opengate")
|
||||
|| args[0].equalsIgnoreCase("closegate")
|
||||
|| args[0].equalsIgnoreCase("lampon")
|
||||
|| args[0].equalsIgnoreCase("lampoff")
|
||||
|| args[0].equalsIgnoreCase("redstonetimer")) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
Location targetLoc = getTarget(p).getLocation();
|
||||
return StringUtil.copyPartialMatches(args[3], Collections.singletonList("" + targetLoc.getBlockY()), new ArrayList<>());
|
||||
}
|
||||
}
|
||||
} else if (args.length == 5) {
|
||||
if (args[0].equalsIgnoreCase("opengate")
|
||||
|| args[0].equalsIgnoreCase("closegate")
|
||||
|| args[0].equalsIgnoreCase("lampon")
|
||||
|| args[0].equalsIgnoreCase("lampoff")
|
||||
|| args[0].equalsIgnoreCase("redstonetimer")) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
Location targetLoc = getTarget(p).getLocation();
|
||||
return StringUtil.copyPartialMatches(args[4], Collections.singletonList("" + targetLoc.getBlockZ()), new ArrayList<>());
|
||||
}
|
||||
}
|
||||
} else if (args.length == 6) {
|
||||
if (args[0].equalsIgnoreCase("opengate")) {
|
||||
return StringUtil.copyPartialMatches(args[5], Arrays.stream(WalkingDirection.values()).map(Enum::toString).collect(Collectors.toList()), new ArrayList<>());
|
||||
}
|
||||
} else if (args.length == 7) {
|
||||
if (args[0].equalsIgnoreCase("opengate")) {
|
||||
return StringUtil.copyPartialMatches(args[6], Arrays.stream(WalkingDirection.values()).map(Enum::toString).collect(Collectors.toList()), new ArrayList<>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Block getTarget(Player p) {
|
||||
return p.getTargetBlock(null, 200);
|
||||
}
|
||||
}
|
Reference in a new issue