下面列出了org.bukkit.util.CachedServerIcon#com.destroystokyo.paper.profile.PlayerProfile 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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?)");
}
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;
}
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;
}
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;
}
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;
}
@Deprecated
public List<String> getSampleText() {
List<String> sampleText = new ArrayList<>();
for (PlayerProfile profile : getPlayerSample()) {
sampleText.add(Strings.nullToEmpty(profile.getName()));
}
return sampleText;
}
public PlayerProfile getPlayerProfile(String owner) {
Optional<Skin> skin = getSkin(owner);
if (skin.isPresent()) {
return getPlayerProfile(skin.get());
} else {
return cache.get(owner);
}
}
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;
}
/**
* 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()));
}
}
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();
}
@Override
@Nullable
public String[] get(Event e) {
return ((PaperServerListPingEvent) e).getPlayerSample().stream()
.map(PlayerProfile::getName)
.toArray(String[]::new);
}
@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();
}
}
@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;
}
/**
* @return The profile of the player trying to connect
*/
public PlayerProfile getPlayerProfile() {
return profile;
}
public LookupProfileEvent(@Nonnull PlayerProfile profile) {
super(!Bukkit.isPrimaryThread());
this.profile = profile;
}
/**
* @return The profile that was recently looked up. This profile can be mutated
*/
@Nonnull
public PlayerProfile getPlayerProfile() {
return profile;
}
public FillProfileEvent(@Nonnull PlayerProfile profile) {
super(!org.bukkit.Bukkit.isPrimaryThread());
this.profile = profile;
}
/**
* @return The Profile that had properties filled
*/
@Nonnull
public PlayerProfile getPlayerProfile() {
return profile;
}
public PreFillProfileEvent(PlayerProfile profile) {
super(!org.bukkit.Bukkit.isPrimaryThread());
this.profile = profile;
}
/**
* @return The profile that needs its properties filled
*/
public PlayerProfile getPlayerProfile() {
return profile;
}
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;
}
public PlayerProfile getPlayerProfile(UUID uuid) {
return cache.get(uuid);
}
public PlayerProfile getErrorProfile() {
return errorProfile;
}
@Override
public JsonElement serialize(PlayerProfile playerProfile, Type type, JsonSerializationContext jsonSerializationContext) {
return jsonSerializationContext.serialize(new Dummy(playerProfile.getId(), playerProfile.getName(), playerProfile.getProperties()));
}
public PlayerProfile get(String name) {
PlayerProfile playerProfile = Bukkit.createProfile(name);
currentNames.add(name);
fill(playerProfile);
return playerProfile;
}
public PlayerProfile get(UUID id) {
PlayerProfile playerProfile = Bukkit.createProfile(id);
currentUUIDs.add(id);
fill(playerProfile);
return playerProfile;
}
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));
}