diff --git a/src/main/java/me/skiincraft/api/paladins/entity/match/MatchPlayer.java b/src/main/java/me/skiincraft/api/paladins/entity/match/MatchPlayer.java index e268ec6..21ba428 100644 --- a/src/main/java/me/skiincraft/api/paladins/entity/match/MatchPlayer.java +++ b/src/main/java/me/skiincraft/api/paladins/entity/match/MatchPlayer.java @@ -9,6 +9,9 @@ import me.skiincraft.api.paladins.enums.Tier; import me.skiincraft.api.paladins.objects.Kills; import me.skiincraft.api.paladins.objects.LeagueSeason; +import me.skiincraft.api.paladins.objects.LoadoutItem; + +import java.util.List; public interface MatchPlayer { @@ -148,6 +151,21 @@ public interface MatchPlayer { */ Request getPlayer(); + /** + *

Return the party id that this player is a member of

+ */ + long getPartyId(); + + /** + *

Return the loadout the player used this match

+ */ + List getLoadout(); + + /** + *

Return the talent the player used this match

+ */ + LoadoutItem getTalent(); + default boolean isPrivateProfile(){ return getName().length() <= 2; } diff --git a/src/main/java/me/skiincraft/api/paladins/entity/match/objects/ActiveItem.java b/src/main/java/me/skiincraft/api/paladins/entity/match/objects/ActiveItem.java new file mode 100644 index 0000000..d38c7fa --- /dev/null +++ b/src/main/java/me/skiincraft/api/paladins/entity/match/objects/ActiveItem.java @@ -0,0 +1,29 @@ +package me.skiincraft.api.paladins.entity.match.objects; + +import me.skiincraft.api.paladins.enums.ShopItem; + +public class ActiveItem { + private ShopItem item; + private int level; + + public ActiveItem(ShopItem item, int level) { + this.item = item; + this.level = level; + } + + public ShopItem getItem() { + return item; + } + + public int getLevel() { + return level; + } + + @Override + public String toString() { + return "ActiveItem{" + + "item=" + item + + ", level=" + level + + '}'; + } +} diff --git a/src/main/java/me/skiincraft/api/paladins/entity/match/objects/ActiveItems.java b/src/main/java/me/skiincraft/api/paladins/entity/match/objects/ActiveItems.java index ea6a605..a56f9db 100644 --- a/src/main/java/me/skiincraft/api/paladins/entity/match/objects/ActiveItems.java +++ b/src/main/java/me/skiincraft/api/paladins/entity/match/objects/ActiveItems.java @@ -12,33 +12,29 @@ import javax.annotation.Nonnull; -public class ActiveItems implements CustomList{ +public class ActiveItems implements CustomList{ - private final ShopItem[] shopItems; + private final ActiveItem[] shopItems; - public ActiveItems(List itens) { - shopItems = new ShopItem[itens.size()]; - AtomicInteger integer = new AtomicInteger(); - for (ShopItem shopItem : itens) { - shopItems[integer.getAndIncrement()] = shopItem; - } + public ActiveItems(List itens) { + this.shopItems = itens.toArray(ActiveItem[]::new); } @Nonnull - public Iterator iterator() { + public Iterator iterator() { return Arrays.stream(shopItems).iterator(); } - public List getAsList() { + public List getAsList() { return Arrays.stream(shopItems).collect(Collectors.toList()); } - public Stream getAsStream() { + public Stream getAsStream() { return Arrays.stream(shopItems); } - public ShopItem getById(long id) { - return getAsStream().filter(o -> o.getItemId() == id).findFirst().orElse(null); + public ActiveItem getById(long id) { + return getAsStream().filter(o -> o.getItem().getItemId() == id).findFirst().orElse(null); } @Override diff --git a/src/main/java/me/skiincraft/api/paladins/enums/ShopItem.java b/src/main/java/me/skiincraft/api/paladins/enums/ShopItem.java index 668d4d4..cf79755 100644 --- a/src/main/java/me/skiincraft/api/paladins/enums/ShopItem.java +++ b/src/main/java/me/skiincraft/api/paladins/enums/ShopItem.java @@ -22,4 +22,15 @@ public long getItemId() { public String getIconUrl() { return iconUrl; } + + public static ShopItem getById(long id) { + for (ShopItem item : values()) { + if (item.getItemId() == id) { + return item; + } + } + + return null; + } + } diff --git a/src/main/java/me/skiincraft/api/paladins/impl/match/MatchImpl.java b/src/main/java/me/skiincraft/api/paladins/impl/match/MatchImpl.java index 0a14edb..d2e5126 100644 --- a/src/main/java/me/skiincraft/api/paladins/impl/match/MatchImpl.java +++ b/src/main/java/me/skiincraft/api/paladins/impl/match/MatchImpl.java @@ -37,6 +37,10 @@ public MatchImpl(EndPoint endPoint, JsonArray array) { this.object = array.get(0).getAsJsonObject(); } + public JsonArray getRaw() { + return this.array; + } + public String getWinner() { return (object.get("Winning_TaskForce").getAsInt() == 1) ? "Blue" : "Red"; } @@ -108,7 +112,7 @@ public List getTeam2() { } for (JsonElement ele : array) { JsonObject ob = ele.getAsJsonObject(); - if (ob.get("TaskForce").getAsInt() != 1) { + if (ob.get("TaskForce").getAsInt() != 2) { continue; } team2.add(new MatchPlayerImpl(endPoint, ob, this)); diff --git a/src/main/java/me/skiincraft/api/paladins/impl/player/MatchPlayerImpl.java b/src/main/java/me/skiincraft/api/paladins/impl/player/MatchPlayerImpl.java index 83e3000..be477fd 100644 --- a/src/main/java/me/skiincraft/api/paladins/impl/player/MatchPlayerImpl.java +++ b/src/main/java/me/skiincraft/api/paladins/impl/player/MatchPlayerImpl.java @@ -10,6 +10,7 @@ import me.skiincraft.api.paladins.entity.champions.Champion; import me.skiincraft.api.paladins.entity.match.Match; import me.skiincraft.api.paladins.entity.match.MatchPlayer; +import me.skiincraft.api.paladins.entity.match.objects.ActiveItem; import me.skiincraft.api.paladins.entity.match.objects.ActiveItems; import me.skiincraft.api.paladins.entity.match.objects.Damage; import me.skiincraft.api.paladins.enums.ShopItem; @@ -22,6 +23,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import me.skiincraft.api.paladins.objects.LeagueSeason; +import me.skiincraft.api.paladins.objects.LoadoutItem; import javax.annotation.Nullable; @@ -180,16 +182,17 @@ public ActiveItems getActiveItems() { if (activeItems != null) { return activeItems; } - List shopItems = new ArrayList<>(); - Arrays.stream(ShopItem.values()).filter(shopItem -> { - for (int i = 1; i <= 4; i++) { - if (get("ActiveId" + i).getAsLong() == shopItem.getItemId()) { - return true; - } + List shopItems = new ArrayList<>(); + + for (int i = 1; i <= 4; i++) { + long id = get("ActiveId" + i).getAsLong(); + if (id != 0) { + ShopItem item = ShopItem.getById(id); + int level = get("ActiveLevel" + i).getAsInt(); + shopItems.add(new ActiveItem(item, level)); } - return false; - }).collect(Collectors.toList()).addAll(shopItems); - + } + return activeItems = new ActiveItems(shopItems); } public boolean hasWon() { @@ -224,6 +227,30 @@ public Request getPlayer() { return endPoint.getPlayer(getId()); } + @Override + public long getPartyId() { + return get("PartyId").getAsLong(); + } + + @Override + public List getLoadout() { + List res = new ArrayList<>(); + for (int i = 1; i <= 5; i++) { + long id = get("ItemId" + i).getAsLong(); + String name = get("Item_Purch_" + i).getAsString(); + int level = get("ItemLevel" + i).getAsInt(); + res.add(new LoadoutItem(id, name, level)); + } + return res; + } + + @Override + public LoadoutItem getTalent() { + return new LoadoutItem(get("ItemId6").getAsLong(), + get("Item_Purch_6").getAsString(), + get("ItemLevel6").getAsInt()); + } + @Override public String toString() { return "MatchPlayer{" +