Solved Getting lines on a sign

Discussion in 'Plugin Development' started by TheBoy3, Jul 31, 2013.

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

    TheBoy3

    Hi, I've recently been working on a plugin for a while, and I have decided to make a sign shop feature that sells custom kits, but when I try reading lines off a sign to check if the shop is valid, the line returns an empty string. Here is the code of the Event (I put a few temporary info loggers in for debugging purposes):

    Code:java
    1. public void onSignPlace(SignChangeEvent event) {
    2. MultiPlex.logger.info("onBlockPlace Event Triggered for MultiKit Shops!"); //Debug Line
    3. Player player = event.getPlayer();
    4. Block block = event.getBlock();
    5. BlockState state = block.getState();
    6. Sign sign;
    7. if (!(state instanceof Sign)) return;
    8. MultiPlex.logger.info("onBlockPlace Event Triggered for MultiKit Shops! Phase 2"); //Debug Line
    9.  
    10. sign = (Sign)state;
    11.  
    12. MultiPlex.logger.info(sign.getLine(1)); //Debug Line where I found out that the string was empty
    13.  
    14. if (!sign.getLine(1).equalsIgnoreCase("[MultiKit Shop]")) return;
    15. MultiPlex.logger.info("onBlockPlace Event Triggered for MultiKit Shops! Phase 3"); //Debug Line
    16. sign.setLine(1, "[MultiKit Shop]");
    17. String kit = sign.getLine(2);
    18. @SuppressWarnings("unchecked")
    19. ArrayList<ItemStack> kitcontents = (ArrayList<ItemStack>) MultiPlex.config.get("kit." + kit + ".contents");
    20. if (kitcontents == null) {
    21. player.sendMessage(ChatColor.RED + "Invalid Kit Name!");
    22. sign.getBlock().breakNaturally();
    23. return;
    24. }
    25. Double kitprice = MultiPlex.config.getDouble("kit." + kit + ".price");
    26. sign.setLine(3, kitprice.toString());
    27. sign.update();
    28. }


    The event seems to terminate at line 14, because the 4th debug line is never reached.

    Can anyone help? Thanks!:)

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  2. Offline

    krewekomedi

    If the sign.getLine(1) is an empty string, then the if condition at line 14 is true and it executes the return statement.

    Is that what you are looking for?

    I'm guessing here, but perhaps you should look at sign.getLine(0)?
     
  3. Offline

    TheBoy3


    Originally, I actually did use sign.getLine(0), to get the first line, but it appeared to have the same result, so I tried sign.getLine(1)
     
  4. at the moment i cant test it, but maybe you have to get the lines from the event, because the sign still is empty when creating it?
     
    TheBoy3 likes this.
  5. Offline

    TheBoy3

    Adversarius

    I tried that, and it works perfectly! Thanks! :)
     
Thread Status:
Not open for further replies.

Share This Page