use of com.github.games647.changeskin.core.model.skin.SkinModel in project ChangeSkin by games647.
the class ConnectListener method loadProfile.
private void loadProfile(AsyncEvent<?> loginEvent, PendingConnection conn, String playerName) {
try {
UserPreference preferences = plugin.getStorage().getPreferences(conn.getUniqueId());
plugin.startSession(conn, preferences);
Optional<SkinModel> optSkin = preferences.getTargetSkin();
if (optSkin.isPresent()) {
SkinModel targetSkin = optSkin.get();
if (!preferences.isKeepSkin()) {
targetSkin = core.checkAutoUpdate(targetSkin);
}
preferences.setTargetSkin(targetSkin);
} else if (core.getConfig().getBoolean("restoreSkins")) {
refetchSkin(playerName, preferences);
}
} finally {
loginEvent.completeIntent(plugin);
}
}
use of com.github.games647.changeskin.core.model.skin.SkinModel in project ChangeSkin by games647.
the class MessageListener method onPermissionSuccess.
private void onPermissionSuccess(PermResultMessage message, ProxiedPlayer invoker) {
SkinModel targetSkin = message.getSkin();
UUID receiverUUID = message.getReceiverUUID();
ProxiedPlayer receiver = ProxyServer.getInstance().getPlayer(receiverUUID);
if (receiver == null || !receiver.isConnected()) {
// receiver is not online cancel
return;
}
// add cooldown
core.getCooldownService().trackPlayer(invoker.getUniqueId());
// Save the target uuid from the requesting player source
final UserPreference preferences = core.getStorage().getPreferences(receiver.getUniqueId());
preferences.setTargetSkin(targetSkin);
ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> {
if (core.getStorage().save(targetSkin)) {
core.getStorage().save(preferences);
}
});
if (core.getConfig().getBoolean("instantSkinChange")) {
plugin.getApi().applySkin(receiver, targetSkin);
plugin.sendMessage(invoker, "skin-changed");
} else {
plugin.sendMessage(invoker, "skin-changed-no-instant");
}
}
use of com.github.games647.changeskin.core.model.skin.SkinModel in project ChangeSkin by games647.
the class ChangeSkinCore method loadDefaultSkins.
private void loadDefaultSkins(Iterable<String> defaults) {
for (String id : defaults) {
Integer rowId = Ints.tryParse(id);
if (rowId != null) {
Optional.ofNullable(storage.getSkin(rowId)).ifPresent(defaultSkins::add);
}
UUID ownerUUID = UUID.fromString(id);
SkinModel skinData = storage.getSkin(ownerUUID);
if (skinData == null) {
Optional<SkinModel> optSkin = skinApi.downloadSkin(ownerUUID);
if (optSkin.isPresent()) {
skinData = optSkin.get();
uuidCache.put(skinData.getProfileName(), skinData.getProfileId());
storage.save(skinData);
}
}
defaultSkins.add(skinData);
}
}
use of com.github.games647.changeskin.core.model.skin.SkinModel in project ChangeSkin by games647.
the class MojangSkinApi method downloadSkin.
public Optional<SkinModel> downloadSkin(UUID ownerUUID) {
if (crackedUUID.containsKey(ownerUUID)) {
return Optional.empty();
}
// unsigned is needed in order to receive the signature
String uuidString = UUIDTypeAdapter.toMojangId(ownerUUID);
try {
HttpURLConnection httpConnection = getConnection(String.format(SKIN_URL, uuidString));
if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT) {
crackedUUID.put(ownerUUID, new Object());
return Optional.empty();
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream(), StandardCharsets.UTF_8))) {
TexturesModel texturesModel = gson.fromJson(reader, TexturesModel.class);
SkinProperty[] properties = texturesModel.getProperties();
if (properties != null && properties.length > 0) {
SkinProperty propertiesModel = properties[0];
// base64 encoded skin data
String encodedSkin = propertiesModel.getValue();
String signature = propertiesModel.getSignature();
return Optional.of(SkinModel.createSkinFromEncoded(encodedSkin, signature));
}
}
} catch (IOException ex) {
logger.error("Tried downloading skin data of: {} from Mojang", ownerUUID, ex);
}
return Optional.empty();
}
use of com.github.games647.changeskin.core.model.skin.SkinModel in project ChangeSkin by games647.
the class BukkitSkinAPI method setPersistentSkin.
@Override
public void setPersistentSkin(Player player, UUID targetSkinId, boolean applyNow) {
SkinModel newSkin = plugin.getCore().getStorage().getSkin(targetSkinId);
if (newSkin == null) {
Optional<SkinModel> downloadSkin = plugin.getCore().getSkinApi().downloadSkin(targetSkinId);
if (downloadSkin.isPresent()) {
newSkin = downloadSkin.get();
}
}
setPersistentSkin(player, newSkin, applyNow);
}
Aggregations