use of net.minecraft.server.v1_13_R2.DataWatcher.Item in project Citizens2 by CitizensDev.
the class ItemFrameController method createEntity.
@Override
protected Entity createEntity(Location at, NPC npc) {
Entity e = super.createEntity(at, npc);
EntityItemFrame item = (EntityItemFrame) ((CraftEntity) e).getHandle();
item.setDirection(EnumDirection.EAST);
item.blockPosition = new BlockPosition(at.getX(), at.getY(), at.getZ());
return e;
}
use of net.minecraft.server.v1_13_R2.DataWatcher.Item in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method updateEntityNameTagForPlayer.
@Override
public void updateEntityNameTagForPlayer(Player player, org.bukkit.entity.Entity entity, String customName, boolean customNameVisible) {
try {
List<Item<?>> dataWatchers = new ArrayList<>();
Optional<IChatBaseComponent> nameComponent = Optional.ofNullable(CraftChatMessage.fromStringOrNull(customName));
dataWatchers.add(new DataWatcher.Item<>(DataWatcherRegistry.f.a(2), nameComponent));
dataWatchers.add(new DataWatcher.Item<>(DataWatcherRegistry.i.a(3), customNameVisible));
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata();
field_PacketPlayOutEntityMetadata_a.set(packetPlayOutEntityMetadata, entity.getEntityId());
field_PacketPlayOutEntityMetadata_b.set(packetPlayOutEntityMetadata, dataWatchers);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata);
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.minecraft.server.v1_13_R2.DataWatcher.Item in project CokesAddon by Cokes86.
the class v1_13_R2 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_13_R2.DataWatcher.Item in project CokesAddon by Cokes86.
the class v1_16_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_13_R2.DataWatcher.Item in project CokesAddon by Cokes86.
the class v1_16_R2 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);
}
Aggregations