Browse Source

Rework message path

RedstoneFuture 2 years ago
parent
commit
12f0f111c4

+ 20 - 15
missilewars-plugin/src/main/java/de/butzlabben/missilewars/commands/MWCommands.java

@@ -98,7 +98,7 @@ public class MWCommands extends BaseCommand {
         Player player = (Player) sender;
 
         if (args.length < 1) {
-            player.sendMessage(Messages.getPrefix() + "§cMissile needed.");
+            player.sendMessage(Messages.getMessage("command.missile_needed"));
             return;
         }
 
@@ -115,7 +115,7 @@ public class MWCommands extends BaseCommand {
 
         Missile missile = game.getArena().getMissileConfiguration().getMissileFromName(args[0]);
         if (missile == null) {
-            player.sendMessage(Messages.getPrefix() + "§cUnknown missile.");
+            player.sendMessage(Messages.getMessage("command.invalid_missile"));
             return;
         }
 
@@ -141,7 +141,7 @@ public class MWCommands extends BaseCommand {
         if (args.length == 1) {
             game = GameManager.getInstance().getGame(args[0]);
             if (game == null) {
-                player.sendMessage(Messages.getPrefix() + "§cGame not found.");
+                player.sendMessage(Messages.getMessage("command.invalid_game"));
                 return;
             }
         } else {
@@ -153,7 +153,7 @@ public class MWCommands extends BaseCommand {
         }
 
         if (game.getState() != GameState.LOBBY) {
-            player.sendMessage(Messages.getPrefix() + "§cGame already started");
+            player.sendMessage(Messages.getMessage("game.already_startet"));
             return;
         }
 
@@ -161,7 +161,7 @@ public class MWCommands extends BaseCommand {
             game.startGame();
         else {
             if (game.getLobby().getMapChooseProcedure() != MapChooseProcedure.MAPVOTING && game.getArena() == null) {
-                player.sendMessage(Messages.getPrefix() + "§cGame cannot be started");
+                player.sendMessage(Messages.getMessage("game.can_not_startet"));
             } else {
                 Map.Entry<String, Integer> mostVotes = null;
                 for (Map.Entry<String, Integer> arena : game.getVotes().entrySet()) {
@@ -175,7 +175,7 @@ public class MWCommands extends BaseCommand {
                 Optional<Arena> arena = Arenas.getFromName(mostVotes.getKey());
                 if (arena.isEmpty()) throw new IllegalStateException("Voted arena is not present");
                 game.setArena(arena.get());
-                player.sendMessage(Messages.getPrefix() + "A map was elected. Use \"/mw start\" again to start the round");
+                player.sendMessage(Messages.getMessage("game.map_selected"));
             }
         }
     }
@@ -198,7 +198,7 @@ public class MWCommands extends BaseCommand {
         if (args.length == 1) {
             game = GameManager.getInstance().getGame(args[0]);
             if (game == null) {
-                player.sendMessage(Messages.getPrefix() + "§cGame not found.");
+                player.sendMessage(Messages.getMessage("command.invalid_game"));
                 return;
             }
         } else {
@@ -232,7 +232,7 @@ public class MWCommands extends BaseCommand {
         if (args.length == 1) {
             game = GameManager.getInstance().getGame(args[0]);
             if (game == null) {
-                player.sendMessage(Messages.getPrefix() + "§cGame not found.");
+                player.sendMessage(Messages.getMessage("command.invalid_game"));
                 return;
             }
         } else {
@@ -263,7 +263,8 @@ public class MWCommands extends BaseCommand {
         Config.load();
         Messages.load();
         Arenas.load();
-        sender.sendMessage(Messages.getPrefix() + "Reloaded configs");
+        
+        player.sendMessage(Messages.getMessage("reload"));
     }
 
     @Subcommand("debug")
@@ -285,7 +286,8 @@ public class MWCommands extends BaseCommand {
             Logger.NORMAL.log("Printing state for arena " + game.getArena().getName() + ". Number: " + i);
             Logger.NORMAL.log(game.toString());
         }
-        sender.sendMessage(Messages.getPrefix() + "Printed debug message into the log file");
+        
+        player.sendMessage(Messages.getMessage("printed_debug_msg"));
     }
 
     @Subcommand("restartall")
@@ -300,16 +302,19 @@ public class MWCommands extends BaseCommand {
             player.sendMessage(Messages.getMessage("command.to_many_arguments"));
             return;
         }
-
-        sender.sendMessage(Messages.getPrefix() + "§cWarning - Restarting all games. This may take a while");
+        
+        if (GameManager.getInstance().getGames().size() > 10) {
+            player.sendMessage(Messages.getMessage("restart_all_games_warn"));
+        }
+        
         GameManager.getInstance().restartAll();
-        sender.sendMessage(Messages.getPrefix() + "Restarted all games.");
+        player.sendMessage(Messages.getMessage("restart_all_games"));
     }
 
     static boolean senderIsPlayer(CommandSender sender) {
         if (sender instanceof Player) return true;
-
-        sender.sendMessage(Messages.getPrefix() + "§cYou are not a player");
+        
+        sender.sendMessage(Messages.getMessage("command.only_players"));
         return false;
     }
 

+ 12 - 13
missilewars-plugin/src/main/java/de/butzlabben/missilewars/commands/UserCommands.java

@@ -61,24 +61,24 @@ public class UserCommands extends BaseCommand {
         }
 
         if (game.getState() != GameState.LOBBY) {
-            player.sendMessage(Messages.getPrefix() + "§cThe game is not in the right state to vote right now");
+            player.sendMessage(Messages.getMessage("vote.change_team_not_now"));
             return;
         }
 
         if (game.getLobby().getMapChooseProcedure() != MapChooseProcedure.MAPVOTING) {
-            player.sendMessage(Messages.getPrefix() + "§cYou can't vote in this game");
+            player.sendMessage(Messages.getMessage("vote.cant_vote"));
             return;
         }
 
         if (game.getArena() != null) {
-            player.sendMessage(Messages.getPrefix() + "§cA map was already elected");
+            player.sendMessage(Messages.getMessage("vote.change_team_no_longer_now"));
             return;
         }
 
         String arenaName = args[0];
         Optional<Arena> arena = Arenas.getFromName(arenaName);
         if (!game.getVotes().containsKey(arenaName) || arena.isEmpty()) {
-            player.sendMessage(Messages.getPrefix() + "§cNo map with this title was found");
+            player.sendMessage(Messages.getMessage("command.invalid_map"));
             return;
         }
 
@@ -95,7 +95,7 @@ public class UserCommands extends BaseCommand {
         Player player = (Player) sender;
         
         if (args.length < 1) {
-            player.sendMessage(Messages.getPrefix() + "§cNumber needed.");
+            player.sendMessage(Messages.getMessage("command.team_number_needed"));
             return;
         }
 
@@ -111,7 +111,7 @@ public class UserCommands extends BaseCommand {
         }
         
         if (game.getState() != GameState.LOBBY) {
-            player.sendMessage(Messages.getPrefix() + "§cThe game is not in the right state to change your team right now");
+            player.sendMessage(Messages.getMessage("team.change_team_not_now"));
             return;
         }
 
@@ -119,20 +119,19 @@ public class UserCommands extends BaseCommand {
             MWPlayer mwPlayer = game.getPlayer(player);
             int teamNumber = Integer.parseInt(args[0]);
             Team to = teamNumber == 1 ? game.getTeam1() : game.getTeam2();
-            int otherCount = to.getEnemyTeam().getMembers().size() - 1;
-            int toCount = to.getMembers().size() + 1;
-            int diff = toCount - otherCount;
-            if (diff > 1) {
-                player.sendMessage(Messages.getMessage("team.cannot_change_difference"));
+            
+            // Is the same team?
+            if (to == mwPlayer.getTeam()) {
+                player.sendMessage(Messages.getMessage("team.already_in_team"));
                 return;
             }
-
+            
             // Remove the player from the old team and add him to the new team
             to.addMember(mwPlayer);
 
             player.sendMessage(Messages.getMessage("team.team_changed").replace("%team%", to.getFullname()));
         } catch (NumberFormatException exception) {
-            player.sendMessage(Messages.getPrefix() + "§c/mw change <1|2>");
+            sender.sendMessage(Messages.getMessage("command.invalid_team_number"));
         }
     }
 

+ 21 - 5
missilewars-plugin/src/main/java/de/butzlabben/missilewars/configuration/Messages.java

@@ -59,15 +59,29 @@ public class Messages {
 
         cfg.addDefault("prefix", "&6•&e● MissileWars &8▎ &7");
 
+        cfg.addDefault("reload", "&7Reloaded configs.");
+        cfg.addDefault("restart_all_games_warn", "&cWarning: Restarting all games. This may take a while.");
+        cfg.addDefault("restart_all_games", "&7Restarted all games.");
+        cfg.addDefault("printed_debug_msg", "&7Printed debug message into the log file.");
+        
         cfg.addDefault("server.restart_after_game", "&7The server will restart after this game.");
 
-        cfg.addDefault("command.to_many_arguments", "§cToo many arguments.");
-        cfg.addDefault("command.invalid_missile", "&cThe mentioned missile was not found.");
+        cfg.addDefault("command.only_players", "&cYou are not a player.");
+        cfg.addDefault("command.to_many_arguments", "&cToo many arguments.");
+        cfg.addDefault("command.invalid_missile", "&cThe specified missile was not found.");
+        cfg.addDefault("command.invalid_game", "&cThe specified game was not found.");
+        cfg.addDefault("command.invalid_map", "&cThe specified map was not found.");
+        cfg.addDefault("command.invalid_team_number", "&cThe team number is invalid. Use '1' or '2' to specify the target team.");
+        cfg.addDefault("command.missile_needed", "&cPlease specify the missile.");
+        cfg.addDefault("command.team_number_needed", "&cPlease specify the team number.");
 
+        cfg.addDefault("game.map_selected", "&7A map was selected. Use '/mw start' again to start the round.");
         cfg.addDefault("game.player_joined", "&e%player% &7joined the game (%team%&7).");
         cfg.addDefault("game.player_left", "&e%player% &7left the game (%team%&7).");
         cfg.addDefault("game.not_in_game_area", "&cYou are not in an arena right now.");
         cfg.addDefault("game.not_enter_arena", "&cYou may not enter this arena right now.");
+        cfg.addDefault("game.already_startet", "&cGame already started.");
+        cfg.addDefault("game.can_not_startet", "&cGame cannot be started.");
         
         cfg.addDefault("lobby_timer.game_starts_in", "Game starts in &e%seconds% &7seconds.");
 
@@ -82,10 +96,9 @@ public class Messages {
         cfg.addDefault("lobby.teams_unequal", "&cThe teams are unequal distributed.");
         cfg.addDefault("lobby.game_starts", "&aThe game starts.");
         
-        cfg.addDefault("team.change_team_not_now", "&cNow you cannot change your team anymore.");
-        //TODO currently not used:
+        cfg.addDefault("team.change_team_not_now", "&cThe game is not in the right state to change your team right now.");
+        cfg.addDefault("team.change_team_no_longer_now", "&cNow you cannot change your team anymore.");
         cfg.addDefault("team.already_in_team", "&cYou are already in this team.");
-        cfg.addDefault("team.cannot_change_difference", "&cYou cannot change your team.");
         cfg.addDefault("team.team_changed", "You are now in %team%&7.");
         cfg.addDefault("team.team_assigned", "You have been assigned to %team%&7.");
         cfg.addDefault("team.all_teammates_offline", "Everyone from %team% &7is offline.");
@@ -128,6 +141,9 @@ public class Messages {
         cfg.addDefault("vote.success", "You successfully voted for the map %map%.");
         cfg.addDefault("vote.finished", "The map %map% &7was elected.");
         cfg.addDefault("vote.gui", "Vote for a map");
+        cfg.addDefault("vote.cant_vote", "&cYou can't vote in this game.");
+        cfg.addDefault("vote.change_team_not_now", "&cThe game is not in the right state to vote right now.");
+        cfg.addDefault("vote.change_team_no_longer_now", "&cA map was already selected.");
 
     }
 

+ 1 - 1
missilewars-plugin/src/main/java/de/butzlabben/missilewars/listener/game/LobbyListener.java

@@ -70,7 +70,7 @@ public class LobbyListener extends GameBoundListener {
 
             // too late for team change:
             if (getGame().getTimer().getSeconds() < 10) {
-                player.sendMessage(Messages.getMessage("team.change_team_not_now"));
+                player.sendMessage(Messages.getMessage("team.change_team_no_longer_now"));
                 return;
             }