100 lines
5.3 KiB
Java
100 lines
5.3 KiB
Java
package nl.sbdeveloper.themeparkplus.commands;
|
|
|
|
import nl.iobyte.themepark.ThemePark;
|
|
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], ThemePark.getInstance().getAPI().getAttractionService().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);
|
|
}
|
|
}
|