Wrong Code?

Discussion in 'Plugin Development' started by Code0, Apr 22, 2014.

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

    Code0

    Code:java
    1. if(!(b==null) && !(b.getType().equals(Material.AIR)))


    This line of code isn't working properly and doesn't activate any code under that line.
     
  2. Code0 Full code please, including debug

    Edit: Assuming the above advice doesn't work
     
    Code0 likes this.
  3. Offline

    Code0

    I am using Eclipse. ... Doesn't show up any errors.
     
  4. Offline

    Bobit

    Wait, I was wrong, Adam was right.
    Full code please?
    Or, you could simply have above it
    Code:java
    1. System.out.println("b.getType() =" + b.getType());
     
  5. Offline

    Code0

    Code:java
    1. if(e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR){
    2. if(e.getPlayer().getItemInHand().equals(thorAxe)){
    3. if(thorCooldown.contains(e.getPlayer().getName())){
    4. e.getPlayer().sendMessage(prefix+ChatColor.RED+"Your Powers are still on cooldown.");
    5. return;
    6. }else{
    7. for(Block b : e.getPlayer().getLineOfSight(null,10)){
    8. if(!(b==null) && !(b.getType().equals(Material.AIR))){
    9. e.getPlayer().sendMessage(prefix+ChatColor.RED+"Success");
    10. e.getPlayer().getWorld().strikeLightning(b.getLocation());
    11. e.getPlayer().sendMessage(prefix+ChatColor.YELLOW+"Boom!");
    12. thorCooldown.add(e.getPlayer().getName());
    13. break;
    14. }else{
    15. return;
    16. }
    17. }
    18. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this,new Runnable(){
    19. public void run() {
    20. thorCooldown.remove(e.getPlayer().getName());
    21. e.getPlayer().sendMessage(prefix+ChatColor.RED+"You may now use your Powers again.");
    22. }
    23. }
    24. ,100);
    25. }
    26. }
    AdamQpzm
     
  6. Offline

    Bobit

    That's not the "full code", right?
    I mean, you still have the @EventHandler part and all that, right?
    So what event is this triggering on?
    PlayerInteractionEvent?
     
  7. Code0 Put this above the check:

    PHP:
    if(== nullSystem.out.println("block is null");
    else 
    System.out.println("block is " b.getType());
     
  8. Offline

    Bobit

    What I'm trying to say is, you're still getting the System.out.println() on line 21, right? Because otherwise, the error could be anywhere, not just in this code.
     
  9. Bobit Even if 21 doesn't print, there's not necessarily an error anywhere.

    Code0 Just properly looked at your code, are you sure this is the logic you're looking for?

    For each of the blocks in the player's line of sight:
    If the first block is not null and not air, do lightning and message stuff, then stop looking at the blocks. If it is null or air, stop the whole method.
     
    Code0 likes this.
  10. Offline

    Code0

    Not exactly. It selects the first block that is not air or null.

    AdamQpzm
     
  11. Code0 Then remove the else return - because that's what your logic is doing
     
  12. Offline

    itzrobotix

    What happened to getTargetBlock(null, *Distance*) ?
     
    Code0 and Bobit like this.
  13. Offline

    Code0

    itzrobotix I'm trying to give myself a little bit of a challenge xD

    Doesn't change anything. Code isn't executed after that if statement. So it always returns null ( no errors)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
    itzrobotix likes this.
  14. Code0 No, trust me, the else statement executes if the if fails. That's what it's made for.

    You're essentially checking the first block in their line of sight, and no more.
     
    Rocoty likes this.
  15. Offline

    Code0

    You
    You were right! I'm stupid xD.

    Thanks dude.
     
    AdamQpzm likes this.
Thread Status:
Not open for further replies.

Share This Page