Java Code Examples for protocolsupport.api.utils.ProfileProperty

The following examples show how to use protocolsupport.api.utils.ProfileProperty. These examples are extracted from open source projects. 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
public static void checkHasJoinedServerAndUpdateProfile(LoginProfile profile, String hash, String ip) throws AuthenticationUnavailableException, MalformedURLException {
	final URL url = new URL(hasJoinedUrl + "?username=" + profile.getOriginalName() + "&serverId=" + hash + (ip != null ? "&ip=" + ip : ""));
	try {
		JsonObject root = new JsonParser().parse(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8)).getAsJsonObject();
		profile.setOriginalName(JsonUtils.getString(root, "name"));
		profile.setOriginalUUID(UUIDTypeAdapter.fromString(JsonUtils.getString(root, "id")));
		JsonArray properties = JsonUtils.getJsonArray(root, "properties");
		for (JsonElement property : properties) {
			JsonObject propertyobj = property.getAsJsonObject();
			profile.addProperty(new ProfileProperty(
				JsonUtils.getString(propertyobj, "name"),
				JsonUtils.getString(propertyobj, "value"),
				JsonUtils.getString(propertyobj, "signature")
			));
		}
	} catch (IOException | IllegalStateException | JsonParseException e) {
		throw new AuthenticationUnavailableException();
	}
}
 
Example 2
public static NBTCompound serialize(LoginProfile gameProfile) {
	NBTCompound tag = new NBTCompound();
	if (!StringUtils.isEmpty(gameProfile.getName())) {
		tag.setTag(NAME_KEY, new NBTString(gameProfile.getName()));
	}
	if (gameProfile.getUUID() != null) {
		tag.setTag(UUID_KEY, new NBTString(gameProfile.getUUID().toString()));
	}
	if (!gameProfile.getProperties().isEmpty()) {
		NBTCompound propertiesTag = new NBTCompound();
		for (Entry<String, Set<ProfileProperty>> entry : gameProfile.getProperties().entrySet()) {
			NBTList<NBTCompound> propertiesListTag = new NBTList<>(NBTType.COMPOUND);
			for (ProfileProperty property : entry.getValue()) {
				NBTCompound propertyTag = new NBTCompound();
				propertyTag.setTag(PROPERTY_VALUE_KEY, new NBTString(property.getValue()));
				if (property.hasSignature()) {
					propertyTag.setTag(PROPERTY_SIGNATURE_KEY, new NBTString(property.getSignature()));
				}
				propertiesListTag.addTag(propertyTag);
			}
			propertiesTag.setTag(entry.getKey(), propertiesListTag);
		}
		tag.setTag(PROPERTIES_KEY, propertiesTag);
	}
	return tag;
}
 
Example 3
/**
 * Removes property
 * @param property property
 */
public void removeProperty(ProfileProperty property) {
	String propertyName = property.getName();
	Set<ProfileProperty> propertiesWithName = properties.get(propertyName);
	propertiesWithName.remove(property);
	if (propertiesWithName.isEmpty()) {
		properties.remove(propertyName);
	}
}
 
Example 4
public static LoginProfile deserialize(NBTCompound tag) {
	String name = NBTString.getValueOrNull(tag.getTagOfType(NAME_KEY, NBTType.STRING));
	UUID uuid = null;
	try {
		uuid = UUID.fromString(NBTString.getValueOrNull(tag.getTagOfType(UUID_KEY, NBTType.STRING)));
	} catch (Throwable t) {
	}
	if (StringUtils.isEmpty(name) && (uuid == null)) {
		return null;
	}
	LoginProfile gameProfile = new LoginProfile(uuid, name);
	NBTCompound propertiesTag = tag.getTagOfType(PROPERTIES_KEY, NBTType.COMPOUND);
	if (propertiesTag != null) {
		for (String propertyName : propertiesTag.getTagNames()) {
			NBTList<NBTCompound> propertiesListTag = propertiesTag.getTagListOfType(propertyName, NBTType.COMPOUND);
			if (propertiesListTag != null) {
				for (NBTCompound propertyTag : propertiesListTag.getTags()) {
					gameProfile.addProperty(new ProfileProperty(
						propertyName,
						NBTString.getValueOrNull(propertyTag.getTagOfType(PROPERTY_VALUE_KEY, NBTType.STRING)),
						NBTString.getValueOrNull(propertyTag.getTagOfType(PROPERTY_SIGNATURE_KEY, NBTType.STRING))
					));
				}
			}
		}
	}
	return gameProfile;
}
 
Example 5
protected SpoofedData(String hostname, String address, UUID uuid, Collection<ProfileProperty> properties, String failmessage) {
	this.hostname = hostname;
	this.address = address;
	this.uuid = uuid;
	this.properties = properties;
	this.failMessage = failmessage;
}
 
Example 6
public PlayerListEntry(String name, int ping, GameMode gamemode, String displayNameJson, Collection<ProfileProperty> properties) {
	this.name = name;
	this.ping = ping;
	this.gamemode = gamemode;
	this.displayNameJson = displayNameJson;
	properties.forEach(this::addProperty);
}
 
Example 7
public void addProperty(ProfileProperty property) {
	if (property.hasSignature()) {
		propSigned.put(property.getName(), property);
	} else {
		propUnsigned.put(property.getName(), property);
	}
}
 
Example 8
public List<ProfileProperty> getProperties(boolean signedOnly) {
	if (signedOnly) {
		return new ArrayList<>(propSigned.values());
	} else {
		ArrayList<ProfileProperty> properties = new ArrayList<>();
		properties.addAll(propSigned.values());
		properties.addAll(propUnsigned.values());
		return properties;
	}
}
 
Example 9
/**
 * Removes property
 * @param property property
 */
public void removeProperty(ProfileProperty property) {
	String propertyName = property.getName();
	Set<ProfileProperty> propertiesWithName = properties.get(propertyName);
	propertiesWithName.remove(property);
	if (propertiesWithName.isEmpty()) {
		properties.remove(propertyName);
	}
}
 
Example 10
@Override
public Collection<ProfileProperty> getSpoofedProperties() {
	if (internal.spoofedProfile == null) {
		return Collections.emptyList();
	}
	return
		Arrays.asList(internal.spoofedProfile).stream()
		.map(prop -> new ProfileProperty(prop.getName(), prop.getValue(), prop.getSignature()))
		.collect(Collectors.toList());
}
 
Example 11
@Override
public void setSpoofedProfile(UUID uuid, Collection<ProfileProperty> properties) {
	internal.spoofedUUID = uuid;
	if (properties != null) {
		internal.spoofedProfile = properties.stream()
		.map(prop -> new Property(prop.getName(), prop.getValue(), prop.getSignature()))
		.collect(Collectors.toList())
		.toArray(new Property[0]);
	}
}
 
Example 12
@Override
public Set<ProfileProperty> getProperties(String name) {
	return
		platformProfile.getProperties().get(name).stream()
		.map(mojangproperty -> new ProfileProperty(mojangproperty.getName(), mojangproperty.getValue(), mojangproperty.getSignature()))
		.collect(Collectors.toSet());
}
 
Example 13
/**
 * @return a profile property containing the wrapped data.
 */
public ProfileProperty toProfileProperty() {
	return new ProfileProperty(PROPERTY_NAME, getValue(), getSignature());
}
 
Example 14
public GameProfile(UUID uuid, String name, ProfileProperty... properties) {
	this.uuid = uuid;
	this.name = name;
	Arrays.stream(properties).forEach(this::addProperty);
}
 
Example 15
public Map<String, Set<ProfileProperty>> getProperties() {
	return properties;
}
 
Example 16
public void setProperties(Map<String, Set<ProfileProperty>> propertiesMap) {
	properties.clear();
	properties.putAll(propertiesMap);
}
 
Example 17
public void addProperty(ProfileProperty profileProperty) {
	properties.computeIfAbsent(profileProperty.getName(), k -> new HashSet<>()).add(profileProperty);
}
 
Example 18
@Override
public void handle(EncryptionResponse encryptResponse) throws Exception {
	Preconditions.checkState(state == LoginState.KEY, "Not expecting ENCRYPT");
	state = LoginState.AUTHENTICATING;
	SecretKey sharedKey = EncryptionUtil.getSecret(encryptResponse, request);
	BungeeCipher decrypt = EncryptionUtil.getCipher(false, sharedKey);
	channel.addBefore(PipelineUtils.FRAME_DECODER, PipelineUtils.DECRYPT_HANDLER, new CipherDecoder(decrypt));
	if (isFullEncryption(connection.getVersion())) {
		BungeeCipher encrypt = EncryptionUtil.getCipher(true, sharedKey);
		channel.addBefore(PipelineUtils.FRAME_PREPENDER, PipelineUtils.ENCRYPT_HANDLER, new CipherEncoder(encrypt));
	}
	String encName = URLEncoder.encode(getName(), "UTF-8");
	MessageDigest sha = MessageDigest.getInstance("SHA-1");
	for (byte[] bit : new byte[][] { request.getServerId().getBytes("ISO_8859_1"), sharedKey.getEncoded(), EncryptionUtil.keys.getPublic().getEncoded() }) {
		sha.update(bit);
	}
	String encodedHash = URLEncoder.encode(new BigInteger(sha.digest()).toString(16), "UTF-8");
	String preventProxy = BungeeCord.getInstance().config.isPreventProxyConnections() ? ("&ip=" + URLEncoder.encode(getAddress().getAddress().getHostAddress(), "UTF-8")) : "";
	String authURL = "https://sessionserver.mojang.com/session/minecraft/hasJoined?username=" + encName + "&serverId=" + encodedHash + preventProxy;
	Callback<String> handler = new Callback<String>() {
		@Override
		public void done(String result, Throwable error) {
			if (error == null) {
				LoginResult obj = BungeeCord.getInstance().gson.fromJson(result, LoginResult.class);
				if ((obj != null) && (obj.getId() != null)) {
					loginProfile = obj;
					updateUsername(obj.getName(), true);
					updateUUID(Util.getUUID(obj.getId()), true);
					Arrays.stream(loginProfile.getProperties())
					.forEach(bProperty -> connection.getProfile().addProperty(
						new ProfileProperty(bProperty.getName(), bProperty.getValue(), bProperty.getSignature())
					));
					finishLogin();
					return;
				}
				disconnect(BungeeCord.getInstance().getTranslation("offline_mode_player"));
			} else {
				disconnect(BungeeCord.getInstance().getTranslation("mojang_fail"));
				BungeeCord.getInstance().getLogger().log(Level.SEVERE, "Error authenticating " + getName() + " with minecraft.net", error);
			}
		}
	};
	HttpClient.get(authURL, channel.getHandle().eventLoop(), handler);
}
 
Example 19
public LoginProfile(UUID uuid, String name, ProfileProperty... properties) {
	this.uuid = uuid;
	this.name = name;
	Arrays.stream(properties).forEach(this::addProperty);
}
 
Example 20
@Override
public Set<ProfileProperty> getProperties(String name) {
	return Collections.unmodifiableSet(properties.getOrDefault(name, Collections.emptySet()));
}
 
Example 21
public Map<String, Set<ProfileProperty>> getProperties() {
	return properties;
}
 
Example 22
public void addProperty(ProfileProperty profileProperty) {
	properties.computeIfAbsent(profileProperty.getName(), k -> Collections.newSetFromMap(new ConcurrentHashMap<>())).add(profileProperty);
}
 
Example 23
public static SpoofedData create(String hostname, String address, UUID uuid, Collection<ProfileProperty> properties) {
	return new SpoofedData(hostname, address, uuid, properties, null);
}
 
Example 24
public Collection<ProfileProperty> getProperties() {
	return properties;
}
 
Example 25
/**
 * Returns properties
 * @return properties
 */
public Map<String, Set<ProfileProperty>> getProperties() {
	return properties;
}
 
Example 26
/**
 * Returns properties by name
 * @param name property name
 * @return properties
 */
public Set<ProfileProperty> getProperties(String name) {
	return properties.getOrDefault(name, Collections.emptySet());
}
 
Example 27
/**
 * Adds property
 * @param property property
 */
public void addProperty(ProfileProperty property) {
	properties.computeIfAbsent(property.getName(), k -> new HashSet<>()).add(property);
}
 
Example 28
/**
 * Returns properties
 * @return properties
 */
public Map<String, Set<ProfileProperty>> getProperties() {
	return properties;
}
 
Example 29
/**
 * Returns properties by name
 * @param name property name
 * @return properties
 */
public Set<ProfileProperty> getProperties(String name) {
	return properties.getOrDefault(name, Collections.emptySet());
}
 
Example 30
/**
 * Adds property
 * @param property property
 */
public void addProperty(ProfileProperty property) {
	properties.computeIfAbsent(property.getName(), k -> new HashSet<>()).add(property);
}