Java Code Examples for org.bukkit.event.player.PlayerMoveEvent#setTo()

The following examples show how to use org.bukkit.event.player.PlayerMoveEvent#setTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlayerMovementListener.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Modify the to location of the given event to prevent the movement and
 * move the player so they are standing on the center of the block at the
 * from location.
 */
private static void resetPosition(final PlayerMoveEvent event) {
    Location newLoc;
    double yValue = event.getFrom().getY();

    if(yValue <= 0 || event instanceof PlayerTeleportEvent) {
        newLoc = event.getFrom();
    } else {
        newLoc = BlockUtils.center(event.getFrom()).subtract(new Vector(0, 0.5, 0));
        if(newLoc.getBlock() != null) {
            switch(newLoc.getBlock().getType()) {
            case STEP:
            case WOOD_STEP:
                newLoc.add(new Vector(0, 0.5, 0));
                break;
            default: break;
            }
        }
    }

    newLoc.setPitch(event.getTo().getPitch());
    newLoc.setYaw(event.getTo().getYaw());
    event.setCancelled(false);
    event.setTo(newLoc);
}
 
Example 2
Source File: MoveEvent.java    From MCAuthenticator with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
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;
    }

    Player player = event.getPlayer();
    User u = instance.getCache().get(player.getUniqueId());

    if (u != null && u.authenticated()) return;

    event.setTo(from);
}
 
Example 3
Source File: BukkitPlotDenyListener.java    From PlotMe-Core with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerMove(PlayerMoveEvent event) {
    Location location = BukkitUtil.adapt(event.getTo());
    if (manager.isPlotWorld(location)) {
        if (event.getPlayer().hasPermission(PermissionNames.ADMIN_BYPASSDENY)) {
            return;
        }
        Plot plot = manager.getPlot(location);
        if (plot != null) {
            if (plot.getOwnerId().equals(event.getPlayer().getUniqueId())) {
                return;
            }
            if (plot.isDenied(event.getPlayer().getUniqueId())) {
                event.setTo(event.getFrom());
            }
        }
    }
}
 
Example 4
Source File: FreezeMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerMove(final PlayerMoveEvent event) {
  if (freeze.isFrozen(event.getPlayer())) {
    Location old = event.getFrom();
    old.setPitch(event.getTo().getPitch());
    old.setYaw(event.getTo().getYaw());
    event.setTo(old);
  }
}
 
Example 5
Source File: FreezeListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerMove(final PlayerMoveEvent event) {
    if(freeze.isFrozen(event.getPlayer())) {
        Location old = event.getFrom();
        old.setPitch(event.getTo().getPitch());
        old.setYaw(event.getTo().getYaw());
        event.setTo(old);
    }
}
 
Example 6
Source File: PlayerMovementListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private final void handleMovementHigh(final PlayerMoveEvent event) {
    Player player = event.getPlayer();
    EntityLocation originalFrom = event.getEntityFrom();
    EntityLocation originalTo = event.getEntityTo();

    EntityLocation oldTo = this.lastToLocation.get(player);
    if(oldTo != null && !oldTo.equals(originalFrom)) {
        // If this movement does not start where the last known movement ended,
        // we have to make up the missing movement. We do that by (potentially) firing
        // two coarse events for this one event, a "fake" one for the missing movement
        // and a "real" one for the current movement.

        // First, modify this event to look like the missing event, and fire
        // a coarse event that wraps it.
        event.setFrom(oldTo);
        event.setTo(originalFrom);
        this.updateLastToLocation(event);
        if(this.callCoarsePlayerMove(event)) {
            // If the fake coarse event was cancelled, we don't need to fire
            // the real one, so just return. Note that the wrapped event won't
            // actually be cancelled, rather its to location will be modified
            // to return the player to the oldTo location. Also note that if
            // the original event was already cancelled before the coarse event
            // fired, then we will never get here, and both the fake and real
            // events will go through.
            this.updateLastToLocation(event);
            return;
        }

        // Restore the event to its real state
        event.setFrom(originalFrom);
        event.setTo(originalTo);
    }

    this.updateLastToLocation(event);
    if(this.callCoarsePlayerMove(event)) {
        this.updateLastToLocation(event);
    }
}
 
Example 7
Source File: EnterRegion.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
    if (ObserverModule.testObserverOrDead(event.getPlayer())) return;
    if (region.contains(event.getTo().toVector())
            && !region.contains(event.getFrom().toVector())
            && filter.evaluate(event.getPlayer(), event).equals(FilterState.DENY)) {
        event.setTo(event.getFrom());
        ChatUtil.sendWarningMessage(event.getPlayer(), message);
    }
}
 
Example 8
Source File: LeaveRegion.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
    if (ObserverModule.testObserverOrDead(event.getPlayer())) return;
    if (!region.contains(event.getTo().toVector())
            && region.contains(event.getFrom().toVector())
            && filter.evaluate(event.getPlayer(), event).equals(FilterState.DENY)) {
        event.setTo(event.getFrom());
        ChatUtil.sendWarningMessage(event.getPlayer(), message);
    }
}
 
Example 9
Source File: ObserverModule.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
    if (testObserver(event.getPlayer())) {
        if (event.getTo().getY() <= -64) {
            TeamModule teamModule = Teams.getTeamById("observers").get();
            ModuleCollection<SpawnModule> modules = new ModuleCollection<>();
            for (SpawnModule spawnModule : match.getModules().getModules(SpawnModule.class)) {
                if (spawnModule.getTeam() == teamModule) modules.add(spawnModule);
            }
            event.setTo(modules.getRandom().getLocation());
        }
    }
}
 
Example 10
Source File: PlayerListener.java    From AuthMeReloaded with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerMove(PlayerMoveEvent event) {
    if (settings.getProperty(ALLOW_UNAUTHED_MOVEMENT) && settings.getProperty(ALLOWED_MOVEMENT_RADIUS) <= 0) {
        return;
    }

    Location from = event.getFrom();
    Location to = event.getTo();
    if (to == null) {
        return;
    }

    /*
     * Limit player X and Z movements to 1 block
     * Deny player Y+ movements (allows falling)
     */

    if (from.getBlockX() == to.getBlockX()
        && from.getBlockZ() == to.getBlockZ()
        && from.getY() - to.getY() >= 0) {
        return;
    }

    Player player = event.getPlayer();
    if (!listenerService.shouldCancelEvent(player)) {
        return;
    }

    if (!settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)) {
        // "cancel" the event
        event.setTo(event.getFrom());
        return;
    }

    if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) {
        return;
    }

    Location spawn = spawnLoader.getSpawnLocation(player);
    if (spawn != null && spawn.getWorld() != null) {
        if (!player.getWorld().equals(spawn.getWorld())) {
            player.teleport(spawn);
        } else if (spawn.distance(player.getLocation()) > settings.getProperty(ALLOWED_MOVEMENT_RADIUS)) {
            player.teleport(spawn);
        }
    }
}