mirror of
https://github.com/itHotL/PlayerStats.git
synced 2025-02-13 01:11:23 +01:00
Started attempt to make the API more user friendly
This commit is contained in:
parent
a3c9f66fd8
commit
c3bf1e60fc
@ -0,0 +1,15 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.api;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.models.StatRequest;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
public interface APIRequest {
|
||||
|
||||
StatRequest untyped(Statistic statistic);
|
||||
|
||||
StatRequest blockOrItemType(Statistic statistic, Material material);
|
||||
|
||||
StatRequest entityType(Statistic statistic, EntityType entityType);
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.api;
|
||||
|
||||
public abstract class PlayerRequest implements APIRequest {
|
||||
|
||||
protected final String playerName;
|
||||
|
||||
public PlayerRequest(String playerName) {
|
||||
this.playerName = playerName;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.api;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Target;
|
||||
import com.gmail.artemis.the.gr8.playerstats.models.StatRequest;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PlayerStatRequest extends PlayerRequest {
|
||||
|
||||
public PlayerStatRequest(String playerName) {
|
||||
super(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatRequest untyped(Statistic statistic) {
|
||||
StatRequest request = getBasePlayerRequest();
|
||||
request.setStatistic(statistic);
|
||||
return request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatRequest blockOrItemType(@NotNull Statistic statistic, Material material) {
|
||||
StatRequest request = getBasePlayerRequest(statistic);
|
||||
request.setSubStatEntryName(material.toString());
|
||||
if (statistic.getType() == Statistic.Type.BLOCK) {
|
||||
request.setBlock(material);
|
||||
} else {
|
||||
request.setItem(material);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatRequest entityType(Statistic statistic, EntityType entityType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private StatRequest getBasePlayerRequest(@NotNull Statistic statistic) {
|
||||
StatRequest request = new StatRequest(Bukkit.getConsoleSender(), true);
|
||||
request.setStatistic(statistic);
|
||||
request.setTarget(Target.PLAYER);
|
||||
request.setPlayerName(super.playerName);
|
||||
return request;
|
||||
}
|
||||
}
|
@ -26,7 +26,7 @@ public interface PlayerStats {
|
||||
return Main.getPlayerStatsAPI();
|
||||
}
|
||||
|
||||
StatResult<?> getPlayerStat(String playerName, Statistic statistic, Material material, EntityType entity);
|
||||
PlayerRequest getPlayerStat(String playerName);
|
||||
|
||||
StatResult<?> getServerStat(Statistic statistic, Material material, EntityType entity);
|
||||
|
||||
|
@ -27,12 +27,23 @@ public final class PlayerStatsAPI implements PlayerStats {
|
||||
statFormatter = format;
|
||||
}
|
||||
|
||||
public PlayerRequest getPlayerStat(String playerName) {
|
||||
return ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatResult<Integer> getPlayerStat(String playerName, Statistic statistic, Material material, EntityType entity) {
|
||||
StatRequest request = getStatRequest(Target.PLAYER, statistic, material, entity, playerName);
|
||||
int stat = statCalculator.getPlayerStat(request);
|
||||
TextComponent prettyStat = statFormatter.formatPlayerStat(request, stat);
|
||||
return new PlayerStatResult(stat, prettyStat);
|
||||
public StatResult<Integer> getPlayerStat(String playerName, Statistic statistic) {
|
||||
return getPlayerStat(playerName, statistic, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatResult<?> getPlayerStat(String playerName, Statistic statistic, Material material) {
|
||||
return getPlayerStat(playerName, statistic, material, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatResult<?> getPlayerStat(String playerName, Statistic statistic, EntityType entityType) {
|
||||
return getPlayerStat(playerName, statistic, null, entityType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,6 +62,13 @@ public final class PlayerStatsAPI implements PlayerStats {
|
||||
return new TopStatResult(stat, prettyStat);
|
||||
}
|
||||
|
||||
private PlayerStatResult getPlayerStat(String playerName, Statistic statistic, Material material, EntityType entityType) {
|
||||
StatRequest request = getStatRequest(Target.PLAYER, statistic, material, entityType, playerName);
|
||||
int stat = statCalculator.getPlayerStat(request);
|
||||
TextComponent prettyStat = statFormatter.formatPlayerStat(request, stat);
|
||||
return new PlayerStatResult(stat, prettyStat);
|
||||
}
|
||||
|
||||
private StatRequest getStatRequest(Target target, Statistic statistic, Material material, EntityType entity, String playerName) throws NullPointerException {
|
||||
StatRequest request = requestGenerator.generateAPIRequest(target, statistic, material, entity, playerName);
|
||||
if (requestGenerator.validateAPIRequest(request)) {
|
||||
|
@ -0,0 +1,4 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.api;
|
||||
|
||||
public interface ServerStatRequest extends APIRequest {
|
||||
}
|
Loading…
Reference in New Issue
Block a user