From 5db3de8b5a5557a0c23e4a2639cbc8685bd31f25 Mon Sep 17 00:00:00 2001 From: Frizth Lyco Tatierra Date: Tue, 14 Jan 2025 17:29:29 +0800 Subject: [PATCH] make plugin functional --- .gitignore | 5 ++- .idea/.gitignore | 5 ++- .../servercore_za/StartNighttimeTask.java | 33 +++++++++++++++---- .../thedawnph/servercore_za/ZombieKill.java | 14 ++++++-- src/main/resources/config.yml | 9 +++-- src/main/resources/plugin.yml | 11 ------- 6 files changed, 49 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 0fe0ef4..59f5453 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,7 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* -replay_pid* \ No newline at end of file +replay_pid* + +/out/ +/target/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore index 0fe0ef4..59f5453 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -25,4 +25,7 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* -replay_pid* \ No newline at end of file +replay_pid* + +/out/ +/target/ \ No newline at end of file diff --git a/src/main/java/net/thedawnph/servercore_za/StartNighttimeTask.java b/src/main/java/net/thedawnph/servercore_za/StartNighttimeTask.java index ca072f6..039eae7 100644 --- a/src/main/java/net/thedawnph/servercore_za/StartNighttimeTask.java +++ b/src/main/java/net/thedawnph/servercore_za/StartNighttimeTask.java @@ -2,22 +2,41 @@ package net.thedawnph.servercore_za; import com.ericdebouwer.zombieapocalypse.api.ApocalypseAPI; import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; import java.util.Objects; public class StartNighttimeTask implements Listener { + private FileConfiguration getConfig() { + return JavaPlugin.getPlugin(Servercore_za.class).getConfig(); + } ApocalypseAPI apocalypseAPI = ApocalypseAPI.getInstance(); + boolean isApocalyptic = apocalypseAPI.isApocalypse(Objects.requireNonNull(getConfig().getString("worldname"))); + public StartNighttimeTask() { Bukkit.getScheduler().runTaskTimer(Servercore_za.getPlugin(Servercore_za.class), () -> { - long time = Objects.requireNonNull(Bukkit.getWorld("world")).getTime(); - if (time >= 13000 && time <= 23000) { // Check if it is nighttime - boolean isApocalyptic = apocalypseAPI.isApocalypse("world"); - if (isApocalyptic) { - apocalypseAPI.startApocalypse("world", 300, 1, true); - Bukkit.getWorlds().getFirst().playSound(Bukkit.getWorlds().getFirst().getSpawnLocation(), "block.bell.use", 1, 1); + World world = Bukkit.getWorld(Objects.requireNonNull(getConfig().getString("worldname"))); + if (world == null) { + Bukkit.getLogger().severe("World not found!"); + return; + } + + long time = world.getTime(); + + // Check if it is nighttime + if (time >= 13000) { + if (!isApocalyptic) { + // Play bell sound for all players + Bukkit.getOnlinePlayers().forEach(player -> + player.playSound(player.getLocation(), "event.raid.horn", 1.0f, 1.0f) + ); + apocalypseAPI.startApocalypse(Objects.requireNonNull(getConfig().getString("worldname")), getConfig().getInt("ZA-duration"), getConfig().getInt("ZA-mobs"), true); } } - }, 0, 1200L); // Run every minute + }, 0, 13000L); } } + diff --git a/src/main/java/net/thedawnph/servercore_za/ZombieKill.java b/src/main/java/net/thedawnph/servercore_za/ZombieKill.java index 19a1ce0..1356e5e 100644 --- a/src/main/java/net/thedawnph/servercore_za/ZombieKill.java +++ b/src/main/java/net/thedawnph/servercore_za/ZombieKill.java @@ -1,5 +1,6 @@ package net.thedawnph.servercore_za; +import com.ericdebouwer.zombieapocalypse.api.ApocalypseAPI; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDeathEvent; @@ -25,10 +26,17 @@ public class ZombieKill implements Listener { @EventHandler public void onEntityDeath(EntityDeathEvent event) { + ApocalypseAPI apocalypseAPI = ApocalypseAPI.getInstance(); + boolean isApocalyptic = apocalypseAPI.isApocalypse(Objects.requireNonNull(getConfig().getString("worldname"))); + if (event.getEntity().getType().equals(EntityType.ZOMBIE)) { - event.getDrops().clear(); - List items = getConfig().getStringList("zombie-drops"); - event.getDrops().add(new ItemStack(Objects.requireNonNull(Material.getMaterial(Objects.requireNonNull(items.get(randomizer(0, items.size()))))))); + if (isApocalyptic) { + event.getDrops().clear(); + List items = getConfig().getStringList("zombie-drops"); + event.getDrops().add(new ItemStack(Objects.requireNonNull(Material.getMaterial(Objects.requireNonNull(items.get(randomizer(0, items.size()))))))); + } else { + event.getDrops().clear(); + } } } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 9dc5450..f8ef701 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,3 +1,6 @@ +worldname: "world" # Name of the world to spawn zombies in +ZA-duration: 7 # In minutes, default is 7 minutes (or 1 minecraft night) +ZA-mobs: 2 # Number of mobs to spawn per chunk, default is 2 zombie-drops: - "IRON_INGOT" - "GOLD_INGOT" @@ -7,8 +10,4 @@ zombie-drops: - "BREAD" - "STICK" - "LEATHER" - - "BONE" - - "LEATHER_HELMET" - - "LEATHER_CHESTPLATE" - - "LEATHER_LEGGINGS" - - "LEATHER_BOOTS" \ No newline at end of file + - "BONE" \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ee42fe6..963fb79 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,18 +2,7 @@ name: servercore_za version: '1.0-SNAPSHOT' main: net.thedawnph.servercore_za.Servercore_za api-version: '1.20' -load: STARTUP authors: [ princepines ] description: Server Core for TheDawnPH Zombie Apocalypse website: https://thedawnph.net depend: [ZombieApocalypse] -commands: - coreinfo: - description: Server Core for TheDawnPH Zombie Apocalypse - usage: /coreinfo - permission: servercore_za.command - permission-message: You do not have permission to use this command. -permissions: - servercore_za.command: - description: Permission to use Server Core for TheDawnPH Zombie Apocalypse - default: op