(UnSolved) Sign Event

Discussion in 'Plugin Development' started by badboystee, Feb 21, 2014.

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

    badboystee

    So I've come across a problem with my SignEvent, I want to make a sign that I can put at Spawn where it will say

    Welcome
    {Name}
    To
    {ServerName}

    So I made a SignChangeEvent were if I put on the Sign [Welcome] it will come up with the follow

    Welcome
    {Name}
    To
    {ServerName}

    And the {Name} shows the IGN. Now if there is an easier way to do this please share :)

    Is on the e.setLine(1, ChatColor.BLUE + ); I need to add the {Name} Part :)

    Code:
       
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
       
        @EventHandler
        public void onSignChange(SignChangeEvent e) {
            Player p = (Player) e.getPlayer();
            if (e.getLine(0).equalsIgnoreCase("[Welcome]")) {
                e.setLine(0, ChatColor.AQUA + "Welcome");
                e.setLine(1, ChatColor.BLUE + );
                e.setLine(2, ChatColor.AQUA + "To");
                e.setLine(3, ChatColor.RED + "Prison" + ChatColor.YELLOW + "Soul");
            }
        }
     
    }
    
    Take the code if you like :p

    Bump* Anyone Know?

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

    Drew1080

    badboystee
    Use this to set the second line of the sign to the player's name
    Code:java
    1. e.setLine(1, ChatColor.BLUE + p.getName());
     
  3. Offline

    badboystee


    Thanks :) Just when I did that I did
    p.getName().getDisplayName(); which didn't work :p


    Ermm... I just logged in on my Alt Account and it still says my main account name on the sign for some reason it doesn't seem to change on the sign for other people names?

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

    Commander9292

    badboystee
    You need to update the sign on a PlayJoinEvent. I can't give any code samples now though as I am on my phone.
     
  5. Offline

    badboystee


    Yea already done but
    Thank you :D


    For some reason my code doesn't update could you give an example of what would happen?

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

    badboystee

    How would I update the Sign on SignChangeEvent when the Player joins through the PlayerJoinEvent?
     
  7. Offline

    alex123099

    badboystee
    1. Have someone create a sign
    2. Save that sign location somewhere
    3. On player join event get the block at the location you saved
    4. Check whether that block is a sign
    5. if it is, cast the blockstate to a sign object
    6. edit the sign as you like. Don't forget to update it.
     
    badboystee likes this.
  8. Offline

    badboystee


    Check this code

    CODE
    Code:java
    1.  
    2. @EventHandler
    3. public void onSignChange(SignChangeEvent e) {
    4. Player p = (Player) e.getPlayer();
    5. if (e.getLine(0).equalsIgnoreCase("[Welcome]")) {
    6. e.setLine(0, ChatColor.AQUA + "Welcome To");
    7. e.setLine(1, ChatColor.RED + "Prison" + ChatColor.YELLOW + "Soul");
    8. e.setLine(2, ChatColor.BLUE + p.getName());
    9. e.setLine(3, ChatColor.BOLD + "===============");
    10. }
    11. }
    12.  
    13. @EventHandler
    14. public void onPlayerJoin(PlayerJoinEvent e){
    15. Player p = (Player) e.getPlayer();
    16. if(e.getJoinMessage().)
    17. }
    18.  
    19. }
    20.  


    I need to make it so on the sign it shows their name
     
  9. Offline

    alex123099

    badboystee
    The sign change event, the player that you get there is the player that is creating or modifying the sign. So like I said earlier, in your onPlayerJoin event, you will need to create a sign instance from the location of the sign and modify the lines there.
     
  10. Offline

    badboystee


    Ohh okay I will do that :D Thanks for your help and support
     
  11. Offline

    alex123099

    badboystee
    This is how I do it for example:
    Code:
    Location signLoc = questConfig.getLocation(quest + ".Sign.Location");
                if(signLoc != null)
                {
                    Block b = signLoc.getBlock();
                    if(Tools.isBlockASign(b))
                    {
                        Sign sign = (Sign)b.getState();
                        QuestType type = QuestType.valueOf(questConfig.getString(quest + ".Type"));
                        String mission = questConfig.getString(quest + ".Mission");
                        String reward = questConfig.getString(quest + ".Reward");
                       
                        new Quest(sign, type, mission, reward);
                    }
                }
    After you get the sign object, you can modify the lines easily.
     
  12. Offline

    badboystee

    Arr I see I find things way easier when examples am there cus then u never forget thanks alot :D
     
  13. Offline

    badboysteee98

    Changed account also still Unsolved need help getting the PlayerJoinEvent and importing it into the SignChangeEvent and setting the Line on the SignChangeEvent to the Players name and not the player that created the sign



    Code:java
    1.  
    2.  
    3. public void onEnable() {
    4.  
    5. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    6.  
    7. }
    8.  
    9.  
    10.  
    11. @EventHandler
    12.  
    13. public void onPlayerJoin(PlayerJoinEvent e) {
    14.  
    15. // What Would I Do Here?
    16.  
    17. }
    18.  
    19.  
    20.  
    21. @EventHandler
    22.  
    23. public void onSignChange(SignChangeEvent e) {
    24.  
    25. if(e.getLine(0).equalsIgnoreCase("[Welcome]")) {
    26.  
    27. e.setLine(0, "Welcome To");
    28.  
    29. e.setLine(1, "PrisonSoul");
    30.  
    31. e.setLine(2, e.getPlayer().getName());
    32.  
    33. }
    34.  
    35. }
    36.  
    37.  
    38.  
    39. }

     
  14. Offline

    qhenckel

    So there are a couple things that you are getting confused here:
    1.) Create and save the sign.
    2.) When a player joins update the sign.
    Note: this is mock-up code it will be full of syntax errors. but you get the point.
    Code:java
    1. @EventHandler
    2. public void signcreateevent(signChangeEvent e){
    3. if(e.getLine1 == "[welcome]") {
    4. e.getLocation.....
    5. //save the location
    6. }
    7. }
    8.  
    9. @EventHandler
    10. public void Playerjoin(playerJoinEvent e){
    11. Block block = world.getBlock(location); //This is loading the sign
    12. BlockState blockstate = block.getstate(); //this gets the "state"
    13. if(blockstate instanceof Sign){
    14. Sign sign = (Sign) blockstate; //casting the block to a sign
    15. sign.setLine2(e.getName());
    16. sign.update(true);
    17. } else {
    18. //throw an error the sign isn't there
    19. }
    20. }
     
  15. Offline

    badboysteee98

    UPDATE: I haven't bumped this for ages

    But I have the Sign Updated at it's location and it still showing the person name who put down the sign

    Code:java
    1. public class Welcome extends JavaPlugin implements Listener {
    2.  
    3. public static Location Location;
    4.  
    5. public void onEnable() {
    6. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    7. }
    8.  
    9. @EventHandler
    10. public void onPlayerJoin(PlayerJoinEvent e) {
    11.  
    12. Location loc = e.getPlayer().getLocation();
    13. Block b = loc.getBlock();
    14.  
    15. if(b instanceof Sign) {
    16. Sign s = (Sign) b.getState();
    17. s.setLine(2, e.getPlayer().getName());
    18. s.update(true);
    19. }
    20.  
    21.  
    22. }
    23.  
    24. @EventHandler
    25. public void onSignChangeEvent(SignChangeEvent e) {
    26.  
    27. Player p = (Player) e.getPlayer();
    28.  
    29. if(e.getLine(0).equalsIgnoreCase("[Welcome]")) {
    30. e.setLine(0, "Welcome To");
    31. e.setLine(1, "Server");
    32. e.setLine(2, ChatColor.RED + p.getName());
    33. }
    34. }
    35.  
    36. }
     
Thread Status:
Not open for further replies.

Share This Page