Add random event runner
This commit is contained in:
parent
e745193228
commit
21760ecda0
4 changed files with 44 additions and 0 deletions
|
@ -2,7 +2,9 @@ package gent.zeus.mc13dtl;
|
|||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import gent.zeus.mc13dtl.events.RandomEventRunner;
|
||||
import gent.zeus.mc13dtl.gamestate.GameStateCommand;
|
||||
import gent.zeus.mc13dtl.gamestate.GameStateHandler;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
|
@ -21,5 +23,7 @@ public class MC13DTL extends JavaPlugin {
|
|||
Commands commands = event.registrar();
|
||||
commands.register("start-game", "Start a game of 13 days to live", new GameStateCommand());
|
||||
});
|
||||
BukkitScheduler scheduler = this.getServer().getScheduler();
|
||||
scheduler.runTaskTimer(this, new RandomEventRunner(), 0, 100);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package gent.zeus.mc13dtl.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class RandomEventExecutor {
|
||||
public static void executeRandomEvent(Player player) {
|
||||
player.sendMessage("test");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package gent.zeus.mc13dtl.events;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import gent.zeus.mc13dtl.MC13DTL;
|
||||
|
||||
public class RandomEventRunner implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
World world = Bukkit.getWorld("world");
|
||||
NamespacedKey eventKey = new NamespacedKey(MC13DTL.instance, "last-event-day");
|
||||
long lastRunDay = world.getPersistentDataContainer().get(eventKey, PersistentDataType.LONG);
|
||||
long day = Bukkit.getWorld("world").getFullTime() / 24000;
|
||||
if (day > lastRunDay && Bukkit.getWorld("world").getTime() >= 14000) {
|
||||
for (OfflinePlayer i : Bukkit.getOfflinePlayers()) {
|
||||
if (i.isOnline()) {
|
||||
RandomEventExecutor.executeRandomEvent(i.getPlayer());
|
||||
} else {
|
||||
// TODO: Punishment
|
||||
}
|
||||
}
|
||||
world.getPersistentDataContainer().set(eventKey, PersistentDataType.LONG, day);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,6 +18,8 @@ public class GameStateUtil {
|
|||
NamespacedKey key = new NamespacedKey(MC13DTL.instance, "game-state");
|
||||
if (!world.getPersistentDataContainer().has(key)) {
|
||||
world.getPersistentDataContainer().set(key, PersistentDataType.STRING, "lobby");
|
||||
NamespacedKey eventKey = new NamespacedKey(MC13DTL.instance, "last-event-day");
|
||||
world.getPersistentDataContainer().set(eventKey, PersistentDataType.LONG, -1L);
|
||||
}
|
||||
String gameState = world.getPersistentDataContainer().get(key, PersistentDataType.STRING);
|
||||
if (gameState.equals("lobby")) {
|
||||
|
|
Loading…
Reference in a new issue