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. I wrote But it only spams in the chat "You do not have enough ammo"
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4. if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
    5. if (player.getItemInHand().getType() == Material.WOOD_HOE) {
    6. if (event.getPlayer().getInventory().contains(Material.SEEDS, 1)) {
    7. player.getInventory().remove(new ItemStack(Material.SEEDS, 1));
    8. player.launchProjectile(Arrow.class);
    9. }else
    10.  
    11. player.sendMessage(ChatColor.GOLD+"You do not have enough ammo");
    12.  
    13.  
    14.  
    15.  
    16. }}}

    I took out the ! but still gosh I use to be really good as this stuff then after 4 months of not programming u forget shit. And I did use your example Thank You.
     
  2. Offline

    JPG2000

    WauloK I don't think hes trolling. I think hes got issues.

    uyuyuy99 Okay. But I can't belive your still helping this guy?

    thatdubstepgamer Look at your fricken logic. Your checking if the player DOESNT have seeds. (with the !).

    I said this 400 times. USE THE CODE I GAVE YOU. Seriously. Come on!

    This is redicolous. This is getting to the point were I don't even think you know java, I think your RELIYING on us!
     
  3. I wrote But it only spams in the chat "You do not have enough ammo"
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4. if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
    5. if (player.getItemInHand().getType() == Material.WOOD_HOE) {
    6. if (event.getPlayer().getInventory().contains(Material.SEEDS, 1)) {
    7. player.getInventory().remove(new ItemStack(Material.SEEDS, 1));
    8. player.launchProjectile(Arrow.class);
    9. }else
    10.  
    11. player.sendMessage(ChatColor.GOLD+"You do not have enough ammo");
    12.  
    13.  
    14.  
    15.  
    16. }}}

    I took out the ! but still gosh I use to be really good as this stuff then after 4 months of not programming u forget shit. And I did use your example Thank You.
     
  4. Offline

    JPG2000

    thatdubstepgamer You probally were never good.

    Your missing a { on the else statement. Your IDE should tell you that.
     
  5. Hmmmmm I added one still
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4. if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
    5. if (player.getItemInHand().getType() == Material.WOOD_HOE) {
    6. if (event.getPlayer().getInventory().contains(Material.SEEDS, 1)) {
    7. player.launchProjectile(Arrow.class);
    8. player.getInventory().remove(new ItemStack(Material.SEEDS, 1));
    9.  
    10. }else{
    11.  
    12. player.sendMessage(ChatColor.GOLD+"You do not have enough ammo");
    13.  
    14.  
    15.  
    16.  
    17. }}}}


    Ok its working when I have no seeds just my hoe but when I have seeds it does not take 1 every arrow

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

    WauloK

    How many seeds are in your inventory when you test the right-click air with a HOE?
     
  7. 1 and when I right click the seed is still there but then i got to click again and it says "You do not have enough ammo"Do i need a loop?
     
  8. Offline

    JPG2000

    thatdubstepgamer It should work. And again, combine 2 sentances together bro.
     
  9. Offline

    uyuyuy99

    You are too, and given your reactions to his constant questions, that's more unbelievable :p

    thatdubstepgamer In that case, adding the { didn't change anything, because there's only 1 line after it. Also, you may need to add a player.updateInventory() after removing the seeds to refresh the client's view of the inventory.
     
  10. Offline

    WauloK

    Maybe you need this?

    Code:java
    1. player.updateInventory();


    It's deprecated but I think still works?
     
  11. Offline

    JPG2000

    uyuyuy99 I can't argue with that haha :D

    thatdubstepgamer Yeah the } didn't change anything. Mai bad.

    You don't need a loop, since the events happen every time you click with the hoe

    WauloK it doesn't work. I think bukkit removed it.

    Are you even sure Seeds is a material?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 5, 2018
  12. hmmmmmmmmm
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3.  
    4. Player player = event.getPlayer();
    5. if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
    6. if (player.getItemInHand().getType() == Material.WOOD_HOE) {
    7. if (event.getPlayer().getInventory().contains(Material.SEEDS, 1)) {
    8. player.launchProjectile(Arrow.class);
    9. player.getInventory().remove(new ItemStack(Material.SEEDS, 1));
    10.  
    11. }else{
    12.  
    13. player.sendMessage(ChatColor.GOLD+"You do not have enough ammo");
    14.  
    15.  
    16.  
    17.  
    18. }}}}


    Ill try a different material because bukkit is allowing it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 5, 2018
  13. Offline

    JPG2000

    thatdubstepgamer It should work. Does the event actually fire?

    If bukkit is allowing it then it should work.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  14. Nope I tried stone still same issue

    Yes the event is actually firing

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

    JPG2000

    thatdubstepgamer Thats wierd.

    Go in debug mode. After every statement sed the player a message, then determine which one is screwing up the code.
     
  16. Offline

    uyuyuy99

    thatdubstepgamer Did you try what me and WauloK said?

    And JPG, that won't help, because as he said, the arrow is actually firing, which is the deepest part of his code.
     
  17. ok

    When i try player.updateInventory(); it wants Suppressions Warnings
     
  18. Offline

    uyuyuy99

  19. But then it puts a black line through it dosnt work
     
  20. Offline

    WauloK

    Code:java
    1. if (event.getPlayer().getInventory().contains(Material.SEEDS, 1)) {


    Does this need a ,1 in it?
     
  21. It has that Waulok
     
  22. Offline

    uyuyuy99

    thatdubstepgamer Yes, as I said, ignore the black line through it. Just try it.
     
  23. I did try it
     
  24. Offline

    WauloK

    Does the if statement I posted require a ,1 in it?
     
  25. It does not require but will still not take
     
  26. Offline

    JPG2000

    thatdubstepgamer I just copied the code you gave me into a plugin.

    It works perfectly.
     
  27. Offline

    uyuyuy99

    JPG2000 Are you sure it's actually removing the seeds, though?
     
  28. Offline

    Jade

    At JPG2000 earlier; You should calm down. The OP is clearly trying and he tried to implement it on his own. It's not possible for everyone to learn by copy-pasting. The OP could learn through personal and manual implementation, but was confused.

    Thanks.
     
  29. I still need help :'(
     
  30. Offline

    JPG2000

    Jade Yeah. I agree. I was very tired, and had a long day. D:

    thatdubstepgamer Tell me exactly what happens when you click the seeds. Does it work?

    Also, send me the code.

    uyuyuy99 And yes, its removing the seeds. But my IDE gave me a error, that I fixed. I forgot the error.
     
Thread Status:
Not open for further replies.

Share This Page