use of net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket in project MagicPlugin by elBukkit.
the class CompatibilityUtils method spawnFireworkEffect.
@Override
public Entity spawnFireworkEffect(Material fireworkMaterial, Server server, Location location, FireworkEffect effect, int power, Vector direction, Integer expectedLifespan, Integer ticksFlown, boolean silent) {
Entity entity = null;
try {
if (fireworkMaterial == null) {
return null;
}
ServerLevel level = ((CraftWorld) location.getWorld()).getHandle();
ItemStack itemStack = new ItemStack(fireworkMaterial);
FireworkMeta meta = (FireworkMeta) itemStack.getItemMeta();
meta.addEffect(effect);
meta.setPower(power);
itemStack.setItemMeta(meta);
Object item = platform.getItemUtils().getHandle(platform.getItemUtils().makeReal(itemStack));
final FireworkRocketEntity fireworkHandle = new FireworkRocketEntity(level, location.getX(), location.getY(), location.getZ(), (net.minecraft.world.item.ItemStack) item);
fireworkHandle.setSilent(silent);
if (direction != null) {
fireworkHandle.setDeltaMovement(new Vec3(direction.getX(), direction.getY(), direction.getZ()));
}
if (ticksFlown != null) {
ReflectionUtils.setPrivateNeedsFixing(platform.getLogger(), fireworkHandle, FireworkRocketEntity.class, "life", "e", ticksFlown);
}
if (expectedLifespan != null) {
fireworkHandle.lifetime = expectedLifespan;
}
if (direction == null) {
ClientboundAddEntityPacket fireworkPacket = new ClientboundAddEntityPacket(fireworkHandle, CompatibilityConstants.FIREWORK_TYPE);
int fireworkId = fireworkHandle.getId();
SynchedEntityData watcher = fireworkHandle.getEntityData();
ClientboundSetEntityDataPacket metadataPacket = new ClientboundSetEntityDataPacket(fireworkId, watcher, true);
ClientboundEntityEventPacket statusPacket = new ClientboundEntityEventPacket(fireworkHandle, (byte) 17);
ClientboundRemoveEntitiesPacket destroyPacket = new ClientboundRemoveEntitiesPacket(fireworkId);
Collection<? extends Player> players = server.getOnlinePlayers();
sendPacket(server, location, players, fireworkPacket);
sendPacket(server, location, players, metadataPacket);
sendPacket(server, location, players, statusPacket);
sendPacket(server, location, players, destroyPacket);
return null;
}
level.addFreshEntity(fireworkHandle, CreatureSpawnEvent.SpawnReason.CUSTOM);
entity = fireworkHandle.getBukkitEntity();
} catch (Exception ex) {
ex.printStackTrace();
}
return entity;
}
use of net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket in project kit-api by HGLabor.
the class SpidermanKit method onPlayerRightClickKitItem.
@KitEvent
@Override
public void onPlayerRightClickKitItem(PlayerInteractEvent event, KitPlayer kitPlayer) {
Player player = event.getPlayer();
kitPlayer.activateKitCooldown(this);
final Vector direction = player.getEyeLocation().getDirection();
Snowball snowball = player.getWorld().spawn(player.getEyeLocation().add(direction.multiply(shootingVelocity)), Snowball.class);
snowball.setVelocity(direction);
snowball.setShooter(player);
snowball.setMetadata(spidermanSnowballKey, new FixedMetadataValue(KitApi.getInstance().getPlugin(), ""));
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
ClientboundRemoveEntitiesPacket packet = new ClientboundRemoveEntitiesPacket(snowball.getEntityId());
((CraftPlayer) p).getHandle().connection.send(packet);
}
FallingBlock cobWeb = player.getWorld().spawnFallingBlock(player.getEyeLocation().add(direction), spidernetBlock.createBlockData());
cobWeb.setHurtEntities(true);
cobWeb.setVelocity(direction);
cobWeb.setDropItem(false);
snowball.addPassenger(cobWeb);
}
use of net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket in project Denizen by DenizenScript.
the class ProfileEditorImpl method updatePlayer.
@Override
protected void updatePlayer(Player player, final boolean isSkinChanging) {
final ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
final UUID uuid = player.getUniqueId();
ClientboundRemoveEntitiesPacket destroyPacket = new ClientboundRemoveEntitiesPacket(entityPlayer.getId());
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
if (!p.getUniqueId().equals(uuid)) {
PacketHelperImpl.send(p, destroyPacket);
}
}
new BukkitRunnable() {
@Override
public void run() {
ClientboundPlayerInfoPacket playerInfo = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, entityPlayer);
ClientboundAddPlayerPacket spawnPacket = new ClientboundAddPlayerPacket(entityPlayer);
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
PacketHelperImpl.send(player, playerInfo);
if (!player.getUniqueId().equals(uuid)) {
PacketHelperImpl.send(player, spawnPacket);
} else {
if (isSkinChanging) {
((CraftServer) Bukkit.getServer()).getHandle().moveToWorld(entityPlayer, (ServerLevel) entityPlayer.level, true, player.getLocation(), false);
}
player.updateInventory();
}
}
}
}.runTaskLater(NMSHandler.getJavaPlugin(), 5);
}
use of net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket in project Denizen by DenizenScript.
the class ProfileEditorImpl method updatePlayer.
@Override
protected void updatePlayer(Player player, final boolean isSkinChanging) {
final ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
final UUID uuid = player.getUniqueId();
ClientboundRemoveEntitiesPacket destroyPacket = new ClientboundRemoveEntitiesPacket(entityPlayer.getId());
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
if (!p.getUniqueId().equals(uuid)) {
PacketHelperImpl.send(p, destroyPacket);
}
}
new BukkitRunnable() {
@Override
public void run() {
ClientboundPlayerInfoPacket playerInfo = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, entityPlayer);
ClientboundAddPlayerPacket spawnPacket = new ClientboundAddPlayerPacket(entityPlayer);
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
PacketHelperImpl.send(player, playerInfo);
if (!player.getUniqueId().equals(uuid)) {
PacketHelperImpl.send(player, spawnPacket);
} else {
if (isSkinChanging) {
((CraftServer) Bukkit.getServer()).getHandle().respawn(entityPlayer, (ServerLevel) entityPlayer.level, true, player.getLocation(), false);
}
player.updateInventory();
}
}
}
}.runTaskLater(NMSHandler.getJavaPlugin(), 5);
}
use of net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket 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<ArmorStand> fakeArmorStands = fakeArmorStandsMap.get(player);
final List<org.bukkit.entity.Entity> cooldownJump = cooldownJumpMap.get(player);
final ArmorStand as = new ArmorStand(EntityType.ARMOR_STAND, ((CraftWorld) player.getWorld()).getHandle());
as.setInvisible(true);
as.setSharedFlag(5, true);
as.setSmall(true);
as.setNoGravity(true);
as.setShowArms(true);
as.setHeadPose(new Rotations((r.nextInt(360)), (r.nextInt(360)), (r.nextInt(360))));
as.absMoveTo(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()) {
sendPacket(player, new ClientboundAddEntityPacket(as));
sendPacket(players, new ClientboundSetEntityDataPacket(as.getId(), as.getEntityData(), false));
List<Pair<EquipmentSlot, ItemStack>> list = new ArrayList<>();
list.add(new Pair(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(org.bukkit.Material.PACKED_ICE))));
sendPacket(players, new ClientboundSetEquipmentPacket(as.getId(), list));
}
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()) {
sendPacket(pl, new ClientboundRemoveEntitiesPacket(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) {
}
}
Aggregations