Solved Changing text of a sign

Discussion in 'Plugin Development' started by cdnyassuo34, Aug 15, 2019.

  1. Offline

    cdnyassuo34

    Hi, I am creating a plugin with placeholders and I would like to know if it's possible to replace a sign content
    for exemple, if the sign contains [snow_test] it will replace it by 1234
    and if yes how ?

    I tryied with this

    Code:
    public void ReadSigns(SignChangeEvent e)
        {
            String[] content = e.getLines();
          
            String content1 = content[0];
            String content2 = content[1];
            String content3 = content[2];
            String content4 = content[3];
            Player p = e.getPlayer();
            String currentc = p.getLocation().getChunk().getX() + "," + p.getLocation().getChunk().getZ();
            String cc = getChunkCredit(p);
            String ggn = getGroupName(p.getName());
            content1.replace("%%snow_gco%%", getOwner(p.getName()));
            content1.replace("%%snow_test%%", "1234");
            content1.replace("%%snow_curc%%", currentc);
            content1.replace("%%snow_ggn%%", ggn);
            content1.replace("%%snow_cc%%", cc);
          
            content2.replace("%%snow_gco%%", getOwner(p.getName()));
            content2.replace("%%snow_test%%", "1234");
            content2.replace("%%snow_curc%%", currentc);
            content2.replace("%%snow_ggn%%", ggn);
            content2.replace("%%snow_cc%%", cc);
          
            content3.replace("%%snow_gco%%", getOwner(p.getName()));
            content3.replace("%%snow_test%%", "1234");
            content3.replace("%%snow_curc%%", currentc);
            content3.replace("%%snow_ggn%%", ggn);
            content3.replace("%%snow_cc%%", cc);
          
            content4.replace("%%snow_gco%%", getOwner(p.getName()));
            content4.replace("%%snow_test%%", "1234");
            content4.replace("%%snow_curc%%", currentc);
            content4.replace("%%snow_ggn%%", ggn);
            content4.replace("%%snow_cc%%", cc);
            e.setLine(0, content1);
            e.setLine(1, content2);
            e.setLine(2, content3);
            e.setLine(3, content4);
        }
    
     
  2. Online

    KarimAKL

    @cdnyassuo34 String#replace() returns a new string, you have to set the string to that.
    Example:
    Code:Java
    1. content1 = content1.replace(...);
     
  3. Offline

    cdnyassuo34

    The thing is that it isn't changing anything and it don't even return errors ...

    I think it's not the right event for what I am trying to do, when a player place a sign and have finished to edit it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  4. Online

    KarimAKL

    @cdnyassuo34 SignChangeEvent is called when a player has written on a sign after placing it; you are using the right event.
    What is your current code?
     
  5. Offline

    cdnyassuo34

    Code:
    public void ReadSigns(SignChangeEvent e)
        {
            String[] content = e.getLines();
          
            String content1 = content[0];
            String content2 = content[1];
            String content3 = content[2];
            String content4 = content[3];
            Player p = e.getPlayer();
            String currentc = p.getLocation().getChunk().getX() + "," + p.getLocation().getChunk().getZ();
            String cc = getChunkCredit(p);
            String ggn = getGroupName(p.getName());
            content1 = content1.replace("%%snow_gco%%", getOwner(p.getName()));
            content1 = content1.replace("%%snow_test%%", "1234");
            content1 = content1.replace("%%snow_curc%%", currentc);
            content1 = content1.replace("%%snow_ggn%%", ggn);
            content1 = content1.replace("%%snow_cc%%", cc);
          
            content2 = content2.replace("%%snow_gco%%", getOwner(p.getName()));
            content2 = content2.replace("%%snow_test%%", "1234");
            content2 = content2.replace("%%snow_curc%%", currentc);
            content2 = content2.replace("%%snow_ggn%%", ggn);
            content2 = content2.replace("%%snow_cc%%", cc);
          
            content3 = content3.replace("%%snow_gco%%", getOwner(p.getName()));
            content3 = content3.replace("%%snow_test%%", "1234");
            content3 = content3.replace("%%snow_curc%%", currentc);
            content3 = content3.replace("%%snow_ggn%%", ggn);
            content3 = content3.replace("%%snow_cc%%", cc);
          
            content4 = content4.replace("%%snow_gco%%", getOwner(p.getName()));
            content4 = content4.replace("%%snow_test%%", "1234");
            content4 = content4.replace("%%snow_curc%%", currentc);
            content4 = content4.replace("%%snow_ggn%%", ggn);
            content4 = content4.replace("%%snow_cc%%", cc);
            e.setLine(0, content1);
            e.setLine(1, content2);
            e.setLine(2, content3);
            e.setLine(3, content4);
        }
    
    here it is
     
  6. Online

    KarimAKL

    @cdnyassuo34 Do you have the @EventHandler annotation, and have you registered the listener in your main class?
     
  7. Offline

    cdnyassuo34

    I added @EventHandler but it's still not replacing the text :/

    Oh wait, it was caused by a plugin collision :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 15, 2019
  8. Online

    KarimAKL

    @cdnyassuo34 Remember to set the title prefix to solved.
     

Share This Page