Search in sources :

Example 21 with SkinModel

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);
    }
}
Also used : UserPreference(com.github.games647.changeskin.core.model.UserPreference) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel)

Example 22 with SkinModel

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");
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) UserPreference(com.github.games647.changeskin.core.model.UserPreference) UUID(java.util.UUID) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel)

Example 23 with SkinModel

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);
    }
}
Also used : UUID(java.util.UUID) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel)

Example 24 with SkinModel

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();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) SkinProperty(com.github.games647.changeskin.core.model.skin.SkinProperty) TexturesModel(com.github.games647.changeskin.core.model.skin.TexturesModel)

Example 25 with SkinModel

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);
}
Also used : SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel)

Aggregations

SkinModel (com.github.games647.changeskin.core.model.skin.SkinModel)21 UUID (java.util.UUID)9 UserPreference (com.github.games647.changeskin.core.model.UserPreference)8 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)3 SkinProperty (com.github.games647.changeskin.core.model.skin.SkinProperty)2 TextureModel (com.github.games647.changeskin.core.model.skin.TextureModel)2 TextureType (com.github.games647.changeskin.core.model.skin.TextureType)2 ChangeSkinBungee (com.github.games647.changeskin.bungee.ChangeSkinBungee)1 ChangeSkinCore (com.github.games647.changeskin.core.ChangeSkinCore)1 NotPremiumException (com.github.games647.changeskin.core.NotPremiumException)1 RateLimitException (com.github.games647.changeskin.core.RateLimitException)1 SkinStorage (com.github.games647.changeskin.core.SkinStorage)1 CheckPermMessage (com.github.games647.changeskin.core.message.CheckPermMessage)1 PermResultMessage (com.github.games647.changeskin.core.message.PermResultMessage)1 SkinUpdateMessage (com.github.games647.changeskin.core.message.SkinUpdateMessage)1 GameProfile (com.github.games647.changeskin.core.model.GameProfile)1