How To Create An If Event For A Clicked Item In An Inventory

Discussion in 'Plugin Development' started by KingOfTheEast01, Dec 30, 2016.

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

    KingOfTheEast01

    Hey guys, my name is Lucas. I've been wondering how to check if there is an item in a specific spot in an inventory. I've been using an if statement to check for a certain material type, however, this hasn't been working as expected.

    Here's what I've tried. Please keep in mind that this is in an inventory click event though, hence the object 'clicked'.

    Here's the if statement:

    if (clicked.getType ().equals (Material.GOLD_INGOT)) {

    }

    Sent from my SM-G935V using Tapatalk
     
  2. Offline

    Jakeeeee

    There is no need to create a whole new event for it because they already have it implemented. InventoryClickEvent#getSlot (starts the first slot labeled as 1) and InventoryClickEvent#getRawSlot ( starts the first slot labeled as 0)
     
  3. Offline

    KingOfTheEast01

    That has nothing to do with what I'm trying to do. How does it help to get slots from the inventory I'm clicking in, if I'm trying to edit a different inventory?

    Sent from my SM-G935V using Tapatalk
     
  4. Online

    timtower Administrator Administrator Moderator

    KingOfTheEast01 and Asparock like this.
  5. Offline

    oriamrm

    I once designed I code for getting the Item. The problem is that sometimes it's event.getCurrentItem() and sometimes it's the item on the player's curser... Just check wich one of them is Material.AIR and use the other one.
     
    KingOfTheEast01 likes this.
  6. Offline

    KingOfTheEast01

    Thanks guys. I'll see if I can get it to work now with your advice.

    Sent from my SM-G935V using Tapatalk
     
  7. Offline

    KingOfTheEast01

    Sorry about not replying guys. I discontinued working on this project for now, until I feel like coming back to it, if I ever do, but ou guys helped out a lot! Your help is much appreciated. Thanks guys!

    Sent from my SM-G935V using Tapatalk
     
  8. Offline

    JanTuck

    Remember to check for null before getting any data from the itemstack.

    Sendt fra min ALE-L21 med Tapatalk
     
  9. Offline

    KingOfTheEast01

    Oh, I'm not working on this anymore mate! Read my last comment. XD

    Sent from my SM-G935V using Tapatalk
     
  10. Offline

    Brendan22


    This may help out if you ever go back to it.
     
  11. Offline

    Zombie_Striker

    @Brendan22
    NEVER recommend the BcBroz. He teaches so many bad habits and some of the tutorials have been outdated. If you Need to recommend tutorials (*which you don't, there are plenty of written resources in the Resources forum), recommend PogoStickDev.
     
    ipodtouch0218 likes this.
  12. Offline

    Brendan22

    @Zombie_Striker
    What kind of bad habits? I really do want to know because I used his tutorials to start off and I want my code to be ass efficient as possible, thanks!
     
  13. Offline

    Zombie_Striker

    @Brendan22
    1. Logging his own plugins.
    2. He steals minecraft's logger instead of using getLogger (when he does not even need to use it)
    3. Just the amount of videos where he has to go back to his code shows you how ill prepared and un-optimied his code is.
    4. He uses label instead of cmd.getName()
    5. The fact that he checks the command even though his plugin only has one command.
    6. He does a lot of blind casting (he never checks if the sender is a player before casting)
    7. He has most of his code in one class, and does not fully teach OOP and how to properly distribute code.
    8. He does not always follow Java Naming Conventions. Although sometimes he does, he sometimes uses variable names like "e" and "p".
    9. A lot of violations of DRY (Don't Repeat Yourself). A lot of the time, he either copies and pastes his code or re-writes it the same way (for example, video three with the args checks. For length ==2 and ==3 they have near identical cases where only 1 line needs to be changed)
    10. He uses Async threads for tasks and calls bukkit's methods in them.
    And finally, something that does not have to do with anything about who he is/ the bad habits he has is that they are outdated. The first 50 videos came out 5 years ago. To put that into perspective, that was around 1.2.5, and was also only 1 year since bukkit was released (if I remember the dates correctly). A LOT has changed and added since then, so you should use his tutorials loosely (if at all. Again, I would recommend watching PogoStickDev if you have to learn from a video series).
     
  14. Offline

    Brendan22

    @Zombie_Striker
    Thank you for the information, I really do appreciate it. I have one question about #7. From my understanding (very little) about the OOP part are you saying that when making a plugin it is better to have many classes that perform certain smaller tasks and then call them when needed rather than have one or two very cluttered classes?
     
  15. Offline

    KingOfTheEast01

    Thanks for this. This helps out a lot.

    Sent from my SM-G935V using Tapatalk
     
  16. Offline

    johnny boy

    Yes, to make it look tidier and make it more efficient!
     
Thread Status:
Not open for further replies.

Share This Page