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

3
.gitignore vendored
View File

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

3
.idea/.gitignore vendored
View File

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

View File

@ -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);
}
}

View File

@ -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)) {
if (isApocalyptic) {
event.getDrops().clear();
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:
- "IRON_INGOT"
- "GOLD_INGOT"
@ -8,7 +11,3 @@ zombie-drops:
- "STICK"
- "LEATHER"
- "BONE"
- "LEATHER_HELMET"
- "LEATHER_CHESTPLATE"
- "LEATHER_LEGGINGS"
- "LEATHER_BOOTS"

View File

@ -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