fixed score

This commit is contained in:
2024-11-23 23:56:18 +01:00
parent 3fe57d5fe9
commit 18689ac0df
6 changed files with 35 additions and 63 deletions

View File

@@ -8,6 +8,7 @@ import net.minestom.server.entity.Player;
import net.minestom.server.event.instance.AddEntityToInstanceEvent;
import net.minestom.server.event.instance.RemoveEntityFromInstanceEvent;
import net.minestom.server.event.player.PlayerDisconnectEvent;
import org.apache.commons.lang3.NotImplementedException;
import java.util.ArrayList;
import java.util.List;
@@ -22,10 +23,19 @@ public abstract class Score {
public Score() {}
public Score(int ignoreLastPlayers) {
this.ignoreLastPlayers = ignoreLastPlayers;
protected abstract void insertResultImplementation(Set<Player> p);
protected void insertResultImplementation(Set<Player> p, int points) {
throw new NotImplementedException("This Score type is not able to process points");
}
public void insertResult(Player p) {
this.insertResultProcessor(p, () -> this.insertResultImplementation(Set.of(p)));
}
public void insertResult(Player p, int points) {
this.insertResultProcessor(p, () -> this.insertResultImplementation(Set.of(p), points));
}
public void attachListeners() {
this.instance.eventNode()
@@ -46,21 +56,8 @@ public abstract class Score {
}
}
public abstract void insertResultImplementation(Set<Player> p, int points);
protected abstract void insertResultImplementation(Set<Player> p);
public abstract void insertResult(Player p, int points);
protected abstract TranslatableMessage scoreMessage();
public void insertResult(Player p) {
if(hasResult(p)) return;
this.scoreMessage().send(p);
this.insertResultImplementation(Set.of(p));
this.checkGameEnd();
}
public void insertRemainingPlayers(Set<Player> players) {
this.insertResultImplementation(players.stream().filter(p -> !hasResult(p)).collect(Collectors.toSet()));
setDone();
@@ -99,6 +96,13 @@ public abstract class Score {
instance.stop();
}
private void insertResultProcessor(Player p, Runnable callback) {
if(hasResult(p)) return;
this.scoreMessage().send(p);
callback.run();
this.checkGameEnd();
}
public boolean isClosed() {
return isClosed;
}