Skip to content

Commit

Permalink
fix: fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Jan 6, 2025
1 parent 1fbf498 commit da05bc1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 38 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
65 changes: 28 additions & 37 deletions api/src/main/java/org/allaymc/api/scoreboard/ScoreboardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit da05bc1

Please sign in to comment.