Solved Getting the players on a other server

Discussion in 'Spigot Plugin Development' started by Thomas_muur, May 29, 2016.

Thread Status:
Not open for further replies.
  1. Hello,

    I am making a Server Selector, this is my code:
    Code (Text):

    package me.thomasmuur.selector;

    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;

    public class Selector extends JavaPlugin implements Listener {
        public void openSelector(Player p)
           Inventory inv = Bukkit.createInventory(null, 54, "§c§lStereo§f§lSelector");
                  ItemStack glass1 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14);
                  ItemStack glass2 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)0);
                  ItemStack glass3 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14);
                  ItemStack glass4 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)0);
                  ItemStack glass5 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14);
                  ItemStack glass6 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)0);
                  ItemStack glass7 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14);
                  ItemStack glass8 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)0);
                  ItemStack glass9 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14);
                  ItemStack glass10 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)5);
                  ItemStack glass11 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)5);
                  ItemStack glass12 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)5);
                  ItemStack glass13 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)5);
                  ItemStack glass14 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)5);
                  ItemStack glass15 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)5);
                  ItemStack glass16 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)5);
                  ItemStack glass17 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)5);
                  ItemStack glass18 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)5);
                  ItemStack glass19 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)5);
                    ItemMeta glass1m = glass1.getItemMeta();
                        ItemMeta glass2m = glass2.getItemMeta();
                            ItemMeta glass3m = glass3.getItemMeta();
                                ItemMeta glass4m = glass4.getItemMeta();
                                    ItemMeta glass5m = glass5.getItemMeta();
                                        ItemMeta glass6m = glass6.getItemMeta();
                                            ItemMeta glass7m = glass7.getItemMeta();
                                                ItemMeta glass8m = glass8.getItemMeta();
                                                    ItemMeta glass9m = glass9.getItemMeta();
                                                        ItemMeta glass10m = glass10.getItemMeta();
                                                            ItemMeta glass11m = glass11.getItemMeta();
                                                                ItemMeta glass12m = glass12.getItemMeta();
                                                                    ItemMeta glass13m = glass13.getItemMeta();
                                                                        ItemMeta glass14m = glass14.getItemMeta();
                                                                            ItemMeta glass15m = glass15.getItemMeta();
                                                                                ItemMeta glass16m = glass16.getItemMeta();
                                                                                    ItemMeta glass17m = glass17.getItemMeta();
                                                                                        ItemMeta glass18m = glass18.getItemMeta();
                                                                                            ItemMeta glass19m = glass19.getItemMeta();
                            // ORANGE GLASS
                  ItemStack o = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)1);

                   ItemMeta om = o.getItemMeta();
                // IRON BARS
                ItemStack bar = new ItemStack(Material.IRON_FENCE, 1, (short)0);
                 ItemMeta barm = bar.getItemMeta();
               // GLASS
               ItemStack gglass = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)5);
               ItemStack rglass = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14);
               ItemStack wglass = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)0);
               ItemMeta gm = gglass.getItemMeta();
                   ItemMeta rm = rglass.getItemMeta();
                       ItemMeta wm = wglass.getItemMeta();

                         // items
                           ItemStack creative = new ItemStack(Material.WORKBENCH, 1, (short)0);
                           ItemStack kitpvp = new ItemStack(Material.DIAMOND_SWORD, 1, (short)0);
                           ItemStack survival = new ItemStack(Material.GOLD_SPADE, 1, (short)0);
                           ItemStack factions = new ItemStack(Material.TNT, 1, (short)0);
                           ItemStack bouwserver = new ItemStack(Material.COMPASS, 1, (short)0);

                           ItemMeta creativem = creative.getItemMeta();
                             setLore("§fOn §ccreative §fthere are §cplayercount §fplayers online", creative);
                               ItemMeta kitpvpm = kitpvp.getItemMeta();
                                kitpvpm.setDisplayName("§6§lKitPvP §8- §4§lBinnenkort");
                                   ItemMeta survivalm = survival.getItemMeta();
                                       ItemMeta factionsm = factions.getItemMeta();
                                           ItemMeta bouwserverm = bouwserver.getItemMeta();
                // SET ITEMS                                                                            
                 inv.setItem(0, rglass);
                 inv.setItem(1, wglass);
                 inv.setItem(2, rglass);
                 inv.setItem(3, wglass);
                 inv.setItem(4, rglass);
                 inv.setItem(5, wglass);
                 inv.setItem(6, rglass);
                 inv.setItem(7, wglass);
                 inv.setItem(8, rglass);
                 inv.setItem(9, gglass);
                 inv.setItem(10, gglass);
                 inv.setItem(11, gglass);
                 inv.setItem(12, gglass);
                 inv.setItem(13, gglass);
                 inv.setItem(14, gglass);
                 inv.setItem(15, gglass);
                 inv.setItem(16, gglass);
                 inv.setItem(17, gglass);
                 inv.setItem(18, o);
                 inv.setItem(19, bar);
                 inv.setItem(20, o);
                 inv.setItem(21, creative);
                 inv.setItem(22, o);
                 inv.setItem(23, kitpvp);
                 inv.setItem(24, o);
                 inv.setItem(25, bar);
                 inv.setItem(26, o);
                 inv.setItem(27, o);
                 inv.setItem(28, bar);
                 inv.setItem(29, o);
                 inv.setItem(30, survival);
                 inv.setItem(31, o);
                 inv.setItem(32, factions);
                 inv.setItem(33, o);
                 inv.setItem(34, bar);
                 inv.setItem(35, o);

                 inv.setItem(36, gglass);
                 inv.setItem(37, gglass);
                 inv.setItem(38, gglass);
                 inv.setItem(39, gglass);
                 inv.setItem(40, gglass);
                 inv.setItem(41, gglass);
                 inv.setItem(42, gglass);
                 inv.setItem(43, gglass);
                 inv.setItem(44, gglass);
                 inv.setItem(45, rglass);
                 inv.setItem(46, wglass);
                 inv.setItem(47, rglass);
                 inv.setItem(48, wglass);
                 inv.setItem(49, bouwserver);
                 inv.setItem(50, wglass);
                 inv.setItem(51, rglass);
                 inv.setItem(52, wglass);
                 inv.setItem(53, rglass);

        public void onClick(InventoryClickEvent e) {
        //    Player p = (Player) e.getWhoClicked();
            if (e.getClickedInventory().getName().equalsIgnoreCase("§c§lStereo§f§lSelector")) {
        public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("selector")) {
                Player p = (Player) sender;
            return true;
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        public void setLore(String lore, ItemStack item) {
            ItemMeta i = item.getItemMeta();
            ArrayList<String> Lore = new ArrayList<String>();

    But as you see here:
    Code (Text):
    setLore("§fOn §ccreative §fthere are §cplayercount §fplayers online", creative);
    I want to have in the lore how many players are online at that specific server, and replacing "playercount"
    with the playercount, so I found this:
    But can anyone explain to me how I can get that Playercount in my lore?

  2. Use Sockets
  3. Try something like this:
    Where you replace the "playersOnline" with the appropriate integer.
    Code (Text):

    setLore(Arrays.asList("§fOn §ccreative §fthere are §c" + playersOnline + " §fplayers online"));
  4. Yeah I know that, but I want to know how I can get the player count
  5. that would be spoon feeding, all the examples and code you need are on that page. its pretty much copy and paste
  6. Sorry, misunderstood your question.
    • Like Like x 1
  7. I got this now:
    Code (Text):
                              ByteArrayDataOutput out = ByteStreams.newDataOutput();
                              ByteArrayDataInput in = ByteStreams.newDataInput(message);
                              String server = in.readUTF(); // Name of server, as given in the arguments
                              int playercount = in.readInt();
                              setLore("§fOn §ccreative §fthere are §c" + playercount + " §fplayers online", creative);
    But at this line : ByteArrayDataInput in = ByteStreams.newDataInput(message);
    it gives an error at the variable "message" what I understand, but for what do I need to replace that variable?
    Or isn't this right what I am doing now?
  8. I tried a lot of things like this:

    Code (Text):
        public void setLore(ItemStack item, String server) {
            ItemMeta i = item.getItemMeta();
            ArrayList<String> Lore = new ArrayList<String>();
              ByteArrayDataOutput out = ByteStreams.newDataOutput();
            Lore.add("§fOp §c" + server + "§f zijn §c" + out.toByteArray() + "§f online");
    But then it gives a weird code instead of the playercount, can someone please help me?
  9. @Thomas_muur you sir, are one of the lucky 90% of the world who don't know how to read ;D. On the top of that page is full explanation
  10. You sir, can't read to hehe :) caus I already said several times that I want to set the player count in a Lore, and don't know how.
  11. Well, yes. That's kind of a given when you create 19 ItemStacks when you need none but could've used two, use hard coded section signs instead of the chat color enum, blind cast to player, don't use the suggested @Override annotation, and don't save any of the reused ItemStacks, generating them each time a player wants to select a server.

    Get the response from the Bungeed server, and concatenate it to your string. There's a full explanation on what everything does, like @megamichiel said above, on the wiki page that you grabbed the code from.
  12. could you please give me an example?
  13. @Thomas_muur
    1. Learn English
    2. Learn Java (for real)
    3. Get to know bukkit's API
    4. Solve your problem
  14. hehe funny.. not
  15. @Thomas_muur it's not funny when @Msrules123 tells you what to do, and then you respond with "Example please?", like you said multiple times on this thread
  16. So I guess people aren't allowed to ask for small examples on these forums? Either a 'Yes' or a 'No' would be suffice, but putting someone down when they ask for help is pretty sad. Like you said, his first language isn't English. He may understand code better than he does English. So when someone posts a link and you say 'He told you what to do', it's not exactly helping. This forum is for development questions and learning, so when someone asks for an example it's up to the forums if they want to provide one or not. If they do then that's awesome, if they don't then that's cool too. But to put someone down for not having the comprehension of English and the Bukkit API that you do, is pretty sad. As far as i can see you haven't even tried to help, you have only made negative comments towards OP.
    • Friendly Friendly x 1
  17. @Rokl The learn English part was because OP didn't properly read Msrules123's post. I don't know what the cause is, whether they're too lazy or aren't that good at navigating on a page, they did get a full explanation of what they had to do. I might not have been that nice, but there are so many dependant people coming on here asking easy questions way too many times, making this forum start to become more of a "I want spoonfeeding so I'm gonna go there" place, instead of seriously difficult questions.
Thread Status:
Not open for further replies.