Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[contribution] bug fixes and featores #2

Merged
merged 1 commit into from
Feb 6, 2021
Merged
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 @@ -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 {

Expand Down Expand Up @@ -148,6 +151,21 @@ public interface MatchPlayer {
*/
Request<Player> getPlayer();

/**
* <p>Return the party id that this player is a member of</p>
*/
long getPartyId();

/**
* <p>Return the loadout the player used this match</p>
*/
List<LoadoutItem> getLoadout();

/**
* <p>Return the talent the player used this match</p>
*/
LoadoutItem getTalent();

default boolean isPrivateProfile(){
return getName().length() <= 2;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,29 @@

import javax.annotation.Nonnull;

public class ActiveItems implements CustomList<ShopItem>{
public class ActiveItems implements CustomList<ActiveItem>{

private final ShopItem[] shopItems;
private final ActiveItem[] shopItems;

public ActiveItems(List<ShopItem> itens) {
shopItems = new ShopItem[itens.size()];
AtomicInteger integer = new AtomicInteger();
for (ShopItem shopItem : itens) {
shopItems[integer.getAndIncrement()] = shopItem;
}
public ActiveItems(List<ActiveItem> itens) {
this.shopItems = itens.toArray(ActiveItem[]::new);
}

@Nonnull
public Iterator<ShopItem> iterator() {
public Iterator<ActiveItem> iterator() {
return Arrays.stream(shopItems).iterator();
}

public List<ShopItem> getAsList() {
public List<ActiveItem> getAsList() {
return Arrays.stream(shopItems).collect(Collectors.toList());
}

public Stream<ShopItem> getAsStream() {
public Stream<ActiveItem> 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
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/me/skiincraft/api/paladins/enums/ShopItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -108,7 +112,7 @@ public List<MatchPlayer> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -180,16 +182,17 @@ public ActiveItems getActiveItems() {
if (activeItems != null) {
return activeItems;
}
List<ShopItem> 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<ActiveItem> 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() {
Expand Down Expand Up @@ -224,6 +227,30 @@ public Request<Player> getPlayer() {
return endPoint.getPlayer(getId());
}

@Override
public long getPartyId() {
return get("PartyId").getAsLong();
}

@Override
public List<LoadoutItem> getLoadout() {
List<LoadoutItem> 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{" +
Expand Down