@Override public void onPacketSending(PacketEvent event) { if (event.getPacket().getPlayerInfoAction().read(0) != EnumWrappers.PlayerInfoAction.ADD_PLAYER) { return; } List<PlayerInfoData> newPlayerInfo = new ArrayList<>(); for (PlayerInfoData playerInfo : event.getPacket().getPlayerInfoDataLists().read(0)) { Player player; if (playerInfo == null || playerInfo.getProfile() == null || (player = Bukkit.getServer().getPlayer(playerInfo.getProfile().getUUID())) == null) { // Unknown Player newPlayerInfo.add(playerInfo); continue; } newPlayerInfo.add(new PlayerInfoData(getSentName(player.getEntityId(), playerInfo.getProfile(), event.getPlayer()), playerInfo.getPing(), playerInfo.getGameMode(), playerInfo.getDisplayName())); } event.getPacket().getPlayerInfoDataLists().write(0, newPlayerInfo); } });
/** * Retrieve a read/write structure for the PlayerInfoData list fields in the following packet: <br> * <ul> * <li>{@link PacketType.Play.Server#PLAYER_INFO} * </ul> * @return A modifier for PlayerInfoData list fields. */ public StructureModifier<List<PlayerInfoData>> getPlayerInfoDataLists() { // Convert to and from the ProtocolLib wrapper return structureModifier.withType( Collection.class, BukkitConverters.getListConverter(PlayerInfoData.getConverter())); }
public TargetedDisguise addPlayer(String playername) { if (!disguiseViewers.contains(playername)) { disguiseViewers.add(playername); if (DisguiseAPI.isDisguiseInUse(this)) { DisguiseUtilities.checkConflicts(this, playername); DisguiseUtilities.refreshTracker(this, playername); if (isHidePlayer() && getEntity() instanceof Player) { try { Player player = Bukkit.getPlayerExact(playername); if (player != null) { PacketContainer deleteTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); deleteTab.getPlayerInfoAction().write(0, canSee(player) ? PlayerInfoAction.REMOVE_PLAYER : PlayerInfoAction.ADD_PLAYER); deleteTab.getPlayerInfoDataLists().write(0, Arrays.asList( new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, NativeGameMode.SURVIVAL, WrappedChatComponent .fromText(DisguiseUtilities.getPlayerListName((Player) getEntity()))))); ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab); } } catch (InvocationTargetException e) { e.printStackTrace(); } } } } return this; }
@Override public void onPacketSending(final PacketEvent event) { if (event.isCancelled()) return; Player observer = event.getPlayer(); if (event.getPacket().getPlayerInfoAction().read(0) != PlayerInfoAction.ADD_PLAYER) return; List<PlayerInfoData> list = event.getPacket().getPlayerInfoDataLists().read(0); Iterator<PlayerInfoData> itel = list.iterator(); while (itel.hasNext()) { PlayerInfoData data = itel.next(); Player player = Bukkit.getPlayer(data.getProfile().getUUID()); if (player == null) continue; Disguise disguise = DisguiseAPI.getDisguise(observer, player); if (disguise == null) continue; if (!disguise.isHidePlayer()) continue; itel.remove(); } if (list.isEmpty()) { event.setCancelled(true); } else { event.getPacket().getPlayerInfoDataLists().write(0, list); } }
public TargetedDisguise removePlayer(String playername) { if (disguiseViewers.contains(playername)) { disguiseViewers.remove(playername); if (DisguiseAPI.isDisguiseInUse(this)) { DisguiseUtilities.checkConflicts(this, playername); DisguiseUtilities.refreshTracker(this, playername); if (isHidePlayer() && getEntity() instanceof Player) { try { Player player = Bukkit.getPlayerExact(playername); if (player != null) { PacketContainer deleteTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); deleteTab.getPlayerInfoAction().write(0, canSee(player) ? PlayerInfoAction.ADD_PLAYER : PlayerInfoAction.REMOVE_PLAYER); deleteTab.getPlayerInfoDataLists().write(0, Arrays.asList( new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, NativeGameMode.SURVIVAL, WrappedChatComponent .fromText(DisguiseUtilities.getPlayerListName((Player) getEntity()))))); ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab); } } catch (InvocationTargetException e) { e.printStackTrace(); } } } } return this; }
private void sendPacketsSelf(WrappedGameProfile gameProfile) { PacketContainer removeInfo; PacketContainer addInfo; PacketContainer respawn; PacketContainer teleport; try { NativeGameMode gamemode = NativeGameMode.fromBukkit(receiver.getGameMode()); WrappedChatComponent displayName = WrappedChatComponent.fromText(receiver.getPlayerListName()); PlayerInfoData playerInfoData = new PlayerInfoData(gameProfile, 0, gamemode, displayName); //remove the old skin - client updates it only on a complete remove and add removeInfo = new PacketContainer(PLAYER_INFO); removeInfo.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER); removeInfo.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfoData)); //add info containing the skin data addInfo = removeInfo.deepClone(); addInfo.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER); // Respawn packet - notify the client that it should update the own skin respawn = createRespawnPacket(gamemode); //prevent the moved too quickly message teleport = createTeleportPacket(receiver.getLocation().clone()); } catch (ReflectiveOperationException reflectiveEx) { plugin.getLog().error("Error occured preparing packets. Cancelling self update", reflectiveEx); return; } sendPackets(removeInfo, addInfo, respawn, teleport); }
@Override public PlayerInfoData getSpecific(Object generic) { if (MinecraftReflection.isPlayerInfoData(generic)) { StructureModifier<Object> modifier = new StructureModifier<>(generic.getClass(), null, false) .withTarget(generic); StructureModifier<WrappedGameProfile> gameProfiles = modifier.withType( MinecraftReflection.getGameProfileClass(), BukkitConverters.getWrappedGameProfileConverter()); WrappedGameProfile gameProfile = gameProfiles.read(0); StructureModifier<Integer> ints = modifier.withType(int.class); int latency = ints.read(0); StructureModifier<NativeGameMode> gameModes = modifier.withType( EnumWrappers.getGameModeClass(), EnumWrappers.getGameModeConverter()); NativeGameMode gameMode = gameModes.read(0); StructureModifier<WrappedChatComponent> displayNames = modifier.withType( MinecraftReflection.getIChatBaseComponentClass(), BukkitConverters.getWrappedChatComponentConverter()); WrappedChatComponent displayName = displayNames.read(0); return new PlayerInfoData(gameProfile, latency, gameMode, displayName); } // Otherwise, return null return null; }
deleteTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER); deleteTab.getPlayerInfoDataLists().write(0, Collections.singletonList( new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(disguise.getName())))); PlayerInfoData playerInfo = new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, NativeGameMode.fromBukkit(((Player) getEntity()).getGameMode()), WrappedChatComponent.fromText(DisguiseUtilities.getPlayerListName((Player) getEntity())));
addTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER); addTab.getPlayerInfoDataLists().write(0, Arrays.asList( new PlayerInfoData(getGameProfile(), 0, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(getName()))));
new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(disguise.getGameProfile().getName()))));
addTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER); addTab.getPlayerInfoDataLists().write(0, Collections.singletonList( new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(disguise.getName())))); addTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER); addTab.getPlayerInfoDataLists().write(0, Collections.singletonList( new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(""))));