update sign every second

Discussion in 'Spigot Plugin Development' started by james.boy123, Mar 24, 2015.

  1. I want to update a sign every secon. this is my code:

    Code (Text):
    @EventHandler
        public void onSign(SignChangeEvent e) {

            String one = e.getLine(1);
            String two = e.getLine(2);
           
            if(one.equalsIgnoreCase("[Stadtherr]")){
                   
                String n = fileConfig.getString(two);
                   
                e.setLine(0, "§nSTADTHERR:");
                e.setLine(1, "§2"+two);
                if(Bukkit.getPlayer(two) != null){
                    e.setLine(2, "§a"+ "Online");
                } else {
                    e.setLine(2, "§c" + n);
                }
                    e.setLine(3, "§n==============");
            }
           
            if(one.equalsIgnoreCase("[2.Stadtherr]")){
               
                String n = fileConfig.getString(two);
                   
                e.setLine(0, "§n2. STADTHERR:");
                e.setLine(1, "§2"+two);
                if(Bukkit.getPlayer(two) != null){
                    e.setLine(2, "§a" + "Online");
                } else {
                    e.setLine(2, "§c" + n);
                }
                    e.setLine(3, "§n=============");
            }
           
            if(one.equalsIgnoreCase("[2.Stadtherr]")){
               
                String n = fileConfig.getString(two);
                   
                e.setLine(0, "§n2. STADTHERR:");
                e.setLine(1, "§2"+two);
                if(Bukkit.getPlayer(two) != null){
                    e.setLine(2, "§a" + "Online");
                } else {
                    e.setLine(2, "§c" + n);
                }
                    e.setLine(3, "§n=============");
            }
          }
    It changes the text, but doesn't update the sign if the player is offline...

    Dave
     
  2. Make a runnable!
     
  3. If you just want to update the sign, as one of the players might have logged in/out use the suitable listeners instead of checking constantly every second.