use of org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer in project CokesAddon by Cokes86.
the class v1_13_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 org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer in project CokesAddon by Cokes86.
the class v1_13_R1 method hide.
public void hide() {
getParticipant().attributes().TARGETABLE.setValue(false);
final CraftPlayer craftPlayer = (CraftPlayer) getPlayer();
craftPlayer.getHandle().getDataWatcher().set(new DataWatcherObject<>(10, DataWatcherRegistry.b), 0);
craftPlayer.getHandle().setInvisible(true);
final PacketPlayOutEntityEquipment[] packets = { new PacketPlayOutEntityEquipment(getPlayer().getEntityId(), EnumItemSlot.MAINHAND, ItemStack.a), new PacketPlayOutEntityEquipment(getPlayer().getEntityId(), EnumItemSlot.OFFHAND, ItemStack.a), new PacketPlayOutEntityEquipment(getPlayer().getEntityId(), EnumItemSlot.HEAD, ItemStack.a), new PacketPlayOutEntityEquipment(getPlayer().getEntityId(), EnumItemSlot.CHEST, ItemStack.a), new PacketPlayOutEntityEquipment(getPlayer().getEntityId(), EnumItemSlot.LEGS, ItemStack.a), new PacketPlayOutEntityEquipment(getPlayer().getEntityId(), EnumItemSlot.FEET, ItemStack.a) };
for (CraftPlayer player : ((CraftServer) Bukkit.getServer()).getOnlinePlayers()) {
if (player.equals(getPlayer()))
continue;
for (PacketPlayOutEntityEquipment packet : packets) {
player.getHandle().playerConnection.sendPacket(packet);
}
injectPlayer(player);
}
}
use of org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer in project CokesAddon by Cokes86.
the class v1_16_R2 method changeSkin.
@Override
public void changeSkin(Player player, UUID uuid) {
if (origin.containsKey(uuid)) {
CraftPlayer cp = (CraftPlayer) player;
cp.getProfile().getProperties().removeAll("textures");
cp.getProfile().getProperties().put("textures", origin.get(uuid).getRight());
}
}
use of org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer in project CokesAddon by Cokes86.
the class v1_16_R2 method saveData.
@Override
public void saveData() {
for (Player pl : Bukkit.getOnlinePlayers()) {
if (origin.containsKey(pl.getUniqueId()))
continue;
if (pl.getName().isEmpty())
continue;
CraftPlayer cp = (CraftPlayer) pl;
Iterator<Property> iterator = cp.getProfile().getProperties().get("textures").iterator();
if (iterator.hasNext()) {
origin.put(pl.getUniqueId(), Pair.of(pl.getName(), iterator.next()));
}
}
}
use of org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer in project CokesAddon by Cokes86.
the class v1_16_R2 method addData.
@Override
public void addData(UUID uuid) {
if (origin.containsKey(uuid))
return;
Player pl = Bukkit.getPlayer(uuid);
if (pl == null)
return;
CraftPlayer cp = (CraftPlayer) pl;
Iterator<Property> iterator = cp.getProfile().getProperties().get("textures").iterator();
if (iterator.hasNext()) {
origin.put(uuid, Pair.of(pl.getName(), iterator.next()));
}
}
Aggregations