Updated to global api v2

This commit is contained in:
Tim203 2021-11-07 15:41:08 +01:00
parent 0b35449fb7
commit c18404cb52
No known key found for this signature in database
GPG key ID: 064EE9F5BF7C3EE8
4 changed files with 12 additions and 26 deletions

View file

@ -10,6 +10,12 @@
</parent>
<artifactId>common</artifactId>
<!-- Floodgate is still targeting Java 8 -->
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.geysermc.cumulus</groupId>

View file

@ -35,23 +35,21 @@ import java.util.Set;
public final class NewsItem {
private final int id;
private final String project;
private final boolean active;
private final NewsType type;
private final ItemData data;
private final boolean priority;
private final String message;
private final Set<NewsItemAction> actions;
private final String url;
private NewsItem(int id, String project, boolean active, NewsType type, ItemData data,
boolean priority, String message, Set<NewsItemAction> actions, String url) {
private NewsItem(
int id, boolean active, NewsType type, ItemData data,
String message, Set<NewsItemAction> actions, String url) {
this.id = id;
this.project = project;
this.active = active;
this.type = type;
this.data = data;
this.priority = priority;
this.message = message;
this.actions = Collections.unmodifiableSet(actions);
this.url = url;
@ -81,11 +79,9 @@ public final class NewsItem {
return new NewsItem(
newsItem.get("id").getAsInt(),
newsItem.get("project").getAsString(),
newsItem.get("active").getAsBoolean(),
newsType,
newsType.read(newsItem.getAsJsonObject("data")),
newsItem.get("priority").getAsBoolean(),
message,
actions,
newsItem.get("url").getAsString()
@ -96,14 +92,6 @@ public final class NewsItem {
return id;
}
public String getProject() {
return project;
}
public boolean isGlobal() {
return "all".equals(getProject());
}
public boolean isActive() {
return active;
}
@ -121,10 +109,6 @@ public final class NewsItem {
return (T) data;
}
public boolean isPriority() {
return priority;
}
public String getRawMessage() {
return message;
}

View file

@ -32,7 +32,7 @@ public final class Constants {
public static final URI GLOBAL_API_WS_URI;
public static final String NTP_SERVER = "time.cloudflare.com";
public static final String NEWS_OVERVIEW_URL = "https://api.geysermc.org/v1/news";
public static final String NEWS_OVERVIEW_URL = "https://api.geysermc.org/v2/news/";
public static final String NEWS_PROJECT_NAME = "geyser";
public static final String FLOODGATE_DOWNLOAD_LOCATION = "https://ci.opencollab.dev/job/GeyserMC/job/Floodgate/job/master/";

View file

@ -68,7 +68,7 @@ public class NewsHandler {
private void checkNews() {
try {
String body = WebUtils.getBody(Constants.NEWS_OVERVIEW_URL);
String body = WebUtils.getBody(Constants.NEWS_OVERVIEW_URL + Constants.NEWS_PROJECT_NAME);
JsonArray array = gson.fromJson(body, JsonArray.class);
try {
@ -144,10 +144,6 @@ public class NewsHandler {
return;
}
if (!item.isGlobal() && !Constants.NEWS_PROJECT_NAME.equals(item.getProject())) {
return;
}
switch (item.getType()) {
case ANNOUNCEMENT:
if (!item.getDataAs(AnnouncementData.class).isAffected(Constants.NEWS_PROJECT_NAME)) {