major changes, added OneNightSleep
This commit is contained in:
parent
5db3de8b5a
commit
425614b45c
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>net.thedawnph</groupId>
|
<groupId>net.thedawnph</groupId>
|
||||||
<artifactId>servercore_za</artifactId>
|
<artifactId>servercore_za</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.1.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>servercore_za</name>
|
<name>servercore_za</name>
|
||||||
|
|||||||
15
src/main/java/net/thedawnph/servercore_za/OneNightSleep.java
Normal file
15
src/main/java/net/thedawnph/servercore_za/OneNightSleep.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package net.thedawnph.servercore_za;
|
||||||
|
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerBedEnterEvent;
|
||||||
|
|
||||||
|
public class OneNightSleep implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerSleep(PlayerBedEnterEvent event) {
|
||||||
|
|
||||||
|
if (event.getBedEnterResult() == PlayerBedEnterEvent.BedEnterResult.OK) {
|
||||||
|
event.getPlayer().getWorld().setTime(23000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -33,6 +33,8 @@ public final class Servercore_za extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
|
// reset scheduler
|
||||||
|
getServer().getScheduler().cancelTasks(this);
|
||||||
LOGGER.info("ZA ServerCore disabled");
|
LOGGER.info("ZA ServerCore disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,6 +42,7 @@ public final class Servercore_za extends JavaPlugin {
|
|||||||
private void registerEvents() {
|
private void registerEvents() {
|
||||||
getServer().getPluginManager().registerEvents(new ZombieKill(), this);
|
getServer().getPluginManager().registerEvents(new ZombieKill(), this);
|
||||||
// getServer().getPluginManager().registerEvents(new DisableMonsters(), this); // working in progress
|
// getServer().getPluginManager().registerEvents(new DisableMonsters(), this); // working in progress
|
||||||
getServer().getPluginManager().registerEvents(new StartNighttimeTask(), this);
|
getServer().getPluginManager().registerEvents(new OneNightSleep(), this);
|
||||||
|
new StartNighttimeTask(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,40 +3,84 @@ 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.World;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.entity.Item;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class StartNighttimeTask implements Listener {
|
public class StartNighttimeTask {
|
||||||
private FileConfiguration getConfig() {
|
|
||||||
return JavaPlugin.getPlugin(Servercore_za.class).getConfig();
|
private final ApocalypseAPI apocalypseAPI = ApocalypseAPI.getInstance();
|
||||||
|
private final JavaPlugin plugin;
|
||||||
|
private boolean isApocalyptic = false;
|
||||||
|
|
||||||
|
public StartNighttimeTask(JavaPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
startScheduler();
|
||||||
}
|
}
|
||||||
ApocalypseAPI apocalypseAPI = ApocalypseAPI.getInstance();
|
|
||||||
boolean isApocalyptic = apocalypseAPI.isApocalypse(Objects.requireNonNull(getConfig().getString("worldname")));
|
|
||||||
|
|
||||||
public StartNighttimeTask() {
|
private void startScheduler() {
|
||||||
Bukkit.getScheduler().runTaskTimer(Servercore_za.getPlugin(Servercore_za.class), () -> {
|
Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||||
World world = Bukkit.getWorld(Objects.requireNonNull(getConfig().getString("worldname")));
|
String worldName = plugin.getConfig().getString("worldname");
|
||||||
|
if (worldName == null) {
|
||||||
|
Bukkit.getLogger().severe("No worldname specified in the configuration!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
World world = Bukkit.getWorld(worldName);
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
Bukkit.getLogger().severe("World not found!");
|
Bukkit.getLogger().severe("World not found: " + worldName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long time = world.getTime();
|
long time = world.getTime();
|
||||||
|
|
||||||
// Check if it is nighttime
|
// Check if it is nighttime
|
||||||
if (time >= 13000) {
|
if (time >= 12541 && time <= 23458) {
|
||||||
if (!isApocalyptic) {
|
if (!Bukkit.getOnlinePlayers().isEmpty() && !isApocalyptic) {
|
||||||
// Play bell sound for all players
|
// Play raid horn sound for all players
|
||||||
Bukkit.getOnlinePlayers().forEach(player ->
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
player.playSound(player.getLocation(), "event.raid.horn", 1.0f, 1.0f)
|
player.playSound(player.getLocation(), "item.goat_horn.sound.5", 16.0f, 1.0f);
|
||||||
);
|
}
|
||||||
apocalypseAPI.startApocalypse(Objects.requireNonNull(getConfig().getString("worldname")), getConfig().getInt("ZA-duration"), getConfig().getInt("ZA-mobs"), true);
|
|
||||||
|
long duration = 0;
|
||||||
|
if (plugin.getConfig().getInt("ZA-duration") == 0) {
|
||||||
|
// Start the apocalypse
|
||||||
|
apocalypseAPI.startApocalypse(
|
||||||
|
worldName, true
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Start the apocalypse
|
||||||
|
apocalypseAPI.startApocalypse(
|
||||||
|
worldName,
|
||||||
|
plugin.getConfig().getInt("ZA-duration"),
|
||||||
|
plugin.getConfig().getInt("ZA-mobs"),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
isApocalyptic = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isApocalyptic) {
|
||||||
|
// End the apocalypse
|
||||||
|
apocalypseAPI.endApocalypse(worldName, true);
|
||||||
|
|
||||||
|
// Play raid horn sound for all players
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
player.playSound(player.getLocation(), "item.goat_horn.sound.3", 16.0f, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove all dropped items from the world
|
||||||
|
world.getEntities().stream()
|
||||||
|
.filter(entity -> entity instanceof Item)
|
||||||
|
.forEach(Entity::remove);
|
||||||
|
|
||||||
|
isApocalyptic = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 0, 13000L);
|
}, 0L, 40L); // Run every 2 seconds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
worldname: "world" # Name of the world to spawn zombies in
|
worldname: "world" # Name of the world to spawn zombies in
|
||||||
ZA-duration: 7 # In minutes, default is 7 minutes (or 1 minecraft night)
|
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
|
ZA-mobs: 2 # Number of mobs to spawn per chunk, default is 2, ZA-duration must be configured
|
||||||
zombie-drops:
|
zombie-drops:
|
||||||
- "IRON_INGOT"
|
- "IRON_INGOT"
|
||||||
- "GOLD_INGOT"
|
- "GOLD_INGOT"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: servercore_za
|
name: servercore_za
|
||||||
version: '1.0-SNAPSHOT'
|
version: '1.1.1'
|
||||||
main: net.thedawnph.servercore_za.Servercore_za
|
main: net.thedawnph.servercore_za.Servercore_za
|
||||||
api-version: '1.20'
|
api-version: '1.20'
|
||||||
authors: [ princepines ]
|
authors: [ princepines ]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user