Java Code Examples for com.destroystokyo.paper.profile.PlayerProfile

The following examples show how to use com.destroystokyo.paper.profile.PlayerProfile. These examples are extracted from open source projects. 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 Project: AntiVPN   Source File: PaperPlayerInfo.java    License: MIT License 6 votes vote down vote up
private static String nameExpensive(UUID uuid) throws IOException {
    // Currently-online lookup
    Player player = Bukkit.getPlayer(uuid);
    if (player != null) {
        nameCache.put(player.getName(), uuid);
        return player.getName();
    }

    // Cached profile lookup
    PlayerProfile profile = Bukkit.createProfile(uuid);
    if ((profile.isComplete() || profile.completeFromCache()) && profile.getName() != null && profile.getId() != null) {
        nameCache.put(profile.getName(), profile.getId());
        return profile.getName();
    }

    // Network lookup
    if (profile.complete(false) && profile.getName() != null && profile.getId() != null) {
        nameCache.put(profile.getName(), profile.getId());
        return profile.getName();
    }

    // Sorry, nada
    throw new IOException("Could not load player data from Mojang (rate-limited?)");
}
 
Example 2
Source Project: AntiVPN   Source File: PaperPlayerInfo.java    License: MIT License 6 votes vote down vote up
private static UUID uuidExpensive(String name) throws IOException {
    // Currently-online lookup
    Player player = Bukkit.getPlayer(name);
    if (player != null) {
        uuidCache.put(player.getUniqueId(), name);
        return player.getUniqueId();
    }

    // Cached profile lookup
    PlayerProfile profile = Bukkit.createProfile(name);
    if ((profile.isComplete() || profile.completeFromCache()) && profile.getName() != null && profile.getId() != null) {
        uuidCache.put(profile.getId(), profile.getName());
        return profile.getId();
    }

    // Network lookup
    if (profile.complete(false) && profile.getName() != null && profile.getId() != null) {
        uuidCache.put(profile.getId(), profile.getName());
        return profile.getId();
    }

    // Sorry, nada
    throw new IOException("Could not load player data from Mojang (rate-limited?)");
}
 
Example 3
Source Project: VoxelGamesLibv2   Source File: PlayerProfileTypeAdapter.java    License: MIT License 6 votes vote down vote up
@Override
public PlayerProfile deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
    Dummy dummy = jsonDeserializationContext.deserialize(jsonElement, Dummy.class);
    PlayerProfile playerProfile;
    if (dummy.id != null) {
        playerProfile = Bukkit.createProfile(dummy.id);
    } else if (dummy.name != null) {
        playerProfile = Bukkit.createProfile(dummy.name);
    } else {
        throw new VoxelGameLibException("Could not parse player profile! " + jsonElement);
    }
    playerProfile.setProperties(dummy.properties);
    playerProfile.setId(dummy.id);
    playerProfile.setName(dummy.name);
    return playerProfile;
}
 
Example 4
Source Project: VoxelGamesLibv2   Source File: TextureCache.java    License: MIT License 6 votes vote down vote up
private PlayerProfile checkForPrefix(PlayerProfile playerProfile) {
    if (playerProfile.getName() != null) {
        if (playerProfile.getName().contains(":")) {
            String[] args = playerProfile.getName().split(":");
            Optional<Skin> skin = textureHandler.getSkin(args[1].charAt(0));
            if (skin.isPresent()) {
                log.finer("Found prefix marker, return " + skin.get().name);
                return textureHandler.getPlayerProfile(skin.get());
            } else {
                log.warning("Requested prefix marker, but is missing skin! " + playerProfile.getName());
                return textureHandler.getErrorProfile();
            }
        }
    }

    return null;
}
 
Example 5
public AsyncPlayerPreLoginEvent(final String name, final InetAddress ipAddress, final UUID uniqueId, PlayerProfile profile) {
    super(true);
    this.profile = profile;
    // Paper end
    this.result = Result.ALLOWED;
    this.message = "";
    this.name = name;
    this.ipAddress = ipAddress;
    this.uniqueId = uniqueId;
}
 
Example 6
@Nonnull
@Override
public List<PlayerProfile> getPlayerSample() {
    List<PlayerProfile> sample = super.getPlayerSample();

    if (this.originalSample != null) {
        for (GameProfile profile : this.originalSample) {
            sample.add(CraftPlayerProfile.asBukkitCopy(profile));
        }
        this.originalSample = null;
    }

    return sample;
}
 
Example 7
private GameProfile[] getPlayerSampleHandle() {
    if (this.originalSample != null) {
        return this.originalSample;
    }

    List<PlayerProfile> entries = super.getPlayerSample();
    if (entries.isEmpty()) {
        return EMPTY_PROFILES;
    }

    GameProfile[] profiles = new GameProfile[entries.size()];
    for (int i = 0; i < profiles.length; i++) {
        /*
         * Avoid null UUIDs/names since that will make the response invalid
         * on the client.
         * Instead, fall back to a fake/empty UUID and an empty string as name.
         * This can be used to create custom lines in the player list that do not
         * refer to a specific player.
         */

        PlayerProfile profile = entries.get(i);
        if (profile.getId() != null && profile.getName() != null) {
            profiles[i] = CraftPlayerProfile.asAuthlib(profile);
        } else {
            profiles[i] = new GameProfile(MoreObjects.firstNonNull(profile.getId(), FAKE_UUID), Strings.nullToEmpty(profile.getName()));
        }
    }

    return profiles;
}
 
Example 8
public ProfileWhitelistVerifyEvent(final PlayerProfile profile, boolean whitelistEnabled, boolean whitelisted, boolean isOp, String kickMessage) {
    this.profile = profile;
    this.whitelistEnabled = whitelistEnabled;
    this.whitelisted = whitelisted;
    this.isOp = isOp;
    this.kickMessage = kickMessage;
}
 
Example 9
@Deprecated
public List<String> getSampleText() {
    List<String> sampleText = new ArrayList<>();
    for (PlayerProfile profile : getPlayerSample()) {
        sampleText.add(Strings.nullToEmpty(profile.getName()));
    }
    return sampleText;
}
 
Example 10
Source Project: VoxelGamesLibv2   Source File: TextureHandler.java    License: MIT License 5 votes vote down vote up
public PlayerProfile getPlayerProfile(String owner) {
    Optional<Skin> skin = getSkin(owner);
    if (skin.isPresent()) {
        return getPlayerProfile(skin.get());
    } else {
        return cache.get(owner);
    }
}
 
Example 11
Source Project: VoxelGamesLibv2   Source File: TextureCache.java    License: MIT License 5 votes vote down vote up
private boolean checkForPlaceholders(PlayerProfile playerProfile) {
    if (playerProfile.getName() != null) {
        for (Map.Entry<String, SkullPlaceHolder> entry : skullPlaceHolders.getPlaceHolders().entrySet()) {
            if (playerProfile.getName().startsWith(entry.getKey())) {
                PlayerProfile errorProfile = textureHandler.getErrorProfile();
                playerProfile.setProperties(errorProfile.getProperties());
                log.finer("Found placeholder trying to be filled, fill with error profile for now");
                return true;
            }
        }
    }
    return false;
}
 
Example 12
Source Project: VoxelGamesLibv2   Source File: NBTUtil.java    License: MIT License 5 votes vote down vote up
/**
 * Sets a player profile onto the given tag
 *
 * @param nbt           the tag to set the profile to
 * @param playerProfile the profile to set
 */
public static void setPlayerProfile(NbtCompound nbt, PlayerProfile playerProfile) {
    nbt.put("Id", (playerProfile.getId() == null ? UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerProfile.getName()).getBytes()) : playerProfile.getId()).toString());
    nbt.put("Name", playerProfile.getName());
    if (!nbt.containsKey("Properties")) return;
    NbtCompound properties = nbt.getCompound("Properties");
    NbtList list = properties.getList("textures");
    Map<String, NbtBase> texture = (Map<String, NbtBase>) list.getValue(0);
    for (ProfileProperty property : playerProfile.getProperties()) {
        texture.put("name", NbtFactory.of("name", property.getValue()));
        texture.put("Signature", NbtFactory.of("Signature", property.getSignature()));
        texture.put("Value", NbtFactory.of("Value", property.getValue()));
    }
}
 
Example 13
Source Project: VoxelGamesLibv2   Source File: SkullPlaceHolders.java    License: MIT License 5 votes vote down vote up
public PacketContainer modifySkull(WrapperPlayServerTileEntityData packet, Player player) {
    NbtCompound nbt = (NbtCompound) packet.getNbtData();

    Location location = new Location(player.getWorld(), packet.getLocation().getX(), packet.getLocation().getY(), packet.getLocation().getZ());

    if (nbt.containsKey("Owner")) {
        NbtCompound owner = nbt.getCompound("Owner");
        if (owner.containsKey("Name")) {
            String name = owner.getString("Name");
            PlayerProfile profile = null;

            String[] args = name.split(":");
            SkullPlaceHolder skullPlaceHolder = placeHolders.get(args[0]);
            if (skullPlaceHolder != null) {
                profile = skullPlaceHolder.apply(name, player, location, args);
            }

            if (profile != null && profile.hasTextures()) {
                NBTUtil.setPlayerProfile(owner, profile);
            } else {
                //log.warning("Error while applying placeholder '" + name + "' null? " + (profile == null) + " textures? " + (profile == null ? "" : profile.hasTextures()));
                NBTUtil.setPlayerProfile(owner, textureHandler.getErrorProfile());
            }

            owner.setName(name);
        }

        // update last seen signs
        Block b = location.getBlock();
        if (!(b.getState() instanceof Skull)) {
            return packet.getHandle();
        }
        Skull skull = (Skull) b.getState();
        lastSeenSkulls.put(location, skull);
    }

    return packet.getHandle();
}
 
Example 14
Source Project: Skript   Source File: ExprHoverList.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public String[] get(Event e) {
	return ((PaperServerListPingEvent) e).getPlayerSample().stream()
			.map(PlayerProfile::getName)
			.toArray(String[]::new);
}
 
Example 15
Source Project: Skript   Source File: ExprHoverList.java    License: GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("null")
@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
	List<PlayerProfile> values = new ArrayList<>();
	if (mode != ChangeMode.DELETE && mode != ChangeMode.RESET) {
		for (Object o : delta) {
			if (o instanceof Player) {
				Player player = ((Player) o);
				values.add(Bukkit.createProfile(player.getUniqueId(), player.getName()));
			} else {
				values.add(Bukkit.createProfile(UUID.randomUUID(), (String) o));
			}
		}
	}

	List<PlayerProfile> sample = ((PaperServerListPingEvent) e).getPlayerSample();
	switch (mode){
		case SET:
			sample.clear();
			sample.addAll(values);
			break;
		case ADD:
			sample.addAll(values);
			break;
		case REMOVE:
			sample.removeAll(values);
			break;
		case DELETE:
		case RESET:
			sample.clear();
	}
}
 
Example 16
@Override
public ServerPingResponseEvent createResponse(Connection connection) {
	PaperServerListPingEvent bevent = new PaperServerListPingEvent(
		new StatusClientImpl(connection),
		Bukkit.getMotd(),
		Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers(),
		createServerVersionString(), connection.getVersion().getId(),
		Bukkit.getServerIcon()
	);
	List<PlayerProfile> playerSample = bevent.getPlayerSample();
	Bukkit.getOnlinePlayers().stream()
	.limit(SpigotConfig.playerSample)
	.map(player -> new NameUUIDPlayerProfile(player.getUniqueId(), player.getName()))
	.forEach(playerSample::add);
	Bukkit.getPluginManager().callEvent(bevent);

	ServerPingResponseEvent revent = new ServerPingResponseEvent(
		connection,
		new ProtocolInfo(bevent.getProtocolVersion(), bevent.getVersion()),
		bevent.getServerIcon() != null ? ServerPlatform.get().getMiscUtils().convertBukkitIconToBase64(bevent.getServerIcon()) : null,
		bevent.getMotd(),
		bevent.getNumPlayers(), bevent.getMaxPlayers(),
		bevent.getPlayerSample().stream().map(PlayerProfile::getName).collect(Collectors.toList())
	);
	Bukkit.getPluginManager().callEvent(revent);

	return revent;
}
 
Example 17
/**
 * @return The profile of the player trying to connect
 */
public PlayerProfile getPlayerProfile() {
    return profile;
}
 
Example 18
Source Project: Kettle   Source File: LookupProfileEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
public LookupProfileEvent(@Nonnull PlayerProfile profile) {
    super(!Bukkit.isPrimaryThread());
    this.profile = profile;
}
 
Example 19
Source Project: Kettle   Source File: LookupProfileEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * @return The profile that was recently looked up. This profile can be mutated
 */
@Nonnull
public PlayerProfile getPlayerProfile() {
    return profile;
}
 
Example 20
Source Project: Kettle   Source File: FillProfileEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
public FillProfileEvent(@Nonnull PlayerProfile profile) {
    super(!org.bukkit.Bukkit.isPrimaryThread());
    this.profile = profile;
}
 
Example 21
Source Project: Kettle   Source File: FillProfileEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * @return The Profile that had properties filled
 */
@Nonnull
public PlayerProfile getPlayerProfile() {
    return profile;
}
 
Example 22
Source Project: Kettle   Source File: PreFillProfileEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
public PreFillProfileEvent(PlayerProfile profile) {
    super(!org.bukkit.Bukkit.isPrimaryThread());
    this.profile = profile;
}
 
Example 23
Source Project: Kettle   Source File: PreFillProfileEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * @return The profile that needs its properties filled
 */
public PlayerProfile getPlayerProfile() {
    return profile;
}
 
Example 24
Source Project: VoxelGamesLibv2   Source File: TextureHandler.java    License: MIT License 4 votes vote down vote up
public PlayerProfile getPlayerProfile(Skin skin) {
    PlayerProfile playerProfile = Bukkit.createProfile(skin.data.uuid, skin.name);
    playerProfile.setProperty(new ProfileProperty("textures", skin.data.texture.value, skin.data.texture.signature));
    return playerProfile;
}
 
Example 25
Source Project: VoxelGamesLibv2   Source File: TextureHandler.java    License: MIT License 4 votes vote down vote up
public PlayerProfile getPlayerProfile(UUID uuid) {
    return cache.get(uuid);
}
 
Example 26
Source Project: VoxelGamesLibv2   Source File: TextureHandler.java    License: MIT License 4 votes vote down vote up
public PlayerProfile getErrorProfile() {
    return errorProfile;
}
 
Example 27
Source Project: VoxelGamesLibv2   Source File: PlayerProfileTypeAdapter.java    License: MIT License 4 votes vote down vote up
@Override
public JsonElement serialize(PlayerProfile playerProfile, Type type, JsonSerializationContext jsonSerializationContext) {
    return jsonSerializationContext.serialize(new Dummy(playerProfile.getId(), playerProfile.getName(), playerProfile.getProperties()));
}
 
Example 28
Source Project: VoxelGamesLibv2   Source File: TextureCache.java    License: MIT License 4 votes vote down vote up
public PlayerProfile get(String name) {
    PlayerProfile playerProfile = Bukkit.createProfile(name);
    currentNames.add(name);
    fill(playerProfile);
    return playerProfile;
}
 
Example 29
Source Project: VoxelGamesLibv2   Source File: TextureCache.java    License: MIT License 4 votes vote down vote up
public PlayerProfile get(UUID id) {
    PlayerProfile playerProfile = Bukkit.createProfile(id);
    currentUUIDs.add(id);
    fill(playerProfile);
    return playerProfile;
}
 
Example 30
Source Project: VoxelGamesLibv2   Source File: VoxelGamesLibModule.java    License: MIT License 4 votes vote down vote up
private void addTypeAdapters(@Nonnull GsonBuilder builder, @Nonnull Injector injector) {
    builder.registerTypeAdapter(Phase.class, injector.getInstance(PhaseTypeAdapter.class));
    builder.registerTypeAdapter(Feature.class, injector.getInstance(FeatureTypeAdapter.class));
    builder.registerTypeAdapter(Game.class, injector.getInstance(GameTypeAdapter.class));
    builder.registerTypeAdapter(PlayerProfile.class, injector.getInstance(PlayerProfileTypeAdapter.class));
}