Search in sources :

Example 1 with PlayerVelocityEvent

use of org.bukkit.event.player.PlayerVelocityEvent in project BKCommonLib by bergerhealer.

the class EntityNetworkController method onSync.

/**
 * Called at a set interval to synchronize data to clients.
 * Deprecated: please use {@link #onTick()} instead.
 */
@Deprecated
public void onSync() {
    if (entity.isDead()) {
        return;
    }
    // TODO: Item frame support? Meh. Not for now.
    // Vehicle
    this.syncPassengers();
    // Position / Rotation
    if (this.isUpdateTick() || entity.isPositionChanged() || entity.getDataWatcher().isChanged()) {
        entity.setPositionChanged(false);
        // Update location
        if (this.getTicksSinceLocationSync() > ABSOLUTE_UPDATE_INTERVAL) {
            this.syncLocationAbsolute();
        } else {
            this.syncLocation();
        }
        // Update velocity when position changes
        this.syncVelocity();
    }
    // Refresh/resend velocity when requested (isVelocityChanged sets this)
    if (entity.isVelocityChanged()) {
        entity.setVelocityChanged(false);
        Vector velocity = velLive.vector();
        boolean cancelled = false;
        if (entity.getEntity() instanceof Player) {
            PlayerVelocityEvent event = new PlayerVelocityEvent((Player) entity.getEntity(), velocity);
            if (CommonUtil.callEvent(event).isCancelled()) {
                cancelled = true;
            } else if (!velocity.equals(event.getVelocity())) {
                velocity = event.getVelocity();
                velLive.set(velocity);
            }
        }
        // Send update packet if not cancelled
        if (!cancelled) {
            this.broadcast(getVelocityPacket(velocity.getX(), velocity.getY(), velocity.getZ()));
        }
    }
    // Meta Data
    this.syncMetaData();
    // Head rotation
    this.syncHeadRotation();
}
Also used : Player(org.bukkit.entity.Player) PlayerVelocityEvent(org.bukkit.event.player.PlayerVelocityEvent) Vector(org.bukkit.util.Vector)

Aggregations

Player (org.bukkit.entity.Player)1 PlayerVelocityEvent (org.bukkit.event.player.PlayerVelocityEvent)1 Vector (org.bukkit.util.Vector)1