ServerAPI/src/main/java/xyz/etztech/serverapi/web/api/WorldAPI.java

51 lines
1.3 KiB
Java

package xyz.etztech.serverapi.web.api;
import com.expediagroup.graphql.annotations.GraphQLDescription;
import com.expediagroup.graphql.annotations.GraphQLName;
import org.bukkit.World;
@GraphQLName("World")
@GraphQLDescription("World GraphQL")
public class WorldAPI {
public static int WEATHER_UNKNOWN = -1;
public static int WEATHER_CLEAR = 0;
public static int WEATHER_STORM = 1;
public static int WEATHER_THUNDER = 2;
private final String name;
private final long time;
private final int weather;
public WorldAPI(String name, long time, int weather) {
this.name = name;
this.time = time;
this.weather = weather;
}
@GraphQLName("name")
public String getName() {
return name;
}
@GraphQLName("time")
public long getTime() {
return time;
}
@GraphQLName("weather")
public int getWeather() {
return weather;
}
public static WorldAPI fromMinecraft(World world) {
int state = WEATHER_CLEAR;
if (world.hasStorm()) {
state = WEATHER_STORM;
if (world.isThundering()) {
state = WEATHER_THUNDER;
}
}
return new WorldAPI(world.getName(), world.getFullTime(), state);
}
}