use of org.spongepowered.api.profile.property.ProfileProperty in project SkinsRestorerX by DoNotSpamPls.
the class LoginListener method handle.
@Override
public void handle(Login e) {
String name = e.getTargetUser().getName().toLowerCase();
Collection<ProfileProperty> props = e.getProfile().getPropertyMap().get("textures");
String skin = SkinsRestorer.getInstance().getDataRoot().getNode("Players", name).getString();
if (skin == null || skin.isEmpty())
skin = name;
skin = skin.toLowerCase();
ProfileProperty cachedTextures = null;
try {
cachedTextures = Sponge.getServer().getGameProfileManager().createProfileProperty("textures", SkinsRestorer.getInstance().getDataRoot().getNode("Skins", skin, "Value").getString(), SkinsRestorer.getInstance().getDataRoot().getNode("Skins", skin, "Signature").getString());
props.clear();
props.add(cachedTextures);
} catch (Exception ex) {
}
if (cachedTextures == null) {
Optional<String> uid = MojangAPI.getUUID(skin);
if (!uid.isPresent())
return;
Optional<ProfileProperty> textures = MojangAPI.getSkinProperty(uid.get());
if (!textures.isPresent())
return;
cachedTextures = textures.get();
if (!name.equalsIgnoreCase(skin))
SkinsRestorer.getInstance().getDataRoot().getNode("Players", name).setValue(skin);
else
SkinsRestorer.getInstance().getDataRoot().getNode("Players", name).setValue(null);
SkinsRestorer.getInstance().getDataRoot().getNode("Skins", skin, "Value").setValue(textures.get().getValue());
SkinsRestorer.getInstance().getDataRoot().getNode("Skins", skin, "Signature").setValue(textures.get().getSignature().get());
SkinsRestorer.getInstance().saveConfigs();
props.clear();
props.add(cachedTextures);
return;
}
}
use of org.spongepowered.api.profile.property.ProfileProperty in project ChangeSkin by games647.
the class SpongeSkinAPI method applyProperties.
@Override
public void applyProperties(GameProfile profile, SkinModel targetSkin) {
// remove existing skins
profile.getPropertyMap().clear();
if (targetSkin != null) {
GameProfileManager profileManager = Sponge.getServer().getGameProfileManager();
ProfileProperty profileProperty = profileManager.createProfileProperty(SkinProperty.SKIN_KEY, targetSkin.getEncodedValue(), targetSkin.getSignature());
profile.getPropertyMap().put(SkinProperty.SKIN_KEY, profileProperty);
}
}
use of org.spongepowered.api.profile.property.ProfileProperty in project LanternServer by LanternPowered.
the class LanternProfileProperty method createPropertiesMapFromJson.
/**
* Creates a multimap with {@link LanternProfileProperty}s from the specified {@link JsonArray}.
*
* @param jsonArray The json array
* @return The multimap
*/
public static Multimap<String, ProfileProperty> createPropertiesMapFromJson(JsonArray jsonArray) {
final Multimap<String, ProfileProperty> properties = LinkedHashMultimap.create();
for (int i = 0; i < jsonArray.size(); i++) {
final ProfileProperty profileProperty = createFromJson(jsonArray.get(i).getAsJsonObject());
properties.put(profileProperty.getName(), profileProperty);
}
return properties;
}
use of org.spongepowered.api.profile.property.ProfileProperty in project LanternServer by LanternPowered.
the class HandlerEncryptionResponse method performAuth.
private void performAuth(NetworkSession session, String username, String hash, @Nullable String preventProxiesIp) {
final String postUrl = AUTH_BASE_URL + "?username=" + username + "&serverId=" + hash + (preventProxiesIp == null ? "" : "?ip=" + preventProxiesIp);
try {
// Authenticate
URLConnection connection = new URL(postUrl).openConnection();
JsonObject json;
try (InputStream is = connection.getInputStream()) {
if (is.available() == 0) {
session.disconnect(t("Invalid username or session id!"));
return;
}
try {
json = GSON.fromJson(new InputStreamReader(is), JsonObject.class);
} catch (Exception e) {
Lantern.getLogger().warn("Username \"{}\" failed to authenticate!", username);
session.disconnect(t("multiplayer.disconnect.unverified_username"));
return;
}
}
final String name = json.get("name").getAsString();
final String id = json.get("id").getAsString();
// Parse UUID
final UUID uuid;
try {
uuid = UUIDHelper.fromFlatString(id);
} catch (IllegalArgumentException e) {
Lantern.getLogger().error("Returned authentication UUID invalid: {}", id, e);
session.disconnect(t("Invalid UUID."));
return;
}
final Multimap<String, ProfileProperty> properties = LanternProfileProperty.createPropertiesMapFromJson(json.getAsJsonArray("properties"));
final LanternGameProfile gameProfile = new LanternGameProfile(uuid, name, properties);
Lantern.getLogger().info("Finished authenticating.");
final Cause cause = Cause.of(EventContext.empty(), session, gameProfile);
final ClientConnectionEvent.Auth event = SpongeEventFactory.createClientConnectionEventAuth(cause, session, new MessageEvent.MessageFormatter(t("multiplayer.disconnect.not_allowed_to_join")), gameProfile, false);
Sponge.getEventManager().post(event);
if (event.isCancelled()) {
session.disconnect(event.isMessageCancelled() ? t("multiplayer.disconnect.generic") : event.getMessage());
} else {
session.messageReceived(new MessageLoginInFinish(gameProfile));
}
} catch (Exception e) {
Lantern.getLogger().error("Error in authentication thread", e);
session.disconnect(t("Internal error during authentication."));
}
}
Aggregations