fixed score
This commit is contained in:
@@ -8,21 +8,11 @@ import java.time.Duration;
|
||||
import java.util.Set;
|
||||
|
||||
public class FirstWinsScore extends Score {
|
||||
@Override
|
||||
public void insertResultImplementation(Set<Player> p, int points) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertResultImplementation(Set<Player> p) {
|
||||
getScores().add(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertResult(Player p, int points) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TranslatableMessage scoreMessage() {
|
||||
return new TitleMessage(Duration.ofMillis(1000), Duration.ofSeconds(1)).appendTranslated("score#finish");
|
||||
|
@@ -8,21 +8,11 @@ import java.time.Duration;
|
||||
import java.util.Set;
|
||||
|
||||
public class LastWinsScore extends Score {
|
||||
@Override
|
||||
public void insertResultImplementation(Set<Player> p, int points) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertResultImplementation(Set<Player> p) {
|
||||
getScores().addFirst(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertResult(Player p, int points) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TranslatableMessage scoreMessage() {
|
||||
return new TitleMessage(Duration.ofMillis(1000), Duration.ofSeconds(1)).appendTranslated("score#death");
|
||||
|
@@ -10,21 +10,11 @@ public class NoScore extends Score {
|
||||
protected void checkGameEnd() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertResultImplementation(Set<Player> p, int points) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertResultImplementation(Set<Player> p) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertResult(Player p, int points) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TranslatableMessage scoreMessage() {
|
||||
return null;
|
||||
|
@@ -15,8 +15,8 @@ public class PointsWinScore extends Score {
|
||||
private Map<Set<Player>, Integer> scoreOrder = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void insertResultImplementation(Set<Player> p, int points) {
|
||||
this.scoreOrder.put(p, points);
|
||||
protected void insertResultImplementation(Set<Player> p, int currentPoints) {
|
||||
this.scoreOrder.put(p, currentPoints);
|
||||
this.scoreOrder = MapUtil.sortByValue(this.scoreOrder);
|
||||
getScores().clear();
|
||||
this.scoreOrder.forEach((player, integer) -> getScores().addFirst(player));
|
||||
@@ -27,14 +27,6 @@ public class PointsWinScore extends Score {
|
||||
this.insertResultImplementation(p, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertResult(Player p, int points) {
|
||||
if(hasResult(p)) return;
|
||||
this.scoreMessage().send(p);
|
||||
this.insertResultImplementation(Set.of(p), points);
|
||||
this.checkGameEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDone() {
|
||||
if(isClosed()) return;
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user