/** * Construct a wrapper around an existing game profile. * * @param handle - the underlying profile, or NULL. * @return A wrapper around an existing game profile. */ public static WrappedGameProfile fromHandle(Object handle) { if (handle == null) return null; return new WrappedGameProfile(handle); }
/** * Construct a new game profile with the same ID, but different name. * * @param name - the new name of the profile to create. * @return The new game profile. */ public WrappedGameProfile withName(String name) { return new WrappedGameProfile(getId(), name); }
public static WrappedGameProfile getGameProfile(UUID uuid, String playerName) { try { return new WrappedGameProfile(uuid != null ? uuid : getRandomUUID(), playerName); } catch (Exception ex) { ex.printStackTrace(); } return null; }
/** * Construct a new game profile with the same name, but different id. * * @param id - the new id of the profile to create. * @return The new game profile. */ public WrappedGameProfile withId(String id) { return new WrappedGameProfile(id, getName()); }
public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName, WrappedGameProfile profileWithSkin) { try { WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : getRandomUUID(), playerName); if (profileWithSkin != null) { gameProfile.getProperties().putAll(profileWithSkin.getProperties()); } return gameProfile; } catch (Exception ex) { ex.printStackTrace(); } return null; }
private static WrappedGameProfile getSentName(int sentEntityId, WrappedGameProfile sent, Player destinationPlayer) { // Preconditions.checkState(Bukkit.getServer().isPrimaryThread(), "Can only process events on main thread."); Player namedPlayer = entityIdMap.get(sentEntityId); if (namedPlayer == null) { // They probably were dead when we reloaded return sent; } PlayerReceiveNameTagEvent oldEvent = new PlayerReceiveNameTagEvent(destinationPlayer, namedPlayer, sent.getName()); Bukkit.getServer().getPluginManager().callEvent(oldEvent); StringBuilder builtUUID = new StringBuilder(); if (!sent.getId().contains("-")) { IntStream.range(0, uuidSplit.length - 1).forEach(i -> builtUUID.append(sent.getId(), uuidSplit[i], uuidSplit[i + 1]).append("-")); } else { builtUUID.append(sent.getId()); } AsyncPlayerReceiveNameTagEvent newEvent = new AsyncPlayerReceiveNameTagEvent(destinationPlayer, namedPlayer, getPlayerDisplayName(namedPlayer), UUID.fromString(builtUUID.toString())); Bukkit.getServer().getPluginManager().callEvent(newEvent); return new WrappedGameProfile(newEvent.getUUID(), newEvent.getTag().substring(0, Math.min(newEvent.getTag().length(), 16))); }
private void setSkullSkin(ItemStack itemStack, SkinModel skinData) { if (itemStack == null || skinData == null || itemStack.getType() != Material.SKULL_ITEM) return; try { SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta(); WrappedGameProfile gameProfile = new WrappedGameProfile(UUID.randomUUID(), null); plugin.getApi().applyProperties(gameProfile, skinData); skullProfileSetter.invoke(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; } } }