Sign Event Gone wrong!

Discussion in 'Plugin Development' started by PolarCraft, Nov 11, 2013.

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

    PolarCraft

    Okay so when i right click on the sign it says :
    [​IMG]

    And then it does not setline0 to what it is supposed to -_-

    Code:java
    1. package net.jc.minecraft.yg;
    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 SignListener2 implements Listener{
    14.  
    15.  
    16. @EventHandler
    17. public void clicksign2(PlayerInteractEvent f) {
    18. Player p = f.getPlayer();
    19. if (f.getAction() == Action.RIGHT_CLICK_BLOCK) {
    20. Block c = f.getClickedBlock();
    21. if (c.getType() == Material.SIGN_POST || c.getType() == Material.WALL_SIGN) {
    22. Sign sign = (Sign) c.getState();
    23. if ((sign.getLine(0).equalsIgnoreCase("yg"))) {
    24. sign.setLine(0, "[YG]");
    25. if (sign.getLine(1).equalsIgnoreCase("feed")) {
    26. p.setFoodLevel(25);
    27. p.sendMessage(ChatColor.LIGHT_PURPLE+ toString()+ ChatColor.BOLD+ "You have now been feed!");
    28. }
    29. }
    30. }
    31. }
    32. }
    33. }
    34.  
     
  2. Offline

    amhokies

    Call sign.update() and remove the random toString() call in your p.sendMessage()
     
  3. Offline

    PolarCraft

    amhokies So:
    Code:java
    1. package net.jc.minecraft.yg;
    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 SignListener2 implements Listener{
    14.  
    15.  
    16. @EventHandler
    17. public void clicksign2(PlayerInteractEvent f) {
    18. Player p = f.getPlayer();
    19. if (f.getAction() == Action.RIGHT_CLICK_BLOCK) {
    20. Block c = f.getClickedBlock();
    21. if (c.getType() == Material.SIGN_POST || c.getType() == Material.WALL_SIGN) {
    22. Sign sign = (Sign) c.getState();
    23. if ((sign.getLine(0).equalsIgnoreCase("yg"))) {
    24. sign.setLine(0, "[YG]");
    25. sign.update();
    26. if (sign.getLine(1).equalsIgnoreCase("feed")) {
    27. p.setFoodLevel(25);
    28. p.sendMessage(ChatColor.LIGHT_PURPLE+ toString()+ ChatColor.BOLD+ "You have now been feed!");
    29. }
    30. }
    31. }
    32. }
    33. }
    34. }
    35.  
     
  4. Offline

    Goblom

    PolarCraft you still forgot to remove the toString() in line 28
     
  5. Offline

    PolarCraft

    Goblom Still does not want to change the sign -_-
    [Edit] Facepalm. When you right click it it changes the text to [YG]. That is not what i wanted it to do. I want it to change once the sign is placed.
     
  6. Offline

    d33k40

    Then use the correct event, use the documentation.
     
  7. Offline

    DAZ3DNDC0NFUS3D

    What you are looking for is SignChangeEvent
    Code:java
    1. public void onSignChangeEvent(SignChangeEvent event)
     
Thread Status:
Not open for further replies.

Share This Page