/** * 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); }
@Override public int hashCode() { // Mojang's hashCode() is broken, it doesn't handle NULL id or name. So we implement our own return Objects.hashCode(getId(), getName()); }
/** * Retrieve the UUID of the player. * <p> * Note that Minecraft 1.7.5 and earlier doesn't use UUIDs internally, and it may not be possible to convert the string to an UUID. * <p> * We use the same lax conversion as in {@link #WrappedGameProfile(String, String)}. * * @return The UUID, or NULL if the UUID is NULL. * @throws IllegalStateException If we cannot parse the internal ID as an UUID. */ public UUID getUUID() { UUID uuid = parsedUUID; if (uuid == null) { try { if (GET_UUID_STRING != null) { uuid = parseUUID(getId()); } else if (GET_ID != null) { uuid = (UUID) GET_ID.invoke(handle); } else { throw new IllegalStateException("Unsupported getId() method"); } // Cache for later parsedUUID = uuid; } catch (IllegalArgumentException e) { throw new IllegalStateException("Cannot parse ID " + getId() + " as an UUID in player profile " + getName(), e); } } return uuid; }
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))); }