summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/command
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command')
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Help.java10
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Join.java24
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java4
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java4
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Send.java6
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java8
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Start.java14
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java4
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Top.java4
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java4
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java4
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java6
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java15
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java4
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java4
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java6
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java14
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java4
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java4
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java4
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java4
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java4
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java4
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java7
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java7
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java12
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java173
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/util/ICommand.java (renamed from src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java)12
28 files changed, 198 insertions, 172 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java
index d94b48a..3efddcd 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java
@@ -20,7 +20,7 @@
package net.tylermurphy.hideAndSeek.command;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.util.Pair;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@@ -33,11 +33,11 @@ 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 class Help implements ICommand {
public void execute(Player sender, String[] args) {
final int pageSize = 4;
- List<Pair<String, Command>> commands = Main.getInstance().getCommandGroup().getCommands();
+ List<Pair<String, ICommand>> commands = Main.getInstance().getCommandGroup().getCommands();
int pages = (commands.size() - 1) / pageSize + 1;
int page;
try {
@@ -58,8 +58,8 @@ public class Help extends Command {
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();
+ for(Pair<String, ICommand> pair : commands.stream().skip((long) (page - 1) * pageSize).limit(pageSize).collect(Collectors.toList())) {
+ ICommand command = pair.getRight();
String label = pair.getLeft();
String start = label.substring(0, label.indexOf(" "));
String invoke = label.substring(label.indexOf(" ")+1);
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java
index 7b219a7..69387cd 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java
@@ -20,17 +20,19 @@
package net.tylermurphy.hideAndSeek.command;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
+import net.tylermurphy.hideAndSeek.configuration.Maps;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
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 Join extends Command {
+public class Join implements ICommand {
public void execute(Player sender, String[] args) {
if (Main.getInstance().getGame().checkCurrentMap()) {
@@ -46,7 +48,18 @@ public class Join extends Command {
sender.sendMessage(errorPrefix + message("GAME_INGAME"));
return;
}
-
+ if(args.length > 0) {
+ if(Main.getInstance().getBoard().size() > 0) {
+ sender.sendMessage(errorPrefix + message("LOBBY_IN_USE"));
+ return;
+ }
+ net.tylermurphy.hideAndSeek.configuration.Map map = Maps.getMap(args[0]);
+ if(map == null) {
+ sender.sendMessage(errorPrefix + message("INVALID_MAP"));
+ return;
+ }
+ Main.getInstance().getGame().setCurrentMap(map);
+ }
Main.getInstance().getGame().join(player);
}
@@ -55,7 +68,7 @@ public class Join extends Command {
}
public String getUsage() {
- return "";
+ return "<*map>";
}
public String getDescription() {
@@ -63,6 +76,9 @@ public class Join extends Command {
}
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;
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java
index ebfd7ee..cb0c745 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java
@@ -20,7 +20,7 @@
package net.tylermurphy.hideAndSeek.command;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -30,7 +30,7 @@ import java.util.List;
import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Leave extends Command {
+public class Leave implements ICommand {
public void execute(Player sender, String[] args) {
if (Main.getInstance().getGame().checkCurrentMap()) {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java
index 1fc2c95..df2944b 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java
@@ -20,7 +20,7 @@
package net.tylermurphy.hideAndSeek.command;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.configuration.*;
import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.entity.Player;
@@ -32,7 +32,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Reload extends Command {
+public class Reload implements ICommand {
public void execute(Player sender, String[] args) {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java
index 87cc9a6..95c0dd9 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Send.java
@@ -1,7 +1,7 @@
package net.tylermurphy.hideAndSeek.command;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
@@ -14,7 +14,7 @@ import java.util.stream.Collectors;
import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Send extends Command {
+public class Send implements ICommand {
public void execute(Player sender, String[] args) {
@@ -41,7 +41,7 @@ public class Send extends Command {
Main.getInstance().getGame().setCurrentMap(map);
for(Player player : Main.getInstance().getBoard().getPlayers()) {
- player.teleport(map.getLobby());
+ map.getLobby().teleport(player);
}
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java
index e8adf24..0a57cfc 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java
@@ -19,9 +19,10 @@
package net.tylermurphy.hideAndSeek.command;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.command.location.LocationUtils;
import net.tylermurphy.hideAndSeek.command.location.Locations;
+import net.tylermurphy.hideAndSeek.util.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -29,7 +30,7 @@ import java.util.List;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
-public class SetExitLocation extends Command {
+public class SetExitLocation implements ICommand {
public void execute(Player sender, String[] args) {
LocationUtils.setLocation(sender, Locations.EXIT, null, map -> {
@@ -37,8 +38,7 @@ public class SetExitLocation extends Command {
addToConfig("exit.y", sender.getLocation().getBlockY());
addToConfig("exit.z", sender.getLocation().getBlockZ());
addToConfig("exit.world", sender.getLocation().getWorld().getName());
- exitPosition = sender.getLocation();
- exitWorld = sender.getLocation().getWorld().getName();
+ exitPosition = Location.from(sender);
saveConfig();
});
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java
index 0a73591..74b8490 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java
@@ -20,22 +20,20 @@
package net.tylermurphy.hideAndSeek.command;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
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;
-import java.util.Random;
import java.util.stream.Collectors;
import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
import static net.tylermurphy.hideAndSeek.configuration.Config.minPlayers;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Start extends Command {
+public class Start implements ICommand {
public void execute(Player sender, String[] args) {
if (Main.getInstance().getGame().checkCurrentMap()) {
@@ -56,12 +54,8 @@ public class Start extends Command {
}
String seekerName;
if (args.length < 1) {
- Optional<Player> rand = Main.getInstance().getBoard().getPlayers().stream().skip(new Random().nextInt(Main.getInstance().getBoard().size())).findFirst();
- if (!rand.isPresent()) {
- sender.sendMessage(errorPrefix + message("START_FAILED_SEEKER"));
- return;
- }
- seekerName = rand.get().getName();
+ Main.getInstance().getGame().start();
+ return;
} else {
seekerName = args[0];
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java
index 9fd9aab..4bc23fe 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java
@@ -20,7 +20,7 @@
package net.tylermurphy.hideAndSeek.command;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -31,7 +31,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.abortPrefix;
import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Stop extends Command {
+public class Stop implements ICommand {
public void execute(Player sender, String[] args) {
if (Main.getInstance().getGame().checkCurrentMap()) {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java
index e795d77..4ac4aa7 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java
@@ -20,7 +20,7 @@
package net.tylermurphy.hideAndSeek.command;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.database.util.PlayerInfo;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@@ -32,7 +32,7 @@ import java.util.List;
import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Top extends Command {
+public class Top implements ICommand {
public void execute(Player sender, String[] args) {
int page;
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java
index f1feb33..1ba44ac 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java
@@ -20,7 +20,7 @@
package net.tylermurphy.hideAndSeek.command;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.database.util.PlayerInfo;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@@ -33,7 +33,7 @@ import java.util.UUID;
import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Wins extends Command {
+public class Wins implements ICommand {
public void execute(Player sender, String[] args) {
Main.getInstance().getServer().getScheduler().runTaskAsynchronously(Main.getInstance(), () -> {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java
index 89a5b79..72f0740 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java
@@ -1,7 +1,7 @@
package net.tylermurphy.hideAndSeek.command.map;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
@@ -15,7 +15,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Add extends Command {
+public class Add implements ICommand {
public void execute(Player sender, String[] args) {
if (Main.getInstance().getGame().getStatus() != Status.STANDBY) {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java
index c5d0352..209d0d6 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java
@@ -2,7 +2,7 @@ package net.tylermurphy.hideAndSeek.command.map;
import com.cryptomorin.xseries.XMaterial;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.PlayerLoader;
import net.tylermurphy.hideAndSeek.game.util.Status;
@@ -23,7 +23,7 @@ import java.util.stream.Collectors;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Debug extends Command {
+public class Debug implements ICommand {
private static final Map<Player, Map<Integer, Consumer<Player>>> debugMenuFunctions = new HashMap<>();
@@ -68,7 +68,7 @@ public class Debug extends Command {
debugMenu.setItem(3, createOption(functions, 3, XMaterial.BARRIER.parseMaterial(), "&cUnload from Game", 1, player -> {
Main.getInstance().getBoard().remove(player);
PlayerLoader.unloadPlayer(player);
- player.teleport(exitPosition);
+ exitPosition.teleport(player);
}));
debugMenu.setItem(4, createOption(functions, 4, XMaterial.BARRIER.parseMaterial(), "&cDie In Game", 2, player -> {
if((Main.getInstance().getBoard().isSeeker(player) || Main.getInstance().getBoard().isHider(player)) && Main.getInstance().getGame().getStatus() == Status.PLAYING){
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java
index 34ca8f9..7d27642 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java
@@ -1,6 +1,6 @@
package net.tylermurphy.hideAndSeek.command.map;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import org.bukkit.entity.Player;
@@ -10,11 +10,10 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
-import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
-import static net.tylermurphy.hideAndSeek.configuration.Config.exitPosition;
+import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class GoTo extends Command {
+public class GoTo implements ICommand {
public void execute(Player sender, String[] args) {
Map map = Maps.getMap(args[0]);
@@ -28,13 +27,13 @@ public class GoTo extends Command {
}
switch (args[1].toLowerCase()) {
case "spawn":
- sender.teleport(map.getSpawn()); break;
+ map.getSpawn().teleport(sender); break;
case "lobby":
- sender.teleport(map.getLobby()); break;
+ map.getLobby().teleport(sender); break;
case "seekerlobby":
- sender.teleport(map.getSeekerLobby()); break;
+ map.getSeekerLobby().teleport(sender); break;
case "exit":
- sender.teleport(exitPosition); break;
+ exitPosition.teleport(sender); break;
default:
sender.sendMessage(errorPrefix + message("COMMAND_INVALID_ARG").addAmount(args[1].toLowerCase()));
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java
index 65b33d1..ac2badf 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java
@@ -1,6 +1,6 @@
package net.tylermurphy.hideAndSeek.command.map;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import org.bukkit.ChatColor;
@@ -13,7 +13,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class List extends Command {
+public class List implements ICommand {
public void execute(Player sender, String[] args) {
Collection<Map> maps = Maps.getAllMaps();
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java
index 4f708b6..d681848 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java
@@ -1,7 +1,7 @@
package net.tylermurphy.hideAndSeek.command.map;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
@@ -15,7 +15,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Remove extends Command {
+public class Remove implements ICommand {
public void execute(Player sender, String[] args) {
if (Main.getInstance().getGame().getStatus() != Status.STANDBY) {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java
index c28d2e9..a612026 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java
@@ -20,7 +20,7 @@
package net.tylermurphy.hideAndSeek.command.map;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
@@ -35,7 +35,7 @@ import java.util.stream.Collectors;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Save extends Command {
+public class Save implements ICommand {
public static boolean runningBackup = false;
@@ -63,7 +63,7 @@ public class Save extends Command {
}
sender.sendMessage(messagePrefix + message("MAPSAVE_START"));
sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING"));
- World world = map.getSpawn().getWorld();
+ World world = map.getSpawn().load();
if (world == null) {
sender.sendMessage(warningPrefix + message("MAPSAVE_FAIL_WORLD"));
return;
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java
index 053603b..c7da88a 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java
@@ -19,7 +19,7 @@
package net.tylermurphy.hideAndSeek.command.map;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import org.bukkit.entity.Player;
@@ -31,7 +31,7 @@ import java.util.stream.Collectors;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Status extends Command {
+public class Status implements ICommand {
public void execute(Player sender, String[] args) {
@@ -42,19 +42,19 @@ public class Status extends Command {
sender.sendMessage(errorPrefix + message("INVALID_MAP"));
return;
}
- if (map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0 || Map.worldDoesntExist(map.getLobbyName())) {
+ if (map.getSpawn().getBlockX() == 0 && map.getSpawn().getBlockY() == 0 && map.getSpawn().getBlockZ() == 0 || !map.getSpawn().exists()) {
msg = msg + "\n" + message("SETUP_GAME");
count++;
}
- if (map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0 || Map.worldDoesntExist(map.getLobbyName())) {
+ if (map.getLobby().getBlockX() == 0 && map.getLobby().getBlockY() == 0 && map.getLobby().getBlockZ() == 0 || !map.getLobby().exists()) {
msg = msg + "\n" + message("SETUP_LOBBY");
count++;
}
- if (map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0 || Map.worldDoesntExist(map.getSeekerLobbyName())) {
+ if (map.getSeekerLobby().getBlockX() == 0 && map.getSeekerLobby().getBlockY() == 0 && map.getSeekerLobby().getBlockZ() == 0 || !map.getSeekerLobby().exists()) {
msg = msg + "\n" + message("SETUP_SEEKER_LOBBY");
count++;
}
- if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || Map.worldDoesntExist(exitWorld)) {
+ if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !exitPosition.exists()) {
msg = msg + "\n" + message("SETUP_EXIT");
count++;
}
@@ -62,7 +62,7 @@ public class Status extends Command {
msg = msg + "\n" + message("SETUP_BOUNDS");
count++;
}
- if (mapSaveEnabled && Map.worldDoesntExist(map.getGameSpawnName())) {
+ if (mapSaveEnabled && !map.getGameSpawn().exists()) {
msg = msg + "\n" + message("SETUP_SAVEMAP");
count++;
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java
index ed14380..14ae8e0 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java
@@ -1,7 +1,7 @@
package net.tylermurphy.hideAndSeek.command.map.blockhunt;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
@@ -17,7 +17,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Enabled extends Command {
+public class Enabled implements ICommand {
public void execute(Player sender, String[] args) {
if (Main.getInstance().getGame().getStatus() != Status.STANDBY) {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java
index bd4cf9f..fbdeecb 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Add.java
@@ -1,7 +1,7 @@
package net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
@@ -17,7 +17,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Add extends Command {
+public class Add implements ICommand {
public void execute(Player sender, String[] args) {
if (Main.getInstance().getGame().getStatus() != Status.STANDBY) {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java
index 396f2dd..18f1b3c 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/List.java
@@ -1,6 +1,6 @@
package net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
@@ -14,7 +14,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class List extends Command {
+public class List implements ICommand {
public void execute(Player sender, String[] args) {
Map map = Maps.getMap(args[0]);
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java
index fed9dfa..d2afdc1 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/blocks/Remove.java
@@ -1,7 +1,7 @@
package net.tylermurphy.hideAndSeek.command.map.blockhunt.blocks;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
@@ -17,7 +17,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Remove extends Command {
+public class Remove implements ICommand {
public void execute(Player sender, String[] args) {
if (Main.getInstance().getGame().getStatus() != Status.STANDBY) {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java
index 1b59abc..f9e14f8 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java
@@ -20,7 +20,7 @@
package net.tylermurphy.hideAndSeek.command.map.set;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
@@ -34,7 +34,7 @@ import java.util.stream.Collectors;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Border extends Command {
+public class Border implements ICommand {
public void execute(Player sender, String[] args) {
if (Main.getInstance().getGame().getStatus() != Status.STANDBY) {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java
index 1adfc59..960863b 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java
@@ -20,7 +20,7 @@
package net.tylermurphy.hideAndSeek.command.map.set;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.configuration.Map;
import net.tylermurphy.hideAndSeek.configuration.Maps;
import net.tylermurphy.hideAndSeek.game.util.Status;
@@ -33,7 +33,7 @@ import java.util.stream.Collectors;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Bounds extends Command {
+public class Bounds implements ICommand {
public void execute(Player sender, String[] args) {
if (Main.getInstance().getGame().getStatus() != Status.STANDBY) {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java
index f2395f1..ada76e2 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java
@@ -19,21 +19,22 @@
package net.tylermurphy.hideAndSeek.command.map.set;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.command.location.LocationUtils;
import net.tylermurphy.hideAndSeek.command.location.Locations;
import net.tylermurphy.hideAndSeek.configuration.Maps;
+import net.tylermurphy.hideAndSeek.util.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
-public class Lobby extends Command {
+public class Lobby implements ICommand {
public void execute(Player sender, String[] args) {
LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> {
- map.setLobby(sender.getLocation());
+ map.setLobby(Location.from(sender));
});
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java
index ebbef1c..9bc0249 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java
@@ -1,9 +1,10 @@
package net.tylermurphy.hideAndSeek.command.map.set;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.command.location.LocationUtils;
import net.tylermurphy.hideAndSeek.command.location.Locations;
import net.tylermurphy.hideAndSeek.configuration.Maps;
+import net.tylermurphy.hideAndSeek.util.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -12,7 +13,7 @@ import java.util.stream.Collectors;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class SeekerLobby extends Command {
+public class SeekerLobby implements ICommand {
public void execute(Player sender, String[] args) {
LocationUtils.setLocation(sender, Locations.SEEKER, args[0], map -> {
@@ -22,7 +23,7 @@ public class SeekerLobby extends Command {
if(!map.getSpawnName().equals(sender.getLocation().getWorld().getName())) {
throw new RuntimeException(message("SEEKER_LOBBY_INVALID").toString());
}
- map.setSeekerLobby(sender.getLocation());
+ map.setSeekerLobby(Location.from(sender));
});
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java
index c954876..b983404 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java
@@ -19,11 +19,11 @@
package net.tylermurphy.hideAndSeek.command.map.set;
-import net.tylermurphy.hideAndSeek.command.util.Command;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
import net.tylermurphy.hideAndSeek.command.location.LocationUtils;
import net.tylermurphy.hideAndSeek.command.location.Locations;
import net.tylermurphy.hideAndSeek.configuration.Maps;
-import org.bukkit.Location;
+import net.tylermurphy.hideAndSeek.util.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
@@ -34,7 +34,7 @@ import java.util.stream.Collectors;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-public class Spawn extends Command {
+public class Spawn implements ICommand {
public void execute(Player sender, String[] args) {
LocationUtils.setLocation(sender, Locations.GAME, args[0], map -> {
@@ -45,11 +45,11 @@ public class Spawn extends Command {
throw new RuntimeException("World border not enabled or not in valid position!");
}
- map.setSpawn(sender.getLocation());
+ map.setSpawn(Location.from(sender));
- if(map.getSeekerLobby().getWorld() != null && !map.getSeekerLobby().getWorld().getName().equals(sender.getLocation().getWorld().getName())) {
+ if(map.getSeekerLobby().getWorld() != null && !map.getSeekerLobby().getWorld().equals(sender.getLocation().getWorld().getName())) {
sender.sendMessage(message("SEEKER_LOBBY_SPAWN_RESET").toString());
- map.setSeekerLobby(new Location(null, 0, 0, 0));
+ map.setSeekerLobby(Location.getDefault());
}
if (!sender.getLocation().getWorld().getName().equals(map.getSpawnName()) && mapSaveEnabled) {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java
index 5c47860..e9ed90c 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java
@@ -21,9 +21,10 @@ package net.tylermurphy.hideAndSeek.command.util;
import net.tylermurphy.hideAndSeek.command.map.Save;
import net.tylermurphy.hideAndSeek.util.Pair;
+import net.tylermurphy.hideAndSeek.util.Tuple;
import org.bukkit.ChatColor;
-import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.stream.Collectors;
@@ -40,7 +41,9 @@ public class CommandGroup {
public CommandGroup(String label, Object... data) {
this.label = label;
this.commandRegister = new LinkedHashMap<>();
- for(Object o : data) registerCommand(o);
+ for(Object o : data) {
+ registerCommand(o);
+ }
}
public String getLabel() {
@@ -48,8 +51,8 @@ public class CommandGroup {
}
private void registerCommand(Object object) {
- if(object instanceof Command) {
- Command command = (Command) object;
+ if (object instanceof ICommand) {
+ ICommand command = (ICommand) object;
if (!commandRegister.containsKey(command.getLabel())) {
commandRegister.put(command.getLabel().toLowerCase(), command);
}
@@ -61,87 +64,99 @@ public class CommandGroup {
}
}
- public boolean handleCommand(Player player, String permission, String[] args) {
- 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%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)
- );
- }
- } else {
- String invoke = args[0].toLowerCase();
- if (!invoke.equals("about") && !invoke.equals("help") && Save.runningBackup) {
- player.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS"));
- } else {
- try {
- Object object = commandRegister.get(invoke);
+ public void handleCommand(Player player, String[] args) {
- 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;
+ Tuple<ICommand, String, String[]> data = getCommand(args, this.getLabel());
- if (permissionsRequired && !player.hasPermission(permission+"."+command.getLabel())) {
- player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED"));
- return true;
- }
+ if (data == null) {
+ player.sendMessage(
+ 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)
+ );
+ return;
+ }
- 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;
- }
+ ICommand command = data.getLeft();
+ String permission = data.getCenter();
+ String[] parameters = data.getRight();
- command.execute(player,Arrays.copyOfRange(args, 1, args.length));
- }
- } catch (Exception e) {
- player.sendMessage(errorPrefix + "An error has occurred.");
- e.printStackTrace();
- }
+ if (Save.runningBackup) {
+ player.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS"));
+ return;
+ }
+
+ if (permissionsRequired && !player.hasPermission(permission)) {
+ player.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED"));
+ return;
+ }
+
+ int parameterCount = (int) Arrays.stream(command.getUsage().split(" ")).filter(p -> p.startsWith("<") && !p.startsWith("<*")).count();
+ if(parameters.length < parameterCount) {
+ player.sendMessage(errorPrefix + message("ARGUMENT_COUNT"));
+ return;
+ }
+
+ try {
+ command.execute(player, parameters);
+ } catch (Exception e) {
+ player.sendMessage(errorPrefix + "An error has occurred.");
+ e.printStackTrace();
+ }
+ }
+
+ @Nullable
+ private Tuple<ICommand, String, String[]> getCommand(String[] args, String permission) {
+ if(args.length < 1) {
+ return null;
+ }
+ String invoke = args[0];
+ if(commandRegister.containsKey(invoke)) {
+ Object o = commandRegister.get(invoke);
+ if (o instanceof CommandGroup) {
+ CommandGroup group = (CommandGroup) o;
+ return group.getCommand(
+ Arrays.copyOfRange(args, 1, args.length),
+ permission + "." + group.getLabel()
+ );
+ } else if(o instanceof ICommand) {
+ ICommand command = (ICommand) o;
+ return new Tuple<>(command, permission + "." + command.getLabel(), Arrays.copyOfRange(args, 1, args.length));
}
}
- return true;
+ return null;
+ }
+
+ public List<String> handleTabComplete(Player player, String[] args) {
+ return handleTabComplete(player, this.getLabel(), args);
}
- public List<String> handleTabComplete(CommandSender sender, String[] args) {
+ private List<String> handleTabComplete(Player player, String permission, String[] args) {
String invoke = args[0].toLowerCase();
if (args.length == 1) {
- if(sender instanceof Player) {
- Player player = (Player) sender;
- return new ArrayList<>(commandRegister.keySet())
- .stream()
- .filter(handle -> handle.toLowerCase().startsWith(invoke))
- .filter(handle -> {
- Object object = commandRegister.get(handle);
- 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());
- } else {
- return commandRegister.keySet()
- .stream()
- .filter(handle -> handle.toLowerCase().startsWith(invoke))
- .collect(Collectors.toList());
- }
+ return new ArrayList<>(commandRegister.keySet())
+ .stream()
+ .filter(handle -> handle.toLowerCase().startsWith(invoke))
+ .filter(handle -> {
+ Object object = commandRegister.get(handle);
+ if (object instanceof ICommand) {
+ ICommand command = (ICommand) object;
+ return !permissionsRequired || player.hasPermission(permission + "." + command.getLabel());
+ } else if (object instanceof CommandGroup) {
+ CommandGroup group = (CommandGroup) object;
+ return !permissionsRequired || group.hasPermission(player, permission + "." + group.getLabel());
+ }
+ return false;
+ })
+ .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;
+ return group.handleTabComplete(player, permission + "." + group.getLabel(), Arrays.copyOfRange(args, 1, args.length));
+ } else if (object instanceof ICommand) {
+ ICommand command = (ICommand) object;
String[] usage = command.getUsage().split(" ");
if (args.length - 2 < usage.length) {
String parameter = usage[args.length - 2];
@@ -159,26 +174,26 @@ public class CommandGroup {
private boolean hasPermission(Player player, String permission) {
for(Object object : commandRegister.values()) {
- if(object instanceof Command) {
- Command command = (Command) object;
- if(player.hasPermission(permission+"."+command.getLabel())) return true;
+ if(object instanceof ICommand) {
+ ICommand command = (ICommand) 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;
+ if (group.hasPermission(player, permission + this.label + ".")) return true;
}
}
return false;
}
- public List<Pair<String, Command>> getCommands() {
+ public List<Pair<String, ICommand>> getCommands() {
return getCommands(this.getLabel());
}
- private List<Pair<String, Command>> getCommands(String prefix) {
- List<Pair<String, Command>> commands = new LinkedList<>();
+ private List<Pair<String, ICommand>> getCommands(String prefix) {
+ List<Pair<String, ICommand>> commands = new LinkedList<>();
for(Object object : commandRegister.values()) {
- if(object instanceof Command) {
- Command command = (Command) object;
+ if(object instanceof ICommand) {
+ ICommand command = (ICommand) object;
commands.add(new Pair<>(prefix+" "+command.getLabel(), command));
} else if(object instanceof CommandGroup) {
CommandGroup group = (CommandGroup) object;
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/ICommand.java
index 41fd4d5..3aa0ca4 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/Command.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/ICommand.java
@@ -24,16 +24,16 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
-public abstract class Command {
+public interface ICommand {
- public abstract void execute(Player sender, String[] args);
+ void execute(Player sender, String[] args);
- public abstract String getLabel();
+ String getLabel();
- public abstract String getUsage();
+ String getUsage();
- public abstract String getDescription();
+ String getDescription();
- public abstract List<String> autoComplete(@NotNull String parameter, @NotNull String typed);
+ List<String> autoComplete(@NotNull String parameter, @NotNull String typed);
}