use of net.minecraft.server.v1_14_R1.PacketPlayOutEntityMetadata in project DragonsOnline by UniverseCraft.
the class PlayerNPC116R3 method spawnFor.
public void spawnFor(Player player) {
if (isDestroyed)
return;
// resync
location = getEntity().getLocation();
location.setYaw(originalYaw);
handle.setCustomNameVisible(false);
sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, handle), player);
sync(() -> sendPacket(new PacketPlayOutNamedEntitySpawn(handle), player), 1);
PacketPlayOutEntityTeleport tp = new PacketPlayOutEntityTeleport();
setField(tp, "a", getEntityId());
setField(tp, "b", location.getX());
setField(tp, "c", location.getY());
setField(tp, "d", location.getZ());
setField(tp, "e", getPacketRotation(location.getYaw()));
setField(tp, "f", getPacketRotation(location.getPitch()));
setField(tp, "g", handle.isOnGround());
sync(() -> sendPacket(new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true), player), 2);
sync(() -> setTablistName(getTablistName()), 2);
sync(() -> sendPacket(tp, player), 3);
sync(() -> sendPacket(new PacketPlayOutEntityHeadRotation(handle, getPacketRotation(location.getYaw())), player), 6);
sync(() -> removeFromTablistFor(player), 20 + (int) Math.ceil(2 * bridge.getPing(player) * 20 / 1000));
lastSeenLocation.put(player, location.clone());
// https://www.spigotmc.org/threads/remove-nameplate-of-an-nms-player-entity.436099/ (Phaze)
ScoreboardTeam team = new ScoreboardTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), player.getName());
team.setNameTagVisibility(ScoreboardTeamBase.EnumNameTagVisibility.NEVER);
sendPacket(new PacketPlayOutScoreboardTeam(team, 1), player);
sendPacket(new PacketPlayOutScoreboardTeam(team, 0), player);
sendPacket(new PacketPlayOutScoreboardTeam(team, List.of(handle.getName()), 3), player);
}
use of net.minecraft.server.v1_14_R1.PacketPlayOutEntityMetadata in project CokesAddon by Cokes86.
the class v1_14_R1 method injectPlayer.
public void injectPlayer(Player player) {
CraftPlayer player1 = (CraftPlayer) player;
if (!player.isValid())
return;
if (channelHandlers.containsKey(player.getUniqueId())) {
final Pair<CraftPlayer, ChannelOutboundHandlerAdapter> pair = channelHandlers.get(player.getUniqueId());
if (!pair.getLeft().isValid()) {
try {
pair.getLeft().getHandle().playerConnection.networkManager.channel.pipeline().remove(pair.getRight());
} catch (NoSuchElementException ignored) {
}
} else
return;
}
final ChannelOutboundHandlerAdapter handler = new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
if (packet instanceof PacketPlayOutEntityEquipment) {
if ((int) ReflectionUtil.FieldUtil.getValue(packet, "a") == getPlayer().getEntityId()) {
ReflectionUtil.FieldUtil.setValue(packet, "c", ItemStack.a);
}
} else if (packet instanceof PacketPlayOutEntityMetadata) {
if ((int) ReflectionUtil.FieldUtil.getValue(packet, "a") == getPlayer().getEntityId()) {
List<Item<?>> items = ReflectionUtil.FieldUtil.getValue(packet, "b");
if (items.size() != 0) {
Item<?> item = items.get(0);
if (BYTE_DATA_WATCHER_OBJECT.equals(item.a())) {
Item<Byte> byteItem = (Item<Byte>) item;
byteItem.a((byte) (byteItem.b() | 1 << 5));
((CraftPlayer) getPlayer()).getHandle().setInvisible(true);
}
}
}
}
super.write(ctx, packet, promise);
}
};
channelHandlers.put(player.getUniqueId(), Pair.of(player1, handler));
player1.getHandle().playerConnection.networkManager.channel.pipeline().addBefore("packet_handler", hashCode() + ":" + player.getName(), handler);
}
use of net.minecraft.server.v1_14_R1.PacketPlayOutEntityMetadata in project MechanicsMain by WeaponMechanics.
the class FakeEntity_1_14_R1 method show.
@Override
public void show(@NotNull Player player) {
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
if (connections.contains(connection))
throw new IllegalArgumentException();
connection.sendPacket(type.isAlive() ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) : new PacketPlayOutSpawnEntity(entity, type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0));
connection.sendPacket(new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true));
connection.sendPacket(new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false));
connection.sendPacket(new PacketPlayOutEntityVelocity(cache, new Vec3D(motion.getX(), motion.getY(), motion.getZ())));
connection.sendPacket(new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw())));
PacketPlayOutEntityEquipment[] equipment = getEquipmentPacket();
if (equipment != null) {
for (PacketPlayOutEntityEquipment packet : equipment) {
connection.sendPacket(packet);
}
}
// Inject the player's packet connection into this listener, so we can
// show the player position/velocity/rotation changes
connections.add(connection);
}
use of net.minecraft.server.v1_14_R1.PacketPlayOutEntityMetadata in project Citizens2 by CitizensDev.
the class PlayerAnimationImpl method play.
public static void play(PlayerAnimation animation, Player bplayer, int radius) {
// TODO: this is pretty gross
final EntityPlayer player = (EntityPlayer) NMSImpl.getHandle(bplayer);
if (DEFAULTS.containsKey(animation)) {
playDefaultAnimation(player, radius, DEFAULTS.get(animation));
return;
}
switch(animation) {
case SIT:
player.getBukkitEntity().setMetadata("citizens.sitting", new FixedMetadataValue(CitizensAPI.getPlugin(), true));
NPCRegistry registry = CitizensAPI.getNamedNPCRegistry("PlayerAnimationImpl");
if (registry == null) {
registry = CitizensAPI.createNamedNPCRegistry("PlayerAnimationImpl", new MemoryNPCDataStore());
}
final NPC holder = registry.createNPC(EntityType.ARMOR_STAND, "");
holder.spawn(player.getBukkitEntity().getLocation());
ArmorStandTrait trait = holder.getOrAddTrait(ArmorStandTrait.class);
trait.setGravity(false);
trait.setHasArms(false);
trait.setHasBaseplate(false);
trait.setSmall(true);
trait.setMarker(true);
trait.setVisible(false);
holder.data().set(NPC.NAMEPLATE_VISIBLE_METADATA, false);
holder.data().set(NPC.DEFAULT_PROTECTED_METADATA, true);
new BukkitRunnable() {
@Override
public void cancel() {
super.cancel();
holder.destroy();
}
@Override
public void run() {
if (player.dead || !player.valid || !player.getBukkitEntity().hasMetadata("citizens.sitting") || !player.getBukkitEntity().getMetadata("citizens.sitting").get(0).asBoolean()) {
cancel();
return;
}
if (player instanceof NPCHolder && !((NPCHolder) player).getNPC().isSpawned()) {
cancel();
return;
}
if (!NMS.getPassengers(holder.getEntity()).contains(player.getBukkitEntity())) {
NMS.mount(holder.getEntity(), player.getBukkitEntity());
}
}
}.runTaskTimer(CitizensAPI.getPlugin(), 0, 1);
break;
case SLEEP:
PacketPlayOutBed packet = new PacketPlayOutBed(player, new BlockPosition((int) player.locX, (int) player.locY, (int) player.locZ));
sendPacketNearby(packet, player, radius);
break;
case SNEAK:
player.getBukkitEntity().setSneaking(true);
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
break;
case START_ELYTRA:
player.J();
break;
case START_USE_MAINHAND_ITEM:
player.c(EnumHand.MAIN_HAND);
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
break;
case START_USE_OFFHAND_ITEM:
player.c(EnumHand.OFF_HAND);
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
break;
case STOP_SITTING:
player.getBukkitEntity().setMetadata("citizens.sitting", new FixedMetadataValue(CitizensAPI.getPlugin(), false));
NMS.mount(player.getBukkitEntity(), null);
break;
case STOP_SLEEPING:
playDefaultAnimation(player, radius, 2);
break;
case STOP_SNEAKING:
player.getBukkitEntity().setSneaking(false);
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
break;
case STOP_USE_ITEM:
player.clearActiveItem();
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
break;
default:
throw new UnsupportedOperationException();
}
}
use of net.minecraft.server.v1_14_R1.PacketPlayOutEntityMetadata in project Citizens2 by CitizensDev.
the class PlayerAnimationImpl method play.
public static void play(PlayerAnimation animation, Player bplayer, int radius) {
// TODO: this is pretty gross
final EntityPlayer player = (EntityPlayer) NMSImpl.getHandle(bplayer);
if (DEFAULTS.containsKey(animation)) {
playDefaultAnimation(player, radius, DEFAULTS.get(animation));
return;
}
switch(animation) {
case SIT:
player.getBukkitEntity().setMetadata("citizens.sitting", new FixedMetadataValue(CitizensAPI.getPlugin(), true));
NPCRegistry registry = CitizensAPI.getNamedNPCRegistry("PlayerAnimationImpl");
if (registry == null) {
registry = CitizensAPI.createNamedNPCRegistry("PlayerAnimationImpl", new MemoryNPCDataStore());
}
final NPC holder = registry.createNPC(EntityType.ARMOR_STAND, "");
holder.spawn(player.getBukkitEntity().getLocation());
ArmorStandTrait trait = holder.getOrAddTrait(ArmorStandTrait.class);
trait.setGravity(false);
trait.setHasArms(false);
trait.setHasBaseplate(false);
trait.setSmall(true);
trait.setMarker(true);
trait.setVisible(false);
holder.data().set(NPC.NAMEPLATE_VISIBLE_METADATA, false);
holder.data().set(NPC.DEFAULT_PROTECTED_METADATA, true);
new BukkitRunnable() {
@Override
public void cancel() {
super.cancel();
holder.destroy();
}
@Override
public void run() {
if (player.dead || !player.valid || !player.getBukkitEntity().hasMetadata("citizens.sitting") || !player.getBukkitEntity().getMetadata("citizens.sitting").get(0).asBoolean()) {
cancel();
return;
}
if (player instanceof NPCHolder && !((NPCHolder) player).getNPC().isSpawned()) {
cancel();
return;
}
if (!NMS.getPassengers(holder.getEntity()).contains(player.getBukkitEntity())) {
NMS.mount(holder.getEntity(), player.getBukkitEntity());
}
}
}.runTaskTimer(CitizensAPI.getPlugin(), 0, 1);
break;
case SLEEP:
PacketPlayOutBed packet = new PacketPlayOutBed(player, new BlockPosition((int) player.locX, (int) player.locY, (int) player.locZ));
sendPacketNearby(packet, player, radius);
break;
case SNEAK:
player.getBukkitEntity().setSneaking(true);
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
break;
case START_ELYTRA:
player.N();
break;
case START_USE_MAINHAND_ITEM:
player.c(EnumHand.MAIN_HAND);
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
break;
case START_USE_OFFHAND_ITEM:
player.c(EnumHand.OFF_HAND);
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
break;
case STOP_SITTING:
player.getBukkitEntity().setMetadata("citizens.sitting", new FixedMetadataValue(CitizensAPI.getPlugin(), false));
NMS.mount(player.getBukkitEntity(), null);
break;
case STOP_SLEEPING:
playDefaultAnimation(player, radius, 2);
break;
case STOP_SNEAKING:
player.getBukkitEntity().setSneaking(false);
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
break;
case STOP_USE_ITEM:
player.clearActiveItem();
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
break;
default:
throw new UnsupportedOperationException();
}
}
Aggregations