Spielerdaten auslesen
parent
5e9dfcfad2
commit
606d61d438
|
|
@ -11,6 +11,50 @@ public class DotaMatchTracker {
|
|||
while (input.hasNextLine()) json += input.nextLine();
|
||||
input.close();
|
||||
|
||||
System.out.println(json);
|
||||
int playersStart = json.lastIndexOf("\"players\":[");
|
||||
int playersEnd = json.indexOf("],\"leagueid\"", playersStart);
|
||||
if (playersStart < 0 || playersEnd < 0) {
|
||||
System.out.println("Player data was not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
int playerCount = 0;
|
||||
int playerStart = json.indexOf("{\"player_slot\":", playersStart);
|
||||
while (playerStart >= 0 && playerStart < playersEnd) {
|
||||
int nextPlayer = json.indexOf("{\"player_slot\":", playerStart + 1);
|
||||
if (nextPlayer < 0 || nextPlayer > playersEnd) nextPlayer = playersEnd;
|
||||
String player = json.substring(playerStart, nextPlayer);
|
||||
String name = value(player, "personaname");
|
||||
int slot = Integer.parseInt(value(player, "player_slot"));
|
||||
String side = slot < 128 ? "Radiant" : "Dire";
|
||||
int hero = Integer.parseInt(value(player, "hero_id"));
|
||||
int kills = Integer.parseInt(value(player, "kills"));
|
||||
int deaths = Integer.parseInt(value(player, "deaths"));
|
||||
int assists = Integer.parseInt(value(player, "assists"));
|
||||
int lastHits = Integer.parseInt(value(player, "last_hits"));
|
||||
int netWorth = Integer.parseInt(value(player, "net_worth"));
|
||||
int gpm = Integer.parseInt(value(player, "gold_per_min"));
|
||||
System.out.println(name + " | " + side + " | " + hero + " | "
|
||||
+ kills + "/" + deaths + "/" + assists + " | "
|
||||
+ lastHits + " | " + netWorth + " | " + gpm);
|
||||
playerCount++;
|
||||
playerStart = nextPlayer;
|
||||
}
|
||||
System.out.println("Players read: " + playerCount);
|
||||
}
|
||||
|
||||
private static String value(String json, String key) {
|
||||
String marker = "\"" + key + "\":";
|
||||
int start = json.indexOf(marker);
|
||||
if (start < 0) return "0";
|
||||
start += marker.length();
|
||||
if (json.charAt(start) == '"') {
|
||||
start++;
|
||||
return json.substring(start, json.indexOf('"', start));
|
||||
}
|
||||
int end = json.indexOf(',', start);
|
||||
int objectEnd = json.indexOf('}', start);
|
||||
if (end < 0 || (objectEnd >= 0 && objectEnd < end)) end = objectEnd;
|
||||
return json.substring(start, end);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue