Cancel all interaction events before game started

This commit is contained in:
Mathieu Strypsteen 2024-09-14 19:36:13 +02:00
parent bb4b47e84a
commit 2712ee60b3

View file

@ -1,10 +1,16 @@
package gent.zeus.mc13dtl.gamestate; package gent.zeus.mc13dtl.gamestate;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.persistence.PersistentDataType;
import gent.zeus.mc13dtl.MC13DTL;
public class GameStateHandler implements Listener { public class GameStateHandler implements Listener {
@EventHandler @EventHandler
@ -20,4 +26,13 @@ public class GameStateHandler implements Listener {
} }
GameStateUtil.loadWorld(world); GameStateUtil.loadWorld(world);
} }
@EventHandler
void onPlayerInteract(PlayerInteractEvent event) {
NamespacedKey key = new NamespacedKey(MC13DTL.instance, "game-state");
String gameState = Bukkit.getWorld("world").getPersistentDataContainer().get(key, PersistentDataType.STRING);
if (gameState.equals("lobby")) {
event.setCancelled(true);
}
}
} }