diff --git a/bedwars-api/src/main/java/com/andrei1058/bedwars/api/configuration/ConfigManager.java b/bedwars-api/src/main/java/com/andrei1058/bedwars/api/configuration/ConfigManager.java index 3abe8ac57..b1f9d9f6f 100644 --- a/bedwars-api/src/main/java/com/andrei1058/bedwars/api/configuration/ConfigManager.java +++ b/bedwars-api/src/main/java/com/andrei1058/bedwars/api/configuration/ConfigManager.java @@ -47,6 +47,7 @@ public class ConfigManager { */ public ConfigManager(Plugin plugin, String name, String dir) { File d = new File(dir); + if (!d.exists()) { if (!d.mkdirs()) { plugin.getLogger().log(Level.SEVERE, "Could not create " + d.getPath()); diff --git a/bedwars-api/src/main/java/com/andrei1058/bedwars/api/configuration/ConfigPath.java b/bedwars-api/src/main/java/com/andrei1058/bedwars/api/configuration/ConfigPath.java index 1a385db84..a0d7ef2ba 100644 --- a/bedwars-api/src/main/java/com/andrei1058/bedwars/api/configuration/ConfigPath.java +++ b/bedwars-api/src/main/java/com/andrei1058/bedwars/api/configuration/ConfigPath.java @@ -138,6 +138,10 @@ public class ConfigPath { public static final String SB_CONFIG_SIDEBAR_LIST_REFRESH = "scoreboard-settings.player-list.names-refresh-interval"; public static final String SB_CONFIG_SIDEBAR_HEALTH_IN_TAB = "scoreboard-settings.health.display-in-tab"; public static final String SB_CONFIG_SIDEBAR_HEALTH_REFRESH = "scoreboard-settings.health.animation-refresh-interval"; + + public static final String SB_CONFIG_TAB_HEADER_FOOTER_ENABLE = "scoreboard-settings.tab-header-footer.enable"; + public static final String SB_CONFIG_TAB_HEADER_FOOTER_REFRESH_INTERVAL = "scoreboard-settings.tab-header-footer.refresh-interval"; + public static final String GENERAL_CONFIGURATION_DISABLED_LANGUAGES = "disabled-languages"; public static final String GENERAL_CONFIGURATION_ARENA_SELECTOR_PATH = "arena-gui"; diff --git a/bedwars-plugin/pom.xml b/bedwars-plugin/pom.xml index f3a14a85f..ceaa0e3d0 100644 --- a/bedwars-plugin/pom.xml +++ b/bedwars-plugin/pom.xml @@ -242,55 +242,55 @@ com.andrei1058.spigot.sidebar sidebar-base - 23.6 + 23.7-SNAPSHOT compile com.andrei1058.spigot.sidebar sidebar-v1_8_R3 - 23.6 + 23.7-SNAPSHOT compile com.andrei1058.spigot.sidebar sidebar-v1_12_R1 - 23.6 + 23.7-SNAPSHOT compile com.andrei1058.spigot.sidebar sidebar-v1_16_R1 - 23.6 + 23.7-SNAPSHOT compile com.andrei1058.spigot.sidebar sidebar-v1_17_R1 - 23.6 + 23.7-SNAPSHOT compile com.andrei1058.spigot.sidebar sidebar-v1_18_R2 - 23.6 + 23.7-SNAPSHOT compile com.andrei1058.spigot.sidebar sidebar-v1_19_R2 - 23.6 + 23.7-SNAPSHOT compile com.andrei1058.spigot.sidebar sidebar-v1_19_R3 - 23.6 + 23.7-SNAPSHOT compile com.andrei1058.spigot.sidebar sidebar-v1_20_R1 - 23.6 + 23.7-SNAPSHOT compile diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java index 64f45dd24..98d2b5f74 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java @@ -64,10 +64,7 @@ import com.andrei1058.bedwars.money.internal.MoneyListeners; import com.andrei1058.bedwars.shop.ShopManager; import com.andrei1058.bedwars.sidebar.*; -import com.andrei1058.bedwars.sidebar.thread.RefreshTitleTask; -import com.andrei1058.bedwars.sidebar.thread.RefreshPlaceholdersTask; -import com.andrei1058.bedwars.sidebar.thread.RefreshLifeTask; -import com.andrei1058.bedwars.sidebar.thread.RefreshTabListTask; +import com.andrei1058.bedwars.sidebar.thread.*; import com.andrei1058.bedwars.stats.StatsManager; import com.andrei1058.bedwars.support.citizens.CitizensListener; import com.andrei1058.bedwars.support.citizens.JoinNPC; @@ -394,7 +391,7 @@ public void onEnable() { ArenaSocket.sendMessage(Arena.getArenas().get(0)); } }*/ - }, 40L); + }, 5L); /* Save messages for stats gui items if custom items added, for each language */ Language.setupCustomStatsMessages(); @@ -520,49 +517,61 @@ public void onEnable() { int playerListRefreshInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_LIST_REFRESH); if (playerListRefreshInterval < 1) { - Bukkit.getLogger().info("Scoreboard names list refresh is disabled. (Is set to " + playerListRefreshInterval + ")."); + Bukkit.getLogger().info("Scoreboard names list refresh is disabled. (It is set to " + playerListRefreshInterval + ")."); } else { if (playerListRefreshInterval < 20) { Bukkit.getLogger().warning("Scoreboard names list refresh interval is set to: " + playerListRefreshInterval); Bukkit.getLogger().warning("It is not recommended to use a value under 20 ticks."); Bukkit.getLogger().warning("If you expect performance issues please increase its timer."); } - Bukkit.getScheduler().runTaskTimer(this, new RefreshTabListTask(), 23L, playerListRefreshInterval); + Bukkit.getScheduler().runTaskTimer(this, new RefreshPlayerListTask(), 1L, playerListRefreshInterval); } int placeholdersRefreshInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_PLACEHOLDERS_REFRESH_INTERVAL); if (placeholdersRefreshInterval < 1) { - Bukkit.getLogger().info("Scoreboard placeholders refresh is disabled. (Is set to " + placeholdersRefreshInterval + ")."); + Bukkit.getLogger().info("Scoreboard placeholders refresh is disabled. (It is set to " + placeholdersRefreshInterval + ")."); } else { if (placeholdersRefreshInterval < 20) { Bukkit.getLogger().warning("Scoreboard placeholders refresh interval is set to: " + placeholdersRefreshInterval); Bukkit.getLogger().warning("It is not recommended to use a value under 20 ticks."); Bukkit.getLogger().warning("If you expect performance issues please increase its timer."); } - Bukkit.getScheduler().runTaskTimer(this, new RefreshPlaceholdersTask(), 28L, placeholdersRefreshInterval); + Bukkit.getScheduler().runTaskTimer(this, new RefreshPlaceholdersTask(), 1L, placeholdersRefreshInterval); } int titleRefreshInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_TITLE_REFRESH_INTERVAL); if (titleRefreshInterval < 1) { - Bukkit.getLogger().info("Scoreboard title refresh is disabled. (Is set to " + titleRefreshInterval + ")."); + Bukkit.getLogger().info("Scoreboard title refresh is disabled. (It is set to " + titleRefreshInterval + ")."); } else { if (titleRefreshInterval < 4) { Bukkit.getLogger().warning("Scoreboard title refresh interval is set to: " + titleRefreshInterval); Bukkit.getLogger().warning("If you expect performance issues please increase its timer."); } - Bukkit.getScheduler().runTaskTimerAsynchronously(this, new RefreshTitleTask(), 32L, titleRefreshInterval); + Bukkit.getScheduler().runTaskTimerAsynchronously(this, new RefreshTitleTask(), 1L, titleRefreshInterval); } int healthAnimationInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_HEALTH_REFRESH); if (healthAnimationInterval < 1) { - Bukkit.getLogger().info("Scoreboard health animation refresh is disabled. (Is set to " + healthAnimationInterval + ")."); + Bukkit.getLogger().info("Scoreboard health animation refresh is disabled. (It is set to " + healthAnimationInterval + ")."); } else { if (healthAnimationInterval < 20) { Bukkit.getLogger().warning("Scoreboard health animation refresh interval is set to: " + healthAnimationInterval); Bukkit.getLogger().warning("It is not recommended to use a value under 20 ticks."); Bukkit.getLogger().warning("If you expect performance issues please increase its timer."); } - Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new RefreshLifeTask(), 40L, healthAnimationInterval); + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new RefreshLifeTask(), 1L, healthAnimationInterval); + } + + int tabHeaderFooterRefreshInterval = config.getInt(ConfigPath.SB_CONFIG_TAB_HEADER_FOOTER_REFRESH_INTERVAL); + if (tabHeaderFooterRefreshInterval < 1 || !config.getBoolean(ConfigPath.SB_CONFIG_TAB_HEADER_FOOTER_ENABLE)) { + Bukkit.getLogger().info("Scoreboard Tab header-footer refresh is disabled."); + } else { + if (tabHeaderFooterRefreshInterval < 20) { + Bukkit.getLogger().warning("Scoreboard tab header-footer refresh interval is set to: " + tabHeaderFooterRefreshInterval); + Bukkit.getLogger().warning("It is not recommended to use a value under 20 ticks."); + Bukkit.getLogger().warning("If you expect performance issues please increase its timer."); + } + Bukkit.getScheduler().runTaskTimer(this, new RefreshTabHeaderFooterTask(), 1L, tabHeaderFooterRefreshInterval); } registerEvents(new ScoreboardListener()); diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/configuration/MainConfig.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/configuration/MainConfig.java index 938a0cfcb..b04116c38 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/configuration/MainConfig.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/configuration/MainConfig.java @@ -73,6 +73,9 @@ public MainConfig(Plugin plugin, String name) { yml.addDefault(ConfigPath.SB_CONFIG_SIDEBAR_LIST_REFRESH, 1200); yml.addDefault(ConfigPath.SB_CONFIG_SIDEBAR_HEALTH_IN_TAB, true); yml.addDefault(ConfigPath.SB_CONFIG_SIDEBAR_HEALTH_REFRESH, 300); + yml.addDefault(ConfigPath.SB_CONFIG_TAB_HEADER_FOOTER_ENABLE, true); + yml.addDefault(ConfigPath.SB_CONFIG_TAB_HEADER_FOOTER_REFRESH_INTERVAL, 20); + yml.addDefault(ConfigPath.GENERAL_CONFIGURATION_REJOIN_TIME, 60 * 5); yml.addDefault(ConfigPath.GENERAL_CONFIGURATION_RE_SPAWN_INVULNERABILITY, 4000); yml.addDefault(ConfigPath.GENERAL_CONFIGURATION_BUNGEE_MODE_GAMES_BEFORE_RESTART, 30); diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/language/Romanian.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/language/Romanian.java index cd0d903fe..e383d66a8 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/language/Romanian.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/language/Romanian.java @@ -43,28 +43,29 @@ public Romanian() { // this must stay here // move message to new path - if (yml.get("player-die-knocked-regular") != null && yml.get(Messages.PLAYER_DIE_KNOCKED_IN_VOID_REGULAR_KILL) == null){ + if (yml.get("player-die-knocked-regular") != null && yml.get(Messages.PLAYER_DIE_KNOCKED_IN_VOID_REGULAR_KILL) == null) { yml.set(Messages.PLAYER_DIE_KNOCKED_IN_VOID_REGULAR_KILL, yml.getString("player-die-knocked-regular")); yml.set("player-die-knocked-regular", null); } - if (yml.get("player-die-knocked-final") != null && yml.get(Messages.PLAYER_DIE_KNOCKED_IN_VOID_FINAL_KILL) == null){ + if (yml.get("player-die-knocked-final") != null && yml.get(Messages.PLAYER_DIE_KNOCKED_IN_VOID_FINAL_KILL) == null) { yml.set(Messages.PLAYER_DIE_KNOCKED_IN_VOID_FINAL_KILL, yml.getString("player-die-knocked-final")); yml.set("player-die-knocked-final", null); } - yml.addDefault(Messages.FORMATTING_SB_TAB_LOBBY_HEADER, List.of("","&6{serverIp}", "")); - yml.addDefault(Messages.FORMATTING_SB_TAB_LOBBY_FOOTER, List.of("","&6{serverIp}", "", "&fJoci alaturi de {online} jucatori", "Powered by BedWars1058")); - yml.addDefault(Messages.FORMATTING_SB_TAB_WAITING_HEADER,"&a{serverIp}"); + yml.addDefault(Messages.FORMATTING_SB_TAB_LOBBY_HEADER, List.of("", "&a{serverIp}", "")); + yml.addDefault(Messages.FORMATTING_SB_TAB_LOBBY_FOOTER, List.of("", "&fJoci alaturi de {on} jucatori", "Powered by BedWars1058,&a{serverIp}", "")); + yml.addDefault(Messages.FORMATTING_SB_TAB_WAITING_HEADER, List.of("", "&a{serverIp}", "")); + yml.addDefault(Messages.FORMATTING_SB_TAB_WAITING_FOOTER, List.of("", "Se asteapta jucatori,Se asteapta jucatori.,Se asteapta jucatori.., Se asteapta Jucatori...", "&f{on}&a/&f{max}", "", "&a{serverIp}", "&fPowered by BedWars1058", "")); + yml.addDefault(Messages.FORMATTING_SIDEBAR_TAB_HEADER_STARTING, "&6{serverIp}"); yml.addDefault(Messages.FORMATTING_SIDEBAR_TAB_HEADER_PLAYING, "&d{serverIp}"); yml.addDefault(Messages.FORMATTING_SIDEBAR_TAB_HEADER_RESTARTING, "&c{serverIp}"); - yml.addDefault(Messages.FORMATTING_SIDEBAR_TAB_HEADER_SPECTATOR,"&9{serverIp}"); + yml.addDefault(Messages.FORMATTING_SIDEBAR_TAB_HEADER_SPECTATOR, "&9{serverIp}"); - yml.addDefault(Messages.FORMATTING_SB_TAB_WAITING_FOOTER, "&a{serverIp}"); - yml.addDefault(Messages.FORMATTING_SIDEBAR_TAB_FOOTER_STARTING,"&6{serverIp}"); + yml.addDefault(Messages.FORMATTING_SIDEBAR_TAB_FOOTER_STARTING, "&6{serverIp}"); yml.addDefault(Messages.FORMATTING_SIDEBAR_TAB_FOOTER_PLAYING, "&d{serverIp}"); yml.addDefault(Messages.FORMATTING_SIDEBAR_TAB_FOOTER_RESTARTING, "&c{serverIp}"); - yml.addDefault(Messages.FORMATTING_SIDEBAR_TAB_FOOTER_SPECTATOR,"&9{serverIp}"); + yml.addDefault(Messages.FORMATTING_SIDEBAR_TAB_FOOTER_SPECTATOR, "&9{serverIp}"); yml.options().copyDefaults(true); yml.addDefault(Messages.COMMAND_MAIN, Arrays.asList("", "&2▪ &7/" + mainCmd + " stats", "&2▪ &7/" + mainCmd + " join &o", "&2▪ &7/" + mainCmd + " leave", "&2▪ &7/" + mainCmd + " lang", "&2▪ &7/" + mainCmd + " gui", "&2▪ &7/" + mainCmd + " start &3(vip)")); @@ -123,7 +124,7 @@ public Romanian() { yml.addDefault(Messages.COMMAND_PARTY_PROMOTE_OWNER, "{prefix}&eAi fost promovat ca proprietar al petrecerii"); yml.addDefault(Messages.COMMAND_PARTY_PROMOTE_NEW_OWNER, "{prefix}&7 &e{player} a fost promovat ca proprietar"); yml.addDefault(Messages.COMMAND_PARTY_INFO_OWNER, "\n{prefix}&eProprietarul petrecerii este: &7{owner}"); - yml.addDefault(Messages.COMMAND_PARTY_INFO_PLAYERS,"{prefix}&eMembrii sunt:"); + yml.addDefault(Messages.COMMAND_PARTY_INFO_PLAYERS, "{prefix}&eMembrii sunt:"); yml.addDefault(Messages.COMMAND_PARTY_INFO_PLAYER, "&7{player}"); yml.addDefault(Messages.COMMAND_NOT_FOUND_OR_INSUFF_PERMS, "{prefix}&cComanda nu a fost gasita sau nu ai permisiunea!"); yml.addDefault(Messages.COMMAND_FORCESTART_NOT_IN_GAME, "§c▪ §7Nu esti in joc!"); @@ -338,7 +339,7 @@ public Romanian() { addDefaultStatsMsg(yml, "games-played", "&6Partide Jucate", "&f{gamesPlayed}"); - yml.addDefault(Messages.SCOREBOARD_DEFAULT_WAITING, Arrays.asList("&f&lBED WARS", "&7{date} &8{server}", "", "&fHarta: &a{map}", "", "&fJucatori: &a{on}/{max}", "", "&fIn asteptare...", "", "§fMod: &a{group}", "&fVersiune: &7{version}", "", "&e{serverIp}")); + yml.addDefault(Messages.SCOREBOARD_DEFAULT_WAITING, Arrays.asList("&f&lBED WARS", "&7{date} &8{server}", "", "&fHarta: &a{map}", "", "&fJucatori: &a{on}/{max}", "", "&fIn asteptare,&fIn asteptare.,&fIn asteptare..,&fIn asteptare...", "", "§fMod: &a{group}", "&fVersiune: &7{version}", "", "&e{serverIp}")); yml.addDefault(Messages.SCOREBOARD_DEFAULT_STARTING, Arrays.asList("&f&lBED WARS", "&7{date} &8{server}", "", "&fMap: &a{map}", "", "&fJucatori: &a{on}/{max}", "", "&fIncepe in &a{time}s", "", "§fMod: &a{group}", "&fVersiune: &7{version}", "", "&e{serverIp}")); yml.addDefault(Messages.SCOREBOARD_DEFAULT_PLAYING, Arrays.asList("&e&lBED WARS", "&7{date}", "", "&f{nextEvent} in &a{time}", "", "{team}", "{team}", "{team}", "{team}", "{team}", "{team}", "{team}", "{team}", "", "&e{serverIp}")); diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/BwSidebar.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/BwSidebar.java index d9114d881..d4c85410b 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/BwSidebar.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/BwSidebar.java @@ -44,6 +44,7 @@ public class BwSidebar implements ISidebar { private final Player player; private IArena arena; private Sidebar handle; + private TabHeaderFooter headerFooter; private final SimpleDateFormat dateFormat; private final SimpleDateFormat nextEventDateFormat; private final HashMap tabList = new HashMap<>(); @@ -88,7 +89,7 @@ public void setContent(List titleArray, List lineArray, @Nullabl }, 2L); } handlePlayerList(); - setHeaderFooter(); + assignTabHeaderFooter(); } public Player getPlayer() { @@ -97,18 +98,18 @@ public Player getPlayer() { @SuppressWarnings("ConstantConditions") public SidebarLine normalizeTitle(@Nullable List titleArray) { - String[] aolo = new String[titleArray.size()]; + String[] data = new String[titleArray.size()]; for (int x = 0; x < titleArray.size(); x++) { - aolo[x] = titleArray.get(x); + data[x] = titleArray.get(x); } return null == titleArray || titleArray.isEmpty() ? EMPTY_TITLE : - new SidebarLineAnimated(aolo); + new SidebarLineAnimated(data); } @Contract(pure = true) - public @NotNull List normalizeLines(@NotNull List lineArray) { - List lines = new ArrayList<>(); + public @NotNull LinkedList normalizeLines(@NotNull List lineArray) { + LinkedList lines = new LinkedList<>(); int teamCount = 0; Language language = Language.getPlayerLanguage(player); @@ -155,28 +156,40 @@ public SidebarLine normalizeTitle(@Nullable List titleArray) { .replace("{serverIp}", BedWars.config.getString(ConfigPath.GENERAL_CONFIG_PLACEHOLDERS_REPLACEMENTS_SERVER_IP)) .replace("{version}", plugin.getDescription().getVersion()) .replace("{server}", config.getString(ConfigPath.GENERAL_CONFIGURATION_BUNGEE_OPTION_SERVER_ID)) - .replace("{playername}", player.getName()) - .replace("{player}", player.getDisplayName()) - .replace("{money}", String.valueOf(getEconomy().getMoney(player))); +// .replace("{playername}", player.getName()) +// .replace("{player}", player.getDisplayName()) +// .replace("{money}", String.valueOf(getEconomy().getMoney(player))) + ; // Add the line to the sidebar String finalTemp = line; - lines.add(new SidebarLine() { - @Override - public @NotNull String getLine() { - return finalTemp; - } - }); + String[] divided = finalTemp.split(","); + + SidebarLine sidebarLine; + + if (divided.length > 1) { + sidebarLine = normalizeTitle(Arrays.asList(divided)); + } else { + sidebarLine = new SidebarLine() { + @Override + public @NotNull String getLine() { + return finalTemp; + } + }; + } + + lines.add(sidebarLine); } return lines; } @Contract(pure = true) - private @NotNull List getPlaceholders() { - List providers = new ArrayList<>(); + private @NotNull LinkedList getPlaceholders() { + LinkedList providers = new LinkedList<>(); providers.add(new PlaceholderProvider("{player}", player::getDisplayName)); + providers.add(new PlaceholderProvider("{money}", () -> String.valueOf(getEconomy().getMoney(player)))); providers.add(new PlaceholderProvider("{playerName}", player::getCustomName)); providers.add(new PlaceholderProvider("{money}", () -> String.valueOf(getEconomy().getMoney(player)))); providers.add(new PlaceholderProvider("{date}", () -> dateFormat.format(new Date(System.currentTimeMillis())))); @@ -520,64 +533,65 @@ public void giveUpdateTabFormat(@NotNull Player player, boolean skipStateCheck) } // Provide header and footer for current game state - private void setHeaderFooter() { -// if (isTabFormattingDisabled()) { -// return; -// } + private void assignTabHeaderFooter() { + if (!config.getBoolean(ConfigPath.SB_CONFIG_TAB_HEADER_FOOTER_ENABLE)) { + return; + } + Language lang = Language.getPlayerLanguage(player); + String headerPath = null; + String footerPath = null; + if (noArena()) { - SidebarManager.getInstance().sendHeaderFooter( - player, lang.m(Messages.FORMATTING_SB_TAB_LOBBY_HEADER), - lang.m(Messages.FORMATTING_SB_TAB_LOBBY_FOOTER) - ); -// SidebarManager.getInstance().sendHeaderFooter( -// player, lang.l(Messages.FORMATTING_SB_TAB_LOBBY_HEADER), -// lang.l(Messages.FORMATTING_SB_TAB_LOBBY_FOOTER) -// ); - return; - } - if (arena.isSpectator(player)) { - SidebarManager.getInstance().sendHeaderFooter( - player, lang.m(Messages.FORMATTING_SIDEBAR_TAB_HEADER_SPECTATOR), - lang.m(Messages.FORMATTING_SIDEBAR_TAB_FOOTER_SPECTATOR) - ); + if (getServerType() == ServerType.SHARED) { + this.headerFooter = null; + return; + } + headerPath = Messages.FORMATTING_SB_TAB_LOBBY_HEADER; + footerPath = Messages.FORMATTING_SB_TAB_LOBBY_FOOTER; + } else { + if (arena.isSpectator(player)) { + SidebarManager.getInstance().sendHeaderFooter( + player, lang.m(Messages.FORMATTING_SIDEBAR_TAB_HEADER_SPECTATOR), + lang.m(Messages.FORMATTING_SIDEBAR_TAB_FOOTER_SPECTATOR) + ); // SidebarManager.getInstance().sendHeaderFooter( // player, lang.l(Messages.FORMATTING_SIDEBAR_TAB_HEADER_SPECTATOR), // lang.l(Messages.FORMATTING_SIDEBAR_TAB_FOOTER_SPECTATOR) // ); - return; - } - - - String headerPath = null; - String footerPath = null; + return; + } - switch (arena.getStatus()) { - case waiting: - headerPath = Messages.FORMATTING_SB_TAB_WAITING_HEADER; - footerPath = Messages.FORMATTING_SB_TAB_WAITING_FOOTER; - break; - case starting: - headerPath = Messages.FORMATTING_SIDEBAR_TAB_HEADER_STARTING; - footerPath = Messages.FORMATTING_SIDEBAR_TAB_FOOTER_STARTING; - break; - case playing: - headerPath = Messages.FORMATTING_SIDEBAR_TAB_HEADER_PLAYING; - footerPath = Messages.FORMATTING_SIDEBAR_TAB_FOOTER_PLAYING; - break; - case restarting: - headerPath = Messages.FORMATTING_SIDEBAR_TAB_HEADER_RESTARTING; - footerPath = Messages.FORMATTING_SIDEBAR_TAB_FOOTER_RESTARTING; - break; - default: - throw new IllegalStateException("Unhandled arena status"); + switch (arena.getStatus()) { + case waiting: + headerPath = Messages.FORMATTING_SB_TAB_WAITING_HEADER; + footerPath = Messages.FORMATTING_SB_TAB_WAITING_FOOTER; + break; + case starting: + headerPath = Messages.FORMATTING_SIDEBAR_TAB_HEADER_STARTING; + footerPath = Messages.FORMATTING_SIDEBAR_TAB_FOOTER_STARTING; + break; + case playing: + headerPath = Messages.FORMATTING_SIDEBAR_TAB_HEADER_PLAYING; + footerPath = Messages.FORMATTING_SIDEBAR_TAB_FOOTER_PLAYING; + break; + case restarting: + headerPath = Messages.FORMATTING_SIDEBAR_TAB_HEADER_RESTARTING; + footerPath = Messages.FORMATTING_SIDEBAR_TAB_FOOTER_RESTARTING; + break; + default: + throw new IllegalStateException("Unhandled arena status"); + } } - SidebarManager.getInstance().sendHeaderFooter( - player, lang.m(headerPath), - lang.m(footerPath) + this.headerFooter = new TabHeaderFooter( + this.normalizeLines(lang.l(headerPath)), + this.normalizeLines(lang.l(footerPath)), + getPlaceholders() ); + + SidebarManager.getInstance().sendHeaderFooter(player, headerFooter); } private @NotNull String getTabName(@NotNull ITeam team) { @@ -744,4 +758,13 @@ public Sidebar getHandle() { public IArena getArena() { return arena; } + + @Nullable + public TabHeaderFooter getHeaderFooter() { + return headerFooter; + } + + public void setHeaderFooter(@Nullable TabHeaderFooter headerFooter) { + this.headerFooter = headerFooter; + } } diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/SidebarService.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/SidebarService.java index 204d33ab6..50f5f7fd7 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/SidebarService.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/SidebarService.java @@ -165,6 +165,14 @@ public void refreshTabList() { this.sidebars.forEach((k, v) -> v.getHandle().playerTabRefreshAnimation()); } + public void refreshTabHeaderFooter() { + this.sidebars.forEach((k, v) -> { + if (null != v && null != v.getHeaderFooter()) { + this.sidebarHandler.sendHeaderFooter(v.getPlayer(), v.getHeaderFooter()); + } + }); + } + public void refreshHealth() { this.sidebars.forEach((k, v) -> { if (null != v.getArena()) { diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/thread/RefreshTabListTask.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/thread/RefreshPlayerListTask.java similarity index 94% rename from bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/thread/RefreshTabListTask.java rename to bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/thread/RefreshPlayerListTask.java index cbd61ac76..64d257f0e 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/thread/RefreshTabListTask.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/thread/RefreshPlayerListTask.java @@ -22,7 +22,7 @@ import com.andrei1058.bedwars.sidebar.SidebarService; -public class RefreshTabListTask implements Runnable { +public class RefreshPlayerListTask implements Runnable { @Override public void run() { SidebarService.getInstance().refreshTabList(); diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/thread/RefreshTabHeaderFooterTask.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/thread/RefreshTabHeaderFooterTask.java new file mode 100644 index 000000000..c198e33b2 --- /dev/null +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/sidebar/thread/RefreshTabHeaderFooterTask.java @@ -0,0 +1,33 @@ +/* + * BedWars1058 - A bed wars mini-game. + * Copyright (C) 2023 Andrei Dascălu + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Contact e-mail: andrew.dascalu@gmail.com + */ + +package com.andrei1058.bedwars.sidebar.thread; + +import com.andrei1058.bedwars.sidebar.SidebarService; + +/** + * Refresh TAB header and footer. + */ +public class RefreshTabHeaderFooterTask implements Runnable { + @Override + public void run() { + SidebarService.getInstance().refreshTabHeaderFooter(); + } +} diff --git a/bedwars-plugin/src/main/resources/plugin.yml b/bedwars-plugin/src/main/resources/plugin.yml index 1818b4e3c..407b439c2 100644 --- a/bedwars-plugin/src/main/resources/plugin.yml +++ b/bedwars-plugin/src/main/resources/plugin.yml @@ -5,4 +5,4 @@ author: andrei1058 description: BedWars minigame by andrei1058 main: com.andrei1058.bedwars.BedWars softdepend: [Vault,PlaceholderAPI,Citizens,Parties,SlimeWorldManager,VipFeatures,Enhanced-SlimeWorldManager,PartyAndFriends,Spigot-Party-API-PAF] -load: STARTUP +#load: STARTUP diff --git a/versionsupport_1_8_R3/src/main/java/com/andrei1058/bedwars/support/version/v1_8_R3/v1_8_R3.java b/versionsupport_1_8_R3/src/main/java/com/andrei1058/bedwars/support/version/v1_8_R3/v1_8_R3.java index 05f16c983..7a3335db6 100644 --- a/versionsupport_1_8_R3/src/main/java/com/andrei1058/bedwars/support/version/v1_8_R3/v1_8_R3.java +++ b/versionsupport_1_8_R3/src/main/java/com/andrei1058/bedwars/support/version/v1_8_R3/v1_8_R3.java @@ -49,7 +49,6 @@ import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.plugin.Plugin; import org.bukkit.potion.PotionEffectType; -import org.bukkit.scoreboard.Team; import org.bukkit.util.Vector; import java.lang.reflect.Field;