Search in sources :

Example 16 with UserPreference

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

the class InfoCommand method execute.

@Override
public void execute(CommandSender sender, String[] strings) {
    if (!(sender instanceof ProxiedPlayer)) {
        plugin.sendMessage(sender, "no-console");
        return;
    }
    ProxiedPlayer player = (ProxiedPlayer) sender;
    UserPreference preference = plugin.getLoginSession((PendingConnection) player);
    Optional<SkinModel> optSkin = preference.getTargetSkin();
    if (optSkin.isPresent()) {
        String template = plugin.getCore().getMessage("skin-info");
        sender.sendMessage(TextComponent.fromLegacyText(formatter.apply(template, optSkin.get())));
    } else {
        plugin.sendMessage(sender, "skin-not-found");
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) UserPreference(com.github.games647.changeskin.core.model.UserPreference) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel)

Example 17 with UserPreference

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

use of com.github.games647.changeskin.core.model.UserPreference 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 19 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 receiverUUID = receiver.getUniqueId();
    if (invoker instanceof ProxiedPlayer) {
        if (targetSkin != null && core.getConfig().getBoolean("bukkit-permissions")) {
            Server server = ((ProxiedPlayer) invoker).getServer();
            boolean skinPerm = core.getConfig().getBoolean("skinPermission");
            ChannelMessage message = new CheckPermMessage(targetSkin, receiverUUID, skinPerm, bukkitOp);
            plugin.sendPluginMessage(server, message);
            return;
        }
        // uuid was successful resolved, we could now make a cooldown check
        core.getCooldownService().trackPlayer(((ProxiedPlayer) invoker).getUniqueId());
    }
    // check if that specific player is online
    UserPreference preferences = plugin.getLoginSession(receiver.getPendingConnection());
    if (preferences == null) {
        preferences = plugin.getStorage().getPreferences(receiverUUID);
    }
    save(preferences);
    applySkin();
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Server(net.md_5.bungee.api.connection.Server) CheckPermMessage(com.github.games647.changeskin.core.message.CheckPermMessage) UserPreference(com.github.games647.changeskin.core.model.UserPreference) UUID(java.util.UUID) ChannelMessage(com.github.games647.changeskin.core.message.ChannelMessage)

Example 20 with UserPreference

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

the class InfoCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!(sender instanceof Player)) {
        plugin.sendMessage(sender, "no-console");
        return true;
    }
    Player player = (Player) sender;
    UUID uniqueId = player.getUniqueId();
    Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
        UserPreference preferences = plugin.getStorage().getPreferences(uniqueId);
        Bukkit.getScheduler().runTask(plugin, () -> sendSkinDetails(uniqueId, preferences));
    });
    return true;
}
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