org.bukkit.util.CachedServerIcon#com.destroystokyo.paper.profile.PlayerProfile源码实例Demo

下面列出了org.bukkit.util.CachedServerIcon#com.destroystokyo.paper.profile.PlayerProfile 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AntiVPN   文件: PaperPlayerInfo.java
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?)");
}
 
源代码2 项目: AntiVPN   文件: PaperPlayerInfo.java
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?)");
}
 
@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;
}
 
源代码4 项目: VoxelGamesLibv2   文件: TextureCache.java
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;
}
 
源代码5 项目: Kettle   文件: AsyncPlayerPreLoginEvent.java
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;
}
 
@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;
}
 
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;
}
 
源代码8 项目: Kettle   文件: ProfileWhitelistVerifyEvent.java
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;
}
 
源代码9 项目: Kettle   文件: PaperServerListPingEvent.java
@Deprecated
public List<String> getSampleText() {
    List<String> sampleText = new ArrayList<>();
    for (PlayerProfile profile : getPlayerSample()) {
        sampleText.add(Strings.nullToEmpty(profile.getName()));
    }
    return sampleText;
}
 
源代码10 项目: VoxelGamesLibv2   文件: TextureHandler.java
public PlayerProfile getPlayerProfile(String owner) {
    Optional<Skin> skin = getSkin(owner);
    if (skin.isPresent()) {
        return getPlayerProfile(skin.get());
    } else {
        return cache.get(owner);
    }
}
 
源代码11 项目: VoxelGamesLibv2   文件: TextureCache.java
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;
}
 
源代码12 项目: VoxelGamesLibv2   文件: NBTUtil.java
/**
 * 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()));
    }
}
 
源代码13 项目: VoxelGamesLibv2   文件: SkullPlaceHolders.java
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();
}
 
源代码14 项目: Skript   文件: ExprHoverList.java
@Override
@Nullable
public String[] get(Event e) {
	return ((PaperServerListPingEvent) e).getPlayerSample().stream()
			.map(PlayerProfile::getName)
			.toArray(String[]::new);
}
 
源代码15 项目: Skript   文件: ExprHoverList.java
@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();
	}
}
 
源代码16 项目: ProtocolSupport   文件: PaperPingResponseHandler.java
@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;
}
 
源代码17 项目: Kettle   文件: ProfileWhitelistVerifyEvent.java
/**
 * @return The profile of the player trying to connect
 */
public PlayerProfile getPlayerProfile() {
    return profile;
}
 
源代码18 项目: Kettle   文件: LookupProfileEvent.java
public LookupProfileEvent(@Nonnull PlayerProfile profile) {
    super(!Bukkit.isPrimaryThread());
    this.profile = profile;
}
 
源代码19 项目: Kettle   文件: LookupProfileEvent.java
/**
 * @return The profile that was recently looked up. This profile can be mutated
 */
@Nonnull
public PlayerProfile getPlayerProfile() {
    return profile;
}
 
源代码20 项目: Kettle   文件: FillProfileEvent.java
public FillProfileEvent(@Nonnull PlayerProfile profile) {
    super(!org.bukkit.Bukkit.isPrimaryThread());
    this.profile = profile;
}
 
源代码21 项目: Kettle   文件: FillProfileEvent.java
/**
 * @return The Profile that had properties filled
 */
@Nonnull
public PlayerProfile getPlayerProfile() {
    return profile;
}
 
源代码22 项目: Kettle   文件: PreFillProfileEvent.java
public PreFillProfileEvent(PlayerProfile profile) {
    super(!org.bukkit.Bukkit.isPrimaryThread());
    this.profile = profile;
}
 
源代码23 项目: Kettle   文件: PreFillProfileEvent.java
/**
 * @return The profile that needs its properties filled
 */
public PlayerProfile getPlayerProfile() {
    return profile;
}
 
源代码24 项目: VoxelGamesLibv2   文件: TextureHandler.java
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;
}
 
源代码25 项目: VoxelGamesLibv2   文件: TextureHandler.java
public PlayerProfile getPlayerProfile(UUID uuid) {
    return cache.get(uuid);
}
 
源代码26 项目: VoxelGamesLibv2   文件: TextureHandler.java
public PlayerProfile getErrorProfile() {
    return errorProfile;
}
 
源代码27 项目: VoxelGamesLibv2   文件: PlayerProfileTypeAdapter.java
@Override
public JsonElement serialize(PlayerProfile playerProfile, Type type, JsonSerializationContext jsonSerializationContext) {
    return jsonSerializationContext.serialize(new Dummy(playerProfile.getId(), playerProfile.getName(), playerProfile.getProperties()));
}
 
源代码28 项目: VoxelGamesLibv2   文件: TextureCache.java
public PlayerProfile get(String name) {
    PlayerProfile playerProfile = Bukkit.createProfile(name);
    currentNames.add(name);
    fill(playerProfile);
    return playerProfile;
}
 
源代码29 项目: VoxelGamesLibv2   文件: TextureCache.java
public PlayerProfile get(UUID id) {
    PlayerProfile playerProfile = Bukkit.createProfile(id);
    currentUUIDs.add(id);
    fill(playerProfile);
    return playerProfile;
}
 
源代码30 项目: VoxelGamesLibv2   文件: VoxelGamesLibModule.java
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));
}