Search in sources :

Example 1 with GameModeFlag

use of com.sk89q.worldguard.session.handler.GameModeFlag in project WorldGuard by EngineHub.

the class WorldGuardPlayerListener method onPlayerGameModeChange.

@EventHandler
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
    Player player = event.getPlayer();
    LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    WorldConfiguration wcfg = getWorldConfig(player.getWorld());
    Session session = WorldGuard.getInstance().getPlatform().getSessionManager().getIfPresent(localPlayer);
    if (session != null) {
        GameModeFlag handler = session.getHandler(GameModeFlag.class);
        if (handler != null && wcfg.useRegions && !WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
            GameMode expected = handler.getSetGameMode();
            if (handler.getOriginalGameMode() != null && expected != null && expected != BukkitAdapter.adapt(event.getNewGameMode())) {
                log.info("Game mode change on " + player.getName() + " has been blocked due to the region GAMEMODE flag");
                event.setCancelled(true);
            }
        }
    }
}
Also used : GameMode(com.sk89q.worldedit.world.gamemode.GameMode) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) GameModeFlag(com.sk89q.worldguard.session.handler.GameModeFlag) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Session(com.sk89q.worldguard.session.Session) EventHandler(org.bukkit.event.EventHandler)

Aggregations

GameMode (com.sk89q.worldedit.world.gamemode.GameMode)1 LocalPlayer (com.sk89q.worldguard.LocalPlayer)1 WorldConfiguration (com.sk89q.worldguard.config.WorldConfiguration)1 Session (com.sk89q.worldguard.session.Session)1 GameModeFlag (com.sk89q.worldguard.session.handler.GameModeFlag)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1