Search in sources :

Example 26 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project SkinsRestorerX by DoNotSpamPls.

the class SkinApplier method applySkin.

public static void applySkin(final ProxiedPlayer p) {
    ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
        try {
            Property textures = (Property) SkinStorage.getOrCreateSkinForPlayer(p.getName());
            InitialHandler handler = (InitialHandler) p.getPendingConnection();
            if (handler.isOnlineMode()) {
                sendUpdateRequest(p, textures);
                return;
            }
            LoginResult profile;
            try {
                // NEW BUNGEECORD
                profile = (net.md_5.bungee.connection.LoginResult) ReflectionUtil.invokeConstructor(LoginResult, new Class<?>[] { String.class, String.class, Property[].class }, p.getUniqueId().toString(), p.getName(), new Property[] { textures });
            } catch (Exception e) {
                // FALL BACK TO OLD
                profile = (net.md_5.bungee.connection.LoginResult) ReflectionUtil.invokeConstructor(LoginResult, new Class<?>[] { String.class, Property[].class }, p.getUniqueId().toString(), new Property[] { textures });
            }
            Property[] present = profile.getProperties();
            Property[] newprops = new Property[present.length + 1];
            System.arraycopy(present, 0, newprops, 0, present.length);
            newprops[present.length] = textures;
            profile.getProperties()[0].setName(newprops[0].getName());
            profile.getProperties()[0].setValue(newprops[0].getValue());
            profile.getProperties()[0].setSignature(newprops[0].getSignature());
            ReflectionUtil.setObject(InitialHandler.class, handler, "loginProfile", profile);
            if (SkinsRestorer.getInstance().isMultiBungee())
                sendUpdateRequest(p, textures);
            else
                sendUpdateRequest(p, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
}
Also used : LoginResult(net.md_5.bungee.connection.LoginResult) Property(net.md_5.bungee.connection.LoginResult.Property) IOException(java.io.IOException) InitialHandler(net.md_5.bungee.connection.InitialHandler)

Example 27 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project SkinsRestorerX by DoNotSpamPls.

the class AdminCommands method execute.

@SuppressWarnings("deprecation")
public void execute(final CommandSender sender, final String[] args) {
    if (sender.hasPermission("skinsrestorer.cmds")) {
        if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
            Locale.load();
            Config.load(SkinsRestorer.getInstance().getResourceAsStream("config.yml"));
            sender.sendMessage(new TextComponent(Locale.RELOAD));
        } else if (args.length == 2 && args[0].equalsIgnoreCase("drop")) {
            StringBuilder sb = new StringBuilder();
            SkinStorage.removeSkinData(sb.toString());
            sender.sendMessage(Locale.SKIN_DATA_DROPPED.replace("%player", sb.toString()));
        } else if (args.length > 2 && args[0].equalsIgnoreCase("set")) {
            final String skin = args[2];
            ProxiedPlayer player = ProxyServer.getInstance().getPlayer(args[1]);
            if (player == null)
                for (ProxiedPlayer pl : ProxyServer.getInstance().getPlayers()) if (pl.getName().startsWith(args[1])) {
                    player = pl;
                    break;
                }
            if (player == null) {
                sender.sendMessage(Locale.NOT_ONLINE);
                return;
            }
            final ProxiedPlayer p = player;
            ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
                try {
                    MojangAPI.getUUID(skin);
                    SkinStorage.setPlayerSkin(p.getName(), skin);
                    SkinApplier.applySkin(p);
                    sender.sendMessage(Locale.SKIN_CHANGE_SUCCESS);
                } catch (MojangAPI.SkinRequestException e) {
                    sender.sendMessage(e.getReason());
                }
            });
        } else if (args.length == 1 && args[0].equalsIgnoreCase("config")) {
            sender.sendMessage("§e[§2SkinsRestorer§e] §2/sr config has been removed from SkinsRestorer. Farewell!");
        } else if (args.length > 0 && args[0].equalsIgnoreCase("props")) {
            ProxiedPlayer p;
            if (args.length == 1) {
                if (!(sender instanceof ProxiedPlayer)) {
                    sender.sendMessage(Locale.NOT_PLAYER);
                }
                p = (ProxiedPlayer) sender;
            } else {
                StringBuilder name = new StringBuilder();
                for (int i = 1; i < args.length; i++) if (args.length == 2)
                    name.append(args[i]);
                else if (i + 1 == args.length)
                    name.append(args[i]);
                else
                    name.append(args[i]).append(" ");
                p = ProxyServer.getInstance().getPlayer(name.toString());
                if (p == null) {
                    sender.sendMessage(Locale.NOT_ONLINE);
                    return;
                }
            }
            InitialHandler h = (InitialHandler) p.getPendingConnection();
            LoginResult.Property prop = h.getLoginProfile().getProperties()[0];
            if (prop == null) {
                sender.sendMessage(Locale.NO_SKIN_DATA);
                return;
            }
            CommandSender cons = ProxyServer.getInstance().getConsole();
            cons.sendMessage("\n§aName: §8" + prop.getName());
            cons.sendMessage("\n§aValue : §8" + prop.getValue());
            cons.sendMessage("\n§aSignature : §8" + prop.getSignature());
            byte[] decoded = Base64.getDecoder().decode(prop.getValue());
            cons.sendMessage("\n§aValue Decoded: §e" + Arrays.toString(decoded));
            sender.sendMessage("\n§e" + Arrays.toString(decoded));
            sender.sendMessage("§cMore info in console!");
        } else {
            if (!Locale.SR_LINE.isEmpty())
                sender.sendMessage(Locale.SR_LINE);
            sender.sendMessage(Locale.HELP_ADMIN.replace("%ver%", SkinsRestorer.getInstance().getVersion()));
            if (!Locale.SR_LINE.isEmpty())
                sender.sendMessage(Locale.SR_LINE);
        }
    } else {
        sender.sendMessage(Locale.PLAYER_HAS_NO_PERMISSION);
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) LoginResult(net.md_5.bungee.connection.LoginResult) MojangAPI(skinsrestorer.shared.utils.MojangAPI) CommandSender(net.md_5.bungee.api.CommandSender) InitialHandler(net.md_5.bungee.connection.InitialHandler)

Example 28 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project FireAPI by FireBlade-Serv.

the class Events method onChat.

@EventHandler(priority = EventPriority.LOWEST)
public void onChat(ChatEvent e) {
    ProxiedPlayer pp = (ProxiedPlayer) e.getSender();
    if (pp.getServer().getInfo().equals(this.instance.getBungeePlugin().getProxy().getServerInfo("login"))) {
        List<String> success = Arrays.asList("/login", "/register");
        if (!success.contains(e.getMessage().split(" ")[0])) {
            e.setCancelled(true);
        }
        if (e.isCommand()) {
            if (this.instance.getSQL().getCryptPassword(pp.getName()).equals("§default-not-set")) {
                // not registered
                pp.sendMessage(new TextComponent(this.instance.getAuthentification().getRegisterMessage()));
                this.instance.getAuthentification().getRegisterTitle().send(pp);
            } else {
                // registered
                pp.sendMessage(new TextComponent(this.instance.getAuthentification().getLoginMessage()));
                this.instance.getAuthentification().getLoginTitle().send(pp);
            }
        } else {
            if (this.instance.getSQL().getCryptPassword(pp.getName()).equals("§default-not-set")) {
                // not registered
                pp.sendMessage(new TextComponent(this.instance.getAuthentification().getRegisterMessage()));
                this.instance.getAuthentification().getRegisterTitle().send(pp);
            } else {
                // registered
                pp.sendMessage(new TextComponent(this.instance.getAuthentification().getLoginMessage()));
                this.instance.getAuthentification().getLoginTitle().send(pp);
            }
        }
    } else {
        try {
            PacketSpyAction ps = new PacketSpyAction(pp.getName(), pp.getAddress().getAddress().getHostAddress(), e.getMessage(), SpyAction.PLAYER_CHAT);
            ps.setDateToNow();
            this.c.sendPacket(ps);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        if (e.getMessage().startsWith(":")) {
            if (this.instance.getRankSystem().hasRankAndSup(pp.getName(), Rank.GUIDE)) {
                if (this.scc.getPlayers().containsKey(pp)) {
                    if (this.scc.getPlayers().get(pp)) {
                        this.scc.send(pp, e.getMessage().substring(1));
                        e.setCancelled(true);
                    }
                }
            }
        }
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) PacketSpyAction(fr.glowstoner.fireapi.bigbrother.spy.packets.PacketSpyAction) IOException(java.io.IOException) EventHandler(net.md_5.bungee.event.EventHandler)

Example 29 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project FireAPI by FireBlade-Serv.

the class Events method onLogin.

@EventHandler
public void onLogin(PostLoginEvent e) {
    final ProxiedPlayer pp = e.getPlayer();
    pp.setTabHeader(new TextComponent("§6Fireblade-serv"), new TextComponent("§eplay.fireblade-serv.eu"));
    if (!this.instance.getSQL().hasFireAccount(pp.getName())) {
        this.instance.getSQL().createFireAccount(pp);
    }
    PacketSpyAction ps = new PacketSpyAction(pp.getName(), pp.getAddress().getAddress().getHostAddress(), "Connection sur le proxy principal.", SpyAction.PLAYER_JOIN);
    ps.setDateToNow();
    try {
        this.c.sendPacket(ps);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    this.stillconnected.add(pp);
    this.instance.getBungeePlugin().getProxy().getScheduler().schedule(this.instance.getBungeePlugin(), new Runnable() {

        @Override
        public void run() {
            if (pp != null) {
                if (pp.isConnected() && stillconnected.contains(pp)) {
                    pp.disconnect(new TextComponent("§cVous mettez trop de temps pour vous connecter !"));
                }
            }
        }
    }, 15L, TimeUnit.SECONDS);
    if (this.instance.getSQL().getCryptPassword(pp.getName()).equals("§default-not-set")) {
        // not registered
        pp.sendMessage(new TextComponent(this.instance.getAuthentification().getRegisterMessage()));
        this.instance.getAuthentification().getRegisterTitle().send(pp);
    } else {
        // registered
        pp.sendMessage(new TextComponent(this.instance.getAuthentification().getLoginMessage()));
        this.instance.getAuthentification().getLoginTitle().send(pp);
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) PacketSpyAction(fr.glowstoner.fireapi.bigbrother.spy.packets.PacketSpyAction) IOException(java.io.IOException) EventHandler(net.md_5.bungee.event.EventHandler)

Example 30 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project FireAPI by FireBlade-Serv.

the class FireFriends method getOnlineFriends.

public List<ProxiedPlayer> getOnlineFriends(String pp) throws IOException {
    Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(this.file);
    List<ProxiedPlayer> connected = new ArrayList<>();
    List<String> list = config.getStringList("data." + pp);
    for (String names : list) {
        try {
            ProxiedPlayer player = this.instance.getProxy().getPlayer(names);
            if (player != null) {
                connected.add(player);
            }
        } catch (Exception e) {
            continue;
        }
    }
    return connected;
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) Configuration(net.md_5.bungee.config.Configuration) ArrayList(java.util.ArrayList) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) IOException(java.io.IOException)

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