Solved Sign not changeing line on right click

Discussion in 'Plugin Development' started by Duuckky, May 19, 2014.

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

    Duuckky

    Code:java
    1. package me.duuckky.events;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Material;
    5. import org.bukkit.block.Block;
    6. import org.bukkit.block.Sign;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.Action;
    11. import org.bukkit.event.player.PlayerInteractEvent;
    12.  
    13. public class SignInteract implements Listener {
    14.  
    15. @EventHandler
    16. public void onPlayerInteract(PlayerInteractEvent e) {
    17. Player player = e.getPlayer();
    18. Block b = e.getClickedBlock();
    19. Action action = e.getAction();
    20.  
    21. // Null Check to Prevent Null Pointer Exception
    22. if (e.getClickedBlock() == null) {
    23. return;
    24. }
    25.  
    26. // If they click a sign
    27. if (action == Action.RIGHT_CLICK_BLOCK
    28. && b != null
    29. && (b.getType() == Material.SIGN_POST || b.getType() == Material.WALL_SIGN)) {
    30. Sign sign = (Sign) b.getState();
    31. // If the sign has these lines
    32. if (sign.getLine(0).equals("Test")
    33. && sign.getLine(1).equals(ChatColor.GREEN + "Test2")) {
    34. // Tell the player it works
    35. player.sendMessage(ChatColor.RED + "Sign!");
    36. sign.setLine(0, "§c>" + String.valueOf(sign.getLine(0)) + "§c<");
    37. }
    38. }
    39. }
    40. }
    41.  


    This is the code when i right click the sign, it displays "Sign!" But doesn't add ">" or "<" around the line
     
  2. Offline

    itzrobotix

    Any exceptions or anything?

    Also you can remove && b !=null

    You already did the null check.
     
  3. Offline

    caseif

    Bukkit can be weird about signs sometimes. Try sticking the sign.setLine() call in a scheduler with Bukkit.getScheduler().runTask().
     
  4. Offline

    xTigerRebornx

    ShadyPotato Since he is modifying the state itself, shouldn't he just call update() on it?
     
  5. Offline

    caseif

    Yeah, that would do it. Totally forgot about that little method. I was thinking of updating the sign during a SignChangeEvent when I suggested using a scheduler.
     
  6. Offline

    Duuckky

    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page