001 package org.bukkit.event.player; 002 003 import org.bukkit.Location; 004 import org.bukkit.entity.Player; 005 import org.bukkit.event.Cancellable; 006 import org.bukkit.event.HandlerList; 007 008 /** 009 * Holds information for player movement events 010 */ 011 public class PlayerMoveEvent extends PlayerEvent implements Cancellable { 012 private static final HandlerList handlers = new HandlerList(); 013 private boolean cancel = false; 014 private Location from; 015 private Location to; 016 017 public PlayerMoveEvent(final Player player, final Location from, final Location to) { 018 super(player); 019 this.from = from; 020 this.to = to; 021 } 022 023 /** 024 * Gets the cancellation state of this event. A cancelled event will not 025 * be executed in the server, but will still pass to other plugins 026 * <p> 027 * If a move or teleport event is cancelled, the player will be moved or 028 * teleported back to the Location as defined by getFrom(). This will not 029 * fire an event 030 * 031 * @return true if this event is cancelled 032 */ 033 public boolean isCancelled() { 034 return cancel; 035 } 036 037 /** 038 * Sets the cancellation state of this event. A cancelled event will not 039 * be executed in the server, but will still pass to other plugins 040 * <p> 041 * If a move or teleport event is cancelled, the player will be moved or 042 * teleported back to the Location as defined by getFrom(). This will not 043 * fire an event 044 * 045 * @param cancel true if you wish to cancel this event 046 */ 047 public void setCancelled(boolean cancel) { 048 this.cancel = cancel; 049 } 050 051 /** 052 * Gets the location this player moved from 053 * 054 * @return Location the player moved from 055 */ 056 public Location getFrom() { 057 return from; 058 } 059 060 /** 061 * Sets the location to mark as where the player moved from 062 * 063 * @param from New location to mark as the players previous location 064 */ 065 public void setFrom(Location from) { 066 this.from = from; 067 } 068 069 /** 070 * Gets the location this player moved to 071 * 072 * @return Location the player moved to 073 */ 074 public Location getTo() { 075 return to; 076 } 077 078 /** 079 * Sets the location that this player will move to 080 * 081 * @param to New Location this player will move to 082 */ 083 public void setTo(Location to) { 084 this.to = to; 085 } 086 087 @Override 088 public HandlerList getHandlers() { 089 return handlers; 090 } 091 092 public static HandlerList getHandlerList() { 093 return handlers; 094 } 095 }