Help with signs

Discussion in 'Plugin Development' started by arnie231, May 31, 2012.

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

    arnie231

    How would I go about getting the lines of a sign on the player interact event

    it seems that (Sign)event.getClickedBlock().getState().getLines(0) doesnt work

    it gives a red error line under the .getLines(0)
     
  2. String[] lines = ((Sign)event.getClickedBlock().getState()).getLines();
     
  3. Offline

    arnie231


    Hmm I'm still getting cannot find symbol
     
  4. Offline

    AmoebaMan

    There are two objects called "Sign" in Bukkit. Make sure you are importing the correct one.
     
  5. Offline

    arnie231

    Code:java
    1. package com.arnie.sh2.Listeners;
    2.  
    3. import com.arnie.sh2.Main;
    4. import org.bukkit.Material;
    5. import org.bukkit.block.Block;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.EventPriority;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.Action;
    11. import org.bukkit.event.player.PlayerInteractEvent;
    12. import org.bukkit.material.Sign;
    13.  
    14.  
    15. public class SignGeneratorListener implements Listener
    16. {
    17. @EventHandler(priority=EventPriority.NORMAL)
    18. public void OutpostClick(PlayerInteractEvent event){
    19.  
    20. Action action = event.getAction();
    21. Player player = event.getPlayer();
    22. Block block = event.getClickedBlock();
    23.  
    24. if ((action == Action.RIGHT_CLICK_BLOCK) && (event.getClickedBlock() != null) && (block.getType() == Material.SIGN_POST) && (((Sign)event.getClickedBlock().getState()).getLine(0).toString().equalsIgnoreCase(Main.config.getString("Stronghold2.Sign.Name"))))){
    25.  
    26. }
    27. }
    28. }
     
  6. Offline

    desht

    Yep, you need to be using org.bukkit.block.Sign there, not org.bukkit.material.Sign.

    And if your lines of code are getting that long, it's a good sign you need to consider a little reformatting, e.g.:
    PHP:
    if (action == Action.RIGHT_CLICK_BLOCK && block != null) {
      if (
    block.getType == Material.SIGN_POST) {  // do you want to also check for WALL_SIGN?
        
    Sign sign = (Sign)block.getState();
        if (
    sign.getLine(0).equalsIgnoreCase(Main.config.getString("Stronghold2.Sign.Name"))) {
          
    // ...
        
    }
      }
    }
    Just a suggestion :)
     
  7. Offline

    arnie231

    thank you it works
     
Thread Status:
Not open for further replies.

Share This Page