Search in sources :

Example 21 with UserPreference

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

the class LoginListener method onPreLogin.

// we are making an blocking request it might be better to ignore it if normal priority events cancelled it
@EventHandler(priority = EventPriority.HIGHEST)
public void onPreLogin(AsyncPlayerPreLoginEvent preLoginEvent) {
    if (preLoginEvent.getLoginResult() != Result.ALLOWED) {
        // in this event isCancelled option in the annotation doesn't work
        return;
    }
    UUID playerUuid = preLoginEvent.getUniqueId();
    String playerName = preLoginEvent.getName();
    UserPreference preferences = core.getStorage().getPreferences(playerUuid);
    if (preferences == null) {
        return;
    }
    plugin.startSession(playerUuid, preferences);
    Optional<SkinModel> optSkin = preferences.getTargetSkin();
    if (optSkin.isPresent()) {
        SkinModel targetSkin = optSkin.get();
        if (!preferences.isKeepSkin()) {
            targetSkin = core.checkAutoUpdate(targetSkin);
        }
        preferences.setTargetSkin(targetSkin);
        save(preferences);
    } else if (core.getConfig().getBoolean("restoreSkins")) {
        refetchSkin(playerName, preferences);
    }
    if (!preferences.getTargetSkin().isPresent()) {
        getRandomSkin().ifPresent(preferences::setTargetSkin);
    }
}
Also used : UserPreference(com.github.games647.changeskin.core.model.UserPreference) UUID(java.util.UUID) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel) EventHandler(org.bukkit.event.EventHandler)

Example 22 with UserPreference

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

the class SkinApplier method run.

@Override
public void run() {
    if (!isConnected()) {
        return;
    }
    // uuid was successful resolved, we could now make a cooldown check
    if (invoker instanceof Player && core != null) {
        UUID uniqueId = ((Player) invoker).getUniqueId();
        core.getCooldownService().trackPlayer(uniqueId);
    }
    if (plugin.getStorage() != null) {
        UserPreference preferences = plugin.getStorage().getPreferences(receiver.getUniqueId());
        save(preferences);
    }
    applySkin();
}
Also used : Player(org.bukkit.entity.Player) UserPreference(com.github.games647.changeskin.core.model.UserPreference) UUID(java.util.UUID)

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