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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations