protocolsupport.api.utils.ProfileProperty Java Examples

The following examples show how to use protocolsupport.api.utils.ProfileProperty. 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: GameProfileSerializer.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
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 #2
Source File: MinecraftSessionService.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
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 #3
Source File: GameProfileSerializer.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
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 #4
Source File: SpigotWrappedGameProfile.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 #5
Source File: SpigotNetworkManagerWrapper.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 #6
Source File: SpigotNetworkManagerWrapper.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 #7
Source File: PlayerProfileCompleteEvent.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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 #8
Source File: PlayerListCache.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
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
Source File: PlayerListCache.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
public void addProperty(ProfileProperty property) {
	if (property.hasSignature()) {
		propSigned.put(property.getName(), property);
	} else {
		propUnsigned.put(property.getName(), property);
	}
}
 
Example #10
Source File: PlayerListCache.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
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 #11
Source File: SpoofedData.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
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 #12
Source File: PlayerProfileCompleteEvent.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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 #13
Source File: LoginProfile.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Set<ProfileProperty> getProperties(String name) {
	return Collections.unmodifiableSet(properties.getOrDefault(name, Collections.emptySet()));
}
 
Example #14
Source File: GameProfile.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 4 votes vote down vote up
public GameProfile(UUID uuid, String name, ProfileProperty... properties) {
	this.uuid = uuid;
	this.name = name;
	Arrays.stream(properties).forEach(this::addProperty);
}
 
Example #15
Source File: GameProfile.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 4 votes vote down vote up
public Map<String, Set<ProfileProperty>> getProperties() {
	return properties;
}
 
Example #16
Source File: GameProfile.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setProperties(Map<String, Set<ProfileProperty>> propertiesMap) {
	properties.clear();
	properties.putAll(propertiesMap);
}
 
Example #17
Source File: GameProfile.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 4 votes vote down vote up
public void addProperty(ProfileProperty profileProperty) {
	properties.computeIfAbsent(profileProperty.getName(), k -> new HashSet<>()).add(profileProperty);
}
 
Example #18
Source File: PSInitialHandler.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 4 votes vote down vote up
@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
Source File: SpoofedData.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public Collection<ProfileProperty> getProperties() {
	return properties;
}
 
Example #20
Source File: SpoofedData.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public static SpoofedData create(String hostname, String address, UUID uuid, Collection<ProfileProperty> properties) {
	return new SpoofedData(hostname, address, uuid, properties, null);
}
 
Example #21
Source File: SkinUtils.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * @return a profile property containing the wrapped data.
 */
public ProfileProperty toProfileProperty() {
	return new ProfileProperty(PROPERTY_NAME, getValue(), getSignature());
}
 
Example #22
Source File: LoginProfile.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public void addProperty(ProfileProperty profileProperty) {
	properties.computeIfAbsent(profileProperty.getName(), k -> Collections.newSetFromMap(new ConcurrentHashMap<>())).add(profileProperty);
}
 
Example #23
Source File: LoginProfile.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public Map<String, Set<ProfileProperty>> getProperties() {
	return properties;
}
 
Example #24
Source File: LoginProfile.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public LoginProfile(UUID uuid, String name, ProfileProperty... properties) {
	this.uuid = uuid;
	this.name = name;
	Arrays.stream(properties).forEach(this::addProperty);
}
 
Example #25
Source File: PlayerProfileCompleteEvent.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Returns properties by name
 * @param name property name
 * @return properties
 */
public Set<ProfileProperty> getProperties(String name) {
	return properties.getOrDefault(name, Collections.emptySet());
}
 
Example #26
Source File: PlayerProfileCompleteEvent.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Returns properties
 * @return properties
 */
public Map<String, Set<ProfileProperty>> getProperties() {
	return properties;
}
 
Example #27
Source File: PlayerProfileCompleteEvent.java    From ProtocolSupport with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Returns properties
 * @return properties
 */
public Map<String, Set<ProfileProperty>> getProperties() {
	return properties;
}
 
Example #28
Source File: PlayerProfileCompleteEvent.java    From ProtocolSupport with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Returns properties by name
 * @param name property name
 * @return properties
 */
public Set<ProfileProperty> getProperties(String name) {
	return properties.getOrDefault(name, Collections.emptySet());
}
 
Example #29
Source File: PlayerProfileCompleteEvent.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Adds property
 * @param property property
 */
public void addProperty(ProfileProperty property) {
	properties.computeIfAbsent(property.getName(), k -> new HashSet<>()).add(property);
}
 
Example #30
Source File: PlayerProfileCompleteEvent.java    From ProtocolSupport with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Adds property
 * @param property property
 */
public void addProperty(ProfileProperty property) {
	properties.computeIfAbsent(property.getName(), k -> new HashSet<>()).add(property);
}