[SignEditor] ~ sign.getLine() doesn't work.

Discussion in 'Plugin Development' started by tamajpm, Sep 22, 2013.

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

    tamajpm

    Hello,

    I have a problem with my plugin called "SignEditor". When i want to get line 1 from the sign i cant do .getLine(1). It seems it doesn't exists in my plugin code. The code is:

    Code:java
    1. package NL.Tamajpm.SignEditor.Plugin;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Material;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.player.PlayerInteractEvent;
    10. import org.bukkit.inventory.ItemStack;
    11. import org.bukkit.material.Sign;
    12. import org.bukkit.plugin.PluginDescriptionFile;
    13. import org.bukkit.plugin.PluginManager;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class SignEditor extends JavaPlugin implements Listener {
    17. public final Logger logger = Logger.getLogger("Minecraft");
    18.  
    19. public void onEnable() {
    20. PluginDescriptionFile pdfFile = this.getDescription();
    21. this.logger.info(pdfFile.getName() + " has been enabled.");
    22. pluginManagerLoader();
    23. }
    24.  
    25. public void onDisable() {
    26. PluginDescriptionFile pdfFile = this.getDescription();
    27. this.logger.info(pdfFile.getName() + " has been disabled.");
    28. }
    29.  
    30. public void pluginManagerLoader() {
    31. PluginManager pm = getServer().getPluginManager();
    32. pm.registerEvents(this, this);
    33. }
    34.  
    35. @EventHandler
    36. public void onSignInteract(PlayerInteractEvent event) {
    37. Player player = event.getPlayer();
    38.  
    39. if(event.getClickedBlock() == null) return;
    40. if(event.getClickedBlock().getType().equals(Material.SIGN_POST) || event.getClickedBlock().getType().equals(Material.SIGN)) {
    41. Sign sign = (Sign) event.getClickedBlock().getState();
    42. if(sign.getLine(1).equals("[TEST]")) {
    43. ^^^^^^^
    44. //The problem!
    45. }
    46. }
    47. }
    48. }
    49.  
     
  2. Offline

    Vandrake

    You imported the wrong sign. It should be the Block
     
  3. Offline

    Mmarz11

    Also, to get the first line you would do sign.getLine(0)
     
  4. Offline

    Vandrake

    What he said^^^^^^^^ that too
     
  5. Offline

    gamermanh

    Little clean-up tip for yah:

    Change line 40 up a bit to look like this
    (be sure to add this variable earlier in the code for it to work well)

    Material block = event.getClickedBlock().getType();

    Code:java
    1. if(block == Material.SIGN_POST || block == Material.SIGN)
     
  6. Offline

    CakeProgrammer

    ------- | line 0
    ------- | line 1
    ------- | line 2
    ------- | line 3
    this how the signs work on bukkit, more think I think he's the problem
    is
    Code:java
    1. if(event.getLine(1).equalsIgnoreCase("YOURTEXT")){
    2.  
    3. }

    the equalsIgnoreCase might be (I'm not sure)
     
  7. Offline

    Mmarz11


    The problem is that he imported the Material Sign which does not have the method.
     
  8. Offline

    CakeProgrammer

    oh =/
    here's kinda old code I made maybe it's will help
    Code:java
    1. @EventHandler
    2. public void onPlayerClickSign(PlayerInteractEvent event){
    3. Player player = event.getPlayer();
    4. if(event.getClickedBlock().getType() == Material.SIGN ||event.getClickedBlock().getType() == Material.SIGN_POST ||event.getClickedBlock().getType() == Material.WALL_SIGN){
    5. if(event.getAction() == Action.LEFT_CLICK_BLOCK){
    6. Sign sign = (Sign) event.getClickedBlock().getState();
    7. if(sign.getLine(1).equalsIgnoreCase( "YOURTEXT")){
    8. //Whatever you wanna do.
    9. }
    10. }
    11. }
    12. }
     
  9. Offline

    KanTe

    CakeProgrammer sign.getLine(1) is the second line of the sign ingame..
     
  10. Offline

    MrDynamo

    Code:JAVA
    1.  
    2. public void signClick(PlayerInteractEvent e) {
    3. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    4. Block b = e.getClickedBlock();
    5. if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST || b.getType() == Material.SIGN) {
    6. Sign sign = (Sign) b.getState();
    7. String[] lines = sign.getLines();
    8. if(lines[0].equalsIgnoreCase("YOUR TEXT HERE")) {
    9. //what you want to do
    10. }
    11. }
    12. }
    13. }
    14.  


    Also do the aformentioned stuff.
     
  11. Offline

    CakeProgrammer

    this was just a example of how to do it :p
     
Thread Status:
Not open for further replies.

Share This Page