From 07ba7aea80e54a4fa53d0a3133ebedd19947e683 Mon Sep 17 00:00:00 2001 From: moo <48740106+moom0o@users.noreply.github.com> Date: Mon, 7 Jun 2021 02:21:00 -0400 Subject: [PATCH] 2.0 --- README.md | 22 ++-- pom.xml | 114 ++++++++++-------- .../moomoo/restartplugin/RestartPlugin.java | 81 +++++++------ src/main/resources/config.yml | 21 ++-- 4 files changed, 129 insertions(+), 109 deletions(-) diff --git a/README.md b/README.md index ec12002..4e8811d 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,23 @@ # RestartPlugin + Restart notifications just like the minecraft server 2b2t Completely configurable messages ``` -# 2b2t restart plugin - +# Minecraft restart notifications plugin by moo # Time to where the server will call a restart Timezone: "America/New_York" -#Time -# 2:00 AM EST # THIS IS IN 24 HOUR TIME -Hour: 2 -Minute: 0 -Seconds: 0 +RestartTimes: + - "2:00:00" # 2AM EST +# - "14:00:00" #2PM EST -string: "&e[SERVER] Server restarting in" +# %timeword% is the minute/seconds/second string. +# %time% is the number, ex: 15/10/5/2 +string: "&e[SERVER] Server restarting in %time% %timeword%" finalstring: "&e[SERVER] Server restarting..." -minutestring: " minutes..." -secondsstring: " seconds..." -secondstring: " second..." +minutestring: "minutes..." +secondsstring: "seconds..." +secondstring: "second..." ``` \ No newline at end of file diff --git a/pom.xml b/pom.xml index df8f4b7..b07ca73 100644 --- a/pom.xml +++ b/pom.xml @@ -1,58 +1,74 @@ - - 4.0.0 + 4.0.0 - me.moomoo - RestartPlugin - 1.1 - jar + me.moomoo + RestartPlugin + 2.0 + jar - RestartPlugin + RestartPlugin - - 1.8 - UTF-8 - + + 1.8 + UTF-8 + - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - ${java.version} - ${java.version} - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - false - - - - - - - - src/main/resources - true - - - + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + false + + + + + + + + src/main/resources + true + + + - papermc-repohttps://papermc.io/repo/repository/maven-public/sonatypehttps://oss.sonatype.org/content/groups/public/ + + + papermc-repo + https://papermc.io/repo/repository/maven-public/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + - com.destroystokyo.paperpaper-api1.12.2-R0.1-SNAPSHOTprovided + + + com.destroystokyo.paper + paper-api + 1.12.2-R0.1-SNAPSHOT + provided + + diff --git a/src/main/java/me/moomoo/restartplugin/RestartPlugin.java b/src/main/java/me/moomoo/restartplugin/RestartPlugin.java index 7189130..1c41ce0 100644 --- a/src/main/java/me/moomoo/restartplugin/RestartPlugin.java +++ b/src/main/java/me/moomoo/restartplugin/RestartPlugin.java @@ -17,7 +17,6 @@ public class RestartPlugin extends JavaPlugin implements Listener { FileConfiguration config = getConfig(); - boolean playerslow = false; public void onEnable() { saveDefaultConfig(); @@ -25,67 +24,73 @@ public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(this, this); ZonedDateTime now = ZonedDateTime.now(ZoneId.of(get("Timezone"))); - ZonedDateTime nextRun = now.withHour(config.getInt("Hour")).withMinute(config.getInt("Minute")).withSecond(config.getInt("Seconds")); - if (now.compareTo(nextRun) > 0) - nextRun = nextRun.plusDays(1); + config.getStringList("RestartTimes").forEach(b -> { + String[] numbers = b.split(":"); + int hour = Integer.parseInt(numbers[0]); + int minute = Integer.parseInt(numbers[1]); + int second = Integer.parseInt(numbers[2]); - Duration duration = Duration.between(now, nextRun); - long initalDelay = duration.getSeconds(); + ZonedDateTime nextRun = now.withHour(hour).withMinute(minute).withSecond(second); + if (now.compareTo(nextRun) > 0) + nextRun = nextRun.plusDays(1); - ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); - scheduler.scheduleAtFixedRate(() -> { - Thread t = new Thread(() -> { - try { - restart(); - } catch (InterruptedException e) { - e.printStackTrace(); - } + Duration duration = Duration.between(now, nextRun); + long initalDelay = duration.getSeconds(); - }); - - t.start(); - }, initalDelay, TimeUnit.DAYS.toSeconds(1), TimeUnit.SECONDS); + ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + scheduler.scheduleAtFixedRate(() -> { + Thread t = new Thread(() -> { + try { + restart(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }); + t.start(); + }, initalDelay, TimeUnit.DAYS.toSeconds(1), TimeUnit.SECONDS); + }); } public void restart() throws InterruptedException { - String s = translate(get("string")); - b(translate(s + " 15" + get("minutestring"))); + String s = get("string"); + // Pull req. If you find a better way to do this! + b(translate(s.replace("%time%", "15").replace("%timeword%", get("minutestring")))); sleep(300000); - b(translate(s + " 10" + get("minutestring"))); + b(translate(s.replace("%time%", "10").replace("%timeword%", get("minutestring")))); sleep(300000); - b(translate(s + " 5" + get("minutestring"))); + b(translate(s.replace("%time%", "5").replace("%timeword%", get("minutestring")))); sleep(180000); - b(translate(s + " 2" + get("minutestring"))); + b(translate(s.replace("%time%", "2").replace("%timeword%", get("minutestring")))); sleep(105000); - b(translate(s + " 15" + get("secondsstring"))); + b(translate(s.replace("%time%", "15").replace("%timeword%", get("secondsstring")))); sleep(1000); - b(translate(s + " 14" + get("secondsstring"))); + b(translate(s.replace("%time%", "14").replace("%timeword%", get("secondsstring")))); sleep(1000); - b(translate(s + " 13" + get("secondsstring"))); + b(translate(s.replace("%time%", "13").replace("%timeword%", get("secondsstring")))); sleep(1000); - b(translate(s + " 12" + get("secondsstring"))); + b(translate(s.replace("%time%", "12").replace("%timeword%", get("secondsstring")))); sleep(1000); - b(translate(s + " 11" + get("secondsstring"))); + b(translate(s.replace("%time%", "11").replace("%timeword%", get("secondsstring")))); sleep(1000); - b(translate(s + " 10" + get("secondsstring"))); + b(translate(s.replace("%time%", "10").replace("%timeword%", get("secondsstring")))); sleep(1000); - b(translate(s + " 9" + get("secondsstring"))); + b(translate(s.replace("%time%", "9").replace("%timeword%", get("secondsstring")))); sleep(1000); - b(translate(s + " 8" + get("secondsstring"))); + b(translate(s.replace("%time%", "8").replace("%timeword%", get("secondsstring")))); sleep(1000); - b(translate(s + " 7" + get("secondsstring"))); + b(translate(s.replace("%time%", "7").replace("%timeword%", get("secondsstring")))); sleep(1000); - b(translate(s + " 6" + get("secondsstring"))); + b(translate(s.replace("%time%", "6").replace("%timeword%", get("secondsstring")))); sleep(1000); - b(translate(s + " 5" + get("secondsstring"))); + b(translate(s.replace("%time%", "5").replace("%timeword%", get("secondsstring")))); sleep(1000); - b(translate(s + " 4" + get("secondsstring"))); + b(translate(s.replace("%time%", "4").replace("%timeword%", get("secondsstring")))); sleep(1000); - b(translate(s + " 3" + get("secondsstring"))); + b(translate(s.replace("%time%", "3").replace("%timeword%", get("secondsstring")))); sleep(1000); - b(translate(s + " 2" + get("secondsstring"))); + b(translate(s.replace("%time%", "2").replace("%timeword%", get("secondsstring")))); sleep(1000); - b(translate(s + " 1" + get("secondstring"))); + b(translate(s.replace("%time%", "1").replace("%timeword%", get("secondstring")))); sleep(1000); b(translate(get("finalstring"))); Bukkit.shutdown(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 865fd60..160dc2f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,16 +1,15 @@ -# 2b2t restart plugin - +# Minecraft restart notifications plugin by moo # Time to where the server will call a restart Timezone: "America/New_York" -#Time -# 2:00 AM EST # THIS IS IN 24 HOUR TIME -Hour: 2 -Minute: 0 -Seconds: 0 +RestartTimes: + - "2:00:00" # 2AM EST +# - "14:00:00" #2PM EST -string: "&e[SERVER] Server restarting in" +# %timeword% is the minute/seconds/second string. +# %time% is the number, ex: 15/10/5/2 +string: "&e[SERVER] Server restarting in %time% %timeword%" finalstring: "&e[SERVER] Server restarting..." -minutestring: " minutes..." -secondsstring: " seconds..." -secondstring: " second..." \ No newline at end of file +minutestring: "minutes..." +secondsstring: "seconds..." +secondstring: "second..." \ No newline at end of file