Bukkit's Logic or Mine is Broken

Discussion in 'Plugin Development' started by TheHandfish, Aug 7, 2014.

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

    TheHandfish

    Okay,

    So I'm making a plugin that allows the player to make [Command] signs. When you make the sign, it checks to see if the first line is [Command] (case is not specific). But for some reason, even if I clearly am making it "[Command]", it still returns false.

    Code:javascript
    1.  
    2. @EventHandler
    3. public void onSignChange(SignChangeEvent event)
    4. {
    5. Block b = event.getBlock();
    6. Sign s = (Sign) b.getState();
    7. if(s.getLine(0).equalsIgnoreCase("[Command]"))
    8. {
    9. if(!"".equals(s.getLine(1).toLowerCase()) && event.getPlayer().hasPermission("signdirectives.makesign"))
    10. {
    11. event.getPlayer().sendMessage("DEBUG: Created Command Sign");
    12. event.setLine(0, "§1[Command]");
    13. event.getBlock().getState().update();
    14. }
    15. else if("".equals(s.getLine(1).toLowerCase()) && event.getPlayer().hasPermission("signdirectives.makesign"))
    16. {
    17. event.getPlayer().sendMessage(ChatColor.RED + "Your Command Sign was incorrectly set up.");
    18. event.setLine(0, ChatColor.DARK_RED + "[Command]");
    19. event.setLine(1, ChatColor.RED + "<Command>");
    20. event.setLine(2, ChatColor.RED + "<Arguments>");
    21. event.setLine(3, ChatColor.RED + "<More Arguments>");
    22. event.getBlock().getState().update();
    23. }
    24. else if(!event.getPlayer().hasPermission("signdirectives.makesign"))
    25. {
    26. event.getPlayer().sendMessage(ChatColor.DARK_RED + "You don't have permission to make command signs.");
    27. event.setCancelled(true);
    28. }
    29. }
    30. else
    31. {
    32. boolean bool = s.getLine(0).equalsIgnoreCase("[Command]");
    33. event.getPlayer().sendMessage("§aDEBUG: Error! onoes! " + bool + ", actually is \"§r" + event.getLine(0) + "§a\"");
    34. }
    35.  
    36. }
    37. [/javascript]
    38.  
    39. event.getPlayer().sendMessage("§aDEBUG: Error! onoes! " + bool + ", actually is \"§r" + event.getLine(0) + "§a\"");
    40. This line tells me that the line is "actually [Command]"... so why is it returning false? It doesn't make sense. I have tried several different methods for comparing the sign line to what it needs to be including the toLowerCase().contains() method. Any advice? This is quite confusing. :P
     
  2. Offline

    fireblast709

    TheHandfish use event.getLine(int). The lines aren't set in set on the Sign yet
     
  3. Offline

    TheHandfish

    fireblast709: Huh? Sorry. I don't understand. x.x Could you explain?
     
  4. Offline

    fireblast709

    TheHandfish line 7 uses the tile entities data, which is set after the event has been handled (of course if the event hasn't been cancelled)
     
  5. Offline

    xize

    TheHandfish

    The SignChangeEvent is pre called and works when you pressed the done button but since you don't have these lines yet because its precalled before it writes the sign data to the actualy blockstate its not really possible to use it that way, in order to fix that use the event it self it contain the same methods as in Sign but not the update() method because the event will care for that.
     
  6. Offline

    TheHandfish

  7. Offline

    Chiller

    TheHandfish Now why would you do that when you could change s.getLine(x) with event.getLine(x)....
     
  8. Offline

    xize

    TheHandfish

    let me geuss, you want real time updates on the signs?

    in that case you may want to use no scheduler but instead using a combination of event.getLine() and blockstate.setLine() and blockstate.update(), but be aware by doing this when the sign is clicked on done it resents all the lines again...

    -edit-
    oh you actually need a scheduler though
     
  9. Offline

    Chiller

    xize TheHandfish Well you could just set the events line so that it updates to the line set.
     
  10. Offline

    fireblast709

    TheHandfish no. Instead of getting the Sign and using s.getLine(x), check if e.getLine(x) matches the stuff you want to compare
     
  11. Offline

    xize

    Chiller

    My concern is that it may not work unless the player has already clicked the done button.
    but if he wants to update the signs live (when still typing on the sign) this event isn't really designed that way it doesn't do a 1 tick update automaticly it only adds things on the sign when done is clicked, so a scheduler would be more suitable but also sort of dangerous to, if I where the op I would strongely advise adding the scheduler outside the event and use a getter system or something smilliar.
     
  12. Offline

    fireblast709

    xize stop advising the scheduler lol. If you read the initial post you can see he wants to make some kind of command executing sign ;)
     
    xize likes this.
  13. Offline

    xize

    fireblast709
    Fair enough, the first lines made me confused what the op intention was,
    but now I see:p.

    TheHandfish
    ignore my last 2 posts, the scheduler is not needed it only creates confusion.
     
  14. Offline

    TheHandfish

    Okay, thanks. I just realized I forgot to change s.getLine to event.getLine. I'll try that next time I'm on a computer.
     
Thread Status:
Not open for further replies.

Share This Page