From d67b003457d4a76533b8edcb13d062815279d313 Mon Sep 17 00:00:00 2001 From: Mykyta Date: Wed, 17 Jul 2019 11:08:23 -0700 Subject: [PATCH] =?UTF-8?q?=E2=8F=B0=20Timer=20fixes=20(actionbar=20fixed?= =?UTF-8?q?=20as=20a=20result)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- src/main/java/xyz/nkomarn/Harbor/Harbor.java | 8 ++++--- .../java/xyz/nkomarn/Harbor/nms/NMSUtils.java | 22 +++++++++---------- .../java/xyz/nkomarn/Harbor/task/Timer.java | 12 +++++----- .../xyz/nkomarn/Harbor/util/Counters.java | 10 +++++---- src/main/resources/config.yml | 2 +- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/pom.xml b/pom.xml index 1bcfd30..a5dc809 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 xyz.nkomarn Harbor - 1.5.1 + 1.5.2 UTF-8 diff --git a/src/main/java/xyz/nkomarn/Harbor/Harbor.java b/src/main/java/xyz/nkomarn/Harbor/Harbor.java index 8e00e65..506339b 100644 --- a/src/main/java/xyz/nkomarn/Harbor/Harbor.java +++ b/src/main/java/xyz/nkomarn/Harbor/Harbor.java @@ -21,7 +21,7 @@ import java.util.stream.Stream; public class Harbor extends JavaPlugin { public static Harbor instance; - public static String version = "1.5.1"; + public static String version = "1.5.2"; public static boolean debug = false; public static boolean enabled = false; public static boolean prerelease = false; @@ -50,7 +50,9 @@ public class Harbor extends JavaPlugin { }); }); - if (enabled) Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Timer(), 0L, config.getInteger("values.clock") * 20); + int interval = config.getInteger("values.clock"); + if (enabled) Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, + new Timer(), 0L, interval * 20); if (getConfig().getBoolean("debug")) debug = true; if (enabled && this.getConfig().getBoolean("features.notifier")) { if (debug) Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', @@ -65,6 +67,6 @@ public class Harbor extends JavaPlugin { } public void onDisable() { - + // Nothing lol } } diff --git a/src/main/java/xyz/nkomarn/Harbor/nms/NMSUtils.java b/src/main/java/xyz/nkomarn/Harbor/nms/NMSUtils.java index 7d9a314..47dd068 100644 --- a/src/main/java/xyz/nkomarn/Harbor/nms/NMSUtils.java +++ b/src/main/java/xyz/nkomarn/Harbor/nms/NMSUtils.java @@ -25,17 +25,17 @@ public class NMSUtils { Harbor.enabled = false; } if (Harbor.debug) Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', c.getString("messages.miscellaneous.prefix") + c.getString("messages.miscellaneous.running").replace("[version]", v))); - if (v.equals("v1_8_R1")) {nms = new NMS_1_8_R1();} - else if (v.equals("v1_8_R2")) {nms = new NMS_1_8_R2();} - else if (v.equals("v1_8_R3")) {nms = new NMS_1_8_R3();} - else if (v.equals("v1_9_R1")) {nms = new NMS_1_9_R1();} - else if (v.equals("v1_9_R2")) {nms = new NMS_1_9_R2();} - else if (v.equals("v1_10_R1")) {nms = new NMS_1_10_R1();} - else if (v.equals("v1_11_R1")) {nms = new NMS_1_11_R1();} - else if (v.equals("v1_12_R1")) {nms = new NMS_1_12_R1();} - else if (v.equals("v1_13_R1")) {nms = new NMS_1_13_R1();} - else if (v.equals("v1_13_R2")) {nms = new NMS_1_13_R2();} - else if (v.equals("v1_14_R1")) {nms = new NMS_1_14_R1();} + if (v.equals("v1_8_R1")) {nms = new NMS_1_8_R1(); Harbor.enabled = true;} + else if (v.equals("v1_8_R2")) {nms = new NMS_1_8_R2(); Harbor.enabled = true;} + else if (v.equals("v1_8_R3")) {nms = new NMS_1_8_R3(); Harbor.enabled = true;} + else if (v.equals("v1_9_R1")) {nms = new NMS_1_9_R1(); Harbor.enabled = true;} + else if (v.equals("v1_9_R2")) {nms = new NMS_1_9_R2(); Harbor.enabled = true;} + else if (v.equals("v1_10_R1")) {nms = new NMS_1_10_R1(); Harbor.enabled = true;} + else if (v.equals("v1_11_R1")) {nms = new NMS_1_11_R1(); Harbor.enabled = true;} + else if (v.equals("v1_12_R1")) {nms = new NMS_1_12_R1(); Harbor.enabled = true;} + else if (v.equals("v1_13_R1")) {nms = new NMS_1_13_R1(); Harbor.enabled = true;} + else if (v.equals("v1_13_R2")) {nms = new NMS_1_13_R2(); Harbor.enabled = true;} + else if (v.equals("v1_14_R1")) {nms = new NMS_1_14_R1(); Harbor.enabled = true;} else { Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', c.getString("messages.miscellaneous.prefix") + "This version of Harbor is incompatible with your server version. As such, Harbor will be disabled.")); Bukkit.getPluginManager().disablePlugin(Harbor.instance); diff --git a/src/main/java/xyz/nkomarn/Harbor/task/Timer.java b/src/main/java/xyz/nkomarn/Harbor/task/Timer.java index 2246821..af5c6bc 100644 --- a/src/main/java/xyz/nkomarn/Harbor/task/Timer.java +++ b/src/main/java/xyz/nkomarn/Harbor/task/Timer.java @@ -18,15 +18,17 @@ public class Timer implements Runnable { public void run() { try { Bukkit.getServer().getWorlds().forEach(w -> { + if (n.getSleeping(w) > 0 && n.getNeeded(w) != 0) { + w.getPlayers().forEach(p -> nms.sendActionbar(p, c.getString("messages.actionbar.sleeping"), w)); + } + else if (n.getSleeping(w) > 0 && n.getNeeded(w) == 0) { + w.getPlayers().forEach(p -> nms.sendActionbar(p, c.getString("messages.actionbar.everyone"), w)); + } + if (w.getTime() >= 12516 && w.getTime() <= 12535 && c.getBoolean("messages.title.title")) w.getPlayers().forEach(p -> nms.sendTitle(p, c.getString("messages.title.evening.top"), c.getString("messages.title.evening.bottom"))); if (n.getSleeping(w) > 0 && n.getNeeded(w) == 0) n.skip(w); - if (n.getSleeping(w) > 0 && n.getSleeping(w) < n.getNeeded(w)) - w.getPlayers().forEach(p -> nms.sendActionbar(p, c.getString("messages.actionbar.sleeping"), w)); - else if (n.getSleeping(w) == n.getNeeded(w) && n.getSleeping(w) > 0) - w.getPlayers().forEach(p -> nms.sendActionbar(p, c.getString("messages.actionbar.everyone"), w)); - if (c.getBoolean("features.afk")) w.getPlayers().forEach(p -> { if (TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - Counters.activity.get(p)) >= c.getInteger("values.timeout")) { if (Counters.sleeping.get(w).contains(p)) { diff --git a/src/main/java/xyz/nkomarn/Harbor/util/Counters.java b/src/main/java/xyz/nkomarn/Harbor/util/Counters.java index 29d697f..ae0ecf7 100644 --- a/src/main/java/xyz/nkomarn/Harbor/util/Counters.java +++ b/src/main/java/xyz/nkomarn/Harbor/util/Counters.java @@ -61,7 +61,7 @@ public class Counters { return a; } - public boolean isExcluded(Player p) { + private boolean isExcluded(Player p) { boolean s = false; if (c.getBoolean("features.ignore")) if (p.getGameMode() == GameMode.SURVIVAL) s = false; else s = true; if (c.getBoolean("features.bypass")) if (p.hasPermission("harbor.bypass")) s = true; else s = false; @@ -73,10 +73,12 @@ public class Counters { if (c.getBoolean("features.skip") && Math.max(0, this.getNeeded(w) - this.getExcluded(w).size()) == 0) { w.setTime(1000L); - // Set weather to clear TODO ASYNC NO BAD DON'T ASYNC CAUSE 1.14 API CHANGE BAD + // Synchronously set weather to clear if (c.getBoolean("features.weather")) { - w.setStorm(false); - w.setThundering(false); + Bukkit.getScheduler().runTask(Harbor.instance, () -> { + w.setStorm(false); + w.setThundering(false); + }); } // Display messages diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ddee2ae..7f33499 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -104,5 +104,5 @@ gui: sleeping: "Sleeping Players | Page [page]" # Spooky controls (don't change) -version: 1.5.1 +version: 1.5.2 debug: false