Need help on Right Click Air Event (ERROR)

Discussion in 'Plugin Development' started by thatdubstepgamer, Sep 12, 2013.

Thread Status:
Not open for further replies.
  1. The RIGHT_CLICK_AIR is underlined in red Ive tried equals and == as my equal but can't figure it out! please help!

    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if(e.getAction().equals(Action.RIGHT_CLICK_AIR)){
    5. if(p.getItemInHand().getType() == Material.GOLD_HOE) {
    6. if(!e.getPlayer().getInventory().contains(Material.FLINT)){p.sendMessage(ChatColor.YELLOW + "You need Flient to reload");}
    7. e.getPlayer().getInventory().removeItem(new ItemStack(Material.FLINT, 1));
    8. p.launchProjectile(Arrow.class);
    9. }}}
     
  2. Offline

    WauloK

    Code:java
    1. (action == Action.RIGHT_CLICK_BLOCK)


    use RIGHT_CLICK_BLOCK and then test if the clicked block was Material.AIR
     
  3. Where would I insert this code???
     
  4. Offline

    metalhedd

    You're probably importing 'Action' from the wrong package. it should be org.bukkit.event.block.Action check your imports at the top of the file.

    Sorry, but that's nonsense, where did you learn that?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  5. Im kinda a noob how do I test if the clicked bloack was Material.Air sorry
     
  6. Offline

    WauloK

    Code:java
    1. Action action = event.getAction();
    2. Block clickedBlock = event.getClickedBlock();
    3. if (action == Action.RIGHT_CLICK_BLOCK) {
    4. if((clickedBlock.getType()==Material.AIR) {
     
  7. can someone please help me!!

    Sorry dosnt work :'(

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

    WauloK

    Sorry. I thought that's how you do it. I didn't know there's a RIGHT_CLICK_AIR
    Ignore my posts.
     
  9. Hmmm this is hard I dont get it :'(

    Java Please Help me all I want to do is
    -right click a wooden hoe fire 1 snowball and take 1 seed from my inventory

    cAN YOU STILL HELP ME?

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

    uyuyuy99

    Did you even see what metalhedd said? I bet that's your problem.
     
  11. Yes I saw but can you guys give me not just the sliver of code but all of it so I can understand where to put it and stuff please...
     
  12. Offline

    uyuyuy99

    thatdubstepgamer He literally gave you all the steps you need to be able to fix it.
     
  13. Im sorry but I did not get them please explain/code
     
  14. Offline

    uyuyuy99

    There's your explanation. You shouldn't need to change any of the actual code to fix it, just look at the imports at the top of your code, look for a line with "Action" on the end, and replace that line with org.bukkit.event.block.Action
     
  15. Ok i got rid of the errors but how do I make It throw snowball?
     
  16. Offline

    uyuyuy99

    thatdubstepgamer Going by the code you showed us, it looks like you already know how. Just change Arrow to Snowball:
    Code:java
    1. p.launchProjectile(Snowball.class);
     
  17. It still wont fire heres my code
    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent e) {
    3. Player player = e.getPlayer();
    4. if(e.getAction().equals(Action.RIGHT_CLICK_AIR)){
    5. if(player.getItemInHand().getType() == Material.WOOD_HOE) {
    6. if(!e.getPlayer().getInventory().contains(Material.SEEDS));
    7. e.getPlayer().getInventory().removeItem(new ItemStack(Material.SEEDS, 1));
    8. player.launchProjectile(Snowball.class);
    9.  
    10.  
    11. }}}
     
  18. Offline

    uyuyuy99

    thatdubstepgamer That code works fine for me. Are you registering the listeners?
     
  19. No how do I do that?
     
  20. Offline

    uyuyuy99

  21. Can you share your code just to see how I would do ill still read this
     
  22. Offline

    JPG2000

    thatdubstepgamer Were not going to just give you exactly what you want. If we do that your going to write a thousand threads.

    Let me explain this step by step.

    First, lets create our event.
    Code:java
    1. public void onPlayerInteract(PlayerInteractEvent event) {
    2. }


    Now lets store some usefull information:
    Code:java
    1. public void onPlayerInteract(PlayerInteractEvent event) {
    2. Player player = event.getPlayer(); //This is the player who did the event
    3. ItemStack hand = player.getItemInHand(); //This is the itemstack the player is holding
    4. Inventory inv = player.getInventory(); //The players inventory
    5. }


    Now lets respond appropriately:
    Code:java
    1. public void onPlayerInteract(PlayerInteractEvent event) {
    2. Player player = event.getPlayer(); //This is the player who did the event
    3. ItemStack hand = player.getItemInHand(); //This is the itemstack the player is holding
    4. Inventory inv = player.getInventory(); //The players inventory
    5.  
    6. if (hand.getType() == Material.WOODEN_HOE) { // The item in the players hand is a hoe
    7. if (inventory.contains(Material.SEED, 1)) { // If the player has 1 seed
    8. //This is were we shoot the snowball. Im going to leave that to you becuase im not going to spoon feed you!
    9. inventory.remove(new ItemStack(Material.SEED, 1))//We removed 1 seed
    10. }
    11. }
    12. }


    And by the way, stop asking for plain code. Its very annoying. Were not going to just give you what you want. Were going to teach you, not give you the exact thing.
     
  23. Never mind I registered it thanks! But its not taking me ammo hmm

    Also how do u make it so u take damage?? Contact with player player.setHealth(0);

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

    JPG2000

    thatdubstepgamer Omg. Dude seriosuly.

    1) Don't write tons of reply's its spammy. Do it all in one second.
    2) Google it, a thread will come up. Don't ask EVERY question on here. This is not the place.
    3) Did you read anything I just said?
    4) People will appreciate if actually do research, and don't ask any question that pops in your head.

    EDIT:
    5) Google is your friend. Use it!
    6) If you have multiple questions, atlest right it in one section.
    7) It looks like you don't appreciate help, and want people to do the work for you. It also seems like you just want what you want done, and people will do it for you. *HINT* That won't work.
     
    uyuyuy99 likes this.
  25. I wrote this but when I write click no mater what if I have seeds or not it still fires arrows and when I do have seeds it will not take them hmm...
    Code:java
    1. public void onInteract(PlayerInteractEvent e) {
    2. Player player = e.getPlayer();
    3. if(e.getAction().equals(Action.RIGHT_CLICK_AIR)){
    4. if(player.getItemInHand().getType() == Material.WOOD_HOE) {
    5. if(!e.getPlayer().getInventory().contains(Material.SEEDS));
    6. e.getPlayer().getInventory().removeItem(new ItemStack(Material.SEEDS, 1));
    7. player.launchProjectile(Arrow.class);
    8. }else{
    9. player.sendMessage(ChatColor.GOLD+"You do not have enough ammo");
    10.  
    11.  
    12.  
    13.  
    14. }}}
     
  26. Offline

    JPG2000

    thatdubstepgamer I can't belive you just did that.

    I wrote a whole f*****g thing to help you, and you write your own code.

    I can see alot of erros. This time im not helping you. It should be obvious. Why don't you use the example I f*****g gave you.

    Heres the example;
    Code:java
    1. public void onPlayerInteract(PlayerInteractEvent event) {
    2. Player player = event.getPlayer(); //This is the player who did the event
    3. ItemStack hand = player.getItemInHand(); //This is the itemstack the player is holding
    4. Inventory inv = player.getInventory(); //The players inventory
    5.  
    6. if (hand.getType() == Material.WOODEN_HOE) { // The item in the players hand is a hoe
    7. if (inventory.contains(Material.SEED, 1)) { // If the player has 1 seed
    8. //This is were we shoot the snowball. Im going to leave that to you becuase im not going to spoon feed you!
    9. inventory.remove(new ItemStack(Material.SEED, 1))//We removed 1 seed
    10. }
    11. }
    12. }


    Also, thoose 7 things I said above. You did exactly that.
     
  27. Offline

    uyuyuy99

    thatdubstepgamer You did this:
    Code:java
    1. if(!e.getPlayer().getInventory().contains(Material.SEEDS));
    Why do you have a semicolon after an "if" statement? You need curly brackets.
    Also, can you take a wild guess at why it's shooting arrows instead of snowballs? :p
     
  28. Offline

    JPG2000

    uyuyuy99 I really think we need to stop giving him code. Were more then spood feeding him. I gave him an recource and he completely ignored it.
     
  29. Offline

    WauloK

    I'm wondering if he's trolling...
     
  30. Offline

    uyuyuy99

    JPG2000 I gave him no code at all. That was a snippet of HIS code.
     
Thread Status:
Not open for further replies.

Share This Page