[HELP] Detect item

Discussion in 'Plugin Development' started by MinecraftDorado, Nov 5, 2015.

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

    MinecraftDorado

    Hello, I need to know how to detect an item that the inventory bar, for example detect when selecting a stick. Thank you
     
  2. Offline

    mythbusterma

  3. Offline

    MinecraftDorado

    @mythbusterma Do not understand the question and not much English, but what I need is to be put for example the effect of the player jump, when you have selected a stick in the hotbar. I'd appreciate if you give me an example of how you can use.
     
  4. Offline

    CoolDude53

    @MinecraftDorado

    - Listen for playerhelditemevent
    > if (event.getPlayer().getInventory().getItem(event.getNewSlot()) equals item you want)
    > give player effect
    /> else
    /> remove effect/make sure player does not have effect
     
    Last edited: Nov 5, 2015
  5. Offline

    boomboompower

  6. Offline

    MinecraftDorado

    @CoolDude53 I do not understand how to do, I tried this but not working.
    Code:
            public void onPlayerJoin(PlayerJoinEvent e) {
           
            Player player = (Player) e;
               
            if(player.getPlayer().getInventory().getItemInHand().getType() == Material.STICK);
                player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 18, 1));
     
  7. Offline

    Scimiguy

    Even if that does work, you're only applying your speed effect for 18 ticks, which is only like 9/10ths of a second

    Did you mean 18 seconds? Then you need 360
     
  8. Offline

    MinecraftDorado

    @Scimiguy The same does not work, and not know why.
     
  9. Offline

    sebagius7110

    @MinecraftDorado just a quick question, why are you using a PlayerJoinEvent?
     
  10. Offline

    MinecraftDorado

    @sebagius7110 is the plugin I'm doing what needs to something else, and I think that confused me where to place, for that would have to replace it?
     
  11. Offline

    Scimiguy

    @MinecraftDorado
    Say that again but in a different way, I have no idea what you meant
     
  12. Offline

    MinecraftDorado

    @Scimiguy As I can make the plugin work? (If you can pass me the code)
     
  13. Offline

    Scimiguy

    If you want code written for you, submit a plugin request.

    This board is about solving problems and answering questions. We're not here to write code for you, and we won't.
     
  14. Offline

    MinecraftDorado

    @Scimiguy What I say is how I fix the code, you give me no one from scratch.
     
  15. Offline

    Scimiguy

    What code?
    You haven't given us any code
     
  16. Offline

    MinecraftDorado

    @Scimiguy
    Code:
            public void PlayerItemHeldEvent(Player player, int previous, int current) {
    
            Player player = (Player) e;
              
            if(player.getPlayer().getInventory().getItemInHand().getType() == Material.STICK);
                player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 18, 1));
     
  17. Offline

    Scimiguy

    I'm thinking you probably need to learn java a bit better before you consider doing this.

    Here's a guide on how to handle EventHandlers
    http://wiki.bukkit.org/Event_API_Reference

    Your current code:
    1. Isn't handling any events at all
    2. Doesn't use if statements properly
    3. Uses Player.getPlayer() ????
    4. Still gives the Player an effect for 9/10 of a second, which won't be noticeable

    Learn a bit more about Java before going ahead with this, for your own benefit
     
  18. Offline

    MinecraftDorado

    @Scimiguy What of the time is because I'm just trying to make a push. Player.getPlayer (), use it to get the name of the player and to give the effect. And I appreciate more than dijieses how to fix that criticize me for not being an expert.
     
  19. Offline

    Scimiguy

    @MinecraftDorado
    It's not about criticizing, it's about saving you time.
    You're going to spend a long time trying to solve this simple problem, when you're not ready for it.
     
  20. Offline

    MinecraftDorado

    @Scimiguy Precisely why you think this post ...
     
  21. Offline

    Reynergodoy

    wth pleeeeeeeease learn the basic english of the meaning of words instead using the google translator
    learning english will enable us to help you
    why are you using join event?
    join means "entrar"
    entrar en lo coche
    he will WASTE time, and won't solve the problem
    links for english course
    http://livemocha.com/
    link for java course
    http://youtube.com
     
    Last edited by a moderator: Nov 8, 2015
  22. Offline

    mcdorli

    Link him more useful links for java tutorials because of tbe reasons I mentioned in the another thread, like this:


    This one is the best. There are spanish ones too, Im sure.
     
  23. Offline

    MinecraftDorado

    @Reynergodoy
    We already had changed, but still does not work.

    And sorry for not knowing English
     
  24. Offline

    mythbusterma

    @mcdorli

    For the record, the New Boston is still awful.


    @MinecraftDorado

    That's not a proper event handler, look at the Bukkit tutorial for examples.
     
  25. Offline

    mcdorli

    Yeah, it is, but that's why I said "This one is the best. ". The best is to get something in your hands (a book for example) or go to a course. Interaction can change how much time you spend learning java.
     
  26. Offline

    MinecraftDorado

  27. Offline

    mcdorli

    The easiest way is to learn java. It's very important knowing, what you should cast and what not. But basically:

    1.: You can't cast an event in to a player, use e.getEntity() or e.getPlayer() instead
    2.: When you do

    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 18, 1));

    then you basically give the player a potions effect for 18 ticks (I highlighted, where you messed up),
    1 second is 20 ticks => 18 seconds i 360

    (the arrow (=>) is the thus in mathematics)

    Simplifed english

    1.: Doing "Player player = (Player) e" is wrong, use "Player player = e.getPlayer()" and then in the if do "player.getInventory()..."

    2.: You must use ticks with functions, 1 sec = 20 tick, 18 sec = 360 ticks, change the "18" to 360 in the new PotionEffect()

    Fun fact: I tried to put this in to the google translator, to check out, what it says, I litterally got "You must use all your fleas. 1 second 20 fleas, 18 seconds 360 fleas"....
     
    Last edited: Nov 8, 2015
  28. Offline

    Scimiguy

    @mcdorli
    Your point? I'm always using all my fleas when I'm programming too
     
  29. Offline

    mythbusterma

    @mcdorli

    In Google translate's defence, it simply picked the wrong meaning of "tick," as it also can mean a creature similar to a flea.
     
  30. Offline

    MinecraftDorado

    @mcdorli This is my current code, but it does not work.
    Code:
            public void PlayerItemHeldEvent(Player player, int previous, int current) {
               
           
            if(player.getPlayer().getItemInHand().getType() == Material.STICK);
                        player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 360, 1));
           
        }
     
Thread Status:
Not open for further replies.

Share This Page