Skip to content

Commit

Permalink
All games, leaderboards
Browse files Browse the repository at this point in the history
  • Loading branch information
roccodev committed Oct 31, 2018
1 parent dcf343f commit e3b1144
Show file tree
Hide file tree
Showing 10 changed files with 411 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/main/java/pw/roccodev/beezig/hiveapi/wrapper/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import pw.roccodev.beezig.hiveapi.wrapper.game.achievement.AchievementInfo;
import pw.roccodev.beezig.hiveapi.wrapper.game.leaderboard.GameLeaderboard;
import pw.roccodev.beezig.hiveapi.wrapper.game.map.GameMap;
import pw.roccodev.beezig.hiveapi.wrapper.utils.download.UrlBuilder;
import pw.roccodev.beezig.hiveapi.wrapper.utils.json.JObject;
import pw.roccodev.beezig.hiveapi.wrapper.utils.json.LazyObject;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -42,7 +44,7 @@ public List<GameMap> getMaps() {

List<GameMap> maps = new ArrayList<>();

LazyObject mapsList = new LazyObject(null, new UrlBuilder().hive().gameMaps(shortcode).build());
LazyObject mapsList = new LazyObject(null, new UrlBuilder().hive().game(shortcode).maps().build());
mapsList.fetch();

JSONObject raw = mapsList.getInput();
Expand All @@ -54,4 +56,16 @@ public List<GameMap> getMaps() {
return maps;
}

public GameLeaderboard getLeaderboard(int start, int end) {
URL url;
if(shortcode.matches("BED."))
url = new UrlBuilder().hive().leaderboardWithVariation("BED", shortcode, start, end).build();
else url = new UrlBuilder().hive().game(shortcode).leaderboard(start, end).build();
return new GameLeaderboard(new LazyObject(null, url));
}

public GameLeaderboard getLeaderboard() {
return getLeaderboard(0, 200);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package pw.roccodev.beezig.hiveapi.wrapper.game.leaderboard;

import org.json.simple.JSONObject;
import pw.roccodev.beezig.hiveapi.wrapper.utils.json.LazyObject;

import java.util.List;
import java.util.stream.Collectors;

public class GameLeaderboard {

private LazyObject source;

public GameLeaderboard(LazyObject source) {
this.source = source;
}

public long getStart() {
return source.getLong("start");
}

public long getEnd() {
return source.getLong("end");
}

public List<LeaderboardPlace> getPlayers() {
return (List<LeaderboardPlace>) source.getJSONArray("leaderboard")
.stream().map((place) -> new LeaderboardPlace((JSONObject) place)).collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package pw.roccodev.beezig.hiveapi.wrapper.game.leaderboard;

import org.json.simple.JSONObject;

public class LeaderboardPlace extends JSONObject {

public LeaderboardPlace(JSONObject in) {
putAll(in);
}

public long getPlace() {
return (long) get("index");
}

public long getHumanPlace() {
return getPlace() + 1;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package pw.roccodev.beezig.hiveapi.wrapper.player.games.arcade;

import pw.roccodev.beezig.hiveapi.wrapper.player.PvPStats;
import pw.roccodev.beezig.hiveapi.wrapper.player.Titleable;
import pw.roccodev.beezig.hiveapi.wrapper.utils.json.LazyObject;

public class PmkStats extends PvPStats implements Titleable {

private LazyObject source;

public PmkStats(String usernameOrUUID) {
this(usernameOrUUID, false);
}

public PmkStats(String username, boolean convertToUUID) {
super(username, "PMK", convertToUUID);
source = getSource();
}


public long getInfections() {
return source.getLong("infections");
}

@Override
public long getDeaths() {
return getInfections();
}

@Override
public String getTitle() {
return source.getString("title");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package pw.roccodev.beezig.hiveapi.wrapper.player.games.arcade;

import pw.roccodev.beezig.hiveapi.wrapper.player.GameStats;
import pw.roccodev.beezig.hiveapi.wrapper.utils.json.LazyObject;

import java.util.Date;

public class RrStats extends GameStats {

private LazyObject source;

public RrStats(String usernameOrUUID) {
this(usernameOrUUID, false);
}

public RrStats(String username, boolean convertToUUID) {
super(username, "RR", convertToUUID);
source = getSource();
}


public long getTablesCleared() {
return source.getLong("tablescleared");
}

public long getHighestScore() {
return source.getLong("highscore");
}

@Override
public long getGamesPlayed() {
return source.getLong("gamesplayed");
}

@Override
public long getPoints() {
return source.getLong("points");
}

@Override
public Date getFirstLogin() {
return new Date(source.getLong("firstlogin") * 1000);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package pw.roccodev.beezig.hiveapi.wrapper.player.games.arcade;

import pw.roccodev.beezig.hiveapi.wrapper.player.PvPStats;
import pw.roccodev.beezig.hiveapi.wrapper.player.Titleable;
import pw.roccodev.beezig.hiveapi.wrapper.utils.json.LazyObject;

import java.util.Date;

public class SlapStats extends PvPStats implements Titleable {

private LazyObject source;

public SlapStats(String usernameOrUUID) {
this(usernameOrUUID, false);
}

public SlapStats(String username, boolean convertToUUID) {
super(username, "SLAP", convertToUUID);
source = getSource();
}


@Override
public long getGamesPlayed() {
return source.getLong("gamesplayed");
}

@Override
public long getPoints() {
return source.getLong("points");
}

@Override
public String getTitle() {
return source.getString("title");
}

@Override
public Date getFirstLogin() {
return new Date(source.getLong("firstlogin") * 1000);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package pw.roccodev.beezig.hiveapi.wrapper.player.games.arcade;

import pw.roccodev.beezig.hiveapi.wrapper.player.PvPStats;
import pw.roccodev.beezig.hiveapi.wrapper.player.Titleable;
import pw.roccodev.beezig.hiveapi.wrapper.utils.json.LazyObject;

import java.util.Date;

public class SpStats extends PvPStats implements Titleable {

private LazyObject source;

public SpStats(String usernameOrUUID) {
this(usernameOrUUID, false);
}

public SpStats(String username, boolean convertToUUID) {
super(username, "SP", convertToUUID);
source = getSource();
}

public long getBlocksDestroyed() {
return source.getLong("blocksdestroyed");
}

public long getEggsFired() {
return source.getLong("eggsfired");
}

public long getTimeAlive() {
return source.getLong("timealive");
}

public boolean hasRainbowEggs() {
return source.getBoolean("rainboweggs");
}

public boolean isSheepUnlocked() {
return source.getBoolean("sheepunlock");
}

public boolean hasShovelUpgrade() {
return source.getBoolean("shovelupgrade");
}

@Override
public long getKills() {
return -1;
}

@Override
public long getGamesPlayed() {
return source.getLong("gamesplayed");
}

@Override
public long getPoints() {
return source.getLong("points");
}

@Override
public String getTitle() {
return source.getString("title");
}

@Override
public Date getFirstLogin() {
return new Date(source.getLong("firstlogin") * 1000);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package pw.roccodev.beezig.hiveapi.wrapper.player.games.arcade;

import org.json.simple.JSONObject;
import pw.roccodev.beezig.hiveapi.wrapper.player.PvPStats;
import pw.roccodev.beezig.hiveapi.wrapper.player.Titleable;
import pw.roccodev.beezig.hiveapi.wrapper.utils.json.JObject;
import pw.roccodev.beezig.hiveapi.wrapper.utils.json.LazyObject;

import java.util.HashMap;
import java.util.Map;

public class SplStats extends PvPStats implements Titleable {

private LazyObject source;

public SplStats(String usernameOrUUID) {
this(usernameOrUUID, false);
}

public SplStats(String username, boolean convertToUUID) {
super(username, "SPL", convertToUUID);
source = getSource();
}

public long getBlocksPainted() {
return source.getLong("blockspainted");
}

public long getUltimatesEarned() {
return source.getLong("ultimates_earned");
}

public HashMap<String, SploopCharacterStats> getCharacterStats() {

HashMap<String, SploopCharacterStats> stats = new HashMap<>();

JSONObject rawStats = source.getJSONObject("character_stats");
for(Object o : rawStats.entrySet()) {
if(!(o instanceof Map.Entry)) continue;
Map.Entry<String, JSONObject> entry = (Map.Entry<String, JSONObject>) o;
stats.put(entry.getKey(), new SploopCharacterStats(new JObject(entry.getValue())));
}

return stats;
}

public SploopCharacterStats getStatsByCharacter(String raw) {
return getCharacterStats().get(raw);
}

public SploopCharacterStats getStatsByCharacter(Character character) {
return getStatsByCharacter(character.getApiKey());
}

@Override
public String getTitle() {
return source.getString("title");
}


public class SploopCharacterStats {

private JObject source;

SploopCharacterStats(JObject source) {
this.source = source;
}

public long getBlocksPainted() {
return source.getLong("blocks_painted");
}

public long getKills() {
return source.getLong("kills");
}

public long getDeaths() {
return source.getLong("deaths");
}

public long getGamesPlayed() {
return source.getLong("games_played");
}

public long getUltimateKills() {
return source.getLong("ultimate_kills");
}


}

public enum Character {

TORSTEIN("TorsteinCharacter"),
RAVEN("RavenCharacter"),
BOOSTER("BoosterCharacter"),
OINKY("OinkyCharacter");

private String apiKey;

Character(String apiKey) {
this.apiKey = apiKey;
}

public String getApiKey() {
return apiKey;
}

}

}
Loading

0 comments on commit e3b1144

Please sign in to comment.