Inventory GUI Help

Discussion in 'Plugin Development' started by andrivard4, May 22, 2014.

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

    andrivard4

    Hi, I have a plugin that I'm working on, it's sorta like a beacon to go. I'm trying to make it GUI based and I am failing at. Basically, the best I have is this:
    http://pastebin.com/fBZm8mzs
    It starts up fine, and runs fine but it is applied to the whole inventory meaning that the event.setCancelled(true); doesn't just lock the "Beacon power" inventory, it locks the players inventory as well. What error did I make?
    *Note* I am very new to coding and GUI's, most of my knowledge of this stuff comes from YouTube, so the code might be very bad XD.

    And YES I know I spelt tier wrong, I will fix it once it's done. :p
     
  2. Offline

    caderape

    u should try with getRawSlot(), and not getSlot()
     
  3. Offline

    xTigerRebornx

    andrivard4 You don't actually check if they are interacting with a specific inventory, so the code is executed everytime the event is fired
     
  4. Offline

    chingo247

    The best thing you can do is giving the inventory a (unique) title to recognize it. So only cancel the event if the player was clicking in your GUI.

    As above mentioned, u should use getRawslot() instead of getSlot(). When u execute a statement like if(slot == 1) it will return true at 3 different locations of your GUI (Upper Inventory, PlayerInventory and the HotBar). U can prevent this by using rawslots.
     
  5. Offline

    andrivard4

    Okay, ill give it a try, Thanks!

    chingo247
    I tried changing it to getRawSlot() and it still does the same thing.
    xTigerRebornx
    How would I check what specific inventory they are interacting with?

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

    caderape

    i didnt noticed but yeah, there's not chance to work. U called ur inventory "Beacon Power!"

    #if (inventory.getname.equalsignorecase("beacon Power!"){
    now it will check the name and find the good inventory. then, u juste have to check the slot and if there's an interaction with an item.
    #itemstack item = e.getcurrentitem(); int slot = e.getsawslot();
    then :
    if ((item.gettype() != null) && (slot == 0)){"your code"}}
     
  7. Offline

    andrivard4

    caderape
    I tried
    Code:java
    1. if (inventory.getname.equalsignorecase("beacon Power!")){

    but theres an error with inventory and when I import it with bukkit, I can't use .getname, only .class
     
  8. Offline

    mine-care

    Can we see full code?
     
  9. Offline

    Gater12

    andrivard4
    It was just psuedo code. If you are familiarized with the Java syntax you would be able to know how to fix it.
    Code:java
    1. if(event.getInventory().getName().equalsIgnoreCase("STRING HERE"))
     
  10. Offline

    caderape

    yep, it was just for show. if u wanna do it with a string, u have to put the chatcolor too. And be Carefull with the space.
    the best way is to create a yml and add the title in. then a :

    inventory.getname.equalsignorecase(getconfig.getstring("title"))
     
  11. Offline

    chingo247

    I don't know if inventory.getName() does the same as inventory.getTitle() (it probably does), but when i faced a similar problem I used getTitle() and it worked for me.

    Anyway why check on slot indexes? Why not use the itemstack to determine what power-up should be used?
    It's the most easiest way, you dont have to check what inventory has been clicked in because the powerups are unmovable anyway so they only exist in the powerup gui. Secondly u know exactly what powerup the player wants to use.
     
Thread Status:
Not open for further replies.

Share This Page