make plugin functional

This commit is contained in:
Frizth Lyco Tatierra 2025-01-14 17:29:29 +08:00
parent c837099662
commit 5db3de8b5a
6 changed files with 49 additions and 28 deletions

5
.gitignore vendored
View File

@ -25,4 +25,7 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*
replay_pid* replay_pid*
/out/
/target/

5
.idea/.gitignore vendored
View File

@ -25,4 +25,7 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*
replay_pid* replay_pid*
/out/
/target/

View File

@ -2,22 +2,41 @@ package net.thedawnph.servercore_za;
import com.ericdebouwer.zombieapocalypse.api.ApocalypseAPI; import com.ericdebouwer.zombieapocalypse.api.ApocalypseAPI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Objects; import java.util.Objects;
public class StartNighttimeTask implements Listener { public class StartNighttimeTask implements Listener {
private FileConfiguration getConfig() {
return JavaPlugin.getPlugin(Servercore_za.class).getConfig();
}
ApocalypseAPI apocalypseAPI = ApocalypseAPI.getInstance(); ApocalypseAPI apocalypseAPI = ApocalypseAPI.getInstance();
boolean isApocalyptic = apocalypseAPI.isApocalypse(Objects.requireNonNull(getConfig().getString("worldname")));
public StartNighttimeTask() { public StartNighttimeTask() {
Bukkit.getScheduler().runTaskTimer(Servercore_za.getPlugin(Servercore_za.class), () -> { Bukkit.getScheduler().runTaskTimer(Servercore_za.getPlugin(Servercore_za.class), () -> {
long time = Objects.requireNonNull(Bukkit.getWorld("world")).getTime(); World world = Bukkit.getWorld(Objects.requireNonNull(getConfig().getString("worldname")));
if (time >= 13000 && time <= 23000) { // Check if it is nighttime if (world == null) {
boolean isApocalyptic = apocalypseAPI.isApocalypse("world"); Bukkit.getLogger().severe("World not found!");
if (isApocalyptic) { return;
apocalypseAPI.startApocalypse("world", 300, 1, true); }
Bukkit.getWorlds().getFirst().playSound(Bukkit.getWorlds().getFirst().getSpawnLocation(), "block.bell.use", 1, 1);
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);
} }
} }

View File

@ -1,5 +1,6 @@
package net.thedawnph.servercore_za; package net.thedawnph.servercore_za;
import com.ericdebouwer.zombieapocalypse.api.ApocalypseAPI;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
@ -25,10 +26,17 @@ public class ZombieKill implements Listener {
@EventHandler @EventHandler
public void onEntityDeath(EntityDeathEvent event) { 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)) { if (event.getEntity().getType().equals(EntityType.ZOMBIE)) {
event.getDrops().clear(); if (isApocalyptic) {
List<String> items = getConfig().getStringList("zombie-drops"); event.getDrops().clear();
event.getDrops().add(new ItemStack(Objects.requireNonNull(Material.getMaterial(Objects.requireNonNull(items.get(randomizer(0, items.size()))))))); List<String> 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();
}
} }
} }
} }

View File

@ -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: zombie-drops:
- "IRON_INGOT" - "IRON_INGOT"
- "GOLD_INGOT" - "GOLD_INGOT"
@ -7,8 +10,4 @@ zombie-drops:
- "BREAD" - "BREAD"
- "STICK" - "STICK"
- "LEATHER" - "LEATHER"
- "BONE" - "BONE"
- "LEATHER_HELMET"
- "LEATHER_CHESTPLATE"
- "LEATHER_LEGGINGS"
- "LEATHER_BOOTS"

View File

@ -2,18 +2,7 @@ name: servercore_za
version: '1.0-SNAPSHOT' version: '1.0-SNAPSHOT'
main: net.thedawnph.servercore_za.Servercore_za main: net.thedawnph.servercore_za.Servercore_za
api-version: '1.20' api-version: '1.20'
load: STARTUP
authors: [ princepines ] authors: [ princepines ]
description: Server Core for TheDawnPH Zombie Apocalypse description: Server Core for TheDawnPH Zombie Apocalypse
website: https://thedawnph.net website: https://thedawnph.net
depend: [ZombieApocalypse] 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