Skip to content

Commit

Permalink
fixed logic error and unify things
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperdefined committed Jan 11, 2024
1 parent 5d078a3 commit 588b110
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
22 changes: 15 additions & 7 deletions src/main/java/lol/hyper/timebar/TimeBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions src/main/java/lol/hyper/timebar/events/PlayerJoinLeave.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "]");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 588b110

Please sign in to comment.