Placing mushrooms anywhere?

Discussion in 'Plugin Development' started by DatRefillDoe, Jul 25, 2014.

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

    DatRefillDoe

    Hi everyone! Recently I tried a code to place mushrooms anywhere. Basically, I made an interact event for when you right clicked a block with any mushroom, it'll get the relative above it, and set it to mushroom. But it made it so it crashed the server! So I need some help with making this, thanks!
     
  2. What was the stack-trace when the server crashed?
     
  3. Offline

    teej107

    What have you tried? You got no proof without code. And since your code crashed the server, it might be good to post it so we can spot your errors.
     
  4. Offline

    DatRefillDoe

    teej107
    Code:
        @EventHandler
        public void mushroom(PlayerInteractEvent e){
            Player p = e.getPlayer();
            if(p.isOp()){
                if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
                   
                    if(p.getItemInHand().getType() == Material.RED_MUSHROOM){
                       
                        e.getClickedBlock().getRelative(BlockFace.UP).setType(Material.RED_MUSHROOM);
                       
                    }else{
                        if(p.getItemInHand().getType() == Material.BROWN_MUSHROOM){
                           
                            e.getClickedBlock().getRelative(BlockFace.UP).setType(Material.BROWN_MUSHROOM);
                           
                        }else{
                           
                        }
                    }
                   
                }
            }
        }
    That's it, it's not crashing anymore but it's still not working.
     
  5. Offline

    stormneo7

    Code:java
    1. }else{
    2. if(p.getItemInHand().getType() == Material.BROWN_MUSHROOM){
    3.  
    4. e.getClickedBlock().getRelative(BlockFace.UP).setType(Material.BROWN_MUSHROOM);
    5.  
    6. }else{
    7.  
    8. }
    9. }

    Try using the else if(){ feature.
    Also, check if p.getItemInHand() isn't null because if they are holding nothing and clicking a block, you cannot get the type.
     
  6. Offline

    Code0

    Does the full event not initiate or what? Try debuggin using System.out.println() to see if the code reaches certain sports.

    Also, register your events.
     
  7. Offline

    teej107

    Use .equals() to compare objects. Other than that, are you sure you are OP? and as others pointed out, make sure your event is registered.
     
  8. Offline

    L33m4n123


    Does not matter if he uses .equals() or == for enums

    Code:
    public final boolean equals(Object other) {
      return this==other;
    }
     
  9. Offline

    DatRefillDoe

    Code0 I'll try that, and I've already registered. teej107 Shouldn't matter.
     
  10. Offline

    teej107

    Eh, I am having one those days I guess. I totally forgot that Action is an enum. Put up debug code to make sure the event is firing, and to make sure what if tests are returning false.
     
Thread Status:
Not open for further replies.

Share This Page