From da05bc195741585681fc8e1dfd656b747c9ff806 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Mon, 6 Jan 2025 13:41:35 +0800 Subject: [PATCH] fix: fix build --- CHANGELOG.md | 2 +- .../api/scoreboard/ScoreboardService.java | 65 ++++++++----------- 2 files changed, 29 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0acc731ab..2f10b0957 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,7 +46,7 @@ Unless otherwise specified, any version comparison below is the comparison of se `BlockState`. - (API) `EntityBaseComponent#getBlockStateStandingOn` now return `BlockStateWithPos` instead of `BlockState`. - (API) Removed `BlockFace#horizontalIndex` which is useless. -- (API) Made `ScoreboardService#ServerEventListener` private as it is not supposed to be touched by plugin. +- (API) Removed `ScoreboardService#ServerEventListener` as it is not supposed to be touched by plugin. - Removed useless class `PackageClassLoaderUtils`, dependency `org.reflections.reflections` is also removed. - Added `-dev` suffix to api version in development build. diff --git a/api/src/main/java/org/allaymc/api/scoreboard/ScoreboardService.java b/api/src/main/java/org/allaymc/api/scoreboard/ScoreboardService.java index d5cc97e4f..17fbe574b 100644 --- a/api/src/main/java/org/allaymc/api/scoreboard/ScoreboardService.java +++ b/api/src/main/java/org/allaymc/api/scoreboard/ScoreboardService.java @@ -4,7 +4,6 @@ import com.google.common.collect.Sets; import lombok.Getter; import org.allaymc.api.entity.interfaces.EntityPlayer; -import org.allaymc.api.eventbus.EventHandler; import org.allaymc.api.eventbus.event.entity.EntityDespawnEvent; import org.allaymc.api.eventbus.event.player.PlayerJoinEvent; import org.allaymc.api.eventbus.event.player.PlayerQuitEvent; @@ -40,7 +39,34 @@ public final class ScoreboardService { public ScoreboardService(Server server, ScoreboardStorage storage) { this.storage = storage; - server.getEventBus().registerListener(new ServerEventListener()); + var eventBus = server.getEventBus(); + eventBus.registerListenerFor(EntityDespawnEvent.class, event -> { + var entity = event.getEntity(); + // Do not handle player + if (entity instanceof EntityPlayer) return; + removeScorerFromAllScoreboards(new EntityScorer(entity)); + }); + eventBus.registerListenerFor(PlayerJoinEvent.class, event -> { + var player = event.getPlayer(); + addViewer(player); + var scorer = new PlayerScorer(player); + scoreboards.values().forEach(scoreboard -> { + if (scoreboard.containLine(scorer)) { + viewers.forEach(viewer -> viewer.updateScore(scoreboard.getLine(scorer))); + } + }); + }); + eventBus.registerListenerFor(PlayerQuitEvent.class, event -> { + var player = event.getPlayer(); + if (!player.isInitialized()) return; + var scorer = new PlayerScorer(player); + scoreboards.values().forEach(scoreboard -> { + if (scoreboard.containLine(scorer)) { + viewers.forEach(viewer -> viewer.removeScoreboardLine(scoreboard.getLine(scorer))); + } + }); + removeViewer(player); + }); } public boolean add(Scoreboard scoreboard) { @@ -145,39 +171,4 @@ public void read() { public void removeScorerFromAllScoreboards(Scorer scorer) { scoreboards.values().forEach(scoreboard -> scoreboard.removeLine(scorer)); } - - private class ServerEventListener { - @EventHandler - public void onEntityDespawn(EntityDespawnEvent event) { - var entity = event.getEntity(); - // Do not handle player - if (entity instanceof EntityPlayer) return; - removeScorerFromAllScoreboards(new EntityScorer(entity)); - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - var player = event.getPlayer(); - addViewer(player); - var scorer = new PlayerScorer(player); - scoreboards.values().forEach(scoreboard -> { - if (scoreboard.containLine(scorer)) { - viewers.forEach(viewer -> viewer.updateScore(scoreboard.getLine(scorer))); - } - }); - } - - @EventHandler - public void onPlayerQuit(PlayerQuitEvent event) { - var player = event.getPlayer(); - if (!player.isInitialized()) return; - var scorer = new PlayerScorer(player); - scoreboards.values().forEach(scoreboard -> { - if (scoreboard.containLine(scorer)) { - viewers.forEach(viewer -> viewer.removeScoreboardLine(scoreboard.getLine(scorer))); - } - }); - removeViewer(player); - } - } }