Some questions

Discussion in 'Plugin Development' started by Growl, Mar 16, 2014.

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

    Growl

    Hi guys! I have some questions to you:
    1. If I have the method with "InvenoryClickEvent", how to get the Player from this event and send him a messege "Hello"?
    2. I want plugin to check if player picks up an item with name "Needed Stick". And if so - to place it on the "0" place in the inventory(To move all items on +1 slot). Look at the image with numbers in the inventory:
    [​IMG]
    Please help me!
     
  2. Offline

    Maulss

  3. Offline

    jeussa

    Hi dere Growl,

    getting the player who clicked at an InventoryInteractEvent can be done using:
    Code:java
    1. (Player)event.getWhoClicked();


    Next to check the displayname of the item, use the following:

    Code:java
    1. ItemStack item = event.getCurrentItem();
    2. if(item.getType() == Material.AIR){ return; }
    3. ItemMeta itemMeta = item.getItemMeta();
    4. if(itemMeta.getDisplayName().equalsIgnoreCase("Needed Stick")){
    5. //TODO add your code here
    6. }


    for moving the items, I would recommend you try place the following instead of '//TODO add your code here'

    Code:java
    1. PlayerInventory inv = event.getPlayer().getInventory();
    2.  
    3. for(int slotID = 35; slotID > 0; slotID --){
    4. inv.setItem(slotID + 1, inv.getItem(slotID));
    5. }
    6.  
    7. inv.setItem(0, item);

    I am not sure though if the example above works, for I've never tried anything like this before.
     
Thread Status:
Not open for further replies.

Share This Page