|
25 | 25 | import org.bukkit.entity.Player; |
26 | 26 | import org.screamingsandals.bedwars.Main; |
27 | 27 | import org.screamingsandals.bedwars.api.game.GameStatus; |
| 28 | +import org.screamingsandals.bedwars.api.statistics.LeaderboardEntry; |
28 | 29 | import org.screamingsandals.bedwars.api.statistics.PlayerStatistic; |
29 | 30 | import org.screamingsandals.bedwars.game.CurrentTeam; |
30 | 31 | import org.screamingsandals.bedwars.game.Game; |
@@ -239,9 +240,75 @@ public String onPlaceholderRequest(Player player, String identifier) { |
239 | 240 | } |
240 | 241 | } |
241 | 242 |
|
| 243 | + if (identifier.startsWith("leaderboard_score_")) { |
| 244 | + if (!Main.isPlayerStatisticsEnabled()) { |
| 245 | + return null; |
| 246 | + } |
| 247 | + |
| 248 | + String remainder = identifier.substring(18); |
| 249 | + String[] split = remainder.split("_", 2); |
| 250 | + if (split.length != 2) { |
| 251 | + return null; |
| 252 | + } |
| 253 | + |
| 254 | + int index; |
| 255 | + try { |
| 256 | + index = Integer.parseInt(split[0]); |
| 257 | + } catch (NumberFormatException e) { |
| 258 | + return null; |
| 259 | + } |
| 260 | + |
| 261 | + index--; // 1 -> 0 |
| 262 | + if (index < 0) { |
| 263 | + return null; |
| 264 | + } |
| 265 | + |
| 266 | + LeaderboardEntry entry = Main.getPlayerStatisticsManager().getLeaderboardEntry(index); |
| 267 | + |
| 268 | + if (entry == null) { |
| 269 | + switch (split[1].toLowerCase(Locale.ROOT)) { |
| 270 | + case "uuid": |
| 271 | + case "name": |
| 272 | + return "---"; |
| 273 | + case "score": |
| 274 | + case "deaths": |
| 275 | + case "destroyed_beds": |
| 276 | + case "kills": |
| 277 | + case "loses": |
| 278 | + case "wins": |
| 279 | + case "games": |
| 280 | + case "kd": |
| 281 | + return "0"; |
| 282 | + } |
| 283 | + } else { |
| 284 | + switch (split[1].toLowerCase(Locale.ROOT)) { |
| 285 | + case "uuid": |
| 286 | + return entry.getPlayer().getUniqueId().toString(); |
| 287 | + case "name": |
| 288 | + return entry.getLatestKnownName(); |
| 289 | + case "score": |
| 290 | + return Integer.toString(entry.getTotalScore()); |
| 291 | + case "deaths": |
| 292 | + return Integer.toString(entry.fetchStatistics().getDeaths()); |
| 293 | + case "destroyed_beds": |
| 294 | + return Integer.toString(entry.fetchStatistics().getDestroyedBeds()); |
| 295 | + case "kills": |
| 296 | + return Integer.toString(entry.fetchStatistics().getKills()); |
| 297 | + case "loses": |
| 298 | + return Integer.toString(entry.fetchStatistics().getLoses()); |
| 299 | + case "wins": |
| 300 | + return Integer.toString(entry.fetchStatistics().getWins()); |
| 301 | + case "games": |
| 302 | + return Integer.toString(entry.fetchStatistics().getGames()); |
| 303 | + case "kd": |
| 304 | + return Double.toString(entry.fetchStatistics().getKD()); |
| 305 | + } |
| 306 | + } |
| 307 | + } |
| 308 | + |
242 | 309 | // Player |
243 | 310 | if (player == null) { |
244 | | - return ""; |
| 311 | + return null; |
245 | 312 | } |
246 | 313 |
|
247 | 314 | if (identifier.startsWith("current_")) { |
|
0 commit comments