Search in sources :

Example 1 with GameMode

use of com.sk89q.worldedit.world.gamemode.GameMode in project WorldGuard by EngineHub.

the class GameModeTypeFlag method parseInput.

@Override
public GameMode parseInput(FlagContext context) throws InvalidFlagFormat {
    String input = context.getUserInput();
    input = input.trim();
    GameMode gamemode = unmarshal(input);
    if (gamemode == null) {
        throw new InvalidFlagFormat("Unknown game mode: " + input);
    }
    return gamemode;
}
Also used : GameMode(com.sk89q.worldedit.world.gamemode.GameMode)

Example 2 with GameMode

use of com.sk89q.worldedit.world.gamemode.GameMode 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)

Example 3 with GameMode

use of com.sk89q.worldedit.world.gamemode.GameMode in project WorldGuard by EngineHub.

the class GameModeFlag method updateGameMode.

private void updateGameMode(LocalPlayer player, @Nullable GameMode newValue, World world) {
    if (!getSession().getManager().hasBypass(player, world) && newValue != null) {
        if (player.getGameMode() != newValue) {
            originalGameMode = player.getGameMode();
            player.setGameMode(newValue);
        } else if (originalGameMode == null) {
            originalGameMode = WorldGuard.getInstance().getPlatform().getDefaultGameMode();
        }
    } else {
        if (originalGameMode != null) {
            GameMode mode = originalGameMode;
            originalGameMode = null;
            player.setGameMode(mode);
        }
    }
}
Also used : GameMode(com.sk89q.worldedit.world.gamemode.GameMode)

Aggregations

GameMode (com.sk89q.worldedit.world.gamemode.GameMode)3 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