Sign plugin help

Discussion in 'Plugin Development' started by nico123o, Jan 25, 2015.

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

    nico123o

    So, I am making a plugin for a server and I have seen how to do this before but I cant find it again, basically, I need to globally find signs that have [deathmessage] on the first line and if they have that on the sign, it will update the other lines of the sign.
     
  2. @nico123o If the signs can be retrieved from the SignChangeEvent, then use that.
    Otherwise:
    Get all of the loaded chunks in a world with world.getLoadedChunks()
    Iterate through the chunks and find the loaded tile entities with chunk.getTileEntities()
    Check if the BlockState (From the TileEntities) is an instanceof Sign
    If it is, cast it to sign and check if the first line is [deathmessage], then you can update the rest of the sign.

    Of course, this only works if that chunk is loaded or not.
     
  3. The besy way is when a player place a sign check if the first line is "[deathmessage]" .
     
  4. Offline

    CrystallFTW

    @nico123o For the sign use SignChangeEvent like this:
    Code:
        @EventHandler
        public void onSignChange(SignChangeEvent e) {
          
            if (e.getLines().length > 0 && e.getLine(0).equalsIgnoreCase("[deathmessage]")){
    
            e.setLine(0,"1stline");
            e.setLine(1,"2nd line");
            e.setLine(2,"3rd line");
            e.setLine(3,"4th line");
            }
          
        }
     
  5. Offline

    nico123o

    Was just testing the plugin, uploaded it to multicraft and got the error 'org.bukkit.plugin.InvalidPluginException: java.lang.UnsupportedClassVersionError: me/nico123o/PvpStats/PvpStats : Unsupported major.minor version 52.0' anyone know how to fix it?
     
  6. Offline

    CraftCreeper6

    @nico123o
    Your servers Java version is different to your IDE/A's.
     
  7. Offline

    nico123o

    I fixed the error, Currently I have:
    Code:
    package me.nico123o.DeathSignsTest;
    
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.HandlerList;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class DeathSignsTest extends JavaPlugin {
    
       
          public void onEnable()
          {
            System.out.println("[DeathSigns] Enabling");
           
            }
         
          public void onDisable()
          {
            System.out.println("[DeathSigns] Disabling");
           
            HandlerList.unregisterAll();
          }
       
       
           @EventHandler
            public void onSignChange(SignChangeEvent e) {
            
                if (e.getLines().length > 0 && e.getLine(0).equalsIgnoreCase("[deathsigns]")){
        
                e.setLine(0,"[deathsigns]");
                e.setLine(1,"2nd line");
                e.setLine(2,"3rd line");
                e.setLine(3,"4th line");
                }
            
            }
       
       
       
    }
    
    and I need to it update on a player death

    Can anyone tell me how to update the sign on a players death, I know how to get the killers name and stuff like that, I just need to know how to update a sign other than when you place it down.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  8. Offline

    InfamousSheep

    You need to save the location of the sign.
    Then, use PlayerDeathEvent and get the killers name using event.getKiller().getName();
    With that information, get the block of the sign and cast it to a Sign object. Now you can use sign.setLine() to update the information.
     
Thread Status:
Not open for further replies.

Share This Page