Skip to content

Commit

Permalink
Fix manual earthquake information get were..
Browse files Browse the repository at this point in the history
..not working when EEW was disabled in configuration.
  • Loading branch information
TenkyuChimata committed Jul 12, 2023
1 parent 58ca39d commit 25d8a0b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 82 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ A real-time Earthquake Early Warning(EEW) plugin for Minecraft Server.
* **Supports Spigot/Paper/Folia 1.13+.**
* **Receives Japan JMA EEW.**
* **Receives JMA final reports.**
* **Receives Taiwan CWB EEW.**
* **Receives Sichuan China EEW.**
* **Broadcast messages to chat.**
* **Broadcast messages to title.**
* **Alerts when an earthquake is detected.**
* **Allows manual get earthquake information.**
* **Customizable broadcast messages.**
* **Customizable intensity colors.**
* **Customizable alert sounds.**
* **Customizable EEW switch.**
* **Supports EEW send test.**

## Commands

* List available commands: /eew
* Get the JMA final report /eew final
* Get earthquake information: /eew info
* Run EEW send test: /eew test (need admin)
* Reload configuration: /eew reload (need admin)

Expand All @@ -35,6 +35,7 @@ A real-time Earthquake Early Warning(EEW) plugin for Minecraft Server.
![1.png](https://s2.loli.net/2023/07/12/QSyfaT8DxYBdcs3.png)
![2.png](https://s2.loli.net/2023/07/12/SB3jP2TslVDnR4F.png)
![3.png](https://s2.loli.net/2023/07/12/d58aXyUEieQDN7Z.png)
![4.png](https://s2.loli.net/2023/07/12/y16andOfi4FhkuU.png)
![5.png](https://s2.loli.net/2023/07/12/XMtCy2UfjOqIdY1.png)

## Bstats
Expand Down
43 changes: 0 additions & 43 deletions README_new.md

This file was deleted.

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.2.1-b8</version>
<version>2.2.1</version>
<packaging>jar</packaging>

<name>MCEEW</name>
Expand Down
62 changes: 32 additions & 30 deletions src/main/java/jp/wolfx/mceew/MCEEW.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,20 @@ private static boolean isFolia() {
}
}

private void mceewScheduler(boolean eewBoolean, boolean jpEewBoolean, boolean finalBoolean, boolean scEewBoolean, boolean cwbEewBoolean, boolean updaterBoolean) {
private void mceewScheduler(boolean jpEewBoolean, boolean finalBoolean, boolean scEewBoolean, boolean cwbEewBoolean, boolean updaterBoolean) {
if (!folia) {
Bukkit.getLogger().info("[MCEEW] Using Bukkit API for Scheduler");
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::getEewData, 20L, 20L);
if (eewBoolean) {
Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> eewChecker(jpEewBoolean, finalBoolean, scEewBoolean, cwbEewBoolean), 20L, 20L);
}
Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> eewChecker(jpEewBoolean, finalBoolean, scEewBoolean, cwbEewBoolean), 20L, 20L);
if (updaterBoolean) {
Bukkit.getLogger().info("[MCEEW] Using Bukkit API for Scheduler");
Bukkit.getScheduler().runTaskAsynchronously(this, this::updater);
}
} else {
Bukkit.getLogger().info("[MCEEW] Using Folia API for Scheduler");
Plugin plugin = this;
Bukkit.getAsyncScheduler().runAtFixedRate(plugin, task1 -> getEewData(), 1L, 1L, TimeUnit.SECONDS);
if (eewBoolean) {
Bukkit.getAsyncScheduler().runAtFixedRate(plugin, task2 -> eewChecker(jpEewBoolean, finalBoolean, scEewBoolean, cwbEewBoolean), 1L, 1L, TimeUnit.SECONDS);
}
Bukkit.getAsyncScheduler().runAtFixedRate(plugin, task2 -> eewChecker(jpEewBoolean, finalBoolean, scEewBoolean, cwbEewBoolean), 1L, 1L, TimeUnit.SECONDS);
if (updaterBoolean) {
Bukkit.getLogger().info("[MCEEW] Using Folia API for Scheduler");
Bukkit.getAsyncScheduler().runNow(plugin, task3 -> updater());
}
}
Expand Down Expand Up @@ -190,14 +186,14 @@ private void eewChecker(boolean jpEewBoolean, boolean finalBoolean, boolean scEe
if (jpEewBoolean && jmaEewData != null) {
jmaEewExecute();
}
if (finalBoolean && jmaEqlistData != null) {
jmaEqlistExecute();
if (jmaEqlistData != null) {
jmaEqlistExecute(finalBoolean);
}
if (scEewBoolean && scEewData != null) {
scEewExecute();
if (scEewData != null) {
scEewExecute(scEewBoolean);
}
if (cwbEewBoolean && cwbEewData != null) {
cwbEewExecute();
if (cwbEewData != null) {
cwbEewExecute(cwbEewBoolean);
}
}

Expand Down Expand Up @@ -243,7 +239,7 @@ private static void jmaEewExecute() {
}
}

private static void jmaEqlistExecute() {
private static void jmaEqlistExecute(Boolean finalBoolean) {
if (!Objects.equals(jmaEqlistData.get("md5").getAsString(), final_md5)) {
String time_str = jmaEqlistData.get("No1").getAsJsonObject().get("time").getAsString();
String region = jmaEqlistData.get("No1").getAsJsonObject().get("location").getAsString();
Expand All @@ -256,15 +252,17 @@ private static void jmaEqlistExecute() {
if (debug_bool) {
Bukkit.getLogger().info("[MCEEW] Japan final report updated.");
}
Bukkit.broadcastMessage(
final_broadcast_message.
replaceAll("%origin_time%", origin_time).
replaceAll("%region%", region).
replaceAll("%mag%", mag).
replaceAll("%depth%", depth).
replaceAll("%shindo%", getShindoColor(shindo)).
replaceAll("%info%", info)
);
if (finalBoolean) {
Bukkit.broadcastMessage(
final_broadcast_message.
replaceAll("%origin_time%", origin_time).
replaceAll("%region%", region).
replaceAll("%mag%", mag).
replaceAll("%depth%", depth).
replaceAll("%shindo%", getShindoColor(shindo)).
replaceAll("%info%", info)
);
}
}
final_md5 = jmaEqlistData.get("md5").getAsString();
final_info.clear();
Expand All @@ -281,7 +279,7 @@ private static void jmaEqlistExecute() {
}
}

private static void scEewExecute() {
private static void scEewExecute(Boolean scEewBoolean) {
if (!Objects.equals(scEewData.get("EventID").getAsString(), EventID)) {
String report_time = scEewData.get("ReportTime").getAsString();
String num = scEewData.get("ReportNum").getAsString();
Expand All @@ -299,7 +297,9 @@ private static void scEewExecute() {
if (debug_bool) {
Bukkit.getLogger().info("[MCEEW] Sichuan EEW detected.");
}
scEewAction(report_time, origin_time, num, lat, lon, region, mag, depth + "km", getIntensityColor(intensity));
if (scEewBoolean) {
scEewAction(report_time, origin_time, num, lat, lon, region, mag, depth + "km", getIntensityColor(intensity));
}
}
EventID = scEewData.get("EventID").getAsString();
sc_info.clear();
Expand All @@ -319,7 +319,7 @@ private static void scEewExecute() {
}
}

private static void cwbEewExecute() {
private static void cwbEewExecute(Boolean cwbEewBoolean) {
if (!Objects.equals(cwbEewData.get("ReportTime").getAsString(), cwbTS)) {
String report_time = cwbEewData.get("ReportTime").getAsString();
String num = cwbEewData.get("ReportNum").getAsString();
Expand All @@ -333,7 +333,9 @@ private static void cwbEewExecute() {
if (debug_bool) {
Bukkit.getLogger().info("[MCEEW] Taiwan EEW detected.");
}
cwbEewAction(report_time, origin_time, num, lat, lon, region, mag, depth);
if (cwbEewBoolean) {
cwbEewAction(report_time, origin_time, num, lat, lon, region, mag, depth);
}
}
cwbTS = cwbEewData.get("ReportTime").getAsString();
cwb_info.clear();
Expand Down Expand Up @@ -769,7 +771,7 @@ private void loadEew(boolean first) {
cwb_alert_sound_type = this.getConfig().getString("Sound.Taiwan.type");
cwb_alert_sound_volume = this.getConfig().getDouble("Sound.Taiwan.volume");
cwb_alert_sound_pitch = this.getConfig().getDouble("Sound.Taiwan.pitch");
this.mceewScheduler(this.getConfig().getBoolean("EEW"), this.getConfig().getBoolean("enable_jp"), this.getConfig().getBoolean("Action.final"), this.getConfig().getBoolean("enable_sc"), this.getConfig().getBoolean("enable_cwb"), first);
this.mceewScheduler(this.getConfig().getBoolean("enable_jp"), this.getConfig().getBoolean("Action.final"), this.getConfig().getBoolean("enable_sc"), this.getConfig().getBoolean("enable_cwb"), first);
}

@Override
Expand Down
9 changes: 3 additions & 6 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@
# \n Change to next line
########################

# Enable all EEW
EEW: true

# Enable Japan JMA EEW
# Enable Japan JMA EEW broadcast
enable_jp: true

# Enable Sichuan EEW
# Enable Sichuan EEW broadcast
enable_sc: true

# Enable Taiwan CWB EEW
# Enable Taiwan CWB EEW broadcast
enable_cwb: true

# Set the time format
Expand Down

0 comments on commit 25d8a0b

Please sign in to comment.