diff options
6 files changed, 43 insertions, 67 deletions
| diff --git a/src/main/java/com/MylesAndMore/Tumble/Main.java b/src/main/java/com/MylesAndMore/Tumble/Main.java index 067b839..e4c9452 100644 --- a/src/main/java/com/MylesAndMore/Tumble/Main.java +++ b/src/main/java/com/MylesAndMore/Tumble/Main.java @@ -24,8 +24,8 @@ public class Main extends JavaPlugin{          plugin = this;          languageManager = new LanguageManager(); -        arenaManager = new ArenaManager();          configManager = new ConfigManager(); +        arenaManager = new ArenaManager();          Objects.requireNonNull(this.getCommand("tumble")).setExecutor(new Tumble());          new Metrics(this, 16940); diff --git a/src/main/java/com/MylesAndMore/Tumble/commands/Join.java b/src/main/java/com/MylesAndMore/Tumble/commands/Join.java index 3177f3e..3989960 100644 --- a/src/main/java/com/MylesAndMore/Tumble/commands/Join.java +++ b/src/main/java/com/MylesAndMore/Tumble/commands/Join.java @@ -106,6 +106,7 @@ public class Join implements SubCommand, CommandExecutor, TabCompleter {              } else {                  sender.sendMessage(languageManager.fromKey("arena-not-ready"));              } +            return false;          }          if (game.gameState != GameState.WAITING) { diff --git a/src/main/java/com/MylesAndMore/Tumble/config/ArenaManager.java b/src/main/java/com/MylesAndMore/Tumble/config/ArenaManager.java index b4364d3..186184c 100644 --- a/src/main/java/com/MylesAndMore/Tumble/config/ArenaManager.java +++ b/src/main/java/com/MylesAndMore/Tumble/config/ArenaManager.java @@ -3,7 +3,6 @@ package com.MylesAndMore.Tumble.config;  import com.MylesAndMore.Tumble.game.Arena;  import com.MylesAndMore.Tumble.game.Game;  import com.MylesAndMore.Tumble.plugin.CustomConfig; -import com.MylesAndMore.Tumble.plugin.Result;  import org.bukkit.Bukkit;  import org.bukkit.Location;  import org.bukkit.World; @@ -11,7 +10,6 @@ import org.bukkit.configuration.ConfigurationSection;  import org.bukkit.configuration.file.FileConfiguration;  import org.bukkit.entity.Player;  import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable;  import java.util.HashMap;  import java.util.Objects; @@ -44,46 +42,38 @@ public class ArenaManager {          // arenas          ConfigurationSection arenasSection = config.getConfigurationSection("arenas");          if (arenasSection == null) { -            plugin.getLogger().warning("Section 'arenas' is missing from config"); +            plugin.getLogger().warning("config.yml is missing key 'arenas'");              return;          }          arenas = new HashMap<>();          for (String arenaName: arenasSection.getKeys(false)) { - -            ConfigurationSection anArenaSection = arenasSection.getConfigurationSection(arenaName); -            if (anArenaSection == null) { -                plugin.getLogger().warning("Failed to load arena "+arenaName+": Error loading config section"); -                continue; -            } -              Arena arena = new Arena(arenaName); -            arenas.put(arena.name, arena); -            int killAtY = anArenaSection.getInt("kill-at-y", 0); -            if (killAtY != 0) { -                arena.killAtY = killAtY; +            if (config.contains("arenas." + arenaName + ".kill-at-y", true)) { +                arena.killAtY = config.getInt("arenas." + arenaName + ".kill-at-y");              } - -            Result<Location> res = readWorld(anArenaSection.getConfigurationSection("game-spawn")); -            if (res.success) { -                arena.gameSpawn = res.value; +            if (config.contains("arenas." + arenaName + ".game-spawn")) { +                arena.gameSpawn = readWorld("arenas." + arenaName + ".game-spawn");              } - -            Result<Location> lobbyRes = readWorld(anArenaSection.getConfigurationSection("lobby")); -            if (lobbyRes.success) { -                arena.lobby = lobbyRes.value; +            if (config.contains("arenas." + arenaName + ".lobby")) { +                arena.lobby = readWorld("arenas." + arenaName + ".lobby");              } - -            Result<Location> winnerLobbyRes = readWorld(anArenaSection.getConfigurationSection("winner-lobby")); -            if (winnerLobbyRes.success) { -                arena.winnerLobby = winnerLobbyRes.value; +            if (config.contains("arenas." + arenaName + ".winner-lobby")) { +                arena.winnerLobby = readWorld("arenas." + arenaName + ".winner-lobby"); +            } +            if (config.contains("arenas." + arenaName + ".wait-area")) { +                arena.waitArea = readWorld("arenas." + arenaName + ".wait-area");              } -            Result<Location> waitAreaRes = readWorld(anArenaSection.getConfigurationSection("wait-area")); -            if (waitAreaRes.success) { -                arena.waitArea = waitAreaRes.value; +            // validate +            if (arena.gameSpawn == null) { +                plugin.getLogger().severe("arenas.yml: Arena " + arenaName + " is missing a game spawn, before you can join you must set it with '/tmbl setgamespawn'."); +            } +            if (arena.gameSpawn == null) { +                plugin.getLogger().severe("arenas.yml: Arena " + arenaName + " is missing a lobby location. The spawn point of the default world will be used.");              } +            arenas.put(arena.name, arena);          }      } @@ -136,35 +126,40 @@ public class ArenaManager {       *   y:       *   z:       *   world: -     * @param section The section in the yaml with x, y, z, and world as its children +     * @param path The section in the yaml with x, y, z, and world as its children       * @return Result of either:       *   Result#success = true and Result#value OR       *   Result#success = false and Result#error       */ -    private Result<Location> readWorld(@Nullable ConfigurationSection section) { +    private Location readWorld(String path) { +        ConfigurationSection section = config.getConfigurationSection(path);          if (section == null) { -            return new Result<>("Section missing from config"); +            plugin.getLogger().warning("arenas.yml: Error loading location at '" + path + "' - " + "Section is null"); +            return null;          }          double x = section.getDouble("x");          double y = section.getDouble("y");          double z = section.getDouble("z");          if (x == 0 || y == 0 || z == 0) { -            return new Result<>("Arena coordinates are missing or are zero. Coordinates cannot be zero."); +            plugin.getLogger().warning("arenas.yml: Error loading location at '" + path + "' - " + "Arena coordinates are missing or are zero. Coordinates cannot be zero."); +            return null;          }          String worldName = section.getString("world");          if (worldName == null) { -            return new Result<>("World name is missing"); +            plugin.getLogger().warning("arenas.yml: Error loading location at '" + path +"' - " + "World name is missing"); +            return null;          }          World world = Bukkit.getWorld(worldName);          if (world == null) { -            return new Result<>("Failed to load world " + worldName); +            plugin.getLogger().warning("arenas.yml: Error loading location at '" + path + "' - " + "Failed to load world '" + worldName + "'"); +            return null;          } -        return new Result<>(new Location(world,x,y,z)); +        return new Location(world,x,y,z);      }      /** diff --git a/src/main/java/com/MylesAndMore/Tumble/game/Game.java b/src/main/java/com/MylesAndMore/Tumble/game/Game.java index 169ce33..e32ba92 100644 --- a/src/main/java/com/MylesAndMore/Tumble/game/Game.java +++ b/src/main/java/com/MylesAndMore/Tumble/game/Game.java @@ -43,7 +43,7 @@ public class Game {      public Game(@NotNull Arena arena, @NotNull GameType type) {          this.arena = arena;          this.type = type; -        this.gameSpawn = arena.gameSpawn; +        this.gameSpawn = Objects.requireNonNull(arena.gameSpawn);      }      /** diff --git a/src/main/java/com/MylesAndMore/Tumble/plugin/Result.java b/src/main/java/com/MylesAndMore/Tumble/plugin/Result.java deleted file mode 100644 index 9a07771..0000000 --- a/src/main/java/com/MylesAndMore/Tumble/plugin/Result.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.MylesAndMore.Tumble.plugin; - -// java does not have result types (i miss rust </3) so i did this -public class Result<T> { -    public final boolean success; -    public final T value; -    public final String error; - -    public Result(String error) { -        success = false; -        this.error = error; -        this.value = null; -    } - -    public Result(T value) { -        success = true; -        this.value = value; -        this.error = null; -    } -} diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 7b67114..835d577 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -4,18 +4,18 @@ unknown-command: "&4Unknown command '%command%'"  no-permission: "&4You do not have permission to perform this command! &7Required permission: '%permission%.'"  missing-arena-parameter: "&4Missing arena name!"  invalid-arena: "&4arena '%arena%' does not exist!" -invalid-type: "&4Invalid game type" -no-game-in-arena: "&4No game is currently running in this arena" +invalid-type: "&4Invalid game type!" +no-game-in-arena: "&4No game is currently running in this arena!"  player-not-in-game: "&4You are not in a game!" -not-for-console: "&4This cannot be run by the console" -game-in-progress: "&4This game is still in progress!&7 wait until it finishes or join another game" -another-type-in-arena: "A game of %type% is currently taking place in this arena!&7 choose another arena or join it with &a/tmbl join %arena% %type%" +not-for-console: "&4This cannot be run by the console!" +game-in-progress: "&4This game is still in progress!&7 wait until it finishes or join another game." +another-type-in-arena: "A game of %type% is currently taking place in this arena!&7 choose another arena or join it with '/tmbl join %arena% %type%'."  already-in-game: "&4You are already in a game! Leave it to join another one." -arena-not-ready: "&4This arena is not finished being set up" -arena-not-ready-op: "&4Incomplete arena. &7Set a game spawn with /tmbl setGameSpawn" -specify-game-type: "&4No game is currently taking place in this arena, provide the game type to start one" +arena-not-ready: "&4This arena is not finished being set up!" +arena-not-ready-op: "&4Incomplete arena. &7Set a game spawn with '/tmbl setGameSpawn'." +specify-game-type: "&4No game is currently taking place in this arena! &7Provide the game type to start one." -create-success: "&aArena created successfully! &eBefore you can join, you must set a game spawn location with /tmbl setGameSpawn" +create-success: "&aArena created successfully! &eBefore you can join, you must set a game spawn location with '/tmbl setgamespawn'."  forcestart-success: "&aStarting game."  forcestop-success: "&aGame stopped."  join-success: "&aJoined game &d%arena% - %type%" | 
