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;
}
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);
}
}
}
}
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);
}
}
}
Aggregations