Updating signs on logout?

Discussion in 'Plugin Development' started by SirLittlemonster7, Jan 31, 2013.

Thread Status:
Not open for further replies.
  1. How would I get a sign and update it on a PlayerQuitEvent?

    Code:
        @EventHandler
        public void onPlayerLeave(final PlayerQuitEvent event) {
            TDTeam.remove(event.getPlayer().getName());
            final World world = event.getPlayer().getWorld();
            final Location loc = new Location(world, 538, 7, 265);
            event.getPlayer().teleport(loc);
        }
     
        @EventHandler
        public void onPlayerLogin(final PlayerJoinEvent event) {
            final Player player = event.getPlayer();
            final World world = event.getPlayer().getWorld();
            final Location loc = new Location(world, 538, 7, 265);
            player.teleport(loc);
            TDTeam.remove(player.getName());
        }    
    Because that wont update the Total players sign when a person logs out. Please help!
     
  2. Offline

    Jack1312

    Do you have the block location of the sign you want to update for the player stored anywhere?
     
  3. No, I forget how to save block locations.
     
  4. Offline

    Jack1312

    Do you need to update the signs placed by specifically a player, or what? Please explain.
     
  5. Well, what I got here is a game mode, and when you click on it it teleports you and adds you to a (started players) list. On the sign it updates when a player right clicks and shows how many players are in the game. like: 1/40 players. When a person logs out I want them to be removed from the List and it needs to update the sign saying that theres 1 less player. The way I have counted is counting the size of the list:

    Code:
                    TDTeam.add(player.getName());
                    if(TDTeam.size() < 41){
                    sign.setLine(3, TDTeam.size() + "/40");
                    sign.update(true);
                    sign.update();
    Which should work, but when someone logs out it does not update the sign, so it gets confusing to the players.
     
  6. Offline

    Jack1312

    So your sign simply says how many players you have online?
     
  7. Not really, it says how many players are playing that certain "game mode" you see its like a game hub server :p I have many different game modes and people need to know how many people are playing.
     
  8. Offline

    Jack1312

    How about you add a variable into your plugin:

    public Block gameSign = null;

    Make sure you set the gameSign, when your plugin loads and we can work from there?
     
  9. Just asking, why would I need that?
     
  10. Offline

    Jack1312

    So we can store the location of the sign for your gamemode?
     
  11. Yeah sure ok.

    final or nothing is the thing thats only allowed though.
    so it would be:
    final Block gameSign = null;
    or
    Block gameSign = null;

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  12. Offline

    Rprrr

    Ehm... before you can modify a sign, you need to know where it is.
    The plugin can't just magically do what you want it to do and find the sign you're looking for; you need to tell it where it is. Make sure you've saved that sign location somewhere, then it's not that hard to do.
     
  13. Offline

    s0undx

    If you stored the Sign Block as a Block then you can use it like this:
    Code:
    Block gameSign;
     
    Sign s = gameSign.getState();
    s.setLine(0, "...");
    s.update();
    
    Thats the proper way to update.
    If you hook your events right and update the signs like that it should work.

    (And btw storing it as a Location seems better, (then you can use the location.getBlock() ))
     
Thread Status:
Not open for further replies.

Share This Page