Search in sources :

Example 11 with Skin

use of com.github.games647.craftapi.model.skin.Skin in project ChangeSkin by games647.

the class SetCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) {
    if (!(src instanceof Player)) {
        plugin.sendMessage(src, "no-console");
        return CommandResult.empty();
    }
    UUID uniqueId = ((Player) src).getUniqueId();
    if (core.getCooldownService().isTracked(uniqueId)) {
        plugin.sendMessage(src, "cooldown");
        return CommandResult.empty();
    }
    Player receiver = (Player) src;
    String targetSkin = args.<String>getOne("skin").get();
    boolean keepSkin = args.hasAny("keep");
    if ("reset".equals(targetSkin)) {
        targetSkin = receiver.getUniqueId().toString();
    }
    if (targetSkin.length() > 16) {
        UUID targetUUID = UUID.fromString(targetSkin);
        if (core.getConfig().getBoolean("skinPermission") && !plugin.hasSkinPermission(src, targetUUID, true)) {
            return CommandResult.empty();
        }
        plugin.sendMessage(src, "skin-change-queue");
        Runnable skinDownloader = new SkinDownloader(plugin, src, receiver, targetUUID, keepSkin);
        Task.builder().async().execute(skinDownloader).submit(plugin);
        return CommandResult.success();
    }
    Runnable nameResolver = new NameResolver(plugin, src, targetSkin, receiver, keepSkin);
    Task.builder().async().execute(nameResolver).submit(plugin);
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) SkinDownloader(com.github.games647.changeskin.sponge.task.SkinDownloader) UUID(java.util.UUID) NameResolver(com.github.games647.changeskin.sponge.task.NameResolver)

Example 12 with Skin

use of com.github.games647.craftapi.model.skin.Skin 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 13 with Skin

use of com.github.games647.craftapi.model.skin.Skin in project ChangeSkin by games647.

the class AbstractSkinListener method initializeProfile.

protected UserPreference initializeProfile(UUID uniqueId, String playerName) {
    UserPreference preferences = plugin.getStorage().getPreferences(uniqueId);
    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);
        if (!preferences.getTargetSkin().isPresent()) {
            // still no skin
            getRandomSkin().ifPresent(preferences::setTargetSkin);
        }
    }
    return preferences;
}
Also used : UserPreference(com.github.games647.changeskin.core.model.UserPreference) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel)

Example 14 with Skin

use of com.github.games647.craftapi.model.skin.Skin 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;
    }
    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 15 with Skin

use of com.github.games647.craftapi.model.skin.Skin 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 (connectEvent.isCancelled() || !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, () -> {
            UserPreference preference = initializeProfile(player.getUniqueId(), plugin.getName());
            plugin.startSession(player.getPendingConnection(), preference);
            preference.getTargetSkin().ifPresent(skin -> plugin.getApi().applySkin(player, skin));
        });
    } 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)11 UserPreference (com.github.games647.changeskin.core.model.UserPreference)10 UUID (java.util.UUID)8 Skin (com.github.games647.craftapi.model.skin.Skin)7 SkinProperty (com.github.games647.craftapi.model.skin.SkinProperty)6 SkinPropertyTest (com.github.games647.craftapi.model.skin.SkinPropertyTest)6 Test (org.junit.Test)6 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)5 Texture (com.github.games647.craftapi.model.skin.Texture)3 EventHandler (net.md_5.bungee.event.EventHandler)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 TexturesModel (com.github.games647.changeskin.core.model.skin.TexturesModel)2 IOException (java.io.IOException)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Optional (java.util.Optional)2