"> Foro - [Ayuda] Como conseguir el numero de jugadores de un servidor [BungeeCord] en Desarrollo de Plugins - Page 1 of 1
Julio 01, 2025, 05:44:16 am
Visitante

Autor Tema: [Ayuda] Como conseguir el numero de jugadores de un servidor [BungeeCord]  (Leído 4060 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Julio 21, 2014, 02:52:06 am

ChikenGamer




  • Desconectado

  • *

    • *
    • *
    • *
  • Mensaje personal
    Joven Developer, constructor y Dj
  • Actividad

  • 0%
  • Logros

Más información

Hola pues como dice el titulo me gustaría saber como puedo conseguir el numero de jugadores que hay en un servidor el cual esta unido al BungeeCord.
Lo quiero usar para un menu, esto es lo que tengo pero da error :D, nunca he usado BungeeCord

Codigo actualizado, puse casi todo el codigo aunq no es necesario, lo de bungee cord esta en medio y hasta abajo

Código: [Seleccionar]
private static int playerCount;
       @SuppressWarnings("unused")
       private static String serverName;
       private static ByteArrayOutputStream b = new ByteArrayOutputStream();
       private static DataOutputStream out = new DataOutputStream(b);
   
       Inventory inv;
   
    public void onEnable (){
       
          item = getConfig().getInt("Item_Id");
          itemonjoin = getConfig().getBoolean("Item_On_Join");
         
          if (itemonjoin){
              itemname = getConfig().getString("Item_Name").replaceAll("&", "§");
              itemlore = getConfig().getString("Item_lore").replaceAll("&", "§");
    }
       
        saveDefaultConfig();
       
        Bukkit.getServer().getPluginManager().registerEvents(this, this);
        Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
       
        //String s1 = "Online: " + getPlayerCount("test");
        //String s2 = "Online: " + getPlayerCount("test1");
           
       
        inv = Bukkit.createInventory(null, 36, "Navigation");
       
        Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
           
            String s1 = "Online: " + getPlayerCount("survival");
            String s2 = "Online: " + getPlayerCount("pizzaspleef");
           
                    public void run() {
                       
                       
                        //String pls1 = "§lJugadores: " + Bukkit.getServer().getOnlinePlayers().length;
                        //inv.setItem(12, createItem(Material.DIAMOND_SWORD, 1, (short) 0, "Ghost", pls1));

                       
                       
                        inv.setItem(3, createItem(Material.GOLD_SWORD, 1, (short) 0, "survival", s1));
                       
                        inv.setItem(5, createItem(Material.ANVIL, 1, (short) 0, "pizzaspleef", s2));
                       
                                }
}, 0L, 20L);
    }
   
    public ItemStack createItem(Material material, int amount, short shrt, String displayname, String lore) {
                ItemStack i = new ItemStack(material, amount, (short) shrt);
                ItemMeta im = i.getItemMeta();
                im.setDisplayName(displayname);
               
                ArrayList<String> loreList = new ArrayList<String>();
                String[] lores = lore.split("/");
                loreList.addAll(Arrays.asList(lores));
               
                im.setLore(loreList);
                i.setItemMeta(im);
                return i;
    }
            public void show(Player p) {
                p.openInventory(inv);
    }
           
            @EventHandler
        public void onInventoryClick(InventoryClickEvent e) throws IOException{
                if (!e.getInventory().getName().equalsIgnoreCase(inv.getName())) return;
                if (e.getCurrentItem() == null) return;
                if (e.getCurrentItem().getItemMeta() == null) return;
               
                if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("survival")){
                    Player p = (Player) e.getWhoClicked();
                        ByteArrayOutputStream b = new ByteArrayOutputStream();
                        DataOutputStream out = new DataOutputStream(b);
                        out.writeUTF("Connect");
                        out.writeUTF("survival");
                        p.sendPluginMessage(this, "BungeeCord", b.toByteArray());
                }
               
                if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("pizza")){
                    Player p = (Player) e.getWhoClicked();
                        ByteArrayOutputStream b = new ByteArrayOutputStream();
                        DataOutputStream out = new DataOutputStream(b);
                        out.writeUTF("Connect");
                        out.writeUTF("pizzaspleef");
                        p.sendPluginMessage(this, "BungeeCord", b.toByteArray());
                }
               
                /*if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Ghost")) {
                        e.setCancelled(true);
                        e.getWhoClicked().addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 30, 2));
                        getServer().dispatchCommand(((Player) e.getWhoClicked()), "ghost-me");
                        e.getWhoClicked().closeInventory();
                }*/
    }
       
        @EventHandler
                public static void onPlayerJoin(PlayerJoinEvent e){
                   
                Player p = e.getPlayer();
                if ((itemonjoin) && (!e.getPlayer().getInventory().contains(item))){
                    ItemStack Item = new ItemStack(item);
                        ItemMeta meta = Item.getItemMeta();
                            meta.setDisplayName(itemname);
                                Object lores = new ArrayList();
                                    ((List)lores).add(itemlore);
                                        meta.setLore((List)lores);
                                            Item.setItemMeta(meta);
                                                e.getPlayer().getInventory().addItem(new ItemStack[] { Item });
    }
}
                @EventHandler
                public void onPlayerInteract(PlayerInteractEvent e) {
                    Player p = e.getPlayer();
                   if ((e.getAction() == Action.RIGHT_CLICK_AIR) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
                           if (e.getItem().getTypeId() == item) {
                               if (p.hasPermission("mpo.use")){
                                   p.openInventory(inv);
                }
            }
        }
    }
       /*public int getPlayerCount() {
        try {
            out.writeUTF("PlayerCount");
            out.writeUTF("ALL");
            Player p = Bukkit.getOnlinePlayers()[0];
            p.sendPluginMessage(this, "BungeeCord", b.toByteArray());
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        reset();
        return playerCount;
    }*/
 
    public void reset() {
        b.reset();
    }

    public int getPlayerCount(String serverName) {
        try {
            out.writeUTF("PlayerCount");
            out.writeUTF(serverName);
            Player p = Bukkit.getOnlinePlayers()[0];
            p.sendPluginMessage(this, "BungeeCord", b.toByteArray());
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        return playerCount;
    }

    @SuppressWarnings("static-access")
    public void onPluginMessageReceived(String channel, Player player,
            byte[] message) {
        if (!channel.equals("BungeeCord")) {
            return;
        }

        DataInputStream in = new DataInputStream(new ByteArrayInputStream(
                message));
     
        try {
            String subchannel = in.readUTF();
            if (subchannel.equals("PlayerCount")) {
                this.serverName = in.readUTF();
                Bukkit.broadcastMessage(this.serverName);
                this.playerCount = in.readInt();
                Bukkit.broadcastMessage(this.playerCount + "");
            }
        } catch (IOException e) {
            System.out.println("Something wrent wrong at the onPluginMessageReceiver at ServerSelector.java!");
            e.printStackTrace();
        }
    }



Linkback: https://minecraftmin.net/index.php?topic=3751.0
« Última modificación: Julio 26, 2014, 07:11:06 pm por ChikenGamer »


Respuesta #1 Julio 26, 2014, 01:55:29 pm

concuncan


  • *

  • Desconectado

  • *

    • *
    • *
    • *
  • Mensaje personal
    MinecraftMin, el mejor foro Español!
  • Actividad

  • 0%
  • Logros

Más información




Respuesta #2 Julio 26, 2014, 06:26:13 pm

markLDM




  • Desconectado

  • *

    • *
    • *
    • *
  • Mensaje personal
    Moderador del apartado servidores
  • Actividad

  • 0%
  • Logros

Más información

No soy un profesional de plugins pero bungeecord es un plugin no?... y yo no veo ninguna clase de dependencia
Te he ayudado? Comenta!


Respuesta #3 Julio 26, 2014, 07:08:18 pm

ChikenGamer




  • Desconectado

  • *

    • *
    • *
    • *
  • Mensaje personal
    Joven Developer, constructor y Dj
  • Actividad

  • 0%
  • Logros

Más información

¿Que error te da?
Ninguno simplemete no me da los jugadores
No soy un profesional de plugins pero bungeecord es un plugin no?... y yo no veo ninguna clase de dependencia

Si es un plugin, dependencia de que?

Nota: He actualizado el codigo



Respuesta #4 Julio 26, 2014, 08:34:58 pm

Jesus997




  • Desconectado

  • *

    • *
    • *
    • *
  • Mensaje personal
    BukkitMX - Tu comunidad Bukkit en español!
  • Actividad

  • 0%
  • Logros

Más información

No soy un profesional de plugins pero bungeecord es un plugin no?... y yo no veo ninguna clase de dependencia

Es un plugin y a la vez una libreria, al igual que muchos plugins comunes (vault, iDisguise, Magic, etc.). Saludos!
Desarrollador Bukkit || Mis Plugins: http://dev.bukkit.org/profiles/jesus997/ | Mi GitHub: https://github.com/jesus997
BukkitMX - Tu comunidad de programadores en español!


Respuesta #5 Julio 27, 2014, 01:05:24 pm

concuncan


  • *

  • Desconectado

  • *

    • *
    • *
    • *
  • Mensaje personal
    MinecraftMin, el mejor foro Español!
  • Actividad

  • 0%
  • Logros

Más información

BungeeCord no es un plugin, es un proxy con la función de unir varios servidores de Minecraft. En cuanto al tema, el method que has usado está mal hecho. El dato de los usuarios online se coje con in.readUTF(). Para ello, deberías cojerlo desde el method PluginMessageRecieved que tienes que implementar al poner PluginMessageListener como listener.



Respuesta #6 Julio 28, 2014, 12:23:32 am

ChikenGamer




  • Desconectado

  • *

    • *
    • *
    • *
  • Mensaje personal
    Joven Developer, constructor y Dj
  • Actividad

  • 0%
  • Logros

Más información

BungeeCord no es un plugin, es un proxy con la función de unir varios servidores de Minecraft. En cuanto al tema, el method que has usado está mal hecho. El dato de los usuarios online se coje con in.readUTF(). Para ello, deberías cojerlo desde el method PluginMessageRecieved que tienes que implementar al poner PluginMessageListener como listener.

Me lo puedes traducir al español? Por favor :3, como dije, no soy experto en Bungee apenas y lo conosco




Share via delicious Share via digg Share via facebook Share via furl Share via linkedin Share via myspace Share via reddit Share via stumble Share via technorati Share via twitter

question
Ayuda con el uso de la API!

Iniciado por ElCreeperHD

0 Respuestas
1780 Vistas
Último mensaje Abril 24, 2015, 07:18:12 pm
por ElCreeperHD
xx
Pls, ayuda

Iniciado por iLuisORO_

0 Respuestas
2253 Vistas
Último mensaje Febrero 26, 2016, 03:05:26 pm
por iLuisORO_
xx
Necesito Programador de plugins para servidor de Minecraft 1.8

Iniciado por SirWisp97

0 Respuestas
2418 Vistas
Último mensaje Diciembre 08, 2015, 05:06:38 pm
por SirWisp97
xx
Necesito ayuda con 2 cosas...

Iniciado por aJorgeMC

3 Respuestas
2798 Vistas
Último mensaje Octubre 08, 2016, 08:06:49 am
por Eliaseeg