Search in sources :

Example 1 with UserPreference

use of com.github.games647.changeskin.core.model.UserPreference 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 2 with UserPreference

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

the class ServerSwitchListener method onLazyLoad.

private void onLazyLoad(ProxiedPlayer player) {
    UserPreference preferences = plugin.getStorage().getPreferences(player.getUniqueId());
    plugin.startSession(player.getPendingConnection(), preferences);
    if (!preferences.getTargetSkin().isPresent() && core.getConfig().getBoolean("restoreSkins")) {
        refetchSkin(player.getName(), preferences);
        if (!preferences.getTargetSkin().isPresent()) {
            // still no skin
            getRandomSkin().ifPresent(preferences::setTargetSkin);
        }
    }
    if (preferences.getTargetSkin().isPresent()) {
        plugin.getApi().applySkin(player, preferences.getTargetSkin().get());
    }
}
Also used : UserPreference(com.github.games647.changeskin.core.model.UserPreference)

Example 3 with UserPreference

use of com.github.games647.changeskin.core.model.UserPreference 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)

Example 4 with UserPreference

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

the class SharedInvalidator method run.

@Override
public void run() {
    UserPreference preferences = core.getStorage().getPreferences(receiverUUID);
    Optional<SkinModel> ownedSkin = preferences.getTargetSkin();
    if (ownedSkin.isPresent()) {
        sendMessageInvoker("invalidate-request");
        core.getSkinApi().downloadSkin(ownedSkin.get().getProfileId()).ifPresent(this::scheduleApplyTask);
    } else {
        sendMessageInvoker("dont-have-skin");
    }
}
Also used : UserPreference(com.github.games647.changeskin.core.model.UserPreference) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel)

Example 5 with UserPreference

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

the class InfoCommand method sendSkinDetails.

private void sendSkinDetails(UUID uuid, UserPreference preference) {
    Player player = Bukkit.getPlayer(uuid);
    if (player != null) {
        Optional<SkinModel> optSkin = preference.getTargetSkin();
        if (optSkin.isPresent()) {
            String template = plugin.getCore().getMessage("skin-info");
            player.sendMessage(formatter.apply(template, optSkin.get()));
        } else {
            plugin.sendMessage(player, "skin-not-found");
        }
    }
}
Also used : Player(org.bukkit.entity.Player) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel)

Aggregations

UserPreference (com.github.games647.changeskin.core.model.UserPreference)17 SkinModel (com.github.games647.changeskin.core.model.skin.SkinModel)13 UUID (java.util.UUID)9 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)5 Player (org.bukkit.entity.Player)4 EventHandler (net.md_5.bungee.event.EventHandler)3 Player (org.spongepowered.api.entity.living.player.Player)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Server (net.md_5.bungee.api.connection.Server)2 EventHandler (org.bukkit.event.EventHandler)2 ChangeSkinBungee (com.github.games647.changeskin.bungee.ChangeSkinBungee)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 ChannelMessage (com.github.games647.changeskin.core.message.ChannelMessage)1 CheckPermMessage (com.github.games647.changeskin.core.message.CheckPermMessage)1 SharedListener (com.github.games647.changeskin.core.shared.SharedListener)1