com.destroystokyo.paper.profile.PlayerProfile Java Examples
The following examples show how to use
com.destroystokyo.paper.profile.PlayerProfile.
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: PlayerProfileTypeAdapter.java From VoxelGamesLibv2 with MIT License | 6 votes |
@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 #2
Source File: PaperPlayerInfo.java From AntiVPN with MIT License | 6 votes |
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 File: StandardPaperServerListPingEventImpl.java From Kettle with GNU General Public License v3.0 | 6 votes |
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 #4
Source File: PaperPlayerInfo.java From AntiVPN with MIT License | 6 votes |
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 #5
Source File: TextureCache.java From VoxelGamesLibv2 with MIT License | 6 votes |
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 #6
Source File: NBTUtil.java From VoxelGamesLibv2 with MIT License | 5 votes |
/** * 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 #7
Source File: TextureHandler.java From VoxelGamesLibv2 with MIT License | 5 votes |
public PlayerProfile getPlayerProfile(String owner) { Optional<Skin> skin = getSkin(owner); if (skin.isPresent()) { return getPlayerProfile(skin.get()); } else { return cache.get(owner); } }
Example #8
Source File: PaperServerListPingEvent.java From Kettle with GNU General Public License v3.0 | 5 votes |
@Deprecated public List<String> getSampleText() { List<String> sampleText = new ArrayList<>(); for (PlayerProfile profile : getPlayerSample()) { sampleText.add(Strings.nullToEmpty(profile.getName())); } return sampleText; }
Example #9
Source File: TextureCache.java From VoxelGamesLibv2 with MIT License | 5 votes |
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 #10
Source File: SkullPlaceHolders.java From VoxelGamesLibv2 with MIT License | 5 votes |
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 #11
Source File: ExprHoverList.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public String[] get(Event e) { return ((PaperServerListPingEvent) e).getPlayerSample().stream() .map(PlayerProfile::getName) .toArray(String[]::new); }
Example #12
Source File: ExprHoverList.java From Skript with GNU General Public License v3.0 | 5 votes |
@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 #13
Source File: PaperPingResponseHandler.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@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 #14
Source File: ProfileWhitelistVerifyEvent.java From Kettle with GNU General Public License v3.0 | 5 votes |
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 #15
Source File: StandardPaperServerListPingEventImpl.java From Kettle with GNU General Public License v3.0 | 5 votes |
@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 #16
Source File: AsyncPlayerPreLoginEvent.java From Kettle with GNU General Public License v3.0 | 5 votes |
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 #17
Source File: VoxelGamesLibModule.java From VoxelGamesLibv2 with MIT License | 4 votes |
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)); }
Example #18
Source File: TextureHandler.java From VoxelGamesLibv2 with MIT License | 4 votes |
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 #19
Source File: TextureCache.java From VoxelGamesLibv2 with MIT License | 4 votes |
public PlayerProfile get(UUID id) { PlayerProfile playerProfile = Bukkit.createProfile(id); currentUUIDs.add(id); fill(playerProfile); return playerProfile; }
Example #20
Source File: TextureCache.java From VoxelGamesLibv2 with MIT License | 4 votes |
public PlayerProfile get(String name) { PlayerProfile playerProfile = Bukkit.createProfile(name); currentNames.add(name); fill(playerProfile); return playerProfile; }
Example #21
Source File: PlayerProfileTypeAdapter.java From VoxelGamesLibv2 with MIT License | 4 votes |
@Override public JsonElement serialize(PlayerProfile playerProfile, Type type, JsonSerializationContext jsonSerializationContext) { return jsonSerializationContext.serialize(new Dummy(playerProfile.getId(), playerProfile.getName(), playerProfile.getProperties())); }
Example #22
Source File: PaperEventHandler.java From ServerListPlus with GNU General Public License v3.0 | 4 votes |
private void handlePaperServerListPing(final PaperServerListPingEvent event) { if (bukkit.getCore() == null) return; // Too early, we haven't finished initializing yet StatusRequest request = bukkit.getCore().createRequest(event.getAddress()); request.setProtocolVersion(event.getClient().getProtocolVersion()); InetSocketAddress host = event.getClient().getVirtualHost(); if (host != null) { request.setTarget(host); } StatusResponse response = request.createResponse(bukkit.getCore().getStatus(), // Return unknown player counts if it has been hidden new ResponseFetcher() { @Override public Integer getOnlinePlayers() { return event.shouldHidePlayers() ? null : event.getNumPlayers(); } @Override public Integer getMaxPlayers() { return event.shouldHidePlayers() ? null : event.getMaxPlayers(); } @Override public int getProtocolVersion() { return event.getProtocolVersion(); } } ); // Description String message = response.getDescription(); if (message != null) event.setMotd(message); // Version name message = response.getVersion(); if (message != null) event.setVersion(message); // Protocol version Integer protocol = response.getProtocolVersion(); if (protocol != null) event.setProtocolVersion(protocol); if (response.hidePlayers()) { event.setHidePlayers(true); } else { // Online players Integer count = response.getOnlinePlayers(); if (count != null) event.setNumPlayers(count); // Max players count = response.getMaxPlayers(); if (count != null) event.setMaxPlayers(count); // Player hover message = response.getPlayerHover(); if (message != null) { List<PlayerProfile> profiles = event.getPlayerSample(); profiles.clear(); if (!message.isEmpty()) { if (response.useMultipleSamples()) { count = response.getDynamicSamples(); List<String> lines = count != null ? Helper.splitLinesCached(message, count) : Helper.splitLinesCached(message); for (String line : lines) { profiles.add(bukkit.getServer().createProfile(line)); } } else { profiles.add(bukkit.getServer().createProfile(message)); } } } } // Favicon FaviconSource favicon = response.getFavicon(); if (favicon != null) { CachedServerIcon icon = bukkit.getFavicon(favicon); if (icon != null) try { event.setServerIcon(icon); } catch (UnsupportedOperationException ignored) {} } }
Example #23
Source File: TextureHandler.java From VoxelGamesLibv2 with MIT License | 4 votes |
public PlayerProfile getErrorProfile() { return errorProfile; }
Example #24
Source File: TextureHandler.java From VoxelGamesLibv2 with MIT License | 4 votes |
public PlayerProfile getPlayerProfile(UUID uuid) { return cache.get(uuid); }
Example #25
Source File: PreFillProfileEvent.java From Kettle with GNU General Public License v3.0 | 4 votes |
/** * @return The profile that needs its properties filled */ public PlayerProfile getPlayerProfile() { return profile; }
Example #26
Source File: PreFillProfileEvent.java From Kettle with GNU General Public License v3.0 | 4 votes |
public PreFillProfileEvent(PlayerProfile profile) { super(!org.bukkit.Bukkit.isPrimaryThread()); this.profile = profile; }
Example #27
Source File: FillProfileEvent.java From Kettle with GNU General Public License v3.0 | 4 votes |
/** * @return The Profile that had properties filled */ @Nonnull public PlayerProfile getPlayerProfile() { return profile; }
Example #28
Source File: FillProfileEvent.java From Kettle with GNU General Public License v3.0 | 4 votes |
public FillProfileEvent(@Nonnull PlayerProfile profile) { super(!org.bukkit.Bukkit.isPrimaryThread()); this.profile = profile; }
Example #29
Source File: LookupProfileEvent.java From Kettle with GNU General Public License v3.0 | 4 votes |
/** * @return The profile that was recently looked up. This profile can be mutated */ @Nonnull public PlayerProfile getPlayerProfile() { return profile; }
Example #30
Source File: LookupProfileEvent.java From Kettle with GNU General Public License v3.0 | 4 votes |
public LookupProfileEvent(@Nonnull PlayerProfile profile) { super(!Bukkit.isPrimaryThread()); this.profile = profile; }