Pārlūkot izejas kodu

Adding Actionbar msg for Spectators

RedstoneFuture 1 gadu atpakaļ
vecāks
revīzija
f6661b6283

+ 19 - 0
missilewars-plugin/src/main/java/de/butzlabben/missilewars/configuration/Config.java

@@ -131,6 +131,17 @@ public class Config {
                 add("");
                 add("%team2% &7» %team2_color%%team2_amount%");
             }});
+            
+        }
+        
+        cfg.addDefault("actionbar_msg.spectator.delay", 6);
+        
+        if (isNewConfig) {
+            
+            cfg.set("actionbar_msg.spectator.messages", new ArrayList<String>() {{
+                add("&eChoose your team to join: &7/mw teammenu");
+            }});
+            
         }
 
         String gameJoinMenu = "menus.hotbar_menu.game_join_menu";
@@ -404,6 +415,14 @@ public class Config {
         return Messages.getConvertedMsgList(cfg.getStringList("sidebar.entries"));
     }
     
+    public static int getActionbarForSpecDelay() {
+        return cfg.getInt("actionbar_msg.spectator.delay");
+    }
+    
+    public static String[] getActionbarForSpecEntries() {
+        return Messages.getConvertedMsgArray(cfg.getStringList("actionbar_msg.spectator.messages"));
+    }
+    
     public static Map<Integer, Map<Integer, MenuItem>> getGameJoinMenuItems() {
         // Config keys inspired by DeluxeMenus https://wiki.helpch.at/helpchat-plugins/deluxemenus/options-and-configurations/item
         

+ 13 - 1
missilewars-plugin/src/main/java/de/butzlabben/missilewars/configuration/Messages.java

@@ -241,7 +241,7 @@ public class Messages {
      * to the final text message.
      * 
      * @param messageList the target message list
-     * @return (String) the converted message list
+     * @return (List of Strings) the converted message list
      */
     public static List<String> getConvertedMsgList(List<String> messageList) {
         List<String> convertedMsgList = new ArrayList<>();
@@ -251,6 +251,18 @@ public class Messages {
         return convertedMsgList;
     }
     
+    /**
+     * This method returns the desired message array. 
+     * Legacy color-codes with '&' will be converted 
+     * to the final text message.
+     * 
+     * @param messageList the target message list
+     * @return (String[]) the converted message array
+     */
+    public static String[] getConvertedMsgArray(List<String> messageList) {
+        return getConvertedMsgList(messageList).toArray(String[]::new);
+    }
+    
     public static String getPapiMessage(String message, Player player) {
         return ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(player, message));
     }

+ 36 - 8
missilewars-plugin/src/main/java/de/butzlabben/missilewars/game/timer/GameTimer.java

@@ -18,8 +18,12 @@
 
 package de.butzlabben.missilewars.game.timer;
 
+import de.butzlabben.missilewars.configuration.Config;
 import de.butzlabben.missilewars.configuration.Messages;
 import de.butzlabben.missilewars.game.Game;
+import de.butzlabben.missilewars.game.enums.TeamType;
+import net.md_5.bungee.api.ChatMessageType;
+import net.md_5.bungee.api.chat.TextComponent;
 import org.bukkit.GameMode;
 import org.bukkit.entity.Player;
 
@@ -28,7 +32,9 @@ import org.bukkit.entity.Player;
  * @since 06.01.2018
  */
 public class GameTimer extends Timer {
-
+    
+    int actionbarMsgCounter = 0;
+    
     public GameTimer(Game game) {
         super(game);
         seconds = game.getArena().getGameDuration() * 60;
@@ -69,20 +75,42 @@ public class GameTimer extends Timer {
                 break;
         }
 
-        if (seconds % 10 == 0) {
+        if (seconds % 5 == 0) {
             game.getScoreboardManager().updateScoreboard();
+            
+            game.getPlayers().values().forEach(mwPlayer -> {
+                Player player = mwPlayer.getPlayer();
+                
+                if (mwPlayer.getTeam().getTeamType() == TeamType.PLAYER) {
+                    
+                    if (mwPlayer.getPlayer().getGameMode() != GameMode.SURVIVAL) return;
+                    
+                    if (game.isInGameArea(player.getLocation())) return;
+                    
+                    player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.ARENA_LEAVED));
+                    mwPlayer.getTeam().teleportToTeamSpawn(player);
+                    
+                }
+            
+            });
         }
         
-        if (seconds % 4 == 0) {
+        if ((Config.getActionbarForSpecEntries().length > 0) && (seconds % Config.getActionbarForSpecDelay() == 0)) {
             game.getPlayers().values().forEach(mwPlayer -> {
-                if (mwPlayer.getPlayer().getGameMode() != GameMode.SURVIVAL) return;
-                
                 Player player = mwPlayer.getPlayer();
-                if (game.isInGameArea(player.getLocation())) return;
                 
-                player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.ARENA_LEAVED));
-                mwPlayer.getTeam().teleportToTeamSpawn(player);
+                if (mwPlayer.getTeam().getTeamType() == TeamType.PLAYER) return;
+                
+                player.spigot().sendMessage(ChatMessageType.ACTION_BAR, 
+                        TextComponent.fromLegacyText(Config.getActionbarForSpecEntries()[actionbarMsgCounter]));
             });
+            
+            // Array-Iteration:
+            if (actionbarMsgCounter >= Config.getActionbarForSpecEntries().length - 1) {
+                actionbarMsgCounter = 0;
+            } else {
+                actionbarMsgCounter++;
+            }
         }
 
         game.checkPortals();