本文整理汇总了Java中cn.nukkit.Server.broadcastPacket方法的典型用法代码示例。如果您正苦于以下问题:Java Server.broadcastPacket方法的具体用法?Java Server.broadcastPacket怎么用?Java Server.broadcastPacket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cn.nukkit.Server
的用法示例。
在下文中一共展示了Server.broadcastPacket方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addSound
import cn.nukkit.Server; //导入方法依赖的package包/类
public void addSound(Sound sound, Player[] players) {
DataPacket[] packets = sound.encode();
if (players == null) {
if (packets != null) {
for (DataPacket packet : packets) {
this.addChunkPacket((int) sound.x >> 4, (int) sound.z >> 4, packet);
}
}
} else {
if (packets != null) {
if (packets.length == 1) {
Server.broadcastPacket(players, packets[0]);
} else {
this.server.batchPackets(players, packets, false);
}
}
}
}
示例2: setRaining
import cn.nukkit.Server; //导入方法依赖的package包/类
public boolean setRaining(boolean raining) {
WeatherChangeEvent ev = new WeatherChangeEvent(this, raining);
this.getServer().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return false;
}
this.raining = raining;
LevelEventPacket pk = new LevelEventPacket();
// These numbers are from Minecraft
if (raining) {
pk.evid = LevelEventPacket.EVENT_START_RAIN;
pk.data = rand.nextInt(50000) + 10000;
setRainTime(rand.nextInt(12000) + 12000);
} else {
pk.evid = LevelEventPacket.EVENT_STOP_RAIN;
setRainTime(rand.nextInt(168000) + 12000);
}
Server.broadcastPacket(this.getPlayers().values(), pk);
return true;
}
示例3: sendWeather
import cn.nukkit.Server; //导入方法依赖的package包/类
public void sendWeather(Player[] players) {
if (players == null) {
players = this.getPlayers().values().stream().toArray(Player[]::new);
}
LevelEventPacket pk = new LevelEventPacket();
if (this.isRaining()) {
pk.evid = LevelEventPacket.EVENT_START_RAIN;
pk.data = rand.nextInt(50000) + 10000;
} else {
pk.evid = LevelEventPacket.EVENT_STOP_RAIN;
}
Server.broadcastPacket(players, pk);
if (this.isThundering()) {
pk.evid = LevelEventPacket.EVENT_START_THUNDER;
pk.data = rand.nextInt(50000) + 10000;
} else {
pk.evid = LevelEventPacket.EVENT_STOP_THUNDER;
}
Server.broadcastPacket(players, pk);
}
示例4: addLevelSoundEvent
import cn.nukkit.Server; //导入方法依赖的package包/类
public void addLevelSoundEvent(byte type, int pitch, int data, Vector3 pos, Collection<Player> players, boolean unknown, boolean disableRelativeVolume) {
LevelSoundEventPacket pk = new LevelSoundEventPacket();
pk.sound = type;
pk.pitch = pitch;
pk.extraData = data;
pk.x = (float) pos.x;
pk.y = (float) pos.y;
pk.z = (float) pos.z;
pk.unknownBool = unknown;
pk.disableRelativeVolume = disableRelativeVolume;
if (players == null) {
this.addChunkPacket(pos.getFloorX(), pos.getFloorZ(), pk);
} else {
Server.broadcastPacket(players, pk);
}
}
示例5: addParticle
import cn.nukkit.Server; //导入方法依赖的package包/类
public void addParticle(Particle particle, Player[] players) {
DataPacket[] packets = particle.encode();
if (players == null) {
if (packets != null) {
for (DataPacket packet : packets) {
this.addChunkPacket((int) particle.x >> 4, (int) particle.z >> 4, packet);
}
}
} else {
if (packets != null) {
if (packets.length == 1) {
Server.broadcastPacket(players, packets[0]);
} else {
this.server.batchPackets(players, packets, false);
}
}
}
}
示例6: setHealth
import cn.nukkit.Server; //导入方法依赖的package包/类
@Override
public void setHealth(float health) {
boolean wasAlive = this.isAlive();
super.setHealth(health);
if (this.isAlive() && !wasAlive) {
EntityEventPacket pk = new EntityEventPacket();
pk.eid = this.getId();
pk.eid = EntityEventPacket.RESPAWN;
Server.broadcastPacket(this.hasSpawned.values(), pk);
}
}
示例7: setThundering
import cn.nukkit.Server; //导入方法依赖的package包/类
public boolean setThundering(boolean thundering) {
ThunderChangeEvent ev = new ThunderChangeEvent(this, thundering);
this.getServer().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return false;
}
if (thundering && !isRaining()) {
setRaining(true);
}
this.thundering = thundering;
LevelEventPacket pk = new LevelEventPacket();
// These numbers are from Minecraft
if (thundering) {
pk.evid = LevelEventPacket.EVENT_START_THUNDER;
pk.data = rand.nextInt(50000) + 10000;
setThunderTime(rand.nextInt(12000) + 3600);
} else {
pk.evid = LevelEventPacket.EVENT_STOP_THUNDER;
setThunderTime(rand.nextInt(168000) + 12000);
}
Server.broadcastPacket(this.getPlayers().values(), pk);
return true;
}
示例8: attack
import cn.nukkit.Server; //导入方法依赖的package包/类
@Override
public boolean attack(EntityDamageEvent source) {
if (super.attack(source)) {
if (source instanceof EntityDamageByEntityEvent) {
Entity damager = ((EntityDamageByEntityEvent) source).getDamager();
if (damager instanceof Player) {
if (((Player) damager).isCreative()) {
this.kill();
}
if (this.getHealth() <= 0) {
if (((Player) damager).isSurvival()) {
this.level.dropItem(this, new ItemBoat());
}
this.close();
}
}
}
EntityEventPacket pk = new EntityEventPacket();
pk.eid = this.getId();
pk.event = this.getHealth() <= 0 ? EntityEventPacket.DEATH_ANIMATION : EntityEventPacket.HURT_ANIMATION;
Server.broadcastPacket(this.hasSpawned.values(), pk);
return true;
} else {
return false;
}
}
示例9: sendBlockExtraData
import cn.nukkit.Server; //导入方法依赖的package包/类
public void sendBlockExtraData(int x, int y, int z, int id, int data, Player[] players) {
LevelEventPacket pk = new LevelEventPacket();
pk.evid = LevelEventPacket.EVENT_SET_DATA;
pk.x = x + 0.5f;
pk.y = y + 0.5f;
pk.z = z + 0.5f;
pk.data = (data << 8) | id;
Server.broadcastPacket(players, pk);
}
示例10: play
import cn.nukkit.Server; //导入方法依赖的package包/类
public void play() {
if (this.recordItem instanceof ItemRecord) {
LevelSoundEventPacket pk = new LevelSoundEventPacket();
pk.sound = ((ItemRecord) this.recordItem).getSoundId();
pk.pitch = 1;
pk.extraData = -1;
pk.x = (float) this.x;
pk.y = (float) this.y;
pk.z = (float) this.z;
Server.broadcastPacket(this.level.getPlayers().values(), pk);
}
}
示例11: sendTime
import cn.nukkit.Server; //导入方法依赖的package包/类
public void sendTime(Player... players) {
/*if (this.stopTime) { //TODO
SetTimePacket pk0 = new SetTimePacket();
pk0.time = (int) this.time;
player.dataPacket(pk0);
}*/
SetTimePacket pk = new SetTimePacket();
pk.time = (int) this.time;
Server.broadcastPacket(players, pk);
}
示例12: sendEnchantmentList
import cn.nukkit.Server; //导入方法依赖的package包/类
public void sendEnchantmentList() {
CraftingDataPacket pk = new CraftingDataPacket();
if (this.entries != null && this.levels != null) {
EnchantmentList list = new EnchantmentList(this.entries.length);
for (int i = 0; i < list.getSize(); i++) {
list.setSlot(i, this.entries[i]);
}
pk.addEnchantList(list);
}
Server.broadcastPacket(this.getViewers(), pk);
}
示例13: sendBlockExtraData
import cn.nukkit.Server; //导入方法依赖的package包/类
public void sendBlockExtraData(int x, int y, int z, int id, int data, Collection<Player> players) {
LevelEventPacket pk = new LevelEventPacket();
pk.evid = LevelEventPacket.EVENT_SET_DATA;
pk.x = x + 0.5f;
pk.y = y + 0.5f;
pk.z = z + 0.5f;
pk.data = (data << 8) | id;
Server.broadcastPacket(players, pk);
}
示例14: setHealth
import cn.nukkit.Server; //导入方法依赖的package包/类
@Override
public void setHealth(float health) {
boolean wasAlive = this.isAlive();
super.setHealth(health);
if (this.isAlive() && !wasAlive) {
EntityEventPacket pk = new EntityEventPacket();
pk.entityRuntimeId = this.getId();
pk.event = EntityEventPacket.RESPAWN;
Server.broadcastPacket(this.level.getPlayers().values(), pk);
}
}
示例15: onCollideWithPlayer
import cn.nukkit.Server; //导入方法依赖的package包/类
@Override
public void onCollideWithPlayer(Player player) {
if(!this.hadCollision) {
return;
}
Item item = new Item(Item.ARROW, 0, 1);
PlayerInventory playerInventory = player.getInventory();
if(player.isSurvival() && playerInventory.canAddItem(item)) {
return;
}
InventoryPickupArrowEvent ev;
this.server.getPluginManager().callEvent(ev = new InventoryPickupArrowEvent(playerInventory, this));
if(ev.isCancelled()) {
return;
}
TakeItemEntityPacket pk = new TakeItemEntityPacket();
pk.entityRuntimeId = player.getId();
pk.target = this.getId();
Server.broadcastPacket(this.getViewers().values(), pk);
playerInventory.addItem(item);
this.kill();
}