1.7.0 beta 4

This commit is contained in:
tylermurphy534 2022-11-03 21:03:59 -04:00
parent 37b3840ca1
commit 0f1d49ba80
30 changed files with 255 additions and 136 deletions

View file

@ -212,6 +212,8 @@ public class Main extends JavaPlugin implements Listener {
public EntityHider getEntityHider() { return entityHider; }
public CommandGroup getCommandGroup() { return commandGroup; }
public boolean supports(int v){
return version >= v;
}

View file

@ -19,22 +19,72 @@
package net.tylermurphy.hideAndSeek.command;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.command.util.Command;
import net.tylermurphy.hideAndSeek.command.util.CommandGroup;
import net.tylermurphy.hideAndSeek.util.Pair;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
public class Help extends Command {
public void execute(Player sender, String[] args) {
// StringBuilder message = new StringBuilder();
// for(Command command : CommandGroup.COMMAND_REGISTER.values()) {
// message.append(String.format("%s/hs %s%s %s%s\n %s%s%s", ChatColor.AQUA, ChatColor.WHITE, command.getLabel().toLowerCase(), ChatColor.BLUE, command.getUsage(), ChatColor.GRAY, ChatColor.ITALIC, command.getDescription() + "\n"));
// }
// message = new StringBuilder(message.substring(0, message.length() - 1));
// sender.sendMessage(message.toString());
final int pageSize = 4;
List<Pair<String, Command>> commands = Main.getInstance().getCommandGroup().getCommands();
int pages = (commands.size() - 1) / pageSize + 1;
int page;
try {
if(args.length < 1) {
page = 1;
} else {
page = Integer.parseInt(args[0]);
if (page < 1) {
throw new IllegalArgumentException("Inavlid Input");
}
}
} catch (Exception e) {
sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0]));
return;
}
String spacer = ChatColor.GRAY + "?" + ChatColor.WHITE;
StringBuilder message = new StringBuilder();
message.append(String.format("%s================ %sHelp: Page (%s/%s) %s================",
ChatColor.AQUA, ChatColor.WHITE, page, pages, ChatColor.AQUA));
int lines = 0;
for(Pair<String, Command> pair : commands.stream().skip((long) (page - 1) * pageSize).limit(pageSize).collect(Collectors.toList())) {
Command command = pair.getRight();
String label = pair.getLeft();
String start = label.substring(0, label.indexOf(" "));
String invoke = label.substring(label.indexOf(" ")+1);
message.append(String.format("\n%s %s/%s %s%s %s%s\n%s %s%s%s",
spacer,
ChatColor.AQUA,
start,
ChatColor.WHITE,
invoke,
ChatColor.BLUE,
command.getUsage(),
spacer,
ChatColor.GRAY,
ChatColor.ITALIC,
command.getDescription()
));
lines += 2;
}
if(lines / 2 < pageSize) {
for(int i = 0; i < pageSize * 2 - lines; i++) {
message.append("\n").append(spacer);
}
}
message.append("\n").append(ChatColor.AQUA).append("===============================================");
sender.sendMessage(message.toString());
}
public String getLabel() {
@ -42,15 +92,15 @@ public class Help extends Command {
}
public String getUsage() {
return "";
return "<*page>";
}
public String getDescription() {
return "Get the commands for the plugin";
}
public List<String> autoComplete(String parameter) {
return null;
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
return Collections.singletonList(parameter);
}
}

View file

@ -23,6 +23,7 @@ import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.command.util.Command;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@ -61,7 +62,7 @@ public class Join extends Command {
return "Joins the lobby if game is set to manual join/leave";
}
public List<String> autoComplete(String parameter) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
return null;
}

View file

@ -23,6 +23,7 @@ import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.command.util.Command;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@ -60,7 +61,7 @@ public class Leave extends Command {
return "Leaves the lobby if game is set to manual join/leave";
}
public List<String> autoComplete(String parameter) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
return null;
}

View file

@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command;
import net.tylermurphy.hideAndSeek.configuration.*;
import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@ -66,7 +67,7 @@ public class Reload extends Command {
return "Reloads the config";
}
public List<String> autoComplete(String parameter) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
return null;
}

View file

@ -6,6 +6,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
@ -57,8 +58,8 @@ public class Send extends Command {
return "Set the current lobby to another map";
}
public List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("map")) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("map")) {
return Maps.getAllMaps().stream().filter(map -> !map.isNotSetup()).map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
}
return null;

View file

@ -23,6 +23,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command;
import net.tylermurphy.hideAndSeek.command.location.LocationUtils;
import net.tylermurphy.hideAndSeek.command.location.Locations;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@ -51,10 +52,10 @@ public class SetExitLocation extends Command {
}
public String getDescription() {
return "Sets hide and seeks exit location to current position and world";
return "Sets the plugins exit location";
}
public List<String> autoComplete(String parameter) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
return null;
}

View file

@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command;
import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Optional;
@ -89,8 +90,8 @@ public class Start extends Command {
return "Starts the game either with a random seeker or chosen one";
}
public List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("player")) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("player")) {
return Main.getInstance().getBoard().getPlayers().stream().map(Player::getName).collect(Collectors.toList());
}
return null;

View file

@ -23,6 +23,7 @@ import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.command.util.Command;
import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@ -57,7 +58,7 @@ public class Stop extends Command {
return "Stops the game";
}
public List<String> autoComplete(String parameter) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
return null;
}

View file

@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command;
import net.tylermurphy.hideAndSeek.database.util.PlayerInfo;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
@ -83,7 +84,7 @@ public class Top extends Command {
return "Gets the top players in the server.";
}
public List<String> autoComplete(String parameter) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
return Collections.singletonList(parameter);
}

View file

@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command;
import net.tylermurphy.hideAndSeek.database.util.PlayerInfo;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
@ -80,7 +81,7 @@ public class Wins extends Command {
return "Get the win information for yourself or another player.";
}
public List<String> autoComplete(String parameter) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
return Collections.singletonList(parameter);
}
}

View file

@ -6,6 +6,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
@ -44,8 +45,8 @@ public class Add extends Command {
return "Add a map to the plugin!";
}
public List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("name")) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("name")) {
return Collections.singletonList("name");
}
return null;

View file

@ -12,6 +12,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.List;
@ -38,7 +39,7 @@ public class Debug extends Command {
private Inventory createMenu(net.tylermurphy.hideAndSeek.configuration.Map map, Player sender){
Map<Integer, Consumer<Player>> functions = new HashMap<>();
Inventory debugMenu = Main.getInstance().getServer().createInventory(null, 18, "Debug Menu");
Inventory debugMenu = Main.getInstance().getServer().createInventory(null, 9, "Debug Menu");
debugMenu.setItem(0, createOption(functions, 0, XMaterial.LEATHER_CHESTPLATE.parseMaterial(), "&6Become a &lHider", 1, player -> {
if(mapSaveEnabled) {
if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap();
@ -75,10 +76,10 @@ public class Debug extends Command {
}
}));
if(map.isBlockHuntEnabled()) {
debugMenu.setItem(9, createOption(functions, 7, XMaterial.GLASS.parseMaterial(), "&dEnable Disguise", 1, player -> {
debugMenu.setItem(7, createOption(functions, 7, XMaterial.GLASS.parseMaterial(), "&dEnable Disguise", 1, player -> {
PlayerLoader.openBlockHuntPicker(player, map);
}));
debugMenu.setItem(10, createOption(functions, 8, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player)));
debugMenu.setItem(8, createOption(functions, 8, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player)));
}
debugMenuFunctions.put(sender, functions);
return debugMenu;
@ -112,8 +113,8 @@ public class Debug extends Command {
return "Run debug commands";
}
public List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("map")) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("map")) {
return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
}
return null;

View file

@ -4,6 +4,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command;
import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
@ -48,13 +49,13 @@ public class GoTo extends Command {
}
public String getDescription() {
return "Get the commands for the plugin";
return "Teleport to a map spawn zone";
}
public List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("map")) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("map")) {
return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
} else if(parameter != null && parameter.equals("spawn")) {
} else if(parameter.equals("spawn")) {
return Arrays.asList("spawn","lobby","seekerlobby","exit");
}
return null;

View file

@ -5,6 +5,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@ -39,7 +40,7 @@ public class List extends Command {
return "List all maps in the plugin";
}
public java.util.List<String> autoComplete(String parameter) {
public java.util.List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
return null;
}

View file

@ -6,6 +6,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
@ -43,8 +44,8 @@ public class Remove extends Command {
return "Remove a map from the plugin!";
}
public List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("map")) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("map")) {
return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
}
return null;

View file

@ -27,6 +27,7 @@ import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
@ -89,11 +90,11 @@ public class Save extends Command {
}
public String getDescription() {
return "Saves current map for the game. May lag server.";
return "Saves the map to its own separate playable map";
}
public List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("map")) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("map")) {
return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
}
return null;

View file

@ -23,6 +23,7 @@ import net.tylermurphy.hideAndSeek.command.util.Command;
import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
@ -84,11 +85,11 @@ public class Status extends Command {
}
public String getDescription() {
return "Shows what needs to be setup";
return "Shows what needs to be setup on a map";
}
public List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("map")) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("map")) {
return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
}
return null;

View file

@ -7,6 +7,7 @@ import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
@ -47,11 +48,11 @@ public class Enabled extends Command {
return "Sets blockhunt enabled or disabled in a current map";
}
public List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("map")) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("map")) {
return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
}
if(parameter != null && parameter.equals("bool")) {
if(parameter.equals("bool")) {
return Arrays.asList("true", "false");
}
return null;

View file

@ -7,6 +7,7 @@ import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
@ -56,11 +57,15 @@ public class Add extends Command {
return "Add a blockhunt block to a map!";
}
public List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("map")) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("map")) {
return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
} else if(parameter != null && parameter.equals("block")) {
return Arrays.stream(Material.values()).filter(Material::isBlock).map(Material::toString).collect(Collectors.toList());
} else if(parameter.equals("block")) {
return Arrays.stream(Material.values())
.filter(Material::isBlock)
.map(Material::toString)
.filter(s -> s.toUpperCase().startsWith(typed.toUpperCase()))
.collect(Collectors.toList());
}
return null;
}

View file

@ -6,6 +6,7 @@ import net.tylermurphy.hideAndSeek.configuration.Maps;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.stream.Collectors;
@ -45,8 +46,8 @@ public class List extends Command {
return "List all blockhunt blocks in a map";
}
public java.util.List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("map")) {
public java.util.List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("map")) {
return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
}
return null;

View file

@ -7,6 +7,7 @@ import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
@ -56,11 +57,15 @@ public class Remove extends Command {
return "Remove a blockhunt block from a map!";
}
public List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("map")) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("map")) {
return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
} else if(parameter != null && parameter.equals("block")) {
return Arrays.stream(Material.values()).filter(Material::isBlock).map(Material::toString).collect(Collectors.toList());
} else if(parameter.equals("block")) {
return Arrays.stream(Material.values())
.filter(Material::isBlock)
.map(Material::toString)
.filter(s -> s.toUpperCase().startsWith(typed.toUpperCase()))
.collect(Collectors.toList());
}
return null;
}

View file

@ -25,6 +25,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
@ -99,11 +100,11 @@ public class Border extends Command {
}
public String getDescription() {
return "Sets worldboarder's center location, size in blocks, and delay in minutes per shrink. Add no arguments to disable.";
return "Sets a maps world border information";
}
public List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("map")) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("map")) {
return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
}
return Collections.singletonList(parameter);

View file

@ -25,6 +25,7 @@ import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
@ -102,8 +103,8 @@ public class Bounds extends Command {
return "Sets the map bounds for the game.";
}
public List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("map")) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("map")) {
return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
}
return null;

View file

@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.command.location.LocationUtils;
import net.tylermurphy.hideAndSeek.command.location.Locations;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
@ -45,11 +46,11 @@ public class Lobby extends Command {
}
public String getDescription() {
return "Sets hide and seeks lobby location to current position";
return "Sets the maps lobby location";
}
public List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("map")) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("map")) {
return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
}
return null;

View file

@ -5,6 +5,7 @@ import net.tylermurphy.hideAndSeek.command.location.LocationUtils;
import net.tylermurphy.hideAndSeek.command.location.Locations;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
@ -34,11 +35,11 @@ public class SeekerLobby extends Command {
}
public String getDescription() {
return "Sets hide and seeks seeker lobby location to current position";
return "Sets the maps seeker lobby location";
}
public List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("map")) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("map")) {
return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
}
return null;

View file

@ -26,6 +26,7 @@ import net.tylermurphy.hideAndSeek.configuration.Maps;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
@ -66,11 +67,11 @@ public class Spawn extends Command {
}
public String getDescription() {
return "Sets hide and seeks spawn location to current position";
return "Sets the maps game spawn location";
}
public List<String> autoComplete(String parameter) {
if(parameter != null && parameter.equals("map")) {
public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
if(parameter.equals("map")) {
return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
}
return null;

View file

@ -20,7 +20,7 @@
package net.tylermurphy.hideAndSeek.command.util;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@ -34,10 +34,6 @@ public abstract class Command {
public abstract String getDescription();
public abstract List<String> autoComplete(@Nullable String parameter);
public abstract List<String> autoComplete(@NotNull String parameter, @NotNull String typed);
public boolean hasPermission(Player sender, String permission) {
return sender.hasPermission(permission+"."+getLabel());
}
}

View file

@ -19,8 +19,8 @@
package net.tylermurphy.hideAndSeek.command.util;
import net.tylermurphy.hideAndSeek.command.*;
import net.tylermurphy.hideAndSeek.command.map.Save;
import net.tylermurphy.hideAndSeek.util.Pair;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -62,12 +62,12 @@ public class CommandGroup {
}
public boolean handleCommand(Player player, String permission, String[] args) {
if (args.length < 1 && permission.equals("hs") || !commandRegister.containsKey(args[0].toLowerCase()) ) {
if (args.length < 1 || !commandRegister.containsKey(args[0].toLowerCase()) ) {
if (permissionsRequired && !player.hasPermission("hs.about")) {
player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED"));
} else {
player.sendMessage(
String.format("%s%sHide and Seek %s(%s1.7.0 BETA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) +
String.format("%s%sKenshin's Hide and Seek %s(%s1.7.0 BETA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) +
String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) +
String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE)
);
@ -76,20 +76,29 @@ public class CommandGroup {
String invoke = args[0].toLowerCase();
if (!invoke.equals("about") && !invoke.equals("help") && Save.runningBackup) {
player.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS"));
} else if (permissionsRequired && !player.hasPermission(permission+"."+invoke)) {
player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED"));
} else {
try {
Object object = commandRegister.get(invoke);
if(object instanceof CommandGroup) return ((CommandGroup) object).handleCommand(player, permission+"."+this.label, Arrays.copyOfRange(args, 1, args.length));
Command command = (Command) object;
int parameters = (int) Arrays.stream(command.getUsage().split(" ")).filter(p -> p.startsWith("<") && !p.startsWith("<*")).count();
if(args.length - 1 < parameters) {
player.sendMessage(errorPrefix + message("ARGUMENT_COUNT"));
return true;
if(object instanceof CommandGroup) {
CommandGroup group = (CommandGroup) object;
return group.handleCommand(player, permission+"."+group.getLabel(), Arrays.copyOfRange(args, 1, args.length));
} else if(object instanceof Command) {
Command command = (Command) object;
if (permissionsRequired && !player.hasPermission(permission+"."+command.getLabel())) {
player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED"));
return true;
}
int parameterCount = (int) Arrays.stream(command.getUsage().split(" ")).filter(p -> p.startsWith("<") && !p.startsWith("<*")).count();
if(args.length - 1 < parameterCount) {
player.sendMessage(errorPrefix + message("ARGUMENT_COUNT"));
return true;
}
command.execute(player,Arrays.copyOfRange(args, 1, args.length));
}
command.execute(player,Arrays.copyOfRange(args, 1, args.length));
} catch (Exception e) {
player.sendMessage(errorPrefix + "An error has occurred.");
e.printStackTrace();
@ -109,67 +118,75 @@ public class CommandGroup {
.filter(handle -> handle.toLowerCase().startsWith(invoke))
.filter(handle -> {
Object object = commandRegister.get(handle);
if (object instanceof Command) return ((Command) object).hasPermission(player, this.label);
if (object instanceof CommandGroup)
return ((CommandGroup) object).hasPermission(player, this.label);
if (object instanceof Command) {
Command command = (Command) object;
return player.hasPermission(command.getLabel());
} else if (object instanceof CommandGroup) {
CommandGroup group = (CommandGroup) object;
return group.hasPermission(player, group.getLabel());
}
return false;
})
.collect(Collectors.toList());
}
return commandRegister.keySet().stream().filter(handle -> handle.toLowerCase().startsWith(invoke)).collect(Collectors.toList());
} else {
if (!commandRegister.containsKey(invoke)) {
return new ArrayList<>();
} else {
Object object = commandRegister.get(invoke);
if(object instanceof CommandGroup) return ((CommandGroup) object).handleTabComplete(sender, Arrays.copyOfRange(args, 1, args.length));
Command command = (Command) object;
String[] usage = command.getUsage().split(" ");
List<String> complete;
if (args.length - 2 < usage.length) {
String parameter = usage[args.length-2];
String name = parameter.replace("<", "").replace(">", "");
complete = command.autoComplete(name);
} else {
complete = command.autoComplete(null);
}
if(complete == null) return new ArrayList<>();
else return complete;
return commandRegister.keySet()
.stream()
.filter(handle -> handle.toLowerCase().startsWith(invoke))
.collect(Collectors.toList());
}
} else {
if (commandRegister.containsKey(invoke)) {
Object object = commandRegister.get(invoke);
if (object instanceof CommandGroup) {
CommandGroup group = (CommandGroup) object;
return group.handleTabComplete(sender, Arrays.copyOfRange(args, 1, args.length));
} else if (object instanceof Command) {
Command command = (Command) object;
String[] usage = command.getUsage().split(" ");
if (args.length - 2 < usage.length) {
String parameter = usage[args.length - 2];
String name = parameter.replace("<", "").replace(">", "");
List<String> list = command.autoComplete(name, args[args.length - 1]);
if (list != null) {
return list;
}
}
}
}
return new ArrayList<>();
}
}
private boolean hasPermission(Player player, String permission) {
for(Object object : commandRegister.values()) {
if(object instanceof Command) if(((Command) object).hasPermission(player, this.label)) return true;
if(object instanceof CommandGroup) if (((CommandGroup) object).hasPermission(player, permission+"."+this.label)) return true;
if(object instanceof Command) {
Command command = (Command) object;
if(player.hasPermission(permission+"."+command.getLabel())) return true;
} else if(object instanceof CommandGroup) {
CommandGroup group = (CommandGroup) object;
if (group.hasPermission(player, permission+"."+group.getLabel())) return true;
}
}
return false;
}
// public static void registerCommands() {
// registerCommand(new About());
// registerCommand(new Help());
// registerCommand(new Setup());
// registerCommand(new Start());
// registerCommand(new Stop());
// registerCommand(new SetSpawnLocation());
// registerCommand(new SetLobbyLocation());
// registerCommand(new SetSeekerLobbyLocation());
// registerCommand(new SetExitLocation());
// registerCommand(new SetBorder());
// registerCommand(new Reload());
// registerCommand(new SaveMap());
// registerCommand(new SetBounds());
// registerCommand(new Join());
// registerCommand(new Leave());
// registerCommand(new Top());
// registerCommand(new Wins());
// registerCommand(new Debug());
// registerCommand(new AddMap());
// registerCommand(new RemoveMap());
// registerCommand(new ListMaps());
// registerCommand(new SetMap());
// }
public List<Pair<String, Command>> getCommands() {
return getCommands(this.getLabel());
}
private List<Pair<String, Command>> getCommands(String prefix) {
List<Pair<String, Command>> commands = new LinkedList<>();
for(Object object : commandRegister.values()) {
if(object instanceof Command) {
Command command = (Command) object;
commands.add(new Pair<>(prefix+" "+command.getLabel(), command));
} else if(object instanceof CommandGroup) {
CommandGroup group = (CommandGroup) object;
commands.addAll(group.getCommands(prefix+" "+group.getLabel()));
}
}
return commands;
}
}

View file

@ -0,0 +1,21 @@
package net.tylermurphy.hideAndSeek.util;
public class Pair<L, R> {
private final L left;
private final R right;
public Pair(L left, R right) {
this.left = left;
this.right = right;
}
public L getLeft() {
return left;
}
public R getRight() {
return right;
}
}