From b8eaaa61b21473cd0ffc3bfcaaf6545b6ce7f694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Dasc=C4=83lu?= Date: Tue, 21 Nov 2023 21:01:06 +0100 Subject: [PATCH 1/2] add new metrics, clean up (#910) --- .../bedwars/api/language/Language.java | 2 +- .../java/com/andrei1058/bedwars/BedWars.java | 127 ++++-------------- .../arena/feature/SpoilPlayerTNTFeature.java | 16 ++- .../bedwars/halloween/HalloweenSpecial.java | 12 +- .../bedwars/metrics/MetricsManager.java | 49 +++++++ .../bedwars/sidebar/SidebarService.java | 80 ++++++++++- 6 files changed, 174 insertions(+), 112 deletions(-) create mode 100644 bedwars-plugin/src/main/java/com/andrei1058/bedwars/metrics/MetricsManager.java diff --git a/bedwars-api/src/main/java/com/andrei1058/bedwars/api/language/Language.java b/bedwars-api/src/main/java/com/andrei1058/bedwars/api/language/Language.java index 46d7ed201..19ed52c1b 100644 --- a/bedwars-api/src/main/java/com/andrei1058/bedwars/api/language/Language.java +++ b/bedwars-api/src/main/java/com/andrei1058/bedwars/api/language/Language.java @@ -289,7 +289,7 @@ public static void setupCustomStatsMessages() { if (l == null) continue; if (l.getYml() == null) continue; /* save messages for stats gui items if custom items added */ - if (api.getConfigs().getMainConfig().getYml().get("ConfigPath.GENERAL_CONFIGURATION_STATS_PATH") == null) + if (api.getConfigs().getMainConfig().getYml().get(ConfigPath.GENERAL_CONFIGURATION_STATS_PATH) == null) return; for (String item : api.getConfigs().getMainConfig().getYml().getConfigurationSection(ConfigPath.GENERAL_CONFIGURATION_STATS_PATH).getKeys(false)) { if (ConfigPath.GENERAL_CONFIGURATION_STATS_GUI_SIZE.contains(item)) continue; 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 6f351c6b1..b2cc5d97d 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java @@ -62,10 +62,10 @@ import com.andrei1058.bedwars.lobbysocket.LoadedUsersCleaner; import com.andrei1058.bedwars.lobbysocket.SendTask; import com.andrei1058.bedwars.maprestore.internal.InternalAdapter; +import com.andrei1058.bedwars.metrics.MetricsManager; import com.andrei1058.bedwars.money.internal.MoneyListeners; import com.andrei1058.bedwars.shop.ShopManager; import com.andrei1058.bedwars.sidebar.*; -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; @@ -81,8 +81,6 @@ import com.andrei1058.bedwars.support.vipfeatures.VipListeners; import com.andrei1058.vipfeatures.api.IVipFeatures; import com.andrei1058.vipfeatures.api.MiniGameAlreadyRegistered; -import org.bstats.bukkit.Metrics; -import org.bstats.charts.SimplePie; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -105,7 +103,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.*; -@SuppressWarnings("WeakerAccess") +@SuppressWarnings({"WeakerAccess", "CallToPrintStackTrace"}) public class BedWars extends JavaPlugin { private static ServerType serverType = ServerType.MULTIARENA; @@ -238,9 +236,12 @@ public void onEnable() { /* Setup plugin messaging channel */ Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); + // define logger + var out = plugin.getLogger(); + /* Check if lobby location is set. Required for non Bungee servers */ if (config.getLobbyWorldName().isEmpty() && serverType != ServerType.BUNGEE) { - plugin.getLogger().log(java.util.logging.Level.WARNING, "Lobby location is not set!"); + out.log(java.util.logging.Level.WARNING, "Lobby location is not set!"); } /* Load lobby world if not main level @@ -323,19 +324,19 @@ public void onEnable() { if (config.getYml().getBoolean(ConfigPath.GENERAL_CONFIGURATION_ALLOW_PARTIES)) { if (getServer().getPluginManager().isPluginEnabled("Parties")) { - getLogger().info("Hook into Parties (by AlessioDP) support!"); + out.info("Hook into Parties (by AlessioDP) support!"); party = new PartiesAdapter(); } else if (Bukkit.getServer().getPluginManager().isPluginEnabled("PartyAndFriends")) { - getLogger().info("Hook into Party and Friends for Spigot (by Simonsator) support!"); + out.info("Hook into Party and Friends for Spigot (by Simonsator) support!"); party = new PAF(); } else if (Bukkit.getServer().getPluginManager().isPluginEnabled("Spigot-Party-API-PAF")) { - getLogger().info("Hook into Spigot Party API for Party and Friends Extended (by Simonsator) support!"); + out.info("Hook into Spigot Party API for Party and Friends Extended (by Simonsator) support!"); party = new PAFBungeecordRedisApi(); } if (party instanceof NoParty) { party = new com.andrei1058.bedwars.support.party.Internal(); - getLogger().info("Loading internal Party system. /party"); + out.info("Loading internal Party system. /party"); } } else { party = new NoParty(); @@ -381,7 +382,7 @@ public void onEnable() { Bukkit.getScheduler().runTaskLater(plugin, () -> { if (this.getServer().getPluginManager().getPlugin("Citizens") != null) { JoinNPC.setCitizensSupport(true); - getLogger().info("Hook into Citizens support. /bw npc"); + out.info("Hook into Citizens support. /bw npc"); registerEvents(new CitizensListener()); } @@ -392,20 +393,14 @@ public void onEnable() { this.getLogger().severe("Could not spawn CmdJoin NPCs. Make sure you have right version of Citizens for your server!"); JoinNPC.setCitizensSupport(false); } - /*if (getServerType() == ServerType.BUNGEE) { - if (Arena.getArenas().size() > 0) { - ArenaSocket.sendMessage(Arena.getArenas().get(0)); - } - }*/ }, 5L); /* Save messages for stats gui items if custom items added, for each language */ Language.setupCustomStatsMessages(); - /* PlaceholderAPI Support */ if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { - getLogger().info("Hooked into PlaceholderAPI support!"); + out.info("Hooked into PlaceholderAPI support!"); new PAPISupport().register(); SupportPAPI.setSupportPAPI(new SupportPAPI.withPAPI()); } @@ -484,120 +479,54 @@ public void onEnable() { MoneyConfig.init(); // bStats metrics - Metrics metrics = new Metrics(this, 1885); - metrics.addCustomChart(new SimplePie("server_type", () -> getServerType().toString())); - metrics.addCustomChart(new SimplePie("default_language", () -> Language.getDefaultLanguage().getIso())); - metrics.addCustomChart(new SimplePie("auto_scale", () -> String.valueOf(autoscale))); - metrics.addCustomChart(new SimplePie("party_adapter", () -> party.getClass().getName())); - metrics.addCustomChart(new SimplePie("chat_adapter", () -> chat.getClass().getName())); - metrics.addCustomChart(new SimplePie("level_adapter", () -> getLevelSupport().getClass().getName())); - metrics.addCustomChart(new SimplePie("db_adapter", () -> getRemoteDatabase().getClass().getName())); - metrics.addCustomChart(new SimplePie("map_adapter", () -> String.valueOf(getAPI().getRestoreAdapter().getOwner().getName()))); + MetricsManager.initService(this); if (Bukkit.getPluginManager().getPlugin("VipFeatures") != null) { try { IVipFeatures vf = Bukkit.getServicesManager().getRegistration(IVipFeatures.class).getProvider(); vf.registerMiniGame(new VipFeatures(this)); registerEvents(new VipListeners(vf)); - getLogger().log(java.util.logging.Level.INFO, "Hook into VipFeatures support."); + out.log(java.util.logging.Level.INFO, "Hook into VipFeatures support."); } catch (Exception e) { - getLogger().warning("Could not load support for VipFeatures."); + out.warning("Could not load support for VipFeatures."); } catch (MiniGameAlreadyRegistered miniGameAlreadyRegistered) { miniGameAlreadyRegistered.printStackTrace(); } } - Bukkit.getScheduler().runTaskLater(this, () -> getLogger().info("This server is running in " + getServerType().toString() + " with auto-scale " + autoscale), 100L); + Bukkit.getScheduler().runTaskLater(this, + () -> out.info("This server is running in " + getServerType() + " with auto-scale " + autoscale), + 100L + ); // Initialize team upgrades com.andrei1058.bedwars.upgrades.UpgradesManager.init(); // Initialize sidebar manager - if (SidebarService.init()) { - this.getLogger().info("Initializing SidebarLib by andrei1058"); + if (SidebarService.init(this)) { + out.info("Initializing SidebarLib by andrei1058"); } else { this.getLogger().severe("SidebarLib by andrei1058 does not support your server version"); Bukkit.getPluginManager().disablePlugin(this); return; } - int playerListRefreshInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_LIST_REFRESH); - if (playerListRefreshInterval < 1) { - 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 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. (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(), 1L, placeholdersRefreshInterval); - } - - int titleRefreshInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_TITLE_REFRESH_INTERVAL); - if (titleRefreshInterval < 1) { - 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(), 1L, titleRefreshInterval); - } - - int healthAnimationInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_HEALTH_REFRESH); - if (healthAnimationInterval < 1) { - 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(), 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()); - - if (config.getBoolean(ConfigPath.GENERAL_CONFIGURATION_ENABLE_HALLOWEEN)) { - // Halloween Special - HalloweenSpecial.init(); - } + // Halloween Special + HalloweenSpecial.init(); + // TNT Spoil Feature SpoilPlayerTNTFeature.init(); } /** * Try loading custom adapter support. + * * @return true when custom adapter was registered. */ private boolean handleWorldAdapter() { Plugin swmPlugin = Bukkit.getPluginManager().getPlugin("SlimeWorldManager"); - if (null == swmPlugin){ + if (null == swmPlugin) { return false; } PluginDescriptionFile pluginDescription = swmPlugin.getDescription(); @@ -625,11 +554,11 @@ private boolean handleWorldAdapter() { } Constructor constructor = Class.forName(adapterPath).getConstructor(Plugin.class); - getLogger().info("Loading restore adapter: "+adapterPath+" ..."); + getLogger().info("Loading restore adapter: " + adapterPath + " ..."); RestoreAdapter candidate = (RestoreAdapter) constructor.newInstance(this); api.setRestoreAdapter(candidate); - getLogger().info("Hook into "+candidate.getDisplayName()+" as restore adapter."); + getLogger().info("Hook into " + candidate.getDisplayName() + " as restore adapter."); return true; } catch (Exception e) { e.printStackTrace(); diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/arena/feature/SpoilPlayerTNTFeature.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/arena/feature/SpoilPlayerTNTFeature.java index 7bce58bdd..6aa28c961 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/arena/feature/SpoilPlayerTNTFeature.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/arena/feature/SpoilPlayerTNTFeature.java @@ -26,6 +26,7 @@ import com.andrei1058.bedwars.api.events.player.PlayerKillEvent; import com.andrei1058.bedwars.api.events.player.PlayerLeaveArenaEvent; import com.andrei1058.bedwars.arena.Arena; +import com.andrei1058.bedwars.metrics.MetricsManager; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -51,11 +52,13 @@ private SpoilPlayerTNTFeature() { } public static void init() { - if (BedWars.config.getBoolean(ConfigPath.GENERAL_CONFIGURATION_PERFORMANCE_SPOIL_TNT_PLAYERS)) { + var enable = BedWars.config.getBoolean(ConfigPath.GENERAL_CONFIGURATION_PERFORMANCE_SPOIL_TNT_PLAYERS); + if (enable) { if (instance == null) { instance = new SpoilPlayerTNTFeature(); } } + MetricsManager.appendPie("tnt_spoil_enable", () -> String.valueOf(enable)); } private static class ParticleTask implements Runnable { @@ -109,12 +112,11 @@ public void onPlace(BlockPlaceEvent event) { if (arena == null || !arena.isPlayer(event.getPlayer()) || arena.isSpectator(event.getPlayer())) return; if (inHand.getType() == Material.TNT) { if (!instance.playersWithTnt.contains(event.getPlayer())) return; - Bukkit.getScheduler().runTaskLater(BedWars.plugin, - () -> { - if (!event.getPlayer().getInventory().contains(Material.TNT)) { - instance.playersWithTnt.remove(event.getPlayer()); - } - }, 1L); + Bukkit.getScheduler().runTaskLater(BedWars.plugin, () -> { + if (!event.getPlayer().getInventory().contains(Material.TNT)) { + instance.playersWithTnt.remove(event.getPlayer()); + } + }, 1L); } } diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/halloween/HalloweenSpecial.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/halloween/HalloweenSpecial.java index c6d8c4fdf..b8674985c 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/halloween/HalloweenSpecial.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/halloween/HalloweenSpecial.java @@ -21,7 +21,9 @@ package com.andrei1058.bedwars.halloween; import com.andrei1058.bedwars.BedWars; +import com.andrei1058.bedwars.api.configuration.ConfigPath; import com.andrei1058.bedwars.halloween.shop.PumpkinContent; +import com.andrei1058.bedwars.metrics.MetricsManager; import com.andrei1058.bedwars.shop.ShopManager; import com.andrei1058.bedwars.shop.main.ShopCategory; import org.bukkit.Bukkit; @@ -54,10 +56,14 @@ private HalloweenSpecial() { * Initialize Halloween Special. */ public static void init() { - if (INSTANCE == null) { - if (!checkAvailabilityDate()) return; - INSTANCE = new HalloweenSpecial(); + var enable = BedWars.config.getBoolean(ConfigPath.GENERAL_CONFIGURATION_ENABLE_HALLOWEEN); + if (enable) { + if (INSTANCE == null && checkAvailabilityDate()) { + //noinspection InstantiationOfUtilityClass + INSTANCE = new HalloweenSpecial(); + } } + MetricsManager.appendPie("halloween_special_enable", () -> String.valueOf(enable)); } protected static boolean checkAvailabilityDate() { diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/metrics/MetricsManager.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/metrics/MetricsManager.java new file mode 100644 index 000000000..782960761 --- /dev/null +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/metrics/MetricsManager.java @@ -0,0 +1,49 @@ +package com.andrei1058.bedwars.metrics; + +import com.andrei1058.bedwars.BedWars; +import com.andrei1058.bedwars.api.language.Language; +import com.andrei1058.bedwars.support.citizens.JoinNPC; +import org.bstats.bukkit.Metrics; +import org.bstats.charts.SimplePie; + +import java.util.concurrent.Callable; + +public class MetricsManager { + + private static MetricsManager instance; + + private final Metrics metrics; + + private MetricsManager(BedWars plugin) { + metrics = new Metrics(plugin, 97320); + + // base metrics + metrics.addCustomChart(new SimplePie("server_type", () -> BedWars.getServerType().toString())); + metrics.addCustomChart(new SimplePie("default_language", () -> Language.getDefaultLanguage().getIso())); + metrics.addCustomChart(new SimplePie("auto_scale", () -> String.valueOf(BedWars.autoscale))); + metrics.addCustomChart(new SimplePie("party_adapter", () -> BedWars.getParty().getClass().getName())); + metrics.addCustomChart(new SimplePie("chat_adapter", () -> BedWars.getChatSupport().getClass().getName())); + metrics.addCustomChart(new SimplePie("level_adapter", () -> BedWars.getLevelSupport().getClass().getName())); + metrics.addCustomChart(new SimplePie("db_adapter", () -> BedWars.getRemoteDatabase().getClass().getName())); + metrics.addCustomChart(new SimplePie("map_adapter", () -> BedWars.getAPI().getRestoreAdapter().getClass().getName())); + metrics.addCustomChart(new SimplePie("citizens_support", () -> String.valueOf(JoinNPC.isCitizensSupport()))); + } + + public Metrics getMetrics() { + return metrics; + } + + public static void appendPie(String id, Callable callable) { + if (null == instance) { + throw new RuntimeException("Metrics manager is not initialized!"); + } + instance.getMetrics().addCustomChart(new SimplePie(id, callable)); + } + + public static void initService(BedWars plugin) { + if (null != instance) { + return; + } + instance = new MetricsManager(plugin); + } +} 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 a1dbeda84..d328776a8 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 @@ -11,9 +11,12 @@ import com.andrei1058.bedwars.api.server.ServerType; import com.andrei1058.bedwars.api.sidebar.ISidebar; import com.andrei1058.bedwars.api.sidebar.ISidebarService; +import com.andrei1058.bedwars.metrics.MetricsManager; +import com.andrei1058.bedwars.sidebar.thread.*; import com.andrei1058.spigot.sidebar.SidebarManager; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -29,10 +32,83 @@ public class SidebarService implements ISidebarService { private final SidebarManager sidebarHandler; private final HashMap sidebars = new HashMap<>(); - - public static boolean init() { + public static boolean init(JavaPlugin plugin) { if (null == instance) { instance = new SidebarService(); + + var log = Bukkit.getLogger(); + + int playerListRefreshInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_LIST_REFRESH); + if (playerListRefreshInterval < 1) { + Bukkit.getLogger().info("Scoreboard names list refresh is disabled. (It is set to " + playerListRefreshInterval + ")."); + } else { + if (playerListRefreshInterval < 20) { + log.warning("Scoreboard names list refresh interval is set to: " + playerListRefreshInterval); + log.warning("It is not recommended to use a value under 20 ticks."); + log.warning("If you expect performance issues please increase its timer."); + } + Bukkit.getScheduler().runTaskTimer(plugin, new RefreshPlayerListTask(), 1L, playerListRefreshInterval); + } + MetricsManager.appendPie("sb_list_refresh_interval", () -> String.valueOf(playerListRefreshInterval)); + + int placeholdersRefreshInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_PLACEHOLDERS_REFRESH_INTERVAL); + if (placeholdersRefreshInterval < 1) { + log.info("Scoreboard placeholders refresh is disabled. (It is set to " + placeholdersRefreshInterval + ")."); + } else { + if (placeholdersRefreshInterval < 20) { + log.warning("Scoreboard placeholders refresh interval is set to: " + placeholdersRefreshInterval); + log.warning("It is not recommended to use a value under 20 ticks."); + log.warning("If you expect performance issues please increase its timer."); + } + Bukkit.getScheduler().runTaskTimer(plugin, new RefreshPlaceholdersTask(), 1L, placeholdersRefreshInterval); + } + MetricsManager.appendPie("sb_placeholder_refresh_interval", () -> String.valueOf(playerListRefreshInterval)); + + int titleRefreshInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_TITLE_REFRESH_INTERVAL); + if (titleRefreshInterval < 1) { + log.info("Scoreboard title refresh is disabled. (It is set to " + titleRefreshInterval + ")."); + } else { + if (titleRefreshInterval < 4) { + log.warning("Scoreboard title refresh interval is set to: " + titleRefreshInterval); + log.warning("If you expect performance issues please increase its timer."); + } + Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, new RefreshTitleTask(), 1L, titleRefreshInterval); + } + MetricsManager.appendPie("sb_title_refresh_interval", () -> String.valueOf(titleRefreshInterval)); + + int healthAnimationInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_HEALTH_REFRESH); + if (healthAnimationInterval < 1) { + log.info("Scoreboard health animation refresh is disabled. (It is set to " + healthAnimationInterval + ")."); + } else { + if (healthAnimationInterval < 20) { + log.warning("Scoreboard health animation refresh interval is set to: " + healthAnimationInterval); + log.warning("It is not recommended to use a value under 20 ticks."); + log.warning("If you expect performance issues please increase its timer."); + } + Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new RefreshLifeTask(), 1L, healthAnimationInterval); + } + MetricsManager.appendPie("sb_health_refresh_interval", () -> String.valueOf(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)) { + log.info("Scoreboard Tab header-footer refresh is disabled."); + } else { + if (tabHeaderFooterRefreshInterval < 20) { + log.warning("Scoreboard tab header-footer refresh interval is set to: " + tabHeaderFooterRefreshInterval); + log.warning("It is not recommended to use a value under 20 ticks."); + log.warning("If you expect performance issues please increase its timer."); + } + Bukkit.getScheduler().runTaskTimer(plugin, new RefreshTabHeaderFooterTask(), 1L, tabHeaderFooterRefreshInterval); + } + MetricsManager.appendPie("sb_header_footer_refresh_interval", () -> String.valueOf(tabHeaderFooterRefreshInterval)); + + var lobbySidebar = config.getBoolean(ConfigPath.SB_CONFIG_SIDEBAR_USE_LOBBY_SIDEBAR) && + BedWars.getServerType() == ServerType.MULTIARENA; + MetricsManager.appendPie("sb_lobby_enable", () -> String.valueOf(lobbySidebar)); + var gameSidebar = config.getBoolean(ConfigPath.SB_CONFIG_SIDEBAR_USE_GAME_SIDEBAR); + MetricsManager.appendPie("sb_game_enable", () -> String.valueOf(gameSidebar)); + + BedWars.registerEvents(new ScoreboardListener()); } return instance.sidebarHandler != null; } From e9b3c21455c5567695760fdc9cad3a1d256c5a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Dasc=C4=83lu?= Date: Tue, 21 Nov 2023 21:04:55 +0100 Subject: [PATCH 2/2] slime format conversion improvement (#908) (#911) * fix #906, slime world conversion improvement * downgrade java version to 17 for 1.20 and 1.19