Search in sources :

Example 1 with SkinModel

use of com.github.games647.changeskin.core.model.skin.SkinModel in project ChangeSkin by games647.

the class BungeeSkinAPI method applySkin.

@Override
public void applySkin(ProxiedPlayer player, SkinModel targetSkin) {
    plugin.getLog().debug("Applying skin for {}", player.getName());
    InitialHandler initialHandler = (InitialHandler) player.getPendingConnection();
    LoginResult loginProfile = initialHandler.getLoginProfile();
    // this is null in offline mode
    if (loginProfile == null) {
        String mojangUUID = UUIDTypeAdapter.toMojangId(player.getUniqueId());
        if (profileSetter != null) {
            try {
                LoginResult loginResult = new LoginResult(mojangUUID, player.getName(), toProperties(targetSkin));
                profileSetter.invokeExact(initialHandler, loginResult);
            } catch (Error error) {
                // rethrow errors we shouldn't silence them like OutOfMemoryError
                throw error;
            } catch (Throwable throwable) {
                plugin.getLog().error("Error applying skin: {} for {}", targetSkin, player, throwable);
            }
        }
    } else {
        applyProperties(loginProfile, targetSkin);
    }
    // send plugin channel update request
    plugin.sendPluginMessage(player.getServer(), new SkinUpdateMessage(player.getName()));
}
Also used : SkinUpdateMessage(com.github.games647.changeskin.core.message.SkinUpdateMessage) LoginResult(net.md_5.bungee.connection.LoginResult) InitialHandler(net.md_5.bungee.connection.InitialHandler)

Example 2 with SkinModel

use of com.github.games647.changeskin.core.model.skin.SkinModel in project ChangeSkin by games647.

the class BungeeSkinAPI method toProperties.

private Property[] toProperties(SkinModel targetSkin) {
    if (targetSkin == null) {
        return emptyProperties;
    }
    String encodedValue = targetSkin.getEncodedValue();
    String signature = targetSkin.getSignature();
    Property prop = new Property(SkinProperty.SKIN_KEY, encodedValue, signature);
    return new Property[] { prop };
}
Also used : SkinProperty(com.github.games647.changeskin.core.model.skin.SkinProperty) Property(net.md_5.bungee.connection.LoginResult.Property)

Example 3 with SkinModel

use of com.github.games647.changeskin.core.model.skin.SkinModel in project ChangeSkin by games647.

the class SharedUploader method run.

@Override
public void run() {
    GameProfile profile = owner.getProfile();
    String oldSkinUrl = core.getSkinApi().downloadSkin(profile.getId()).map(skinModel -> skinModel.getTextures().get(TextureType.SKIN).getUrl()).orElse("");
    UUID uuid = profile.getId();
    UUID accessToken = UUIDTypeAdapter.parseId(owner.getAccessToken());
    core.getAuthApi().changeSkin(uuid, accessToken, url, false);
    // this could properly cause issues for uuid resolving to this database entry
    core.getSkinApi().downloadSkin(uuid).ifPresent(skinData -> {
        core.getStorage().save(skinData);
        core.getAuthApi().changeSkin(uuid, accessToken, oldSkinUrl, false);
        String localeMessage = core.getMessage("skin-uploaded").replace("{0}", owner.getProfile().getName()).replace("{1}", "Skin-" + skinData.getRowId());
        sendMessageInvoker(localeMessage);
    });
}
Also used : ChangeSkinCore(com.github.games647.changeskin.core.ChangeSkinCore) UUIDTypeAdapter(com.github.games647.changeskin.core.model.UUIDTypeAdapter) GameProfile(com.github.games647.changeskin.core.model.GameProfile) Account(com.github.games647.changeskin.core.model.auth.Account) UUID(java.util.UUID) TextureType(com.github.games647.changeskin.core.model.skin.TextureType) GameProfile(com.github.games647.changeskin.core.model.GameProfile) UUID(java.util.UUID)

Example 4 with SkinModel

use of com.github.games647.changeskin.core.model.skin.SkinModel in project ChangeSkin by games647.

the class LoginListener method onPlayerPreLogin.

@Listener
public void onPlayerPreLogin(ClientConnectionEvent.Auth preLoginEvent) {
    SkinStorage storage = core.getStorage();
    GameProfile profile = preLoginEvent.getProfile();
    UUID playerUUID = profile.getUniqueId();
    UserPreference preferences = storage.getPreferences(playerUUID);
    Optional<SkinModel> optSkin = preferences.getTargetSkin();
    if (optSkin.isPresent()) {
        SkinModel targetSkin = optSkin.get();
        if (!preferences.isKeepSkin()) {
            targetSkin = core.checkAutoUpdate(targetSkin);
        }
        plugin.getApi().applyProperties(profile, targetSkin);
        save(preferences);
    } else {
        String playerName = profile.getName().get();
        if (!core.getConfig().getBoolean("restoreSkins") || !refetchSkin(playerName, preferences)) {
            setDefaultSkin(preferences, profile);
        }
    }
}
Also used : GameProfile(org.spongepowered.api.profile.GameProfile) UserPreference(com.github.games647.changeskin.core.model.UserPreference) UUID(java.util.UUID) SkinStorage(com.github.games647.changeskin.core.SkinStorage) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel) Listener(org.spongepowered.api.event.Listener) SharedListener(com.github.games647.changeskin.core.shared.SharedListener)

Example 5 with SkinModel

use of com.github.games647.changeskin.core.model.skin.SkinModel in project ChangeSkin by games647.

the class ServerSwitchListener method onServerConnect.

@EventHandler(priority = EventPriority.HIGHEST)
public void onServerConnect(ServerConnectEvent connectEvent) {
    ServerInfo targetServer = connectEvent.getTarget();
    Server fromServer = connectEvent.getPlayer().getServer();
    if (fromServer != null && Objects.equals(targetServer, fromServer.getInfo())) {
        // check if we are switching to the same server
        return;
    }
    if (!isBlacklistEnabled()) {
        return;
    }
    ProxiedPlayer player = connectEvent.getPlayer();
    UserPreference session = plugin.getLoginSession(player.getPendingConnection());
    List<String> blacklist = core.getConfig().getStringList("server-blacklist");
    if (blacklist.contains(targetServer.getName())) {
        // clear the skin
        plugin.getApi().applySkin(player, null);
    } else if (session == null) {
        // lazy load
        ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> onLazyLoad(player));
    } else {
        // player switched to an enabled server
        Optional<SkinModel> optSkin = session.getTargetSkin();
        optSkin.ifPresent(skin -> plugin.getApi().applySkin(player, skin));
    }
}
Also used : UserPreference(com.github.games647.changeskin.core.model.UserPreference) ServerInfo(net.md_5.bungee.api.config.ServerInfo) ProxyServer(net.md_5.bungee.api.ProxyServer) Objects(java.util.Objects) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) List(java.util.List) EventPriority(net.md_5.bungee.event.EventPriority) ChangeSkinBungee(com.github.games647.changeskin.bungee.ChangeSkinBungee) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel) Server(net.md_5.bungee.api.connection.Server) Optional(java.util.Optional) EventHandler(net.md_5.bungee.event.EventHandler) ServerConnectEvent(net.md_5.bungee.api.event.ServerConnectEvent) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ProxyServer(net.md_5.bungee.api.ProxyServer) Server(net.md_5.bungee.api.connection.Server) Optional(java.util.Optional) ServerInfo(net.md_5.bungee.api.config.ServerInfo) UserPreference(com.github.games647.changeskin.core.model.UserPreference) EventHandler(net.md_5.bungee.event.EventHandler)

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