Search in sources :

Example 16 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer 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 17 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project ChangeSkin by games647.

the class SetCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    boolean isOp = sender.getGroups().contains(plugin.getName() + "-OP");
    if (sender instanceof ProxiedPlayer) {
        sender.removeGroups(plugin.getName() + "-OP");
        if (plugin.getCore().getCooldownService().isTracked(((ProxiedPlayer) sender).getUniqueId())) {
            plugin.sendMessage(sender, "cooldown");
            return;
        }
    }
    if (args.length > 0 && "set".equalsIgnoreCase(args[0])) {
        args = Arrays.copyOfRange(args, 1, args.length);
    }
    if (args.length > 1) {
        if (!sender.hasPermission(plugin.getName().toLowerCase() + ".command.setskin.other") && !sender.hasPermission(plugin.getName().toLowerCase() + ".command.setskin.*")) {
            plugin.sendMessage(sender, "no-permission-other");
            return;
        }
        String targetPlayerName = args[0];
        String toSkin = args[1];
        ProxiedPlayer targetPlayer = ProxyServer.getInstance().getPlayer(targetPlayerName);
        if (targetPlayer == null) {
            plugin.sendMessage(sender, "not-online");
        } else {
            setSkin(sender, targetPlayer, toSkin, isOp, isKeepSkin(args));
        }
    } else if (sender instanceof ProxiedPlayer) {
        if (args.length == 1) {
            if ("reset".equalsIgnoreCase(args[0])) {
                onReset(sender, isOp);
                return;
            }
            setSkin(sender, (ProxiedPlayer) sender, args[0], isOp, isKeepSkin(args));
        } else {
            plugin.sendMessage(sender, "no-skin");
        }
    } else {
        plugin.sendMessage(sender, "no-console");
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer)

Example 18 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer 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 19 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer 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 20 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project ViaCheckConnection by x9nico.

the class Bungee method join.

@SuppressWarnings({ "unchecked" })
@EventHandler
public void join(ServerConnectedEvent e) throws IOException {
    ProxiedPlayer p = e.getPlayer();
    Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
    if (Bungee.isProtocolSupport()) {
        if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_8.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_8").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_9").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_1.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_9_1").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_2.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_9_2").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_3.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_9_3").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_10.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_10").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_11.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_11").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_11_1.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_11_1").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_12").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.unknown.getId()) {
            p.sendMessage(new TextComponent(config.getString("unknown_version").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_7_1.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_7_1").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_7_6.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_7_6").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12_1.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_12_1").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12_2.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_12_2").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_13.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_13").replace("&", "§")));
        }
    } else {
        if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_8.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_8").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_9").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_1.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_9_1").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_2.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_9_2").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_3.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_9_3").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_10.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_10").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_11.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_11").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_11_1.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_11_1").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_12").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.unknown.getId()) {
            p.sendMessage(new TextComponent(config.getString("unknown_version").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12_1.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_12_1").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12_2.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_12_2").replace("&", "§")));
        } else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_13.getId()) {
            p.sendMessage(new TextComponent(config.getString("v1_13").replace("&", "§")));
        }
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) Configuration(net.md_5.bungee.config.Configuration) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) File(java.io.File) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)50 EventHandler (net.md_5.bungee.event.EventHandler)20 TextComponent (net.md_5.bungee.api.chat.TextComponent)17 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 Configuration (net.md_5.bungee.config.Configuration)6 YamlConfiguration (net.md_5.bungee.config.YamlConfiguration)6 UserPreference (com.github.games647.changeskin.core.model.UserPreference)5 Message (at.pcgamingfreaks.Bungee.Message.Message)4 User (me.lucko.luckperms.common.model.User)4 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)4 Test (org.junit.Test)4 SkinModel (com.github.games647.changeskin.core.model.skin.SkinModel)3 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)3 PacketSpyAction (fr.glowstoner.fireapi.bigbrother.spy.packets.PacketSpyAction)3 Tristate (me.lucko.luckperms.api.Tristate)3 Chat (net.md_5.bungee.protocol.packet.Chat)3 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)2 FirePlayer (fr.glowstoner.fireapi.player.FirePlayer)2 Message (io.github.lxgaming.discordbot.entries.Message)2