Search in sources :

Example 6 with Session

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

the class GeneralCommands method ungod.

@Command(aliases = { "ungod" }, usage = "[player]", desc = "Disable godmode on a player", flags = "s", max = 1)
public void ungod(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
    Iterable<? extends LocalPlayer> targets;
    boolean included = false;
    // Detect arguments based on the number of arguments provided
    if (args.argsLength() == 0) {
        targets = worldGuard.getPlatform().getMatcher().matchPlayers(worldGuard.checkPlayer(sender));
        // Check permissions!
        sender.checkPermission("worldguard.god");
    } else {
        targets = worldGuard.getPlatform().getMatcher().matchPlayers(sender, args.getString(0));
        // Check permissions!
        sender.checkPermission("worldguard.god.other");
    }
    for (LocalPlayer player : targets) {
        Session session = WorldGuard.getInstance().getPlatform().getSessionManager().get(player);
        if (GodMode.set(player, session, false)) {
            // Tell the user
            if (player.equals(sender)) {
                player.print("God mode disabled!");
                // Keep track of this
                included = true;
            } else {
                player.print("God disabled by " + sender.getDisplayName() + ".");
            }
        }
    }
    // user a message so s/he know that something is indeed working
    if (!included && args.hasFlag('s')) {
        sender.print("Players no longer have god mode.");
    }
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Session(com.sk89q.worldguard.session.Session) Command(com.sk89q.minecraft.util.commands.Command)

Example 7 with Session

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

the class PlayerModesListener method onProcessPlayer.

@EventHandler
public void onProcessPlayer(ProcessPlayerEvent event) {
    Player player = event.getPlayer();
    LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
    Session session = WorldGuard.getInstance().getPlatform().getSessionManager().get(localPlayer);
    if (hasGodModeGroup(player) || hasGodModePermission(player)) {
        if (GodMode.set(localPlayer, session, true)) {
            log.log(Level.INFO, "Enabled auto-god mode for " + player.getName());
        }
    }
    if (hasAmphibiousGroup(player)) {
        if (WaterBreathing.set(localPlayer, session, true)) {
            log.log(Level.INFO, "Enabled water breathing mode for " + player.getName() + " (player is in group 'wg-amphibious')");
        }
    }
}
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 8 with Session

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

the class PlayerMoveListener method onVehicleEnter.

@EventHandler
public void onVehicleEnter(VehicleEnterEvent event) {
    Entity entity = event.getEntered();
    if (entity instanceof Player) {
        LocalPlayer player = getPlugin().wrapPlayer((Player) entity);
        Session session = WorldGuard.getInstance().getPlatform().getSessionManager().get(player);
        if (null != session.testMoveTo(player, BukkitAdapter.adapt(event.getVehicle().getLocation()), MoveType.EMBARK, true)) {
            event.setCancelled(true);
        }
    }
}
Also used : 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) Session(com.sk89q.worldguard.session.Session) EventHandler(org.bukkit.event.EventHandler)

Example 9 with Session

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

the class BukkitSessionManager method resetAllStates.

/**
 * Re-initialize handlers and clear "last position," "last state," etc.
 * information for all players.
 */
@Override
public void resetAllStates() {
    Collection<? extends Player> players = Bukkit.getServer().getOnlinePlayers();
    for (Player player : players) {
        BukkitPlayer bukkitPlayer = new BukkitPlayer(WorldGuardPlugin.inst(), player);
        Session session = getIfPresent(bukkitPlayer);
        if (session != null) {
            session.resetState(bukkitPlayer);
        }
    }
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Player(org.bukkit.entity.Player) BukkitPlayer(com.sk89q.worldguard.bukkit.BukkitPlayer) BukkitPlayer(com.sk89q.worldguard.bukkit.BukkitPlayer) Session(com.sk89q.worldguard.session.Session)

Example 10 with Session

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

the class GeneralCommands method god.

@Command(aliases = { "god" }, usage = "[player]", desc = "Enable godmode on a player", flags = "s", max = 1)
public void god(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
    Iterable<? extends LocalPlayer> targets = null;
    boolean included = false;
    // Detect arguments based on the number of arguments provided
    if (args.argsLength() == 0) {
        targets = worldGuard.getPlatform().getMatcher().matchPlayers(worldGuard.checkPlayer(sender));
        // Check permissions!
        sender.checkPermission("worldguard.god");
    } else {
        targets = worldGuard.getPlatform().getMatcher().matchPlayers(sender, args.getString(0));
        // Check permissions!
        sender.checkPermission("worldguard.god.other");
    }
    for (LocalPlayer player : targets) {
        Session session = WorldGuard.getInstance().getPlatform().getSessionManager().get(player);
        if (GodMode.set(player, session, true)) {
            player.setFireTicks(0);
            // Tell the user
            if (player.equals(sender)) {
                player.print("God mode enabled! Use /ungod to disable.");
                // Keep track of this
                included = true;
            } else {
                player.print("God enabled by " + sender.getDisplayName() + ".");
            }
        }
    }
    // user a message so s/he know that something is indeed working
    if (!included && args.hasFlag('s')) {
        sender.print("Players now have god mode.");
    }
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Session(com.sk89q.worldguard.session.Session) Command(com.sk89q.minecraft.util.commands.Command)

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