Search in sources :

Example 6 with CommonPacket

use of com.bergerkiller.bukkit.common.protocol.CommonPacket in project BKCommonLib by bergerhealer.

the class CommonObjective method handle.

private void handle(int type) {
    CommonPacket packet = new CommonPacket(PacketType.OUT_SCOREBOARD_OBJECTIVE);
    packet.write(PacketType.OUT_SCOREBOARD_OBJECTIVE.name, this.name);
    packet.write(PacketType.OUT_SCOREBOARD_OBJECTIVE.displayName, this.displayName);
    packet.write(PacketType.OUT_SCOREBOARD_OBJECTIVE.action, type);
    PacketUtil.sendPacket(this.scoreboard.getPlayer(), packet);
}
Also used : CommonPacket(com.bergerkiller.bukkit.common.protocol.CommonPacket)

Example 7 with CommonPacket

use of com.bergerkiller.bukkit.common.protocol.CommonPacket in project BKCommonLib by bergerhealer.

the class CommonScore method remove.

/**
     * Remove the score
     */
protected void remove() {
    if (!this.created) {
        return;
    }
    CommonPacket packet = new CommonPacket(PacketType.OUT_SCOREBOARD_SCORE);
    packet.write(PacketType.OUT_SCOREBOARD_SCORE.name, this.name);
    packet.write(PacketType.OUT_SCOREBOARD_SCORE.action, ScoreboardAction.REMOVE);
    PacketUtil.sendPacket(scoreboard.getPlayer(), packet);
    this.created = false;
}
Also used : CommonPacket(com.bergerkiller.bukkit.common.protocol.CommonPacket)

Example 8 with CommonPacket

use of com.bergerkiller.bukkit.common.protocol.CommonPacket in project BKCommonLib by bergerhealer.

the class MapPlayerInput method updateInputInterception.

@SuppressWarnings("deprecation")
private void updateInputInterception(boolean intercept) {
    if (!intercept && _fakeMountShown) {
        _fakeMountShown = false;
        // Despawn the mount
        PacketUtil.sendPacket(player, PacketType.OUT_ENTITY_DESTROY.newInstance(this._fakeMountId));
        return;
    }
    if (intercept && !_fakeMountShown) {
        _fakeMountShown = true;
        // Generate unique mount Id (we can re-use it)
        if (this._fakeMountId == -1) {
            this._fakeMountId = EntityUtil.getUniqueEntityId();
        }
        // Spawn the mount
        Location loc = player.getLocation();
        {
            DataWatcher data = new DataWatcher();
            data.set(EntityHandle.DATA_FLAGS, (byte) (EntityHandle.DATA_FLAG_INVISIBLE));
            data.set(EntityLivingHandle.DATA_HEALTH, 10.0F);
            CommonPacket packet = PacketType.OUT_ENTITY_SPAWN_LIVING.newInstance();
            packet.write(PacketType.OUT_ENTITY_SPAWN_LIVING.entityId, this._fakeMountId);
            packet.write(PacketType.OUT_ENTITY_SPAWN_LIVING.entityType, (int) EntityType.PIG.getTypeId());
            packet.write(PacketType.OUT_ENTITY_SPAWN_LIVING.x, loc.getX());
            packet.write(PacketType.OUT_ENTITY_SPAWN_LIVING.y, loc.getY() - 0.28);
            packet.write(PacketType.OUT_ENTITY_SPAWN_LIVING.z, loc.getZ());
            packet.write(PacketType.OUT_ENTITY_SPAWN_LIVING.UUID, UUID.randomUUID());
            packet.write(PacketType.OUT_ENTITY_SPAWN_LIVING.dataWatcher, data);
            PacketUtil.sendPacket(player, packet);
        }
        {
            CommonPacket packet = PacketType.OUT_MOUNT.newInstance();
            packet.write(PacketType.OUT_MOUNT.entityId, this._fakeMountId);
            packet.write(PacketType.OUT_MOUNT.mountedEntityIds, new int[] { player.getEntityId() });
            PacketUtil.sendPacket(player, packet);
        }
        return;
    }
}
Also used : CommonPacket(com.bergerkiller.bukkit.common.protocol.CommonPacket) Location(org.bukkit.Location) DataWatcher(com.bergerkiller.bukkit.common.wrappers.DataWatcher)

Example 9 with CommonPacket

use of com.bergerkiller.bukkit.common.protocol.CommonPacket in project BKCommonLib by bergerhealer.

the class PacketHandlerHooked method handlePacketSend.

/**
     * Handles a packet before it is being sent to a player
     *
     * @param player for which the packet was meant
     * @param packet that is handled
     * @param wasCancelled - True if it was originally cancelled, False if not
     * @return True if the packet is allowed to be sent, False if not
     */
public boolean handlePacketSend(Player player, Object packet, boolean wasCancelled) {
    if (player == null || packet == null) {
        return true;
    }
    // Check if silent
    boolean is_silent = false;
    if (!silentQueue.isEmpty()) {
        long time = System.currentTimeMillis();
        synchronized (silentQueue) {
            ListIterator<SilentPacket> iter = silentQueue.listIterator();
            while (iter.hasNext()) {
                SilentPacket sp = iter.next();
                if (time >= sp.timeout) {
                    iter.remove();
                } else if (sp.player == player && sp.packet == packet) {
                    is_silent = true;
                    iter.remove();
                }
            }
        }
    }
    // Handle listeners
    PacketType type = PacketType.getType(packet);
    if (!is_silent) {
        List<PacketListener> listenerList = listeners.get(type);
        if (listenerList != null) {
            CommonPacket cp = new CommonPacket(packet, type);
            PacketSendEvent ev = new PacketSendEvent(player, cp);
            ev.setCancelled(wasCancelled);
            for (PacketListener listener : listenerList) {
                listener.onPacketSend(ev);
            }
            if (ev.isCancelled()) {
                return false;
            }
        }
    }
    // Handle monitors
    handlePacketSendMonitor(player, type, packet);
    return true;
}
Also used : PacketType(com.bergerkiller.bukkit.common.protocol.PacketType) CommonPacket(com.bergerkiller.bukkit.common.protocol.CommonPacket) PacketListener(com.bergerkiller.bukkit.common.protocol.PacketListener) PacketSendEvent(com.bergerkiller.bukkit.common.events.PacketSendEvent)

Example 10 with CommonPacket

use of com.bergerkiller.bukkit.common.protocol.CommonPacket in project BKCommonLib by bergerhealer.

the class PacketHandlerHooked method handlePacketReceive.

/**
     * Handles a packet before it is being handled by the server
     *
     * @param player from which the packet came
     * @param packet that is handled
     * @param wasCancelled - True if the packet is allowed to be received, False
     * if not
     * @return True if the packet is allowed to be received, False if not
     */
public boolean handlePacketReceive(Player player, Object packet, boolean wasCancelled) {
    if (player == null || packet == null) {
        return true;
    }
    // Handle listeners
    PacketType type = PacketType.getType(packet);
    List<PacketListener> listenerList = listeners.get(type);
    if (listenerList != null) {
        CommonPacket cp = new CommonPacket(packet, type);
        PacketReceiveEvent ev = new PacketReceiveEvent(player, cp);
        ev.setCancelled(wasCancelled);
        for (PacketListener listener : listenerList) {
            listener.onPacketReceive(ev);
        }
        if (ev.isCancelled()) {
            return false;
        }
    }
    // Handle monitors
    List<PacketMonitor> monitorList = monitors.get(type);
    if (monitorList != null) {
        CommonPacket cp = new CommonPacket(packet, type);
        for (PacketMonitor monitor : monitorList) {
            monitor.onMonitorPacketReceive(cp, player);
        }
    }
    return true;
}
Also used : PacketMonitor(com.bergerkiller.bukkit.common.protocol.PacketMonitor) PacketType(com.bergerkiller.bukkit.common.protocol.PacketType) CommonPacket(com.bergerkiller.bukkit.common.protocol.CommonPacket) PacketListener(com.bergerkiller.bukkit.common.protocol.PacketListener) PacketReceiveEvent(com.bergerkiller.bukkit.common.events.PacketReceiveEvent)

Aggregations

CommonPacket (com.bergerkiller.bukkit.common.protocol.CommonPacket)17 Player (org.bukkit.entity.Player)3 PacketListener (com.bergerkiller.bukkit.common.protocol.PacketListener)2 PacketType (com.bergerkiller.bukkit.common.protocol.PacketType)2 ArrayList (java.util.ArrayList)2 PacketReceiveEvent (com.bergerkiller.bukkit.common.events.PacketReceiveEvent)1 PacketSendEvent (com.bergerkiller.bukkit.common.events.PacketSendEvent)1 MapPlayerInput (com.bergerkiller.bukkit.common.map.MapPlayerInput)1 PacketMonitor (com.bergerkiller.bukkit.common.protocol.PacketMonitor)1 DataWatcher (com.bergerkiller.bukkit.common.wrappers.DataWatcher)1 EntityHandle (com.bergerkiller.generated.net.minecraft.server.EntityHandle)1 NMSEntityPlayer (com.bergerkiller.reflection.net.minecraft.server.NMSEntityPlayer)1 Location (org.bukkit.Location)1