Skip to content

Commit

Permalink
Add back CWA EEW
Browse files Browse the repository at this point in the history
  • Loading branch information
TenkyuChimata committed Apr 2, 2024
1 parent c8a92fd commit cebb6f5
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>jp.wolfx</groupId>
<artifactId>MCEEW</artifactId>
<version>2.4.1-b1</version>
<version>2.4.1-b2</version>
<packaging>jar</packaging>

<name>MCEEW</name>
Expand Down
90 changes: 89 additions & 1 deletion src/main/java/jp/wolfx/mceew/MCEEW.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@

public final class MCEEW extends JavaPlugin {
private static int config_version;
private static final int current_config = 4;
private static final int current_config = 5;
private static boolean jpEewBoolean;
private static boolean scEewBoolean;
private static boolean fjEewBoolean;
private static boolean cwaEewBoolean;
private static boolean broadcast_bool;
private static boolean title_bool;
private static boolean alert_bool;
Expand All @@ -55,6 +56,9 @@ public final class MCEEW extends JavaPlugin {
private static String fj_broadcast_message;
private static String fj_title_message;
private static String fj_subtitle_message;
private static String cwa_broadcast_message;
private static String cwa_title_message;
private static String cwa_subtitle_message;
private static String alert_alert_sound_type;
private static double alert_alert_sound_volume;
private static double alert_alert_sound_pitch;
Expand All @@ -67,6 +71,9 @@ public final class MCEEW extends JavaPlugin {
private static String fj_alert_sound_type;
private static double fj_alert_sound_volume;
private static double fj_alert_sound_pitch;
private static String cwa_alert_sound_type;
private static double cwa_alert_sound_volume;
private static double cwa_alert_sound_pitch;
private static String jmaEqlist_md5 = null;
private static String cencEqlist_md5 = null;
private static JsonObject jmaEqlistData = null;
Expand Down Expand Up @@ -130,6 +137,17 @@ private static void eewTest(int flag) {
String type = "最終報";
String origin_time = getDate("yyyy-MM-dd HH:mm:ss", time_format, "Asia/Shanghai", origin_time_str);
fjEewAction(report_time, origin_time, num, lat, lon, region, mag, type);
} else if (flag == 4) {
String origin_time_str = "2024-04-01 13:51:25";
String report_time = "2024-04-01 13:51:46";
String num = "1";
String lat = "23.36";
String lon = "120.2";
String region = "嘉義縣義竹鄉";
String mag = "4.8";
String depth = "10km";
String origin_time = getDate("yyyy-MM-dd HH:mm:ss", time_format, "Asia/Shanghai", origin_time_str);
cwaEewAction(report_time, origin_time, num, lat, lon, region, mag, depth);
} else {
String flags = "予報";
String origin_time_str = "2024/02/29 18:35:38";
Expand Down Expand Up @@ -261,6 +279,9 @@ public CompletionStage<?> onText(WebSocket webSocket, CharSequence data, boolean
if (Objects.equals(json.get("type").getAsString(), "fj_eew") && fjEewBoolean) {
fjEewExecute(json);
}
if (Objects.equals(json.get("type").getAsString(), "cwa_eew") && cwaEewBoolean) {
cwaEewExecute(json);
}
if (Objects.equals(json.get("type").getAsString(), "cenc_eqlist")) {
cencEqlistData = json;
cencEqlistExecute(cencEqlistBoolean);
Expand Down Expand Up @@ -435,6 +456,18 @@ private static void fjEewExecute(JsonObject fjEewData) {
fjEewAction(report_time, origin_time, num, lat, lon, region, mag, type);
}

private static void cwaEewExecute(JsonObject cwaEewData) {
String report_time = cwaEewData.get("ReportTime").getAsString();
String num = cwaEewData.get("ReportNum").getAsString();
String lat = cwaEewData.get("Latitude").getAsString();
String lon = cwaEewData.get("Longitude").getAsString();
String region = cwaEewData.get("HypoCenter").getAsString();
String mag = cwaEewData.get("Magunitude").getAsString();
String depth = cwaEewData.get("Depth").getAsString() + "km";
String origin_time = getDate("yyyy-MM-dd HH:mm:ss", time_format, "Asia/Shanghai", cwaEewData.get("OriginTime").getAsString());
cwaEewAction(report_time, origin_time, num, lat, lon, region, mag, depth);
}

private static void getEewInfo(Boolean flag, CommandSender sender) {
if (flag) {
if (cencEqlist_md5 != null) {
Expand Down Expand Up @@ -662,6 +695,50 @@ private static void fjEewAction(String report_time, String origin_time, String n
}
}

private static void cwaEewAction(String report_time, String origin_time, String num, String lat, String lon, String region, String mag, String depth) {
if (broadcast_bool) {
Bukkit.broadcastMessage(
cwa_broadcast_message.
replaceAll("%report_time%", report_time).
replaceAll("%origin_time%", origin_time).
replaceAll("%num%", num).
replaceAll("%lat%", lat).
replaceAll("%lon%", lon).
replaceAll("%region%", region).
replaceAll("%mag%", mag).
replaceAll("%depth%", depth)
);
}
if (title_bool) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
player.sendTitle(
cwa_title_message.
replaceAll("%report_time%", report_time).
replaceAll("%origin_time%", origin_time).
replaceAll("%num%", num).
replaceAll("%lat%", lat).
replaceAll("%lon%", lon).
replaceAll("%region%", region).
replaceAll("%mag%", mag).
replaceAll("%depth%", depth),
cwa_subtitle_message.
replaceAll("%report_time%", report_time).
replaceAll("%origin_time%", origin_time).
replaceAll("%num%", num).
replaceAll("%lat%", lat).
replaceAll("%lon%", lon).
replaceAll("%region%", region).
replaceAll("%mag%", mag).
replaceAll("%depth%", depth),
-1, -1, -1
);
}
}
if (alert_bool) {
playSound(cwa_alert_sound_type, cwa_alert_sound_volume, cwa_alert_sound_pitch);
}
}

private static String getShindoColor(String shindo) {
String[] shindo_color = new String[]{"§f", "§7", "§b", "§9", "§a", "§e", "§6", "§c", "§4", "§d"};
if (Objects.equals(shindo, "1")) {
Expand Down Expand Up @@ -732,12 +809,16 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
} else if (args[1].equalsIgnoreCase("fj")) {
eewTest(3);
return true;
} else if (args[1].equalsIgnoreCase("cwa")) {
eewTest(4);
return true;
}
} else {
sender.sendMessage("§a[MCEEW] §3/eew test forecast§a - Run JMA Forecast EEW test.");
sender.sendMessage("§a[MCEEW] §3/eew test alert§a - Run JMA Alert EEW test.");
sender.sendMessage("§a[MCEEW] §3/eew test sc§a - Run Sichuan EEW test.");
sender.sendMessage("§a[MCEEW] §3/eew test fj§a - Run Taiwan/Fujian EEW test.");
sender.sendMessage("§a[MCEEW] §3/eew test cwa§a - Run Taiwan CWA EEW test.");
return true;
}
}
Expand All @@ -751,6 +832,7 @@ private void loadEew(Boolean first) {
jpEewBoolean = this.getConfig().getBoolean("enable_jp");
scEewBoolean = this.getConfig().getBoolean("enable_sc");
fjEewBoolean = this.getConfig().getBoolean("enable_fj");
cwaEewBoolean = this.getConfig().getBoolean("enable_cwa");
broadcast_bool = this.getConfig().getBoolean("Action.broadcast");
title_bool = this.getConfig().getBoolean("Action.title");
alert_bool = this.getConfig().getBoolean("Action.alert");
Expand All @@ -771,6 +853,9 @@ private void loadEew(Boolean first) {
fj_broadcast_message = Objects.requireNonNull(this.getConfig().getString("Message.Fjea.broadcast")).replace("&", "§");
fj_title_message = Objects.requireNonNull(this.getConfig().getString("Message.Fjea.title")).replace("&", "§");
fj_subtitle_message = Objects.requireNonNull(this.getConfig().getString("Message.Fjea.subtitle")).replace("&", "§");
cwa_broadcast_message = Objects.requireNonNull(this.getConfig().getString("Message.Cwa.broadcast")).replace("&", "§");
cwa_title_message = Objects.requireNonNull(this.getConfig().getString("Message.Cwa.title")).replace("&", "§");
cwa_subtitle_message = Objects.requireNonNull(this.getConfig().getString("Message.Cwa.subtitle")).replace("&", "§");
alert_alert_sound_type = this.getConfig().getString("Sound.Alert.type");
alert_alert_sound_volume = this.getConfig().getDouble("Sound.Alert.volume");
alert_alert_sound_pitch = this.getConfig().getDouble("Sound.Alert.pitch");
Expand All @@ -783,6 +868,9 @@ private void loadEew(Boolean first) {
fj_alert_sound_type = this.getConfig().getString("Sound.Fjea.type");
fj_alert_sound_volume = this.getConfig().getDouble("Sound.Fjea.volume");
fj_alert_sound_pitch = this.getConfig().getDouble("Sound.Fjea.pitch");
cwa_alert_sound_type = this.getConfig().getString("Sound.Cwa.type");
cwa_alert_sound_volume = this.getConfig().getDouble("Sound.Cwa.volume");
cwa_alert_sound_pitch = this.getConfig().getDouble("Sound.Cwa.pitch");
config_version = this.getConfig().getInt("config-version");
mceewScheduler(first);
}
Expand Down
17 changes: 15 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# MCEEW configuration
# Last updated on 2.4.0
# Last updated on 2.4.1
#
# API Source: https://api.wolfx.jp
# Plugin Page: https://acg.kr/mceew
Expand Down Expand Up @@ -33,6 +33,9 @@ enable_sc: true
# Enable Taiwan/Fujian EEW broadcast
enable_fj: true

# Enable Taiwan CWA EEW broadcast
enable_cwa: true

# Set the time format
time_format: "yyyy年MM月dd日 HH時mm分ss秒"

Expand Down Expand Up @@ -78,6 +81,11 @@ Message:
broadcast: "&c福建局地震預警 | 第%num%報 %type%\n &e%origin_time% &f發生\n &f震央: &e%region% (北緯: &e%lat%度 東經: &e%lon%度)\n &f規模: &e%mag%\n &f更新時間: &e%report_time%"
title: "&c福建局地震預警"
subtitle: "&e%region%发生芮氏規模%mag%地震"
# Set the Taiwan CWA EEW message format
Cwa:
broadcast: "&c台灣地震預警 | 第%num%報\n &e%origin_time% &f發生\n &f震央: &e%region% (北緯: &e%lat%度 東經: &e%lon%度)\n &f規模: &e%mag%\n &f深度: &e%depth%\n &f更新時間: &e%report_time%"
title: "&c台灣地震預警"
subtitle: "&e%region%发生芮氏規模%mag%地震"

Sound:
# Set the Japan JMA EEW alert report alert
Expand All @@ -103,6 +111,11 @@ Sound:
type: "BLOCK_NOTE_BLOCK_PLING"
volume: 1000.0
pitch: 1.0
# Set the Taiwan CWA EEW alert
Cwa:
type: "BLOCK_NOTE_BLOCK_PLING"
volume: 1000.0
pitch: 1.0

# Do not change this
config-version: 4
config-version: 5

0 comments on commit cebb6f5

Please sign in to comment.