use of net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment in project Citizens2 by CitizensDev.
the class EntityHumanNPC method updatePackets.
private void updatePackets(boolean navigating) {
updateCounter++;
boolean itemChanged = false;
for (EnumItemSlot slot : EnumItemSlot.values()) {
ItemStack equipment = getEquipment(slot);
ItemStack cache = equipmentCache.get(slot);
if (!(cache == null && equipment == null) && (cache == null ^ equipment == null || !ItemStack.equals(cache, equipment))) {
itemChanged = true;
}
equipmentCache.put(slot, equipment);
}
if (updateCounter++ <= npc.data().<Integer>get(NPC.Metadata.PACKET_UPDATE_DELAY, Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
return;
updateCounter = 0;
Location current = getBukkitEntity().getLocation(packetLocationCache);
Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
int i = 0;
for (EnumItemSlot slot : EnumItemSlot.values()) {
packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
}
NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
use of net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment in project Citizens2 by CitizensDev.
the class EntityHumanNPC method updatePackets.
private void updatePackets(boolean navigating) {
updateCounter++;
boolean itemChanged = false;
for (EnumItemSlot slot : EnumItemSlot.values()) {
ItemStack equipment = getEquipment(slot);
ItemStack cache = equipmentCache.get(slot);
if (!(cache == null && equipment == null) && (cache == null ^ equipment == null || !ItemStack.equals(cache, equipment))) {
itemChanged = true;
}
equipmentCache.put(slot, equipment);
}
if (updateCounter++ <= npc.data().<Integer>get(NPC.Metadata.PACKET_UPDATE_DELAY, Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
return;
updateCounter = 0;
Location current = getBukkitEntity().getLocation(packetLocationCache);
Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
int i = 0;
for (EnumItemSlot slot : EnumItemSlot.values()) {
packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
}
NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
use of net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment in project UltraCosmetics by iSach.
the class EntityUtil method sendBlizzard.
@Override
public void sendBlizzard(final Player player, Location loc, boolean affectPlayers, Vector v) {
if (!fakeArmorStandsMap.containsKey(player))
fakeArmorStandsMap.put(player, new ArrayList<>());
if (!cooldownJumpMap.containsKey(player))
cooldownJumpMap.put(player, new ArrayList<>());
final List<EntityArmorStand> fakeArmorStands = fakeArmorStandsMap.get(player);
final List<Entity> cooldownJump = cooldownJumpMap.get(player);
final EntityArmorStand as = new EntityArmorStand(((CraftWorld) player.getWorld()).getHandle());
as.setInvisible(true);
as.setSmall(true);
as.setGravity(false);
as.setArms(true);
as.setHeadPose(new Vector3f(r.nextInt(360), r.nextInt(360), r.nextInt(360)));
as.setLocation(loc.getX() + MathUtils.randomDouble(-1.5, 1.5), loc.getY() + MathUtils.randomDouble(0, .5) - 0.75, loc.getZ() + MathUtils.randomDouble(-1.5, 1.5), 0, 0);
fakeArmorStands.add(as);
for (Player players : player.getWorld().getPlayers()) {
PacketSender.send(players, new PacketPlayOutSpawnEntityLiving(as));
PacketSender.send(players, new PacketPlayOutEntityEquipment(as.getId(), 4, CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.PACKED_ICE))));
}
UtilParticles.display(Particles.CLOUD, loc.clone().add(MathUtils.randomDouble(-1.5, 1.5), MathUtils.randomDouble(0, .5) - 0.75, MathUtils.randomDouble(-1.5, 1.5)), 2, 0.4f);
Bukkit.getScheduler().runTaskLater(UltraCosmeticsData.get().getPlugin(), () -> {
for (Player pl : player.getWorld().getPlayers()) {
if (as == null) {
continue;
}
PacketSender.send(pl, new PacketPlayOutEntityDestroy(as.getId()));
}
fakeArmorStands.remove(as);
}, 20);
if (affectPlayers)
for (final Entity ent : as.getBukkitEntity().getNearbyEntities(0.5, 0.5, 0.5)) {
if (!cooldownJump.contains(ent) && ent != player) {
MathUtils.applyVelocity(ent, new Vector(0, 1, 0).add(v));
cooldownJump.add(ent);
Bukkit.getScheduler().runTaskLater(UltraCosmeticsData.get().getPlugin(), () -> cooldownJump.remove(ent), 20);
}
}
}
use of net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment in project UltraCosmetics by iSach.
the class EntityUtil method sendBlizzard.
@Override
public void sendBlizzard(final Player player, Location loc, boolean affectPlayers, Vector v) {
try {
if (!fakeArmorStandsMap.containsKey(player))
fakeArmorStandsMap.put(player, new ArrayList<>());
if (!cooldownJumpMap.containsKey(player))
cooldownJumpMap.put(player, new ArrayList<>());
final List<EntityArmorStand> fakeArmorStands = fakeArmorStandsMap.get(player);
final List<org.bukkit.entity.Entity> cooldownJump = cooldownJumpMap.get(player);
final EntityArmorStand as = new EntityArmorStand(EntityTypes.ARMOR_STAND, ((CraftWorld) player.getWorld()).getHandle());
as.setInvisible(true);
as.setFlag(5, true);
as.setSmall(true);
as.setNoGravity(true);
as.setArms(true);
as.setHeadPose(new Vector3f((float) (r.nextInt(360)), (float) (r.nextInt(360)), (float) (r.nextInt(360))));
as.setLocation(loc.getX() + MathUtils.randomDouble(-1.5, 1.5), loc.getY() + MathUtils.randomDouble(0, .5) - 0.75, loc.getZ() + MathUtils.randomDouble(-1.5, 1.5), 0, 0);
fakeArmorStands.add(as);
for (Player players : player.getWorld().getPlayers()) {
PacketSender.send(players, new PacketPlayOutSpawnEntityLiving(as));
PacketSender.send(players, new PacketPlayOutEntityMetadata(as.getId(), as.getDataWatcher(), false));
PacketSender.send(players, new PacketPlayOutEntityEquipment(as.getId(), EnumItemSlot.HEAD, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(org.bukkit.Material.PACKED_ICE))));
}
UtilParticles.display(Particles.CLOUD, loc.clone().add(MathUtils.randomDouble(-1.5, 1.5), MathUtils.randomDouble(0, .5) - 0.75, MathUtils.randomDouble(-1.5, 1.5)), 2, 0.4f);
Bukkit.getScheduler().runTaskLater(UltraCosmeticsData.get().getPlugin(), () -> {
for (Player pl : player.getWorld().getPlayers()) PacketSender.send(pl, new PacketPlayOutEntityDestroy(as.getId()));
fakeArmorStands.remove(as);
}, 20);
if (affectPlayers)
as.getBukkitEntity().getNearbyEntities(0.5, 0.5, 0.5).stream().filter(ent -> !cooldownJump.contains(ent) && ent != player).forEachOrdered(ent -> {
MathUtils.applyVelocity(ent, new Vector(0, 1, 0).add(v));
cooldownJump.add(ent);
Bukkit.getScheduler().runTaskLater(UltraCosmeticsData.get().getPlugin(), () -> cooldownJump.remove(ent), 20);
});
} catch (Exception exc) {
}
}
use of net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment in project DragonsOnline by UniverseCraft.
the class PlayerNPC116R3 method setEquipment.
public void setEquipment(EquipmentSlot slot, org.bukkit.inventory.ItemStack item) {
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
this.setField(packet, "a", handle.getId());
this.setField(packet, "b", CraftEquipmentSlot.getNMS(slot));
this.setField(packet, "c", CraftItemStack.asNMSCopy(item));
this.sendPacket(packet);
}
Aggregations