Search in sources :

Example 6 with UserPreference

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

the class LoginListener method onPlayerLogin.

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(PlayerLoginEvent loginEvent) {
    if (loginEvent.getResult() != PlayerLoginEvent.Result.ALLOWED) {
        // in this event isCancelled option in the annotation doesn't work
        return;
    }
    Player player = loginEvent.getPlayer();
    // updates to the chosen one
    UserPreference preferences = plugin.getLoginSession(player.getUniqueId());
    if (preferences != null) {
        preferences.getTargetSkin().ifPresent(skin -> plugin.getApi().applySkin(player, skin));
    }
    plugin.endSession(player.getUniqueId());
}
Also used : Player(org.bukkit.entity.Player) UserPreference(com.github.games647.changeskin.core.model.UserPreference) EventHandler(org.bukkit.event.EventHandler)

Example 7 with UserPreference

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

the class InfoCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    if (!(src instanceof Player)) {
        plugin.sendMessage(src, "no-console");
        return CommandResult.empty();
    }
    UUID uniqueId = ((Player) src).getUniqueId();
    Task.builder().async().execute(() -> {
        UserPreference preferences = plugin.getCore().getStorage().getPreferences(uniqueId);
        Task.builder().execute(() -> sendSkinDetails(uniqueId, preferences)).submit(plugin);
    }).submit(plugin);
    return null;
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) UserPreference(com.github.games647.changeskin.core.model.UserPreference) UUID(java.util.UUID)

Example 8 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) {
        UUID uniqueId = ((Player) invoker).getUniqueId();
        core.getCooldownService().trackPlayer(uniqueId);
    }
    if (core.getStorage() != null) {
        UserPreference preferences = core.getStorage().getPreferences(receiver.getUniqueId());
        save(preferences);
    }
    applySkin();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) UserPreference(com.github.games647.changeskin.core.model.UserPreference) UUID(java.util.UUID)

Example 9 with UserPreference

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

the class ConnectListener method onPlayerLogin.

@EventHandler(priority = EventPriority.HIGH)
public void onPlayerLogin(PostLoginEvent postLoginEvent) {
    ProxiedPlayer player = postLoginEvent.getPlayer();
    UserPreference preferences = plugin.getLoginSession(player.getPendingConnection());
    if (preferences == null || isBlacklistEnabled()) {
        return;
    }
    if (!preferences.getTargetSkin().isPresent()) {
        getRandomSkin().ifPresent(preferences::setTargetSkin);
    }
    preferences.getTargetSkin().ifPresent(skin -> plugin.getApi().applySkin(player, skin));
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) UserPreference(com.github.games647.changeskin.core.model.UserPreference) EventHandler(net.md_5.bungee.event.EventHandler)

Example 10 with UserPreference

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

the class ConnectListener method onDisconnect.

@EventHandler
public void onDisconnect(PlayerDisconnectEvent disconnectEvent) {
    PendingConnection pendingConnection = disconnectEvent.getPlayer().getPendingConnection();
    UserPreference preference = plugin.endSession(pendingConnection);
    if (preference != null) {
        save(preference);
    }
}
Also used : UserPreference(com.github.games647.changeskin.core.model.UserPreference) PendingConnection(net.md_5.bungee.api.connection.PendingConnection) EventHandler(net.md_5.bungee.event.EventHandler)

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