Search in sources :

Example 1 with Session

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

the class PlayerMoveListener method onPlayerRespawn.

@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent event) {
    LocalPlayer player = getPlugin().wrapPlayer(event.getPlayer());
    Session session = WorldGuard.getInstance().getPlatform().getSessionManager().get(player);
    session.testMoveTo(player, BukkitAdapter.adapt(event.getRespawnLocation()), MoveType.RESPAWN, true);
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Session(com.sk89q.worldguard.session.Session) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Session

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

the class PlayerMoveListener method onPlayerMove.

@EventHandler(priority = EventPriority.HIGH)
public void onPlayerMove(PlayerMoveEvent event) {
    Location from = event.getFrom();
    Location to = event.getTo();
    if (from.getBlockX() == to.getBlockX() && from.getBlockY() == to.getBlockY() && from.getBlockZ() == to.getBlockZ()) {
        return;
    }
    final Player player = event.getPlayer();
    LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    Session session = WorldGuard.getInstance().getPlatform().getSessionManager().get(localPlayer);
    MoveType moveType = MoveType.MOVE;
    if (event.getPlayer().isGliding()) {
        moveType = MoveType.GLIDE;
    } else if (event.getPlayer().isSwimming()) {
        moveType = MoveType.SWIM;
    } else if (event.getPlayer().getVehicle() != null && event.getPlayer().getVehicle() instanceof Horse) {
        moveType = MoveType.RIDE;
    }
    com.sk89q.worldedit.util.Location weLocation = session.testMoveTo(localPlayer, BukkitAdapter.adapt(to), moveType);
    if (weLocation != null) {
        final Location override = BukkitAdapter.adapt(weLocation);
        override.setX(override.getBlockX() + 0.5);
        override.setY(override.getBlockY());
        override.setZ(override.getBlockZ() + 0.5);
        override.setPitch(to.getPitch());
        override.setYaw(to.getYaw());
        event.setTo(override.clone());
        Entity vehicle = player.getVehicle();
        if (vehicle != null) {
            vehicle.eject();
            Entity current = vehicle;
            while (current != null) {
                current.eject();
                vehicle.setVelocity(new Vector());
                if (vehicle instanceof LivingEntity) {
                    vehicle.teleport(override.clone());
                } else {
                    vehicle.teleport(override.clone().add(0, 1, 0));
                }
                current = current.getVehicle();
            }
            player.teleport(override.clone().add(0, 1, 0));
            Bukkit.getScheduler().runTaskLater(getPlugin(), () -> player.teleport(override.clone().add(0, 1, 0)), 1);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Horse(org.bukkit.entity.Horse) MoveType(com.sk89q.worldguard.session.MoveType) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) Session(com.sk89q.worldguard.session.Session) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Session

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

the class PlayerMoveListener method onPlayerQuit.

@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
    final Player player = event.getPlayer();
    LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    Session session = WorldGuard.getInstance().getPlatform().getSessionManager().get(localPlayer);
    com.sk89q.worldedit.util.Location loc = session.testMoveTo(localPlayer, BukkitAdapter.adapt(event.getPlayer().getLocation()), // white lie
    MoveType.OTHER_CANCELLABLE);
    if (loc != null) {
        player.teleport(BukkitAdapter.adapt(loc));
    }
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Session(com.sk89q.worldguard.session.Session) EventHandler(org.bukkit.event.EventHandler)

Example 4 with Session

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

the class RegionCommands method toggleBypass.

@Command(aliases = { "toggle-bypass", "bypass" }, usage = "[on|off]", desc = "Toggle region bypassing, effectively ignoring bypass permissions.")
public void toggleBypass(CommandContext args, Actor sender) throws CommandException {
    LocalPlayer player = worldGuard.checkPlayer(sender);
    if (!player.hasPermission("worldguard.region.toggle-bypass")) {
        throw new CommandPermissionsException();
    }
    Session session = WorldGuard.getInstance().getPlatform().getSessionManager().get(player);
    boolean shouldEnableBypass;
    if (args.argsLength() > 0) {
        String arg1 = args.getString(0);
        if (!arg1.equalsIgnoreCase("on") && !arg1.equalsIgnoreCase("off")) {
            throw new CommandException("Allowed optional arguments are: on, off");
        }
        shouldEnableBypass = arg1.equalsIgnoreCase("on");
    } else {
        shouldEnableBypass = session.hasBypassDisabled();
    }
    if (shouldEnableBypass) {
        session.setBypassDisabled(false);
        player.print("You are now bypassing region protection (as long as you have permission).");
    } else {
        session.setBypassDisabled(true);
        player.print("You are no longer bypassing region protection.");
    }
}
Also used : CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) LocalPlayer(com.sk89q.worldguard.LocalPlayer) CommandException(com.sk89q.minecraft.util.commands.CommandException) Session(com.sk89q.worldguard.session.Session) Command(com.sk89q.minecraft.util.commands.Command)

Example 5 with Session

use of com.sk89q.worldguard.session.Session 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

LocalPlayer (com.sk89q.worldguard.LocalPlayer)10 Session (com.sk89q.worldguard.session.Session)10 Player (org.bukkit.entity.Player)6 EventHandler (org.bukkit.event.EventHandler)6 Command (com.sk89q.minecraft.util.commands.Command)3 Entity (org.bukkit.entity.Entity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 CommandException (com.sk89q.minecraft.util.commands.CommandException)1 CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)1 GameMode (com.sk89q.worldedit.world.gamemode.GameMode)1 BukkitPlayer (com.sk89q.worldguard.bukkit.BukkitPlayer)1 WorldConfiguration (com.sk89q.worldguard.config.WorldConfiguration)1 MoveType (com.sk89q.worldguard.session.MoveType)1 GameModeFlag (com.sk89q.worldguard.session.handler.GameModeFlag)1 Location (org.bukkit.Location)1 Horse (org.bukkit.entity.Horse)1 Vector (org.bukkit.util.Vector)1