9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-30 20:39:18 +00:00

Fixed reversed score

This commit is contained in:
XiaoMoMi
2024-09-10 14:56:48 +08:00
parent cac5a10752
commit 1d02db5aad
3 changed files with 33 additions and 4 deletions

View File

@@ -39,6 +39,7 @@ import net.momirealms.customfishing.common.util.Pair;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.time.Instant;
@@ -187,7 +188,7 @@ public class Competition implements FishingCompetition {
Optional<String> player = Optional.ofNullable(this.rankingProvider.getPlayerAt(i));
if (player.isPresent()) {
this.publicContext.arg(ContextKeys.of(i + "_player", String.class), player.get());
this.publicContext.arg(ContextKeys.of(i + "_score", String.class), String.format("%.2f", goal.isReversed() ? -this.rankingProvider.getScoreAt(i) : this.rankingProvider.getScoreAt(i)));
this.publicContext.arg(ContextKeys.of(i + "_score", String.class), String.format("%.2f", getScore(i)));
} else {
this.publicContext.arg(ContextKeys.of(i + "_player", String.class), TranslationManager.miniMessageTranslation(MessageConstants.COMPETITION_NO_PLAYER.build().key()));
this.publicContext.arg(ContextKeys.of(i + "_score", String.class), TranslationManager.miniMessageTranslation(MessageConstants.COMPETITION_NO_SCORE.build().key()));
@@ -199,6 +200,17 @@ public class Competition implements FishingCompetition {
this.publicContext.arg(ContextKeys.SECONDS, remainingTime);
}
@ApiStatus.Internal
public double getScore(String player) {
double score = this.rankingProvider.getPlayerScore(player);
return goal.isReversed() ? -score : score;
}
@ApiStatus.Internal
public double getScore(int rank) {
return goal.isReversed() ? -this.rankingProvider.getScoreAt(rank) : this.rankingProvider.getScoreAt(rank);
}
@Override
public boolean isOnGoing() {
return remainingTime > 0;
@@ -219,6 +231,11 @@ public class Competition implements FishingCompetition {
@Override
public void refreshData(Player player, double score) {
refreshScore(player, score);
}
@Override
public void refreshScore(Player player, double score) {
// if player join for the first time, trigger join actions
if (!hasPlayerJoined(player)) {
ActionManager.trigger(Context.player(player).combine(publicContext), config.joinActions());