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