Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@ protected HypixelBedWars(JSONHandler jsonHandler) {
this.jsonHandler = jsonHandler;
}

/**
* @return The amount of resources the player has collected.
*/
public int getResourcesCollected() {
return jsonHandler.getSafeInt("resources_collected_bedwars");
}

/**
* @return The amount of diamonds the player has collected.
*/
public int getDiamondsCollected() {
return jsonHandler.getSafeInt("diamond_resources_collected_bedwars");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public boolean isRemoved() {
* @return The player's stats for that {@code mode}.
*/
public HypixelBedWars getMode(HypixelBedWarsMode mode) {
return new HypixelBedWars(
jsonHandler.getThisJSONHandlerWithStatsPrefix(mode.getStatsPrefix()));
JSONHandler jsonHandler = this.jsonHandler.getCopy();
jsonHandler.setStatsPrefix(mode.getStatsPrefix());
return new HypixelBedWars(jsonHandler);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,71 @@
import io.github.neopixel.wrapper.util.JSONHandler;
import java.util.Optional;

public class HypixelDuels extends HypixelGame implements HypixelLootChestGame {
public class HypixelDuels {

private final JSONHandler jsonHandler;
protected HypixelDuels(JSONHandler jsonHandler) {
super(jsonHandler);
this.jsonHandler = jsonHandler;
}

@Override
public String getGameID() {
return "DUELS";
public int getWins() {
return jsonHandler.getSafeInt("wins");
}

@Override
public String getGameName() {
return "Duels";
public int getLosses() {
return jsonHandler.getSafeInt("losses");
}

@Override
public boolean isRemoved() {
return false;
public int getWinToLossRatio() {
return getWins() / Math.max(getLosses(), 1);
}

@Override
public final int getOpenedChestsAmount() {
throw new UnsupportedOperationException();
public int getKills() {
return jsonHandler.getSafeInt("kills");
}

@Override
public final int getOpenedCommonChestsAmount() {
throw new UnsupportedOperationException();
public int getDeaths() {
return jsonHandler.getSafeInt("deaths");
}

@Override
public final int getOpenedRareChestsAmount() {
throw new UnsupportedOperationException();
public int getKillToDeathRatio() {
return getKills() / Math.max(getDeaths(), 1);
}

@Override
public final int getOpenedEpicChestsAmount() {
throw new UnsupportedOperationException();
public int getMeleeSwings() {
return jsonHandler.getSafeInt("melee_swings");
}

@Override
public final int getOpenedLegendaryChestsAmount() {
throw new UnsupportedOperationException();
public int getMeleeHits() {
return jsonHandler.getSafeInt("melee_hits");
}

public int getBowShots() {
return jsonHandler.getSafeInt("bow_shots");
}

public int getBowHits() {
return jsonHandler.getSafeInt("bow_hits");
}

public int getDamageDealt() {
return jsonHandler.getSafeInt("damage_dealt");
}

public int getHealthRegenerated() {
return jsonHandler.getSafeInt("health_regenerated");
}

public int getRoundsPlayed() {
return jsonHandler.getSafeInt("rounds_played");
}

/**
* Used for bridge modes only.
* @return The amount of goals a player has in the specific <bold>bridge</bold> mode.
*/
public int getGoals() {
return jsonHandler.getSafeInt("goals");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.github.neopixel.wrapper.games.duels;

public enum HypixelDuelsModes {

SKYWARS_SOLOS("sw_duel"),
SKYWARS_DOUBLES("sw_doubles"),

UHC_SOLOS("uhc_duel"),
UHC_DOUBLES("uhc_doubles"),
UHC_FOURS("uhc_four"),
UHC_MEETUP("uhc_meetup"),

SKYWARS_TOURNAMENT("sw_tournament"),
UHC_TOURNAMENT("uhc_tournament"),
SUMO_TOURNAMENT("sumo_tournament"),
BRIDGE_TOURNAMENT("bridge_tournament"),

CLASSIC_SOLOS("classic_duel"),

OP_SOLOS("op_duel"),
OP_DOUBLES("op_doubles"),

POTION_SOLOS("potion_duel"),

BLITZ_SOLOS("blitz_duel"),

COMBO_SOLOS("combo_duel"),

BOWSPLEEF_SOLOS("bowspleef_duel"),

MEGAWALLS_SOLOS("mw_duel"),
MEGAWALLS_DOUBLES("mw_doubles"),

BOW_SOLOS("bow_duel"),

SUMO("sumo_duel"),

BRIDGE_SOLOS("bridge_duel"),
BRIDGE_DOUBLES("bridge_doubles"),
BRIDGE_FOURS("bridge_four"),

BRIDGE_2v2v2v2("bridge_2v2v2v2"),
BRIDGE_3v3v3v3("bridge_3v3v3v3");

final String statsPrefix;

HypixelDuelsModes(String statsPrefix) {
this.statsPrefix = statsPrefix;
}

public String getStatsPrefix() {
return statsPrefix;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package io.github.neopixel.wrapper.games.duels;

import io.github.neopixel.wrapper.HypixelLootChestGame;
import io.github.neopixel.wrapper.games.HypixelGame;
import io.github.neopixel.wrapper.games.bedwars.HypixelBedWars;
import io.github.neopixel.wrapper.games.bedwars.HypixelBedWarsMode;
import io.github.neopixel.wrapper.util.JSONHandler;

/**
* A player's overall stats for the duels.
* <p>
* To get their stats for a particular {@link HypixelDuelsModes mode}, use the
* {@link #getMode(HypixelDuelsModes) getMode()} method.
*/
public class HypixelDuelsStats extends HypixelGame implements HypixelLootChestGame {

protected HypixelDuelsStats(JSONHandler jsonHandler) {
super(jsonHandler);
}

@Override
public String getGameID() {
return "DUELS";
}

@Override
public String getGameName() {
return "Duels";
}

@Override
public boolean isRemoved() {
return false;
}

/**
* Gets the player's stats for a particular Duels mode.
*
* @param mode The mode to get the player's stats for.
* @return The player's stats for that mode.
*/
public HypixelDuels getMode(HypixelDuelsModes mode) {
JSONHandler jsonHandler = this.jsonHandler.getCopy();
jsonHandler.setStatsPrefix(mode.getStatsPrefix());
return new HypixelDuels(jsonHandler);
}

public boolean isKitMenuOptionEnabled() {
return jsonHandler.getSafeString("kit_menu_option").equals("on");
}

public boolean isShowLeaderboardsEnabled() {
return jsonHandler.getSafeString("show_lb_option").equals("on");
}

public int getGamesPlayed() {
return jsonHandler.getSafeInt("games_played_duels");
}

public String getRematchOption() {
return jsonHandler.getSafeString("rematch_option_1");
}

public int getCoins() {
return jsonHandler.getSafeInt("coins");
}

public String getActiveProjectileTrail() {
return jsonHandler.getSafeString("active_projectile_trail");
}

public String getActiveEmblem() {
return jsonHandler.getSafeString("active_emblem");
}

public String getActiveKillMessage() {
return jsonHandler.getSafeString("active_killmessages");
}

public String getActiveKillEffect() {
return jsonHandler.getSafeString("active_kill_effect");
}

public String getActiveVictoryDance() {
return jsonHandler.getSafeString("active_victory_dance");
}

public String getActiveAuras() {
return jsonHandler.getSafeString("active_auras");
}

public String getActiveWeaponpacks() {
return jsonHandler.getSafeString("active_weaponpacks");
}

public boolean isChallengesEnabled() {
return jsonHandler.getSafeBoolean("challenges_enabled");
}

public String getStatusField() {
return jsonHandler.getSafeString("status_field");
}

public String getEquippedCustomTitle() {
return jsonHandler.getSafeString("equipped_custom_titles");
}

public boolean isProjectileTrailEnabled() {
return jsonHandler.getSafeBoolean("toggle_proj_trail");
}

public String getActiveCosmeticTitle() {
return jsonHandler.getSafeString("active_cosmetictitle");
}

@Override
public int getOpenedChestsAmount() {
return jsonHandler.getSafeInt("Duels_openedChests");
}

@Override
public int getOpenedCommonChestsAmount() {
return jsonHandler.getSafeInt("Duels_openedCommons");
}

@Override
public int getOpenedRareChestsAmount() {
return jsonHandler.getSafeInt("Duels_openedRares");
}

@Override
public int getOpenedEpicChestsAmount() {
return jsonHandler.getSafeInt("Duels_openedEpics");
}

@Override
public int getOpenedLegendaryChestsAmount() {
return jsonHandler.getSafeInt("Duels_openedLegendaries");
}
}
28 changes: 21 additions & 7 deletions src/main/java/io/github/neopixel/wrapper/util/JSONHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,26 @@
public class JSONHandler {

private final JSONObject stats;
private final String statsPrefix;
private String statsPrefix;

private String statsSuffix;


public JSONHandler(JSONObject stats) {
this.stats = stats;
this.statsPrefix = "";
this.statsSuffix = "";
}

public JSONHandler(JSONObject stats, String statsPrefix) {
this.stats = stats;
public void setStatsPrefix(String statsPrefix) {
this.statsPrefix = statsPrefix;
}

public void setStatsSuffix(String statsSuffix) {
this.statsSuffix = statsSuffix;
}


public JSONArray getSafeJSONArray(String key) {
if (stats.has(statsPrefix + key)) {
Object object = this.get(key);
Expand Down Expand Up @@ -114,7 +121,7 @@ public UUID getSafeUUID(String key) {
}

public Object get(String key) {
return stats.get(statsPrefix + key);
return stats.get(statsPrefix + key + statsSuffix);
}

public Iterator<String> getKeys() {
Expand All @@ -123,13 +130,20 @@ public Iterator<String> getKeys() {

public JSONHandler getJSONHandler(String key) {
if (stats.has(key)) {
return new JSONHandler(stats.getJSONObject(key));
JSONHandler handler = new JSONHandler(stats.getJSONObject(key));
handler.setStatsPrefix(statsPrefix);
handler.setStatsSuffix(statsSuffix);
return handler;
} else {
return null;
}
}

public JSONHandler getThisJSONHandlerWithStatsPrefix(String statsPrefix) {
return new JSONHandler(stats, statsPrefix);
public JSONHandler getCopy() {
JSONHandler handler = new JSONHandler(stats);
handler.setStatsPrefix(statsPrefix);
handler.setStatsSuffix(statsSuffix);
return handler;
}

}