From 588b1106ffa7872e8bb823e89adc0e081e638a9a Mon Sep 17 00:00:00 2001 From: hyperdefined Date: Thu, 11 Jan 2024 12:57:09 -0500 Subject: [PATCH] fixed logic error and unify things --- src/main/java/lol/hyper/timebar/TimeBar.java | 22 +++++++++++++------ .../hyper/timebar/events/PlayerJoinLeave.java | 6 ++--- .../timebar/tracker/WorldTimeTracker.java | 2 +- src/main/resources/plugin.yml | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/lol/hyper/timebar/TimeBar.java b/src/main/java/lol/hyper/timebar/TimeBar.java index 448def9..d35015f 100644 --- a/src/main/java/lol/hyper/timebar/TimeBar.java +++ b/src/main/java/lol/hyper/timebar/TimeBar.java @@ -58,21 +58,26 @@ public final class TimeBar extends JavaPlugin { public CommandTimeBar commandReload; public boolean papiSupport = false; + public boolean realisticSeasons = false; public BossBar.Color bossBarColor; @Override public void onEnable() { adventure = BukkitAudiences.create(this); - loadConfig(); - playerJoinLeave = new PlayerJoinLeave(this); - worldChange = new WorldChange(this); - commandReload = new CommandTimeBar(this); - if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { papiSupport = true; logger.info("PlaceholderAPI is detected! Enabling support."); } + if (Bukkit.getPluginManager().getPlugin("RealisticSeasons") != null) { + realisticSeasons = true; + logger.info("RealisticSeasons is detected! Enabling support."); + } + + loadConfig(); + playerJoinLeave = new PlayerJoinLeave(this); + worldChange = new WorldChange(this); + commandReload = new CommandTimeBar(this); this.getCommand("timebar").setExecutor(commandReload); @@ -144,8 +149,7 @@ public void loadConfig() { bossBarColor = BossBar.Color.valueOf(color); } - if (this.getServer().getPluginManager().isPluginEnabled("RealisticSeasons")) { - logger.info("RealisticSeasons is detected! Enabling support."); + if (realisticSeasons) { if (!realisticSeasonsConfigFile.exists()) { this.saveResource("realisticseasons.yml", true); } @@ -186,4 +190,8 @@ public BukkitAudiences getAdventure() { } return this.adventure; } + + public WorldTimeTracker getPlayerTracker(Player player) { + return worldTimeTrackers.stream().filter(worldTimeTracker -> worldTimeTracker.worldGroup().contains(player.getWorld())).findFirst().orElse(null); + } } diff --git a/src/main/java/lol/hyper/timebar/events/PlayerJoinLeave.java b/src/main/java/lol/hyper/timebar/events/PlayerJoinLeave.java index 320a4c5..fc5742a 100644 --- a/src/main/java/lol/hyper/timebar/events/PlayerJoinLeave.java +++ b/src/main/java/lol/hyper/timebar/events/PlayerJoinLeave.java @@ -39,10 +39,10 @@ public void onJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); // add player to tracker - WorldTimeTracker tracker = timeBar.worldTimeTrackers.stream().filter(worldTimeTracker -> worldTimeTracker.worldGroup().contains(player.getWorld())).findFirst().orElse(null); + WorldTimeTracker tracker = timeBar.getPlayerTracker(player); + timeBar.enabledBossBar.add(player); // if the world has a tracker, add them if (tracker != null) { - timeBar.enabledBossBar.add(player); tracker.addPlayer(player); } } @@ -52,7 +52,7 @@ public void onQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); // remove player from tracker since they left - WorldTimeTracker tracker = timeBar.worldTimeTrackers.stream().filter(worldTimeTracker -> worldTimeTracker.worldGroup().contains(player.getWorld())).findFirst().orElse(null); + WorldTimeTracker tracker = timeBar.getPlayerTracker(player); // if the world has a tracker, remove them if (tracker != null) { tracker.removePlayer(player); diff --git a/src/main/java/lol/hyper/timebar/tracker/WorldTimeTracker.java b/src/main/java/lol/hyper/timebar/tracker/WorldTimeTracker.java index 96d7ca8..fdb8152 100644 --- a/src/main/java/lol/hyper/timebar/tracker/WorldTimeTracker.java +++ b/src/main/java/lol/hyper/timebar/tracker/WorldTimeTracker.java @@ -107,7 +107,7 @@ public void startTimer() { } int updateFrequency = timeBar.config.getInt("bar-update-frequency"); String allWorldNames = worldGroup.stream().map(World::getName).collect(Collectors.joining(", ")); - if (Bukkit.getServer().getPluginManager().isPluginEnabled("RealisticSeasons")) { + if (timeBar.realisticSeasons) { timeBarTask = new RealisticSeasonsTask(this).runTaskTimer(timeBar, 0, updateFrequency); timeBar.logger.info("Starting time tracker for '" + mainWorld.getName() + "'" + " (RealisticSeasons support)"); timeBar.logger.info("Display worlds: [" + allWorldNames + "]"); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1f57f18..ef92154 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,7 +5,7 @@ api-version: 1.13 author: hyperdefined website: https://www.spigotmc.org/resources/timebar.90179/ description: See the world's time as a bossbar. -softdepend: [RealisticSeasons, PlaceholderAPI] +softdepend: [RealisticSeasons, PlaceholderAPI, Multiverse-Core] load: POSTWORLD commands: timebar: