From add752567418258289a22b7b99e30badeeb3f2ad Mon Sep 17 00:00:00 2001 From: Frizth Lyco Tatierra Date: Wed, 15 Jan 2025 02:16:35 +0800 Subject: [PATCH] minor changes, added randomizer to get chance to have ZA --- pom.xml | 2 +- .../servercore_za/StartNighttimeTask.java | 32 +++++++++++++------ src/main/resources/plugin.yml | 2 +- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 03bf19f..ae5a257 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.thedawnph servercore_za - 1.1.1 + 1.1.2 jar servercore_za diff --git a/src/main/java/net/thedawnph/servercore_za/StartNighttimeTask.java b/src/main/java/net/thedawnph/servercore_za/StartNighttimeTask.java index 7e6dd33..76af2b0 100644 --- a/src/main/java/net/thedawnph/servercore_za/StartNighttimeTask.java +++ b/src/main/java/net/thedawnph/servercore_za/StartNighttimeTask.java @@ -15,6 +15,10 @@ public class StartNighttimeTask { private final JavaPlugin plugin; private boolean isApocalyptic = false; + public static int randomizer(int min, int max) { + return (int) ((Math.random() * (max - min)) + min); + } + public StartNighttimeTask(JavaPlugin plugin) { this.plugin = plugin; startScheduler(); @@ -36,21 +40,22 @@ public class StartNighttimeTask { long time = world.getTime(); + // Check if it is nighttime if (time >= 12541 && time <= 23458) { + int random = randomizer(0, 4); if (!Bukkit.getOnlinePlayers().isEmpty() && !isApocalyptic) { - // Play raid horn sound for all players - for (Player player : Bukkit.getOnlinePlayers()) { - player.playSound(player.getLocation(), "item.goat_horn.sound.5", 16.0f, 1.0f); - } - - long duration = 0; - if (plugin.getConfig().getInt("ZA-duration") == 0) { + if (plugin.getConfig().getInt("ZA-duration") == 0 && random == 1) { // Start the apocalypse apocalypseAPI.startApocalypse( worldName, true ); - } else { + + // Play raid horn sound for all players + for (Player player : Bukkit.getOnlinePlayers()) { + player.playSound(player.getLocation(), "item.goat_horn.sound.5", 16.0f, 1.0f); + } + } else if (plugin.getConfig().getInt("ZA-duration") != 0 && random == 1) { // Start the apocalypse apocalypseAPI.startApocalypse( worldName, @@ -58,8 +63,17 @@ public class StartNighttimeTask { plugin.getConfig().getInt("ZA-mobs"), true ); - } + // Play raid horn sound for all players + for (Player player : Bukkit.getOnlinePlayers()) { + player.playSound(player.getLocation(), "item.goat_horn.sound.5", 16.0f, 1.0f); + } + } else if (random != 1) { + // send message to all players + for (Player player : Bukkit.getOnlinePlayers()) { + player.sendMessage("The night is quiet..."); + } + } isApocalyptic = true; } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d5ddf6b..27c6617 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: servercore_za -version: '1.1.1' +version: '1.1.2' main: net.thedawnph.servercore_za.Servercore_za api-version: '1.20' authors: [ princepines ]