58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package serverapi
|
|
|
|
import "fmt"
|
|
|
|
// Weather described the weather of a Minecraft World
|
|
type Weather int
|
|
|
|
const (
|
|
// Clear weather
|
|
WeatherClear Weather = iota
|
|
// Raining/Snowing
|
|
WeatherStorm
|
|
// Thundering
|
|
WeatherThunder
|
|
)
|
|
|
|
// String is human-friendly Weather
|
|
func (w Weather) String() string {
|
|
switch w {
|
|
case WeatherClear:
|
|
return "clear"
|
|
case WeatherStorm:
|
|
return "storm"
|
|
case WeatherThunder:
|
|
return "thunder"
|
|
default:
|
|
return "unknown"
|
|
}
|
|
}
|
|
|
|
// World is a Minecraft world
|
|
type World struct {
|
|
Name string `json:"name"`
|
|
Weather Weather `json:"weather"`
|
|
Time int64 `json:"time"`
|
|
FullTime int64 `json:"full_time"`
|
|
}
|
|
|
|
// TimeHours returns Time in hours
|
|
func (w *World) TimeHours() int64 {
|
|
return w.Time / 1000
|
|
}
|
|
|
|
// FullTimeHours returns FullTime in hours
|
|
func (w *World) FullTimeHours() int64 {
|
|
return w.FullTime / 1000
|
|
}
|
|
|
|
// World returns a single World from a ServerAPI instance
|
|
func (c *Client) World(name string) (world *World, err error) {
|
|
return world, c.jsonGET(fmt.Sprintf("%s/worlds/%s", c.endpoint, name), &world)
|
|
}
|
|
|
|
// Worlds returns a list of World from a ServerAPI instance
|
|
func (c *Client) Worlds() (worlds Worlds, err error) {
|
|
return worlds, c.jsonGET(fmt.Sprintf("%s/worlds", c.endpoint), &worlds)
|
|
}
|