use of net.minecraft.server.v1_16_R3.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_16_R3.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_16_R3.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);
}
use of net.minecraft.server.v1_16_R3.DataWatcher.Item in project CokesAddon by Cokes86.
the class v1_16_R3 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_16_R3.DataWatcher.Item in project Denizen by DenizenScript.
the class PlayerHelperImpl method sendEntitySpawn.
@Override
public FakeEntity sendEntitySpawn(List<PlayerTag> players, DenizenEntityType entityType, LocationTag location, ArrayList<Mechanism> mechanisms, int customId, UUID customUUID, boolean autoTrack) {
CraftWorld world = ((CraftWorld) location.getWorld());
net.minecraft.server.v1_16_R3.Entity nmsEntity;
if (entityType.isCustom()) {
if (entityType.customEntityType == CustomEntityType.ITEM_PROJECTILE) {
org.bukkit.inventory.ItemStack itemStack = new ItemStack(Material.STONE);
for (Mechanism mechanism : mechanisms) {
if (mechanism.matches("item") && mechanism.requireObject(ItemTag.class)) {
itemStack = mechanism.valueAsType(ItemTag.class).getItemStack();
}
}
nmsEntity = new EntityItemProjectileImpl(world.getHandle(), location, CraftItemStack.asNMSCopy(itemStack));
} else if (entityType.customEntityType == CustomEntityType.FAKE_PLAYER) {
String name = null;
String skin = null;
for (Mechanism mechanism : new ArrayList<>(mechanisms)) {
if (mechanism.matches("name")) {
name = mechanism.getValue().asString();
mechanisms.remove(mechanism);
} else if (mechanism.matches("skin")) {
skin = mechanism.getValue().asString();
mechanisms.remove(mechanism);
}
if (name != null && skin != null) {
break;
}
}
nmsEntity = ((CraftFakePlayerImpl) CustomEntityHelperImpl.spawnFakePlayer(location, name, skin, false)).getHandle();
} else {
throw new IllegalArgumentException("entityType");
}
} else {
nmsEntity = world.createEntity(location, entityType.getBukkitEntityType().getEntityClass());
}
if (customUUID != null) {
nmsEntity.e(customId);
nmsEntity.a_(customUUID);
}
EntityTag entity = new EntityTag(nmsEntity.getBukkitEntity());
for (Mechanism mechanism : mechanisms) {
entity.safeAdjustDuplicate(mechanism);
}
nmsEntity.dead = false;
FakeEntity fake = new FakeEntity(players, location, entity.getBukkitEntity().getEntityId());
fake.entity = new EntityTag(entity.getBukkitEntity());
fake.entity.isFake = true;
fake.entity.isFakeValid = true;
List<TrackerData> trackers = new ArrayList<>();
fake.triggerSpawnPacket = (player) -> {
EntityPlayer nmsPlayer = ((CraftPlayer) player.getPlayerEntity()).getHandle();
PlayerConnection conn = nmsPlayer.playerConnection;
final EntityTrackerEntry tracker = new EntityTrackerEntry(world.getHandle(), nmsEntity, 1, true, conn::sendPacket, Collections.singleton(nmsPlayer));
tracker.b(nmsPlayer);
final TrackerData data = new TrackerData();
data.player = player;
data.tracker = tracker;
trackers.add(data);
if (autoTrack) {
new BukkitRunnable() {
boolean wasOnline = true;
@Override
public void run() {
if (!fake.entity.isFakeValid) {
cancel();
return;
}
if (player.isOnline()) {
if (!wasOnline) {
tracker.b(((CraftPlayer) player.getPlayerEntity()).getHandle());
wasOnline = true;
}
tracker.a();
} else if (wasOnline) {
wasOnline = false;
}
}
}.runTaskTimer(Denizen.getInstance(), 1, 1);
}
};
for (PlayerTag player : players) {
fake.triggerSpawnPacket.accept(player);
}
fake.triggerUpdatePacket = () -> {
for (TrackerData tracker : trackers) {
if (tracker.player.isOnline()) {
tracker.tracker.a();
}
}
};
fake.triggerDestroyPacket = () -> {
for (TrackerData tracker : trackers) {
if (tracker.player.isOnline()) {
tracker.tracker.a(((CraftPlayer) tracker.player.getPlayerEntity()).getHandle());
}
}
trackers.clear();
};
return fake;
}
Aggregations