com.comphenix.protocol.wrappers.WrappedGameProfile Java Examples

The following examples show how to use com.comphenix.protocol.wrappers.WrappedGameProfile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ItemService.java    From Transport-Pipes with MIT License 6 votes vote down vote up
public ItemStack createHeadItem(String uuid, String textureValue, String textureSignature) {
    WrappedGameProfile wrappedProfile = new WrappedGameProfile(UUID.fromString(uuid), null);
    wrappedProfile.getProperties().put("textures", new WrappedSignedProperty("textures", textureValue, textureSignature));

    ItemStack skull = new ItemStack(Material.PLAYER_HEAD);
    SkullMeta sm = (SkullMeta) skull.getItemMeta();
    sm.setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(uuid)));

    Field profileField;
    try {
        profileField = sm.getClass().getDeclaredField("profile");
        profileField.setAccessible(true);
        profileField.set(sm, wrappedProfile.getHandle());
    } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
        e1.printStackTrace();
    }

    skull.setItemMeta(sm);
    return skull;
}
 
Example #2
Source File: SkullCommand.java    From ChangeSkin with MIT License 6 votes vote down vote up
private void setSkullSkin(ItemStack itemStack, SkinModel skinData) {
    try {
        SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();

        WrappedGameProfile gameProfile = new WrappedGameProfile(UUID.randomUUID(), null);
        plugin.getApi().applyProperties(gameProfile, skinData);

        skullProfileSetter.invokeExact(skullMeta, gameProfile.getHandle());
        itemStack.setItemMeta(skullMeta);
    } catch (Exception ex) {
        plugin.getLog().info("Failed to set skull item {} to {}", itemStack, skinData, ex);
    } catch (Throwable throwable) {
        //rethrow errors we shouldn't silence them like OutOfMemory
        throw (Error) throwable;
    }
}
 
Example #3
Source File: SimpleTabList.java    From tabbed with MIT License 6 votes vote down vote up
private WrappedGameProfile getGameProfile(int index, TabItem item) {
    Skin skin = item.getSkin();
    if (!PROFILE_INDEX_CACHE.containsKey(skin)) // Cached by skins, so if you change the skins a lot, it still works while being efficient.
        PROFILE_INDEX_CACHE.put(skin, new HashMap<>());
    Map<Integer, WrappedGameProfile> indexCache = PROFILE_INDEX_CACHE.get(skin);

    if (!indexCache.containsKey(index)) { // Profile is not cached, generate and cache one.
        String name = String.format("%03d", index) + "|UpdateMC"; // Starts with 00 so they are sorted in alphabetical order and appear in the right order.
        UUID uuid = UUID.nameUUIDFromBytes(name.getBytes());

        WrappedGameProfile profile = new WrappedGameProfile(uuid, name); // Create a profile to cache by skin and index.
        profile.getProperties().put(Skin.TEXTURE_KEY, item.getSkin().getProperty());
        indexCache.put(index, profile); // Cache the profile.
    }

    return indexCache.get(index);
}
 
Example #4
Source File: VanishIndication.java    From SuperVanish with Mozilla Public License 2.0 6 votes vote down vote up
private void sendPlayerInfoChangeGameModePacket(Player p, Player change, boolean spectator) {
    PacketContainer packet = new PacketContainer(PLAYER_INFO);
    packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE);
    List<PlayerInfoData> data = new ArrayList<>();
    int ping = ThreadLocalRandom.current().nextInt(20) + 15;
    data.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(change), ping,
            spectator ? EnumWrappers.NativeGameMode.SPECTATOR
                    : EnumWrappers.NativeGameMode.fromBukkit(change.getGameMode()),
            WrappedChatComponent.fromText(change.getPlayerListName())));
    packet.getPlayerInfoDataLists().write(0, data);
    try {
        ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
    } catch (InvocationTargetException e) {
        throw new RuntimeException("Cannot send packet", e);
    }
}
 
Example #5
Source File: VerifyResponseTask.java    From FastLogin with MIT License 6 votes vote down vote up
private void receiveFakeStartPacket(String username) {
    //see StartPacketListener for packet information
    PacketContainer startPacket = new PacketContainer(START);

    //uuid is ignored by the packet definition
    WrappedGameProfile fakeProfile = new WrappedGameProfile(UUID.randomUUID(), username);
    startPacket.getGameProfiles().write(0, fakeProfile);
    try {
        //we don't want to handle our own packets so ignore filters
        ProtocolLibrary.getProtocolManager().recieveClientPacket(player, startPacket, false);
    } catch (InvocationTargetException | IllegalAccessException ex) {
        plugin.getLog().warn("Failed to fake a new start packet for: {}", username, ex);
        //cancel the event in order to prevent the server receiving an invalid packet
        kickPlayer(plugin.getCore().getMessage("error-kick"));
    }
}
 
Example #6
Source File: SkinApplyListener.java    From FastLogin with MIT License 6 votes vote down vote up
private void applySkin(Player player, String skinData, String signature) {
    WrappedGameProfile gameProfile = WrappedGameProfile.fromPlayer(player);

    WrappedSignedProperty skin = WrappedSignedProperty.fromValues(Textures.KEY, skinData, signature);
    try {
        gameProfile.getProperties().put(Textures.KEY, skin);
    } catch (ClassCastException castException) {
        //Cauldron, MCPC, Thermos, ...
        Object map = GET_PROPERTIES.invoke(gameProfile.getHandle());
        try {
            MethodUtils.invokeMethod(map, "put", new Object[]{Textures.KEY, skin.getHandle()});
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
            plugin.getLog().error("Error setting premium skin of: {}", player, ex);
        }
    }
}
 
Example #7
Source File: TabListRemoveCommand.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
private void updatePlayerInfo(final EnumWrappers.PlayerInfoAction action, final Player affectedPlayer, final Player modifiedPlayer)
{
    DisplayInformation.updatePlayerInformation(action,
                                               WrappedGameProfile.fromPlayer(modifiedPlayer),
                                               ServerUtil.getPing(modifiedPlayer),
                                               EnumWrappers.NativeGameMode.fromBukkit(modifiedPlayer.getGameMode()),
                                               null,
                                               affectedPlayer);
}
 
Example #8
Source File: SimpleTabList.java    From tabbed with MIT License 5 votes vote down vote up
private PlayerInfoData getPlayerInfoData(WrappedGameProfile profile, int ping, String displayName) {
    if (displayName != null) {
        // min width
        while (displayName.length() < this.minColumnWidth)
            displayName += " ";

        // max width
        if (this.maxColumnWidth > 0)
            while (displayName.length() > this.maxColumnWidth)
                displayName = displayName.substring(0, displayName.length() - 1);
    }

    return new PlayerInfoData(profile, ping, NativeGameMode.SURVIVAL, displayName == null ? null : WrappedChatComponent.fromText(displayName));
}
 
Example #9
Source File: Skins.java    From tabbed with MIT License 5 votes vote down vote up
/**
 * Get a skin from an online player.
 * @param player
 * @return
 */
public static Skin getPlayer(Player player) {
    WrappedSignedProperty property = DEFAULT_SKIN.getProperty();
    Collection<WrappedSignedProperty> properties = WrappedGameProfile.fromPlayer(player).getProperties().get(Skin.TEXTURE_KEY);
    if (properties != null && properties.size() > 0)
        property = properties.iterator().next();
    return new Skin(property);
}
 
Example #10
Source File: ServerListPacketListener.java    From SuperVanish with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void onPacketSending(PacketEvent e) {
    try {
        final FileConfiguration settings = plugin.getSettings();
        if (!settings.getBoolean("ExternalInvisibility.ServerList.AdjustAmountOfOnlinePlayers")
                && !settings.getBoolean("ExternalInvisibility.ServerList.AdjustListOfLoggedInPlayers"))
            return;
        WrappedServerPing ping = e.getPacket().getServerPings().read(0);
        Collection<UUID> onlineVanishedPlayers = plugin.getVanishStateMgr().getOnlineVanishedPlayers();
        int vanishedPlayersCount = plugin.getVanishStateMgr().getOnlineVanishedPlayers().size(),
                playerCount = Bukkit.getOnlinePlayers().size();
        if (settings.getBoolean("ExternalInvisibility.ServerList.AdjustAmountOfOnlinePlayers")) {
            ping.setPlayersOnline(playerCount - vanishedPlayersCount);
        }
        if (settings.getBoolean("ExternalInvisibility.ServerList.AdjustListOfLoggedInPlayers")) {
            List<WrappedGameProfile> wrappedGameProfiles = new ArrayList<>(ping.getPlayers());
            Iterator<WrappedGameProfile> iterator = wrappedGameProfiles.iterator();
            while (iterator.hasNext()) {
                if (onlineVanishedPlayers.contains(iterator.next().getUUID())) {
                    iterator.remove();
                }
            }
            ping.setPlayers(wrappedGameProfiles);
        }
    } catch (Exception er) {
        plugin.logException(er);
    }
}
 
Example #11
Source File: BukkitSkinAPI.java    From ChangeSkin with MIT License 5 votes vote down vote up
@Override
public void applySkin(Player receiver, SkinModel targetSkin) {
    //Calling the event for changing skins
    Bukkit.getPluginManager().callEvent(new PlayerChangeSkinEvent(receiver, targetSkin));
    WrappedGameProfile gameProfile = WrappedGameProfile.fromPlayer(receiver);
    applyProperties(gameProfile, targetSkin);
}
 
Example #12
Source File: BukkitSkinAPI.java    From ChangeSkin with MIT License 5 votes vote down vote up
@Override
public void applyProperties(WrappedGameProfile profile, SkinModel targetSkin) {
    //remove existing skins
    profile.getProperties().clear();
    if (targetSkin != null) {
        profile.getProperties().put(SkinProperty.SKIN_KEY, convertToProperty(targetSkin));
    }
}
 
Example #13
Source File: SkinApplier.java    From ChangeSkin with MIT License 5 votes vote down vote up
@Override
protected void applyInstantUpdate() {
    plugin.getApi().applySkin(receiver, targetSkin);

    sendUpdateSelf(WrappedGameProfile.fromPlayer(receiver));
    sendUpdateOthers();

    if (receiver.equals(invoker)) {
        plugin.sendMessage(receiver, "skin-changed");
    } else {
        plugin.sendMessage(invoker, "skin-updated");
    }
}
 
Example #14
Source File: SkinApplier.java    From ChangeSkin with MIT License 5 votes vote down vote up
private void sendUpdateSelf(WrappedGameProfile gameProfile) throws FieldAccessException {
    Optional.ofNullable(receiver.getVehicle()).ifPresent(Entity::eject);

    sendPacketsSelf(gameProfile);

    //trigger update exp
    receiver.setExp(receiver.getExp());

    //triggers updateAbilities
    receiver.setWalkSpeed(receiver.getWalkSpeed());

    //send the current inventory - otherwise player would have an empty inventory
    receiver.updateInventory();

    PlayerInventory inventory = receiver.getInventory();
    inventory.setHeldItemSlot(inventory.getHeldItemSlot());

    //trigger update attributes like health modifier for generic.maxHealth
    try {
        receiver.getClass().getDeclaredMethod("updateScaledHealth").invoke(receiver);
    } catch (ReflectiveOperationException reflectiveEx) {
        plugin.getLog().error("Failed to invoke updateScaledHealth for attributes", reflectiveEx);
    }

    //tell NameTagEdit to refresh the scoreboard
    if (Bukkit.getPluginManager().isPluginEnabled("NametagEdit")) {
        NametagEdit.getApi().reloadNametag(receiver);
    }
}
 
Example #15
Source File: ProtocolLibHandler.java    From ServerListPlus with GNU General Public License v3.0 4 votes vote down vote up
@Override // Status ping
public void onPacketSending(PacketEvent event) {
    if (bukkit.getCore() == null) return; // Too early, we haven't finished initializing yet

    final WrappedServerPing ping = event.getPacket().getServerPings().read(0);
    // Make sure players have not been hidden when getting the player count
    boolean playersVisible = ping.isPlayersVisible();

    InetSocketAddress client = event.getPlayer().getAddress();
    StatusRequest request = bukkit.getRequest(client);
    bukkit.requestCompleted(event.getPlayer().getAddress());

    StatusResponse response = request.createResponse(bukkit.getCore().getStatus(),
                    // Return unknown player counts if it has been hidden
                    new ResponseFetcher() {
                        @Override
                        public Integer getOnlinePlayers() {
                            return ping.getPlayersOnline();
                        }

                        @Override
                        public Integer getMaxPlayers() {
                            return ping.getPlayersMaximum();
                        }

                        @Override
                        public int getProtocolVersion() {
                            return ping.getVersionProtocol();
                        }
                    });

    // Description is modified in BukkitEventHandler, but we modify it here again,
    // because the BukkitEventHandler has no access to information like virtual hosts.
    String message = response.getDescription();
    if (message != null) ping.setMotD(message);

    // Version name
    message = response.getVersion();
    if (message != null) ping.setVersionName(message);
    // Protocol version
    Integer protocol = response.getProtocolVersion();
    if (protocol != null) ping.setVersionProtocol(protocol);

    if (playersVisible) {
        if (response.hidePlayers()) {
            ping.setPlayersVisible(false);
        } else {
            // Online players
            Integer count = response.getOnlinePlayers();
            if (count != null) ping.setPlayersOnline(count);

            // Max players are modified in BukkitEventHandler
            count = response.getMaxPlayers();
            if (count != null) ping.setPlayersMaximum(count);

            // Player hover
            message = response.getPlayerHover();
            if (message != null) {
                if (message.isEmpty()) {
                    ping.setPlayers(Collections.<WrappedGameProfile>emptyList());
                } else if (response.useMultipleSamples()) {
                    count = response.getDynamicSamples();

                    ping.setPlayers(Iterables.transform(
                            count != null ? Helper.splitLines(message, count) : Helper.splitLines(message),
                            new Function<String, WrappedGameProfile>() {
                        @Override
                        public WrappedGameProfile apply(String input) {
                            return new WrappedGameProfile(StatusManager.EMPTY_UUID, input);
                        }
                    }));
                } else
                    ping.setPlayers(Collections.singleton(
                            new WrappedGameProfile(StatusManager.EMPTY_UUID, message)));
            }
        }
    }
}
 
Example #16
Source File: WrapperPlayServerNamedEntitySpawn.java    From PacketWrapper with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Retrieve the UUID of the player.
 * @return The UUID, or NULL if not set.
 */
public String getPlayerUUID() {
	WrappedGameProfile profile = getProfile();
    return profile != null ? profile.getId() : null;
}
 
Example #17
Source File: SimpleTabList.java    From tabbed with MIT License 4 votes vote down vote up
private PlayerInfoData getPlayerInfoData(int index, TabItem item) {
    WrappedGameProfile profile = getGameProfile(index, item);
    return getPlayerInfoData(profile, item.getPing(), item.getText());
}
 
Example #18
Source File: ProtocolUtils.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
private ProtocolUtils(){
    protocolUtils = this;

    ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(UhcCore.getPlugin(), PacketType.Play.Server.PLAYER_INFO) {

        @Override
        public void onPacketSending(PacketEvent event) {
            if (event.getPacket().getPlayerInfoAction().read(0) != EnumWrappers.PlayerInfoAction.ADD_PLAYER){
                return;
            }

            List<PlayerInfoData> newPlayerInfoDataList = new ArrayList<>();
            List<PlayerInfoData> playerInfoDataList = event.getPacket().getPlayerInfoDataLists().read(0);
            PlayersManager pm = GameManager.getGameManager().getPlayersManager();

            for (PlayerInfoData playerInfoData : playerInfoDataList) {
                if (
                        playerInfoData == null ||
                        playerInfoData.getProfile() == null ||
                        Bukkit.getPlayer(playerInfoData.getProfile().getUUID()) == null
                ){ // Unknown player
                    newPlayerInfoDataList.add(playerInfoData);
                    continue;
                }

                WrappedGameProfile profile = playerInfoData.getProfile();
                UhcPlayer uhcPlayer;

                try {
                    uhcPlayer = pm.getUhcPlayer(profile.getUUID());
                }catch (UhcPlayerDoesntExistException ex){ // UhcPlayer does not exist
                    newPlayerInfoDataList.add(playerInfoData);
                    continue;
                }

                // No display-name so don't change player data.
                if (!uhcPlayer.hasNickName()){
                    newPlayerInfoDataList.add(playerInfoData);
                    continue;
                }

                profile = profile.withName(uhcPlayer.getName());

                PlayerInfoData newPlayerInfoData = new PlayerInfoData(profile, playerInfoData.getPing(), playerInfoData.getGameMode(), playerInfoData.getDisplayName());
                newPlayerInfoDataList.add(newPlayerInfoData);
            }
            event.getPacket().getPlayerInfoDataLists().write(0, newPlayerInfoDataList);
        }

    });
}
 
Example #19
Source File: DisplayInformation.java    From AACAdditionPro with GNU General Public License v3.0 3 votes vote down vote up
/**
 * This method updates the player information, and thus the tablist of a player.
 *
 * @param action         the {@link com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction} that will be executed.
 * @param gameProfile    the {@link WrappedGameProfile} of the player whose information will be updated.<br>
 *                       Use {@link WrappedGameProfile#fromPlayer(Player)} in order to get a {@link WrappedGameProfile} from a {@link Player}.
 * @param ping           the new ping of the updated {@link Player}.
 * @param gameMode       the {@link com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode} of the updated {@link Player}.
 *                       Use {@link de.photon.aacadditionpro.util.server.ServerUtil#getPing(Player)} to get the ping of a {@link Player}.
 * @param displayName    the new displayName of the updated {@link Player}
 * @param affectedPlayer the {@link Player} who will see the updated information as the packet is sent to him.
 */
public static void updatePlayerInformation(final EnumWrappers.PlayerInfoAction action, final WrappedGameProfile gameProfile, final int ping, final EnumWrappers.NativeGameMode gameMode, final WrappedChatComponent displayName, final Player affectedPlayer)
{
    final PlayerInfoData playerInfoData = new PlayerInfoData(gameProfile, ping, gameMode, displayName);

    final WrapperPlayServerPlayerInfo playerInfoWrapper = new WrapperPlayServerPlayerInfo();
    playerInfoWrapper.setAction(action);
    playerInfoWrapper.setData(Collections.singletonList(playerInfoData));

    playerInfoWrapper.sendPacket(affectedPlayer);
}
 
Example #20
Source File: WrapperLoginClientStart.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve the initial game profile.
 * <p>
 * Note that the UUID is NULL.
 * @return The current profile.
*/
public WrappedGameProfile getProfile() {
    return handle.getGameProfiles().read(0);
}
 
Example #21
Source File: WrapperLoginClientStart.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Set the initial game profile.
 * @param value - new profile.
*/
public void setProfile(WrappedGameProfile value) {
    handle.getGameProfiles().write(0, value);
}
 
Example #22
Source File: WrapperLoginServerSuccess.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve the UUID and player name of the connected client.
 * @return The current client profile.
*/
public WrappedGameProfile getProfile() {
    return handle.getGameProfiles().read(0);
}
 
Example #23
Source File: WrapperLoginServerSuccess.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Set the UUID and player name of the connected client as a game profile.
 * @param value - new profile.
*/
public void setProfile(WrappedGameProfile value) {
    handle.getGameProfiles().write(0, value);
}
 
Example #24
Source File: WrapperPlayServerNamedEntitySpawn.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve the player name.
 * <p>
 * Max length of 16.
 * @return The current player Name, or NULL if not set.
*/
public String getPlayerName() {
	WrappedGameProfile profile = getProfile();
    return profile != null ? profile.getName() : null;
}
 
Example #25
Source File: WrapperPlayServerNamedEntitySpawn.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Set the player name.
 * <p>
 * Max length of 16.
 * @param value - new value.
*/
public void setPlayerName(String value) {
	if (value != null && value.length() > 16)
		throw new IllegalArgumentException("Maximum player name lenght is 16 characters.");
	setProfile(new WrappedGameProfile(getPlayerUUID(), value));
}
 
Example #26
Source File: WrapperPlayServerNamedEntitySpawn.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Set the UUID of the player.
 * @param uuid - the UUID.
 */
public void setPlayerUUID(String uuid) {
	setProfile(new WrappedGameProfile(uuid, getPlayerName()));
}
 
Example #27
Source File: WrapperPlayServerNamedEntitySpawn.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve player's full profile.
 * @return The spawner player's profile.
*/
public WrappedGameProfile getProfile() {
    return handle.getGameProfiles().read(0);
}
 
Example #28
Source File: WrapperPlayServerNamedEntitySpawn.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Set the spawned player's profile.
 * @param value - new profile.
*/
public void setProfile(WrappedGameProfile value) {
    handle.getGameProfiles().write(0, value);
}