mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-30 12:29:19 +00:00
add new api method
This commit is contained in:
@@ -20,6 +20,7 @@ package net.momirealms.customfishing.mechanic.competition.ranking;
|
||||
import net.momirealms.customfishing.api.common.Pair;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.CompetitionPlayer;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.Ranking;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -87,6 +88,20 @@ public class LocalRankingImpl implements Ranking {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompetitionPlayer getCompetitionPlayer(int rank) {
|
||||
int i = 1;
|
||||
int size = getSize();
|
||||
if (rank > size) return null;
|
||||
for (CompetitionPlayer player : competitionPlayers) {
|
||||
if (rank == i) {
|
||||
return player;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator for iterating over pairs of player names and scores.
|
||||
*
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.momirealms.customfishing.api.common.Pair;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.CompetitionPlayer;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.Ranking;
|
||||
import net.momirealms.customfishing.storage.method.database.nosql.RedisManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.resps.Tuple;
|
||||
|
||||
@@ -54,6 +55,15 @@ public class RedisRankingImpl implements Ranking {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompetitionPlayer getCompetitionPlayer(int rank) {
|
||||
try (Jedis jedis = RedisManager.getInstance().getJedis()) {
|
||||
List<Tuple> player = jedis.zrevrangeWithScores("cf_competition", rank - 1, rank -1);
|
||||
if (player == null || player.size() == 0) return null;
|
||||
return new CompetitionPlayer(player.get(0).getElement(), player.get(0).getScore());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayer(CompetitionPlayer competitionPlayer) {
|
||||
try (Jedis jedis = RedisManager.getInstance().getJedis()) {
|
||||
|
||||
Reference in New Issue
Block a user