reformatted project

This commit is contained in:
2025-10-16 00:58:52 +02:00
parent cf0499df44
commit 794dc1dbb1
150 changed files with 1594 additions and 1771 deletions

View File

@@ -16,12 +16,13 @@ import java.util.Set;
import java.util.stream.Collectors;
public abstract class Score {
private final List<Set<Player>> scores = new ArrayList<>();
protected Game instance;
private int ignoreLastPlayers = 0;
private boolean isClosed = false;
protected Game instance;
private final List<Set<Player>> scores = new ArrayList<>();
public Score() {}
public Score() {
}
protected abstract void insertResultImplementation(Set<Player> p);
@@ -39,28 +40,28 @@ public abstract class Score {
public void attachListeners() {
this.instance.eventNode()
.addListener(AddEntityToInstanceEvent.class, addEntityToInstanceEvent -> checkGameEnd())
.addListener(RemoveEntityFromInstanceEvent.class, addEntityToInstanceEvent -> checkGameEnd())
.addListener(PlayerDisconnectEvent.class, addEntityToInstanceEvent -> checkGameEnd());
.addListener(AddEntityToInstanceEvent.class, addEntityToInstanceEvent -> this.checkGameEnd())
.addListener(RemoveEntityFromInstanceEvent.class, addEntityToInstanceEvent -> this.checkGameEnd())
.addListener(PlayerDisconnectEvent.class, addEntityToInstanceEvent -> this.checkGameEnd());
}
protected void checkGameEnd() {
if(this.isClosed()) return;
if(!instance.isRunning()) return;
if(instance.getPlayers().isEmpty()) return;
if(resultCount() >= instance.getPlayers().size() - ignoreLastPlayers) {
if(ignoreLastPlayers > 0) {
insertRemainingPlayers(instance.getPlayers());
if(!this.instance.isRunning()) return;
if(this.instance.getPlayers().isEmpty()) return;
if(this.resultCount() >= this.instance.getPlayers().size() - this.ignoreLastPlayers) {
if(this.ignoreLastPlayers > 0) {
this.insertRemainingPlayers(this.instance.getPlayers());
}
setDone();
this.setDone();
}
}
protected abstract TranslatableMessage scoreMessage();
public void insertRemainingPlayers(Set<Player> players) {
this.insertResultImplementation(players.stream().filter(p -> !hasResult(p)).collect(Collectors.toSet()));
setDone();
this.insertResultImplementation(players.stream().filter(p -> !this.hasResult(p)).collect(Collectors.toSet()));
this.setDone();
}
public boolean hasResult(Player p) {
@@ -72,49 +73,47 @@ public abstract class Score {
}
public void setDone() {
if(isClosed) return;
isClosed = true;
if(this.isClosed) return;
this.isClosed = true;
new ChatMessage(Icon.STAR, true)
.appendTranslated("score#result")
.newLine()
.indent()
.numberedList(
getScores()
.stream()
.map(players -> players
.stream()
.map(Player::getUsername)
.collect(Collectors.joining(", "))
)
.toList()
)
.undent()
.newLine()
.appendTranslated("score#thanks")
.send(instance.getPlayers());
.appendTranslated("score#result")
.newLine()
.indent()
.numberedList(
this.getScores()
.stream()
.map(players -> players
.stream()
.map(Player::getUsername)
.collect(Collectors.joining(", "))
)
.toList()
)
.undent()
.newLine()
.appendTranslated("score#thanks")
.send(this.instance.getPlayers());
instance.stop();
this.instance.stop();
}
private void insertResultProcessor(Player p, Runnable callback) {
if(hasResult(p)) return;
if(this.hasResult(p)) return;
this.scoreMessage().send(p);
callback.run();
this.checkGameEnd();
}
public boolean isClosed() {
return isClosed;
return this.isClosed;
}
public void close() { isClosed = true; }
protected void onGameEnd() {
this.instance.stop();
public void close() {
this.isClosed = true;
}
public List<Set<Player>> getScores() {
return scores;
return this.scores;
}
public void setInstance(Game instance) {
@@ -122,7 +121,7 @@ public abstract class Score {
}
public int getIgnoreLastPlayers() {
return ignoreLastPlayers;
return this.ignoreLastPlayers;
}
public void setIgnoreLastPlayers(int ignoreLastPlayers) {