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

The following examples show how to use org.bukkit.event.player.PlayerMoveEvent#getFrom() . 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: SignUpdater.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void move(final PlayerMoveEvent event) {
    Player player = event.getPlayer();
    Location to = event.getTo();
    Location from = event.getFrom();
    Block toBlock = to.getBlock();
    Block fromBlock = from.getBlock();

    handleLook(player, to);

    if(PORTAL_MATERIALS.contains(toBlock.getType()) && !PORTAL_MATERIALS.contains(fromBlock.getType())) {
        nearestSign(event.getTo()).ifPresent(
            sign -> sign.connector().teleport(player)
        );
    }
}
 
Example 2
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 3
Source File: Transporter.java    From AnnihilationPro with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST,ignoreCancelled = true)
public void MoveListeners(PlayerMoveEvent event)
{
	///block under your feet
	Block to = event.getTo().getBlock().getRelative(BlockFace.DOWN);
	if(to.getType() == Material.QUARTZ_ORE)
	{
		Location x = event.getTo();
		Location y = event.getFrom();
		if(x.getBlockX() != y.getBlockX() || x.getBlockY() != y.getBlockY() || x.getBlockZ() != y.getBlockZ())
		{
			AnniPlayer user = AnniPlayer.getPlayer(event.getPlayer().getUniqueId());
			UUID owner = getBlocksOwner(to);
			if(owner != null && user != null)
			{
				Teleporter tele = this.teleporters.get(owner);
				if(tele != null && tele.isLinked() && tele.getOwner().getTeam() == user.getTeam())
				{
					event.getPlayer().sendMessage(ChatColor.AQUA+"This is a teleporter owned by "+ChatColor.WHITE+tele.getOwner().getName()+ChatColor.AQUA+", Sneak to go through it.");
				}
			}
		}
	}
}
 
Example 4
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 5
Source File: NoEntryListener.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void onMove(PlayerMoveEvent e) {
    ICombatLogX plugin = this.expansion.getPlugin();
    ICombatManager manager = plugin.getCombatManager();

    Player player = e.getPlayer();
    if(!manager.isInCombat(player)) return;

    LivingEntity enemy = manager.getEnemy(player);
    if(enemy == null) return;

    Location toLocation = e.getTo();
    TagType tagType = (enemy instanceof Player ? TagType.PLAYER : TagType.MOB);

    NoEntryHandler handler = this.expansion.getNoEntryHandler();
    if(!handler.isSafeZone(player, toLocation, tagType)) return;

    Location fromLocation = e.getFrom();
    this.expansion.preventEntry(e, player, fromLocation, toLocation);
}
 
Example 6
Source File: ForceField.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onMove(PlayerMoveEvent e) {
    if(!isEnabled()) return;
    
    Player player = e.getPlayer();
    if(canBypass(player)) return;
    
    ICombatManager combatManager = this.plugin.getCombatManager();
    if(!combatManager.isInCombat(player)) return;

    Location toLoc = e.getTo();
    Location fromLoc = e.getFrom();
    if(toLoc == null) return;

    if(toLoc.getBlock().equals(fromLoc.getBlock())) return;
    if(isSafe(toLoc, player)) return;

    updateForceField(player);
}
 
Example 7
Source File: BrushListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
    Location from = event.getFrom();
    Location to = event.getTo();
    if ((from.getYaw() != to.getYaw() &&  from.getPitch() != to.getPitch()) || from.getBlockX() != to.getBlockX() || from.getBlockZ() != to.getBlockZ() || from.getBlockY() != to.getBlockY()) {
        Player bukkitPlayer = event.getPlayer();
        FawePlayer<Object> fp = FawePlayer.wrap(bukkitPlayer);
        com.sk89q.worldedit.entity.Player player = fp.getPlayer();
        LocalSession session = fp.getSession();
        Tool tool = session.getTool(player);
        if (tool != null) {
            if (tool instanceof MovableTool) {
                ((MovableTool) tool).move(player);
            }
        }
    }
}
 
Example 8
Source File: MoveListener.java    From NovaGuilds with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Performs region checking
 *
 * @param event move event
 */
private void execute(PlayerMoveEvent event) {
	Player player = event.getPlayer();
	NovaPlayer nPlayer = PlayerManager.getPlayer(player);
	Location from = event.getFrom();
	Location to = event.getTo();

	NovaRegion fromRegion = RegionManager.get(from);
	NovaRegion toRegion = RegionManager.get(to);

	//entering
	if((fromRegion == null && toRegion != null && nPlayer.getAtRegion() == null) || (fromRegion != null && toRegion != null && !fromRegion.equals(toRegion))) {
		plugin.getRegionManager().playerEnteredRegion(player, toRegion);
	}

	//exiting
	if(fromRegion != null && toRegion == null && nPlayer.getAtRegion() != null) {
		plugin.getRegionManager().playerExitedRegion(player);
	}
}
 
Example 9
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 10
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 11
Source File: EvtMoveOn.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("null")
@Override
public void execute(final @Nullable Listener l, final @Nullable Event event) throws EventException {
	if (event == null)
		return;
	final PlayerMoveEvent e = (PlayerMoveEvent) event;
	final Location from = e.getFrom(), to = e.getTo();
	
	if (!itemTypeTriggers.isEmpty()) {
		final Block block = getOnBlock(to);
		if (block == null || block.getType() == Material.AIR)
			return;
		final Material id = block.getType();
		final List<Trigger> ts = itemTypeTriggers.get(id);
		if (ts == null)
			return;
		final int y = getBlockY(to.getY(), id);
		if (to.getWorld().equals(from.getWorld()) && to.getBlockX() == from.getBlockX() && to.getBlockZ() == from.getBlockZ()
				&& y == getBlockY(from.getY(), getOnBlock(from).getType()) && getOnBlock(from).getType() == id)
			return;
		SkriptEventHandler.logEventStart(e);
		triggersLoop: for (final Trigger t : ts) {
			final EvtMoveOn se = (EvtMoveOn) t.getEvent();
			for (final ItemType i : se.types) {
				if (i.isOfType(block)) {
					SkriptEventHandler.logTriggerStart(t);
					t.execute(e);
					SkriptEventHandler.logTriggerEnd(t);
					continue triggersLoop;
				}
			}
		}
		SkriptEventHandler.logEventEnd();
	}
}
 
Example 12
Source File: RenderListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
    Location from = event.getFrom();
    Location to = event.getTo();
    if (from.getBlockX() >> OFFSET != to.getBlockX() >> OFFSET || from.getBlockZ() >> OFFSET != to.getBlockZ() >> OFFSET) {
        Player player = event.getPlayer();
        int currentView = getViewDistance(player);
        setViewDistance(player, Math.max(currentView - 1, 1));
    }
}
 
Example 13
Source File: CUIListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
    Location from = event.getFrom();
    Location to = event.getTo();
    if ((int) from.getX() >> 2 != (int) to.getX() >> 2 || (int) from.getZ()  >> 2 != (int) to.getZ() >> 2 || (int) from.getY()  >> 2 != (int) to.getY() >> 2) {
        FawePlayer<Object> player = FawePlayer.wrap(event.getPlayer());
        CUI cui = player.getMeta("CUI");
        if (cui instanceof StructureCUI) {
            StructureCUI sCui = (StructureCUI) cui;
            sCui.update();
        }
    }
}
 
Example 14
Source File: PlayerListener.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onPlayerMove(PlayerMoveEvent event) {
	/*
	 * Abort if we havn't really moved
	 */
	if (event.getFrom().getBlockX() == event.getTo().getBlockX() && 
		event.getFrom().getBlockZ() == event.getTo().getBlockZ() && 
		event.getFrom().getBlockY() == event.getTo().getBlockY()) {
		return;
	}
	
	/* Test for enchants effecting movement. */
	/* TODO can speed be set once? If so we should only calculate speed change when our armor changes. */
	setModifiedMovementSpeed(event.getPlayer());
			
	ChunkCoord fromChunk = new ChunkCoord(event.getFrom());
	ChunkCoord toChunk = new ChunkCoord(event.getTo());
	
	// Haven't moved chunks.
	if (fromChunk.equals(toChunk)) {
		return;
	}
	
	TaskMaster.asyncTask(PlayerChunkNotifyAsyncTask.class.getSimpleName(), 
			new PlayerChunkNotifyAsyncTask(event.getFrom(), event.getTo(), event.getPlayer().getName()), 0);

}
 
Example 15
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);
        }
    }
}
 
Example 16
Source File: CEListener.java    From ce with GNU Lesser General Public License v3.0 3 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void PlayerMoveEvent(PlayerMoveEvent e) {

    Location from = e.getFrom();
    Location to = e.getTo();

    if (from.getBlockX() != to.getBlockX() || from.getBlockY() != to.getBlockY() || from.getBlockZ() != to.getBlockZ()) {

        CEventHandler.handleEvent(e.getPlayer(), e, move);
        CEventHandler.handleMines(e.getPlayer(), e);

    }

}