Solved Changing the lines of a sign.

Discussion in 'Plugin Development' started by Ding1934, Jul 13, 2022.

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

    Ding1934

    Hello, I am writing a core plugin for my minehut server. I want to make a event where if you place a sign and if it contains color codes it will translate.

    This is my current code.
    Code:
    @EventHandler
        public void onSignPlace(BlockPlaceEvent event) {
            BlockState state = event.getBlockPlaced().getState();
         
            if (state instanceof Sign) {
                Sign sign = (Sign) state;
             
                String L1 = sign.getLine(0);
                String L2 = sign.getLine(1);
                String L3 = sign.getLine(2);
                String L4 = sign.getLine(3);
             
                sign.setLine(0, ChatColor.translateAlternateColorCodes('&', L1));
                sign.setLine(1, ChatColor.translateAlternateColorCodes('&', L2));
                sign.setLine(2, ChatColor.translateAlternateColorCodes('&', L3));
                sign.setLine(3, ChatColor.translateAlternateColorCodes('&', L4));
            }
        }
    How do I make this work? It leaves the sign blank in game.
     
    Last edited: Jul 13, 2022
  2. Offline

    KarimAKL

  3. Offline

    Ding1934

    Thank you for telling me it's working intended now!
     
    KarimAKL likes this.
  4. Offline

    gochi9

    Also if you just want to color every line you could use a simple loop instead of repeating yourself. Example

    Code:
    for(int i = 0; i < 4; i++) 
        sign.setLine(i, ChatColor.translateAlternateColorCodes('&', sign.getLine(i)));
    
     
Thread Status:
Not open for further replies.

Share This Page