Add normal time to Worlds and use full Ban Entries (+graphql)
Signed-off-by: Etzelia <etzelia@hotmail.com>query
parent
e41d54e1ed
commit
30f329a32d
|
@ -1,6 +1,8 @@
|
|||
package xyz.etztech.serverapi;
|
||||
|
||||
|
||||
import org.bukkit.BanEntry;
|
||||
import org.bukkit.BanList;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -78,7 +80,7 @@ public class ServerAPI extends JavaPlugin implements IProvider {
|
|||
return WorldAPI.fromMinecraft(world);
|
||||
}
|
||||
}
|
||||
return new WorldAPI("unknown", 0, WorldAPI.WEATHER_UNKNOWN);
|
||||
return new WorldAPI("unknown", 0, 0, WorldAPI.WEATHER_UNKNOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -100,12 +102,12 @@ public class ServerAPI extends JavaPlugin implements IProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<PlayerAPI> bans() {
|
||||
Set<PlayerAPI> players = new HashSet<>();
|
||||
for (OfflinePlayer player : getServer().getBannedPlayers()) {
|
||||
players.add(PlayerAPI.fromMinecraft(player));
|
||||
public Set<BanAPI> bans() {
|
||||
Set<BanAPI> bans = new HashSet<>();
|
||||
for (BanEntry entry : getServer().getBanList(BanList.Type.NAME).getBanEntries()) {
|
||||
bans.add(BanAPI.fromMinecraft(entry));
|
||||
}
|
||||
return players;
|
||||
return bans;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,10 +2,7 @@ package xyz.etztech.serverapi.web;
|
|||
|
||||
import com.expediagroup.graphql.annotations.GraphQLName;
|
||||
import io.javalin.plugin.graphql.graphql.QueryGraphql;
|
||||
import xyz.etztech.serverapi.web.api.PlayerAPI;
|
||||
import xyz.etztech.serverapi.web.api.QueryAPI;
|
||||
import xyz.etztech.serverapi.web.api.TPSAPI;
|
||||
import xyz.etztech.serverapi.web.api.WorldAPI;
|
||||
import xyz.etztech.serverapi.web.api.*;
|
||||
|
||||
public class GraphQL implements QueryGraphql {
|
||||
private final IProvider provider;
|
||||
|
@ -14,6 +11,11 @@ public class GraphQL implements QueryGraphql {
|
|||
this.provider = provider;
|
||||
}
|
||||
|
||||
@GraphQLName("bans")
|
||||
public BanAPI[] getBans() {
|
||||
return provider.bans().toArray(new BanAPI[0]);
|
||||
}
|
||||
|
||||
@GraphQLName("players")
|
||||
public PlayerAPI[] getPlayers() {
|
||||
return provider.players().toArray(new PlayerAPI[0]);
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
package xyz.etztech.serverapi.web;
|
||||
|
||||
import xyz.etztech.serverapi.web.api.PlayerAPI;
|
||||
import xyz.etztech.serverapi.web.api.QueryAPI;
|
||||
import xyz.etztech.serverapi.web.api.TPSAPI;
|
||||
import xyz.etztech.serverapi.web.api.WorldAPI;
|
||||
import xyz.etztech.serverapi.web.api.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface IProvider {
|
||||
Set<PlayerAPI> bans();
|
||||
Set<BanAPI> bans();
|
||||
Set<PlayerAPI> players();
|
||||
QueryAPI query();
|
||||
TPSAPI TPS();
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
package xyz.etztech.serverapi.web.api;
|
||||
|
||||
import com.expediagroup.graphql.annotations.GraphQLDescription;
|
||||
import com.expediagroup.graphql.annotations.GraphQLDirective;
|
||||
import com.expediagroup.graphql.annotations.GraphQLName;
|
||||
import org.bukkit.BanEntry;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@GraphQLName("Ban")
|
||||
@GraphQLDescription("Ban GraphQL")
|
||||
public class BanAPI {
|
||||
private final String target;
|
||||
private final String source;
|
||||
private final String reason;
|
||||
private final long created;
|
||||
private final long expiration;
|
||||
|
||||
public BanAPI(String target, String source, String reason, long created, long expiration) {
|
||||
this.target = target;
|
||||
this.source = source;
|
||||
this.reason = reason;
|
||||
this.created = created;
|
||||
this.expiration = expiration;
|
||||
}
|
||||
|
||||
@GraphQLName("target")
|
||||
public String getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
@GraphQLName("source")
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
@GraphQLName("reason")
|
||||
public String getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
@GraphQLName("created")
|
||||
public long getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
@GraphQLName("expiration")
|
||||
public long getExpiration() {
|
||||
return expiration;
|
||||
}
|
||||
|
||||
public static BanAPI fromMinecraft(BanEntry entry) {
|
||||
long expiration = -1;
|
||||
if (entry.getExpiration() != null) {
|
||||
expiration = entry.getExpiration().getTime();
|
||||
}
|
||||
return new BanAPI(
|
||||
entry.getTarget(),
|
||||
entry.getSource(),
|
||||
entry.getReason(),
|
||||
entry.getCreated().getTime(),
|
||||
expiration
|
||||
);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@ package xyz.etztech.serverapi.web.api;
|
|||
|
||||
import com.expediagroup.graphql.annotations.GraphQLDescription;
|
||||
import com.expediagroup.graphql.annotations.GraphQLName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonNaming;
|
||||
import org.bukkit.World;
|
||||
|
||||
@GraphQLName("World")
|
||||
|
@ -14,11 +16,14 @@ public class WorldAPI {
|
|||
|
||||
private final String name;
|
||||
private final long time;
|
||||
@JsonProperty("full_time")
|
||||
private final long fullTime;
|
||||
private final int weather;
|
||||
|
||||
public WorldAPI(String name, long time, int weather) {
|
||||
public WorldAPI(String name, long time, long fullTime, int weather) {
|
||||
this.name = name;
|
||||
this.time = time;
|
||||
this.fullTime = fullTime;
|
||||
this.weather = weather;
|
||||
}
|
||||
|
||||
|
@ -28,10 +33,17 @@ public class WorldAPI {
|
|||
}
|
||||
|
||||
@GraphQLName("time")
|
||||
@GraphQLDescription("Hours * 1000")
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
@GraphQLName("full_time")
|
||||
@GraphQLDescription("Hours * 1000")
|
||||
public long getFullTime() {
|
||||
return fullTime;
|
||||
}
|
||||
|
||||
@GraphQLName("weather")
|
||||
public int getWeather() {
|
||||
return weather;
|
||||
|
@ -45,6 +57,6 @@ public class WorldAPI {
|
|||
state = WEATHER_THUNDER;
|
||||
}
|
||||
}
|
||||
return new WorldAPI(world.getName(), world.getFullTime(), state);
|
||||
return new WorldAPI(world.getName(), world.getTime(), world.getFullTime(), state);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package xyz.etztech.serverapi;
|
||||
|
||||
import xyz.etztech.serverapi.web.IProvider;
|
||||
import xyz.etztech.serverapi.web.api.PlayerAPI;
|
||||
import xyz.etztech.serverapi.web.api.QueryAPI;
|
||||
import xyz.etztech.serverapi.web.api.TPSAPI;
|
||||
import xyz.etztech.serverapi.web.api.WorldAPI;
|
||||
import xyz.etztech.serverapi.web.api.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -13,9 +10,9 @@ public class MockProvider implements IProvider {
|
|||
|
||||
public MockProvider() {
|
||||
worlds = Arrays.asList(
|
||||
new WorldAPI("overworld", 1000, WorldAPI.WEATHER_CLEAR),
|
||||
new WorldAPI("nether", 1500, WorldAPI.WEATHER_STORM),
|
||||
new WorldAPI("end", 2000, WorldAPI.WEATHER_THUNDER)
|
||||
new WorldAPI("overworld", 1000, 10000, WorldAPI.WEATHER_CLEAR),
|
||||
new WorldAPI("nether", 1500, 15000, WorldAPI.WEATHER_STORM),
|
||||
new WorldAPI("end", 2000, 20000, WorldAPI.WEATHER_THUNDER)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -31,7 +28,7 @@ public class MockProvider implements IProvider {
|
|||
return mock;
|
||||
}
|
||||
}
|
||||
return new WorldAPI("unknown", 0, WorldAPI.WEATHER_CLEAR);
|
||||
return new WorldAPI("unknown", 0, 0, WorldAPI.WEATHER_CLEAR);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,11 +37,12 @@ public class MockProvider implements IProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<PlayerAPI> bans() {
|
||||
public Set<BanAPI> bans() {
|
||||
long now = new Date().getTime();
|
||||
return new HashSet<>(Arrays.asList(
|
||||
new PlayerAPI("Badzelia", "bf0446a8-9695-4c41-aa4c-7ff45bfd1171"),
|
||||
new PlayerAPI("LessThanZeroSD", "fe7e8413-2570-4588-9203-2b69ff188bc3"),
|
||||
new PlayerAPI("Vakbuttzel", "7afbf663-2bf0-49ef-915f-22e81b298d17")
|
||||
new BanAPI("Etzelia", "Console", "Reasons", now, now),
|
||||
new BanAPI("Zero", "Notch", "lol lmao", now, now),
|
||||
new BanAPI("Vak", "Server", "brr", now, now)
|
||||
));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue