diff --git a/data/GameAnnouncement.json b/data/GameAnnouncement.json
index 2bce06fdb..96c88f17c 100644
--- a/data/GameAnnouncement.json
+++ b/data/GameAnnouncement.json
@@ -1,29 +1,22 @@
{
-"list": [
- {
- "ann_id": 1,
- "title": "Welcome to Grasscutter!",
- "subtitle": "Welcome",
- "banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/17/f4aa42d505822805eebf4a55d72a78d8_2755691727027973637.jpg",
- "content": "Hi there!
First of all, welcome to Grasscutter. If you have any issues, please let us know so that Lawnmower can help you! Check out our:
",
- "lang": "es-es"
- },
- {
- "ann_id": 2,
- "title": "How to use announcements",
- "subtitle": "How to use",
- "banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/17/f4aa42d505822805eebf4a55d72a78d8_2755691727027973637.jpg",
- "content": "Tips
>How to use announcements
>Announcement content can use HTML
>The specific content of the announcement is stored in the program directorydata/GameAnnouncement.json
, whileGameAnnouncementList.json
stores the announcement list data
How to use
>In GameAnnouncement
Parameters | Description |
---|
ann_Id | Announcement unique id |
---|
title | Show at the top of the content |
---|
subtitle | title shown on the left |
---|
banner | Display between content and title |
---|
content | as u see |
---|
lang | display language |
---|
total | Announcement quantity |
---|
>In GameAnnouncementList
If you want to add an annouement, please add the list data in the announcement type corresponding to GameAnnouncementList, and finally add the announcement content in GameAnnouncement",
- "lang": "es-es"
- },
- {
- "ann_id": 3,
- "title": "这是活动公告--This is the event announcement",
- "subtitle": "Welcome",
- "banner":"https://uploadstatic-sea.mihoyo.com/announcement/2020/09/22/7d85f19b152d218e73224d7c138a0fd0_5818585260283672899.jpg",
- "content": "Welcome",
- "lang": "es-es"
- }
-],
-"total": 3
+ "list": [
+ {
+ "ann_id": 1,
+ "title": "Welcome to Grasscutter!",
+ "subtitle": "Welcome!",
+ "banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/17/f4aa42d505822805eebf4a55d72a78d8_2755691727027973637.jpg",
+ "content": "Hi there!
First of all, welcome to Grasscutter. If you have any issues, please let us know so that Lawnmower can help you!
銆揇iscord銆
https://discord.gg/T5vZU6UyeG
銆揋itHub銆https://github.com/Grasscutters/Grasscutter",
+
+ "lang": "en-US"
+ },
+ {
+ "ann_id": 2,
+ "title": "How to use announcements",
+ "subtitle": "How to use announcements",
+ "banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/17/f4aa42d505822805eebf4a55d72a78d8_2755691727027973637.jpg",
+ "content": "
Announcement content uses HTML. The specific content of the announcement is stored in the program directory GameAnnouncement.json
, while GameAnnouncementList.json
stores the announcement list data.
GameAnnouncement
Parameter | Description |
---|
ann_id | Unique ID |
title | Title shown at the top of the content |
subtitle | Short title shown on the left |
banner | Image to display between content and title |
content | Content body in HTML |
lang | Language code for this entry |
GameAnnouncementList
If you want to add an announcement, please add the list data in the announcement type corresponding to GameAnnouncementList
, and finally add the announcement content in GameAnnouncement
.
",
+ "lang": "en-US"
+ }
+ ],
+ "total": 2
}
\ No newline at end of file
diff --git a/data/GameAnnouncementList.json b/data/GameAnnouncementList.json
index ea3091fc7..f6566960a 100644
--- a/data/GameAnnouncementList.json
+++ b/data/GameAnnouncementList.json
@@ -5,115 +5,57 @@
"list": [
{
"ann_id": 1,
- "title": "Welcome to Grasscutter!",
- "subtitle": "Welcome",
+
+ "title": "Welcome to Grasscutter!",
+ "subtitle": "Welcome!",
"banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/22/7d85f19b152d218e73224d7c138a0fd0_5818585260283672899.jpg",
- "content": "",
- "type_label": "Juego",
- "tag_label": "1",
"tag_icon": "https://uploadstatic-sea.mihoyo.com/announcement/2020/03/05/a2588f1a51faee9fa8dfe9aead649dd6_7237021399135895303.png",
- "login_alert": 1,
- "lang": "es-es",
- "start_time": "2020-09-25 04:05:30",
- "end_time": "2023-10-30 11:00:00",
"type": 2,
- "remind": 0,
- "alert": 0,
- "tag_start_time": "2000-01-02 15:04:05",
- "tag_end_time": "2030-01-02 15:04:05",
- "remind_ver": 1,
- "has_content": true,
- "extra_remind": 0
+ "type_label": "System",
+ "lang": "en-US",
+ "start_time": "2020-09-25 04:05:30",
+ "end_time": "2030-10-30 11:00:00",
+ "content": "",
+ "has_content": true
},
{
"ann_id": 2,
- "title": "这是游戏公告 -- This is the game announcement",
- "subtitle": "This is the game announcement",
- "banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/17/85b7163c95745a76d49b3d163d893592_6487108933004985049.jpg",
- "content": "",
- "type_label": "Juego",
- "tag_label": "1",
+ "title": "How to use announcements",
+ "subtitle": "How to use announcements",
+ "banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/22/7d85f19b152d218e73224d7c138a0fd0_5818585260283672899.jpg",
"tag_icon": "https://uploadstatic-sea.mihoyo.com/announcement/2020/03/05/a2588f1a51faee9fa8dfe9aead649dd6_7237021399135895303.png",
- "login_alert": 1,
- "lang": "es-es",
- "start_time": "2020-09-25 15:12:09",
- "end_time": "2030-10-30 11:00:00",
"type": 2,
- "remind": 0,
- "alert": 0,
- "tag_start_time": "2000-01-02 08:04:05",
- "tag_end_time": "2030-01-02 08:04:05",
- "remind_ver": 1,
- "has_content": true,
- "extra_remind": 0
+ "type_label": "System",
+ "lang": "en-US",
+ "start_time": "2020-09-25 04:05:30",
+ "end_time": "2030-10-30 11:00:00",
+ "content": "",
+ "has_content": true
}
],
"type_id": 2,
- "type_label": "Juego"
- },
- {
- "list": [
- {
- "ann_id": 3,
- "title": "这是活动公告--This is the event announcement",
- "subtitle": "Welcome",
- "banner": "https://uploadstatic-sea.mihoyo.com/announcement/2020/09/22/7d85f19b152d218e73224d7c138a0fd0_5818585260283672899.jpg",
- "content": "",
- "type_label": "Eventos",
- "tag_label": "1",
- "tag_icon": "https://uploadstatic-sea.mihoyo.com/announcement/2020/03/05/a2588f1a51faee9fa8dfe9aead649dd6_7237021399135895303.png",
- "login_alert": 1,
- "lang": "es-es",
- "start_time": "2020-09-25 04:05:30",
- "end_time": "2022-05-02 00:51:00",
- "type": 2,
- "remind": 0,
- "alert": 0,
- "tag_start_time": "2000-01-02 15:04:05",
- "tag_end_time": "2022-05-02 00:51:00",
- "remind_ver": 1,
- "has_content": true,
- "extra_remind": 0
- }
- ],
- "type_id": 1,
- "type_label": "Eventos"
+ "type_label": "System"
},
{
"list": [
{}
],
"type_id": 3,
- "type_label": "Others"
+ "type_label": "Events"
}
],
- "total": 3,
+ "total": 2,
"type_list": [
{
"id": 2,
- "name": "游戏系统公告",
- "mi18n_name": "Juego"
+ "name": "娓告垙绯荤粺鍏憡",
+ "mi18n_name": "System"
},
{
"id": 1,
- "name": "活动公告",
- "mi18n_name": "Eventos"
- },
- {
- "id": 3,
- "name": "其他",
- "mi18n_name": "Others"
+ "name": "娲诲姩鍏憡",
+ "mi18n_name": "Activity"
}
],
- "alert": true,
- "alert_id": 2,
- "timezone": -5,
- "pic_list": [
- ],
- "pic_total": 0,
- "pic_type_list": [
- ],
- "pic_alert": false,
- "pic_alert_id": 0,
- "static_sign": ""
+ "timezone": -5
}
\ No newline at end of file
diff --git a/src/main/java/emu/grasscutter/server/dispatch/AnnouncementHandler.java b/src/main/java/emu/grasscutter/server/dispatch/AnnouncementHandler.java
index ab752c8e1..a3e69113b 100644
--- a/src/main/java/emu/grasscutter/server/dispatch/AnnouncementHandler.java
+++ b/src/main/java/emu/grasscutter/server/dispatch/AnnouncementHandler.java
@@ -5,34 +5,39 @@ import express.http.HttpContextHandler;
import express.http.Request;
import express.http.Response;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Objects;
import static emu.grasscutter.Configuration.*;
public final class AnnouncementHandler implements HttpContextHandler {
@Override
- public void handle(Request request, Response response) throws IOException {//event
+ public void handle(Request request, Response response) throws IOException {
if (Objects.equals(request.baseUrl(), "/common/hk4e_global/announcement/api/getAnnContent")) {
- response.send("{\"retcode\":0,\"message\":\"OK\",\"data\":" + readToString(new File(DATA("GameAnnouncement.json"))) +"}");
+ String data = readToString(Paths.get(DATA("GameAnnouncement.json")));
+
+ response.send("{\"retcode\":0,\"message\":\"OK\",\"data\":" + data + "}");
} else if (Objects.equals(request.baseUrl(), "/common/hk4e_global/announcement/api/getAnnList")) {
- String data = readToString(new File(DATA("GameAnnouncementList.json"))).replace("System.currentTimeMillis()",String.valueOf(System.currentTimeMillis()));
- response.send("{\"retcode\":0,\"message\":\"OK\",\"data\": "+data +"}");
+ String data = readToString(Paths.get(DATA("GameAnnouncementList.json")))
+ .replace("System.currentTimeMillis()", String.valueOf(System.currentTimeMillis()));
+
+ response.send("{\"retcode\":0,\"message\":\"OK\",\"data\": " + data + "}");
}
}
- @SuppressWarnings("ResultOfMethodCallIgnored")
- private static String readToString(File file) {
- long length = file.length();
- byte[] content = new byte[(int) length];
+
+ private static String readToString(Path path) {
+ String content = "";
+
try {
- FileInputStream in = new FileInputStream(file);
- in.read(content); in.close();
+ content = Files.readString(path, StandardCharsets.UTF_8);
} catch (IOException ignored) {
- Grasscutter.getLogger().warn("File not found: " + file.getAbsolutePath());
+ Grasscutter.getLogger().warn("Unable to open file " + path.toAbsolutePath());
}
- return new String(content);
+ return content;
}
}
\ No newline at end of file