gpt4 book ai didi

java - 收集并排序所有玩家的积分

转载 作者:行者123 更新时间:2023-11-30 03:54:30 26 4
gpt4 key购买 nike

我正在尝试从所有玩家的配置文件中收集点值并对它们进行排序,以便我可以将前五名放入排行榜。我无法弄清楚如何为配置文件中的所有玩家选择“points”键。

这是配置结构:

players:
9e388a50-d930-11e3-9c1a-0800200c9a66:
points: 66
dead: false
63eabd40-d931-11e3-9c1a-0800200c9a66:
points: 120
dead: false

这是我到目前为止的代码:

public void onCommand(Player p, String[] args) {
ConfigurationSection section = config.getConfig().getConfigurationSection("players." + GET ALL PLAYERS HERE + ".points");
String top1 = null;
String top2 = null;
String top3 = null;
String top4 = null;
String top5 = null;
int top1Score = 0;
int top2Score = 0;
int top3Score = 0;
int top4Score = 0;
int top5Score = 0;

if (section != null) {
for (String player : section.getKeys(false)) {
int score = section.getInt(player);
if (top1 == null) {
top1 = player;
top1Score = score;
} else if (top2 == null) {
top2 = player;
top2Score = score;
} else if (top3 == null) {
top3 = player;
top3Score = score;
} else if (top4 == null) {
top4 = player;
top3Score = score;
} else if (top5 == null) {
top5 = player;
top3Score = score;
} else if (score > top1) {
top5 = top4;
top5Score = top4Score;
top4 = top3;
top4Score = top3Score;
top3 = top2;
top3Score = top2Score;
top2 = top1;
top2Score = top1;
top1 = player;
top1Score = score;
}
// This takes continues like the above else if (score > top1)
}
}

这里是 Bukkit 配置 API 引用:http://wiki.bukkit.org/Configuration_API_Reference

最佳答案

我在我的服务器上用货币做了类似的事情。我是这样做的:

long top1Points = 0;
long top2Points = 0;
long top3Points = 0;
long top4Points = 0;
long top5Points = 0;
String top1Player = null;
String top2Player = null;
String top3Player = null;
String top4Player = null;
String top5Player = null;

for(OfflinePlayer p : Bukkit.getOfflinePlayers()){//loop threw all players that have ever played
String uuid = p.getUUID();//get the player's UUID
long points = plugin.getConfig().getLong("players." + uuid + ".points");//get the player's points

if(points > top5Points){ //if the player has more points than the top5Points
if(points > top4Points){ //if the player has more points than the top4Points
if(points > top3Points){ //if the player has more points than the top3Points
if(points > top2Points){ //if the player has more points than the top2Points
if(points > top1Points){ //if the player has more points than the top1Points
//store that this player has the #1 points as of now
top1Points = points;
top1Player = p.getName();
continue;
}
//store that this player has the #2 points as of now
top2Points = points;
top2Player = p.getName();
continue;
}
//store that this player has the #3 points as of now
top3Points = points;
top3Player = p.getName();
continue;
}
//store that this player has the #4 points as of now
top4Points = points;
top4Player = p.getName();
continue;
}
//store that this player has the #5 points as of now
top5Points = points;
top5Player = p.getName();
continue;
}

关于java - 收集并排序所有玩家的积分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23595649/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com