Search in sources :

Example 11 with CommonPacket

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

the class CommonScore method update.

/**
     * Update the score
     */
public void update() {
    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.objName, this.objName);
    packet.write(PacketType.OUT_SCOREBOARD_SCORE.value, this.value);
    packet.write(PacketType.OUT_SCOREBOARD_SCORE.action, ScoreboardAction.CHANGE);
    PacketUtil.sendPacket(scoreboard.getPlayer(), packet);
}
Also used : CommonPacket(com.bergerkiller.bukkit.common.protocol.CommonPacket)

Example 12 with CommonPacket

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

the class CommonTeam method getPacket.

/**
     * Get the team packet with a cusotm action
     *
     * @param action of the packet
     * @return Packet
     */
private CommonPacket getPacket(int action) {
    CommonPacket packet = new CommonPacket(PacketType.OUT_SCOREBOARD_TEAM);
    packet.write(PacketType.OUT_SCOREBOARD_TEAM.name, this.name);
    packet.write(PacketType.OUT_SCOREBOARD_TEAM.displayName, this.displayName);
    packet.write(PacketType.OUT_SCOREBOARD_TEAM.prefix, this.prefix);
    packet.write(PacketType.OUT_SCOREBOARD_TEAM.suffix, this.suffix);
    packet.write(PacketType.OUT_SCOREBOARD_TEAM.players, this.players);
    packet.write(PacketType.OUT_SCOREBOARD_TEAM.friendlyFire, this.friendlyFire.getRawInt());
    packet.write(PacketType.OUT_SCOREBOARD_TEAM.mode, action);
    return packet;
}
Also used : CommonPacket(com.bergerkiller.bukkit.common.protocol.CommonPacket)

Example 13 with CommonPacket

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

the class MapDisplay method createPacket.

private CommonPacket createPacket(MapClip clip) {
    CommonPacket mapUpdate = PacketType.OUT_MAP.newInstance();
    mapUpdate.write(PacketType.OUT_MAP.cursors, new MapCursor[0]);
    mapUpdate.write(PacketType.OUT_MAP.itemId, this.info.id);
    mapUpdate.write(PacketType.OUT_MAP.scale, (byte) 1);
    mapUpdate.write(PacketType.OUT_MAP.track, false);
    if (clip == null || clip.everything) {
        mapUpdate.write(PacketType.OUT_MAP.xmin, 0);
        mapUpdate.write(PacketType.OUT_MAP.ymin, 0);
        mapUpdate.write(PacketType.OUT_MAP.width, RESOLUTION);
        mapUpdate.write(PacketType.OUT_MAP.height, RESOLUTION);
        mapUpdate.write(PacketType.OUT_MAP.pixels, this.livebuffer.clone());
    } else {
        int w = clip.getWidth();
        int h = clip.getHeight();
        byte[] pixels = new byte[w * h];
        int dst_index = 0;
        for (int y = 0; y < h; y++) {
            int src_index = ((y + clip.getY()) * 128) + clip.getX();
            System.arraycopy(this.livebuffer, src_index, pixels, dst_index, w);
            dst_index += w;
        }
        mapUpdate.write(PacketType.OUT_MAP.xmin, clip.getX());
        mapUpdate.write(PacketType.OUT_MAP.ymin, clip.getY());
        mapUpdate.write(PacketType.OUT_MAP.width, w);
        mapUpdate.write(PacketType.OUT_MAP.height, h);
        mapUpdate.write(PacketType.OUT_MAP.pixels, pixels);
    }
    return mapUpdate;
}
Also used : CommonPacket(com.bergerkiller.bukkit.common.protocol.CommonPacket)

Example 14 with CommonPacket

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

the class EntityNetworkController method getSpawnPacket.

/**
     * Creates a new spawn packet for spawning this Entity. To change the
     * spawned entity type, override this method. By default, the entity is
     * evaluated and the right packet is created automatically.
     *
     * @return spawn packet
     */
public CommonPacket getSpawnPacket() {
    final CommonPacket packet = handle.getSpawnPacket();
    if (packet != null && packet.getType() == PacketType.OUT_ENTITY_SPAWN) {
        // NMS error: They are not using the position, but the live position
        // This has some big issues when new players join...
        // Motion
        packet.write(PacketType.OUT_ENTITY_SPAWN.motX, protMot(velSynched.getX()));
        packet.write(PacketType.OUT_ENTITY_SPAWN.motY, protMot(velSynched.getY()));
        packet.write(PacketType.OUT_ENTITY_SPAWN.motZ, protMot(velSynched.getZ()));
        // Position
        packet.write(PacketType.OUT_ENTITY_SPAWN.x, locProt(locSynched.getX()));
        packet.write(PacketType.OUT_ENTITY_SPAWN.y, locProt(locSynched.getY()));
        packet.write(PacketType.OUT_ENTITY_SPAWN.z, locProt(locSynched.getZ()));
        // Rotation
        packet.write(PacketType.OUT_ENTITY_SPAWN.yaw, locSynched.getYaw());
        packet.write(PacketType.OUT_ENTITY_SPAWN.pitch, locSynched.getPitch());
    }
    return packet;
}
Also used : CommonPacket(com.bergerkiller.bukkit.common.protocol.CommonPacket)

Example 15 with CommonPacket

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

the class PacketUtil method broadcastPacketNearby.

public static void broadcastPacketNearby(org.bukkit.World world, double x, double y, double z, double radius, Object packet) {
    CommonPacket packetWrap;
    if (packet instanceof CommonPacket) {
        packetWrap = (CommonPacket) packet;
    } else {
        packetWrap = new CommonPacket(packet);
    }
    CommonNMS.getPlayerList().sendPacketNearby(null, x, y, z, radius, WorldUtil.getDimension(world), packetWrap);
}
Also used : CommonPacket(com.bergerkiller.bukkit.common.protocol.CommonPacket)

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