|
1 | 1 | package com.exaroton.api.server; |
2 | 2 |
|
3 | | -public class ServerStatus { |
4 | | - public static final int OFFLINE = 0; |
5 | | - public static final int ONLINE = 1; |
6 | | - public static final int STARTING = 2; |
7 | | - public static final int STOPPING = 3; |
8 | | - public static final int RESTARTING = 4; |
9 | | - public static final int SAVING = 5; |
10 | | - public static final int LOADING = 6; |
11 | | - public static final int CRASHED = 7; |
12 | | - public static final int PENDING = 8; |
13 | | - public static final int TRANSFERRING = 9; |
14 | | - public static final int PREPARING = 10; |
| 3 | +import com.exaroton.api.BrandColor; |
| 4 | + |
| 5 | +import java.util.Optional; |
| 6 | + |
| 7 | +/** |
| 8 | + * Server status |
| 9 | + */ |
| 10 | +public enum ServerStatus { |
| 11 | + OFFLINE(0, "Offline", BrandColor.DANGER), |
| 12 | + ONLINE(1, "Online", BrandColor.SUCCESS), |
| 13 | + STARTING(2, "Starting", BrandColor.LOADING), |
| 14 | + STOPPING(3, "Stopping", BrandColor.LOADING), |
| 15 | + RESTARTING(4, "Restarting", BrandColor.LOADING), |
| 16 | + SAVING(5, "Saving", BrandColor.LOADING), |
| 17 | + LOADING(6, "Loading", BrandColor.LOADING), |
| 18 | + CRASHED(7, "Crashed", BrandColor.DANGER), |
| 19 | + PENDING(8, "Pending", BrandColor.LOADING), |
| 20 | + TRANSFERRING(9, "Transferring", BrandColor.LOADING), |
| 21 | + PREPARING(10, "Preparing", BrandColor.LOADING), |
| 22 | + ; |
| 23 | + |
| 24 | + private final int value; |
| 25 | + private final String name; |
| 26 | + private final BrandColor color; |
| 27 | + |
| 28 | + ServerStatus(int value, String name, BrandColor color) { |
| 29 | + this.value = value; |
| 30 | + this.name = name; |
| 31 | + this.color = color; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Get the status by its numeric value |
| 36 | + * @param value numeric value |
| 37 | + * @return Empty if not found |
| 38 | + */ |
| 39 | + public static Optional<ServerStatus> fromValue(int value) { |
| 40 | + for (ServerStatus status : values()) { |
| 41 | + if (status.value == value) { |
| 42 | + return Optional.of(status); |
| 43 | + } |
| 44 | + } |
| 45 | + return Optional.empty(); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Get the numeric value of the status |
| 50 | + * @return numeric value |
| 51 | + */ |
| 52 | + public int getValue() { |
| 53 | + return value; |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Get the name of the status |
| 58 | + * @return name |
| 59 | + */ |
| 60 | + public String getName() { |
| 61 | + return name; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Get the color of the status |
| 66 | + * @return color |
| 67 | + */ |
| 68 | + public BrandColor getColor() { |
| 69 | + return color; |
| 70 | + } |
15 | 71 | } |
0 commit comments