BungeeCord PluginChanels

Discussion in 'Skript' started by KrizziLP, May 6, 2017.

  1. Hey,
    I have a question about my plugin. I want to writte a BedWars plugin and have a problem.
    I want that if a player join the game and the round to full is the plyer to another random server send. Here is that what i try.
    Code (Text):
    //in antoher class
    //constuctor is ok
    @EventHandler
        public void OnJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
                    if (plugin.activ == false) {
                            plugin.inHM.add(p.getName());
                int onp = plugin.inHM.size();
                if (onp >= plugin.getConfig().getInt("BedWars.Map.Start.MinPlayer")
                        && onp <= plugin.getConfig().getInt("BedWars.Map.Start.MaxPlayer")) {

                } else if (onp > plugin.getConfig().getInt("BedWars.Map.Start.MaxPlayer")) {
                    System.out.println("1");
                    if (p.hasPermission("bw.join.every")) {
                        KickRandomPlayer(p);
                    } else {
                       
                        p.sendMessage(plugin.prefix + "§4Du wurdest von einen");
                        p.sendMessage(plugin.prefix + "§6PremiumSpieler,§5 YouTuber §4oder §cTeamMitglied");
                        p.sendMessage(plugin.prefix + "§4gekickt!");
                        p.sendMessage(plugin.prefix + "");
                        p.sendMessage(plugin.prefix + "§6Um nich mehr gekickt zu werden kannst du dir Premium kaufen:");
                        p.sendMessage(plugin.prefix + "§a" + plugin.webseite);
                        System.out.println(p.getName());
                        plugin.inHM.remove(p.getName());
                        plugin.HM.remove(p.getName());
                        plugin.sendToRandomLobbyServer(p);
                    }

                }
    }public void KickRandomPlayer(Player p) {

            ArrayList<Player> nonpre = new ArrayList<Player>();
            for (Player all : Bukkit.getOnlinePlayers()) {

                if (!all.hasPermission("bw.join.every")) {
                    nonpre.add(all);
                }
            }
            int i = nonpre.size();
            if (i > 0) {
                Random z = new Random();
                int r = z.nextInt((i--));
                String playern = plugin.inHM.get(r);
                if (!Bukkit.getPlayer(playern).hasPermission("bw.join.every")) {
                    Player player = Bukkit.getPlayer(playern);
                    player.sendMessage(plugin.prefix + "§4Du wurdest von einen");
                    player.sendMessage(plugin.prefix + "§6PremiumSpieler,§5 YouTuber §4oder §cTeamMitglied");
                    player.sendMessage(plugin.prefix + "§4gekickt!");
                    player.sendMessage(plugin.prefix + "");
                    player.sendMessage(plugin.prefix + "§6Um nich mehr gekickt zu werden kannst du dir Premium kaufen:");
                    player.sendMessage(plugin.prefix + "§a" + plugin.webseite);
                    System.out.println(player.getName());
                    plugin.inHM.remove(p.getName());
                    plugin.HM.remove(p.getName());
                    plugin.sendToRandomLobbyServer(player);
                }

            } else {

                p.sendMessage(plugin.prefix + "§4Du wurdest von einen");
                p.sendMessage(plugin.prefix + "§6PremiumSpieler,§5 YouTuber §4oder §cTeamMitglied");
                p.sendMessage(plugin.prefix + "§4gekickt!");
                p.sendMessage(plugin.prefix + "");
                p.sendMessage(plugin.prefix + "§6Um nich mehr gekickt zu werden kannst du dir Premium kaufen:");
                p.sendMessage(plugin.prefix + "§a" + plugin.webseite);
                System.out.println(p.getName());
                plugin.inHM.remove(p.getName());
                plugin.HM.remove(p.getName());
                plugin.sendToRandomLobbyServer(p);
               
            }
        }
    //in main klasse
    public void sendToRandomLobbyServer(Player p) {
            System.out.println("4");

            List<String> list = getConfig().getStringList("BedWars.LobbyServer");
            int i = list.size();

            Random z = new Random();
            int r = z.nextInt((i--));

            String s = list.get(r);
            System.out.println(s);
            ByteArrayOutputStream b = new ByteArrayOutputStream();
            DataOutputStream out = new DataOutputStream(b);
            try {
                wait(5000);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }

            try {
                out.writeUTF("Connect");
                out.writeUTF(s);
            } catch (IOException e) {
                p.sendMessage("[§eSytem§r] §7Dieser Server ist nich verfügbar!");
            }
            getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
            p.sendPluginMessage(this, "BungeeCord", b.toByteArray());
        }
    The System.out.println(); are not importent I look only if the plugin reach the code. Thanks for your help.
     
  2. Wrong section.

    Are you registering the event?
    And using wait and using the API isn't recommended (you don't want to get NullPointerException after the player logs of) and the server full on waits for that time (lag detection goes mental)
     
  3. I register the events and what API did you mean I use only Spigot/CraftBukkit.
     
  4. I mean that the server literally bugs out is you are using the same thread and using wait(long) or Thread.sleep(long)
    And if the player logs out during the 5 second delay then you will get a nullpointerexception.
     
  5. Ok, but i tryied it without it and it don't work
     
  6. This is the script selection not the plugin selection