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

The following examples show how to use org.bukkit.event.player.PlayerMoveEvent#setCancelled() . 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: UHPluginListener.java    From KTP with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerMove(PlayerMoveEvent ev) {
	Location l = ev.getTo();
	Integer mapSize = p.getConfig().getInt("map.size");
	Integer halfMapSize = (int) Math.floor(mapSize/2);
	Integer x = l.getBlockX();
	Integer z = l.getBlockZ();
	
	Location spawn = ev.getPlayer().getWorld().getSpawnLocation();
	Integer limitXInf = spawn.add(-halfMapSize, 0, 0).getBlockX();
	
	spawn = ev.getPlayer().getWorld().getSpawnLocation();
	Integer limitXSup = spawn.add(halfMapSize, 0, 0).getBlockX();
	
	spawn = ev.getPlayer().getWorld().getSpawnLocation();
	Integer limitZInf = spawn.add(0, 0, -halfMapSize).getBlockZ();
	
	spawn = ev.getPlayer().getWorld().getSpawnLocation();
	Integer limitZSup = spawn.add(0, 0, halfMapSize).getBlockZ();
	
	if (x < limitXInf || x > limitXSup || z < limitZInf || z > limitZSup) {
		ev.setCancelled(true);
	}
}
 
Example 3
Source File: ListenerRiptide.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority= EventPriority.HIGH, ignoreCancelled=true)
public void onMove(PlayerMoveEvent e) {
    Player player = e.getPlayer();
    if(!player.isRiptiding()) return;

    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    if(!config.getBoolean("items.prevent-riptide")) return;

    ICombatManager combatManager = this.plugin.getCombatManager();
    if(!combatManager.isInCombat(player)) return;

    e.setCancelled(true);
    sendMessage(player);
}
 
Example 4
Source File: EventListener.java    From iDisguise with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
	Player player = event.getPlayer();
	if(DisguiseManager.isDisguised(player) && DisguiseManager.getDisguise(player).getType().equals(DisguiseType.SHULKER)) {
		event.setCancelled(true);
		long lastSent = mapLastMessageSent.containsKey(player.getUniqueId()) ? mapLastMessageSent.get(player.getUniqueId()) : 0L;
		if(lastSent + 3000L < System.currentTimeMillis()) {
			if(!plugin.getLanguage().MOVE_AS_SHULKER.isEmpty())
				player.sendMessage(plugin.getLanguage().MOVE_AS_SHULKER);
			mapLastMessageSent.put(player.getUniqueId(), System.currentTimeMillis());
		}
	}
}
 
Example 5
Source File: PlayerInteractListener.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerWalk(PlayerMoveEvent event) {
    Player player = event.getPlayer();
    for (GameMap gMap: GameMap.getPlayableArenas(GameType.ALL)) {
    	 if (gMap.getDeathMatchWaiters().contains(player.getUniqueId().toString())) {
             if (event.getFrom().getBlockX() != event.getTo().getBlockX() || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
                 event.setCancelled(true);
             }
         }
    } 
}
 
Example 6
Source File: CreativeModeListener.java    From ShopChest with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerMove(PlayerMoveEvent e) {
    // Cancel any player movement if SelectClickType is set
    ClickType clickType = ClickType.getPlayerClickType(e.getPlayer());
    if (clickType instanceof SelectClickType)
        e.setCancelled(true);
}
 
Example 7
Source File: WorldGuardEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
@SuppressWarnings("unused")
public void onPlayerMove(PlayerMoveEvent e) {
    if (e.getTo() == null || !plugin.getWorldManager().isSkyAssociatedWorld(e.getTo().getWorld())) {
        return;
    }
    String islandNameAt = WorldGuardHandler.getIslandNameAt(e.getTo());
    if (islandNameAt == null) {
        return;
    }
    IslandInfo islandInfo = plugin.getIslandInfo(islandNameAt);
    if (islandInfo == null || islandInfo.getBans().isEmpty()) {
        return;
    }
    Player player = e.getPlayer();
    if (!player.isOp() && !player.hasPermission("usb.mod.bypassprotection") && isBlockedFromEntry(player, islandInfo)) {
        e.setCancelled(true);
        Location l = e.getTo().clone();
        l.subtract(islandInfo.getIslandLocation());
        Vector v = new Vector(l.getX(), l.getY(), l.getZ());
        v.normalize();
        v.multiply(1.5); // Bounce
        player.setVelocity(v);
        if (islandInfo.isBanned(player)) {
            plugin.notifyPlayer(player, tr("\u00a7cBanned:\u00a7e You are banned from this island."));
        } else {
            plugin.notifyPlayer(player, tr("\u00a7cLocked:\u00a7e That island is locked! No entry allowed."));
        }
    }
}
 
Example 8
Source File: Playable.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
    Optional<TeamModule> team = Teams.getTeamByPlayer(event.getPlayer());
    if (GameHandler.getGameHandler().getMatch().isRunning() && team.isPresent() && !team.get().isObserver()) {
        if (region != null) {
            if (region.contains(event.getTo().toVector()) && !region.contains(event.getFrom().toVector())) {
                ChatUtil.sendWarningMessage(event.getPlayer(), new LocalizedChatMessage(ChatConstant.ERROR_PLAYABLE_LEAVE));
                event.setCancelled(true);
            }
        }
    }
}
 
Example 9
Source File: WorldBorderListener.java    From Carbon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
	if (!WorldBorder.getInstance(event.getPlayer().getWorld()).isInside(event.getTo()) && WorldBorder.getInstance(event.getPlayer().getWorld()).isInside(event.getFrom())) {
		event.setCancelled(true);
	}
}