Solved Players online Sign

Discussion in 'Plugin Development' started by malikdbuseck, Dec 28, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    malikdbuseck

    Hello,
    Im currently trying to code a plugin that when a sign says [MOL] on line zero it will add the "1/20 Online" as in players. I was wondering how you would call that into a sign?

    setLine(1, "");

    ?? What goes in the " "
     
  2. Offline

    teej107

     
  3. Offline

    malikdbuseck

    That wont update based on who is in the server
     
  4. Offline

    mythbusterma

  5. @mythbustermaj Or on PlayerJoinEvent and PlayerQuitEvent.
     
    Konato_K and WarmakerT like this.
  6. Offline

    malikdbuseck

    But how do i get it to be the current players online.
     
  7. Offline

    mythbusterma

  8. @malikdbuseck Find a array of online players and get its size. Not going to spoonfeed you.
     
  9. Offline

    malikdbuseck

    lol that is what I needed to know. Jeeze, if you are going to make a big deal about helping someone dont reply on a post asking for help.

    JS
     
    WarmakerT likes this.
  10. @malikdbuseck Not sure where you got big deal from, nether the less I will give you another hint Bukkit#
     
    malikdbuseck likes this.
  11. Offline

    malikdbuseck

    " Not going to spoonfeed you." seems a bit edgey..haha but never the less Ill give this a try when I wake up
     
  12. Offline

    1Rogue

    Konato_K, malikdbuseck and bwfcwalshy like this.
  13. Offline

    malikdbuseck

    GOT IT! May not be proper but this is it. Now I just have to make it so it updates whenever I players clicks it

    Code:
    package me.malikdbuseck.Listeners;
    
    import org.bukkit.Bukkit;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockState;
    import org.bukkit.block.Sign;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    
    public class SignHit implements Listener {
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event)
        {
            if(event.getAction() == Action.RIGHT_CLICK_BLOCK)
            {
                Block i = event.getClickedBlock();
                if(i.getState() instanceof Sign)
                {
                    BlockState stateBlock = i.getState();
                    Sign sign = (Sign) stateBlock;
                    if(sign.getLine(0).equalsIgnoreCase("")){
                        sign.setLine(0, "§4MineofLegends");
                        if(sign.getLine(0).equalsIgnoreCase("§4MineofLegends")){
                        sign.setLine(1,Bukkit.getOnlinePlayers().length + "§f/" + "§0" + Bukkit.getMaxPlayers() + " §aOnline");
                        }
                        sign.update();
    
            }
    
        }
    }
        }
    }
    
    

    EDIT:

    Just move the If statment down
    Code:
                    BlockState stateBlock = i.getState();
                    Sign sign = (Sign) stateBlock;
                    if(sign.getLine(0).equalsIgnoreCase("")){
                        sign.setLine(0, "§4MineofLegends");
                    }
                        if(sign.getLine(0).equalsIgnoreCase("§4MineofLegends")){
                        sign.setLine(1,Bukkit.getOnlinePlayers().length + "§f/" + "§0" + Bukkit.getMaxPlayers() + " §aOnline");
                        }
                        sign.update();
    
            }
    
        }
    }
        }
    @1Rogue
    Actually Mind telling me how I can update the sign on the PlayerJoinEvent. I cant quite seem to get it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 31, 2016
  14. @malikdbuseck On player join, get the sign location. Cast the block to sign and reset the players online or use a method to update it.
     
  15. Offline

    1Rogue

    Keep a reference to the sign/block/location (whatever you prefer), and update it within that method. You could even just make a collection of signs to update, and then have an "update" method which you just call from those events.
     
  16. Offline

    malikdbuseck

    Okay I sort of know what you mean but not quite. Still pretty new to coding if you cant tell. Ill try and trouble shoot tmrw morning but If I cant I will reply back
     
  17. @malikdbuseck Try it then you can always come back if you are stuck or have errors, just provide the code that you are stuck on and/or have errors on.
     
    malikdbuseck likes this.
  18. Offline

    malikdbuseck

    Yea I dont know how to either call back to that sign, or do it within the method
     
  19. Offline

    HeyShibby

    On both playerjoinevent and playerquitevent search for all signs in the world which have the first line as "MineofLegends" then continue with the changing of the number of players online, hope this helps a little!
     
    Last edited: Dec 29, 2014
  20. Offline

    malikdbuseck

    but how do i call for the signs?
     
Thread Status:
Not open for further replies.

Share This Page