Solved Itemstack help

Discussion in 'Plugin Development' started by Hoodiecraft, Apr 8, 2014.

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

    Hoodiecraft

    Ok so I created a itemstack got that all working but I just cant figure out how to get this custom item to work in a player interact event, now this event is in a seperate class from this item also, its in a listener class to listen for the left click event of this item but I just cant seem to get the item to be that left click event item. If anyone knows please help!

    Code:java
    1. package me.dmbowen98765.extarUtilPV;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.block.Action;
    8. import org.bukkit.event.player.PlayerInteractEvent;
    9. import org.bukkit.inventory.ItemStack;
    10.  
    11. public class itemsClickable implements Listener {
    12. public static Main plugin;
    13.  
    14. @EventHandler
    15. public void onPlayerUse(PlayerInteractEvent event){
    16. Player player = event.getPlayer();
    17.  
    18. if(player.getItemInHand().getType() == Material.(Bag)){
    19.  
    20.  
    21. }
    22.  
    23. }
    24. }
    25.  

    Thats all I have for the listener class so far/\
    |
    this is the custom item:
    Code:java
    1. }
    2. ItemStack Bag = new ItemStack(Material.GOLD_NUGGET);
    3. {
    4. ItemMeta itemmeta = Bag.getItemMeta();
    5. ArrayList<String> im = new ArrayList<String>();
    6. itemmeta.setDisplayName(ChatColor.GOLD + "Golden bag of holding");
    7. im.add(ChatColor.DARK_PURPLE + "1 double chests");
    8. im.add(ChatColor.DARK_PURPLE + "worth of storage!");
    9. itemmeta.setLore(im);
    10. Bag.setItemMeta(itemmeta);
    11. }
    12. }
     
  2. Offline

    iPoke111

    Hoodiecraft
    You're doing it wrong, I'll explain.
    First, you're using getType() and Bag is not a material.
    Second, the listener doesn't have a clue what 'Bag' is.
    Third, your parentheses are wrong.

    what you need to do: Put 'static' infront of your 'ItemStack Bag = new ItemStack...' line.
    In the if(player.getItemInHand())... line, make it if(Player.getItemInHand() == Class.Bag) { where Class is the name of the class with 'Bag' in it.

    Hope I helped.
     
  3. Offline

    Hoodiecraft

    Now I have this but the message test didnt work!
    Code:java
    1. @EventHandler
    2. public void onPlayerUse(PlayerInteractEvent event){
    3. Player player = event.getPlayer();
    4.  
    5. if(event.getAction().equals(Action.RIGHT_CLICK_AIR)||event.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
    6. if(player.getItemInHand() == Main.Bag) {
    7. player.sendMessage("TEST");
    8.  
    9. }
    10. }
    11.  
    12. }
    13. }
     
  4. Offline

    khave

    p.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.GOLD + "Golden bag of holding");

    You also need null pointer checks, if you don't want errors.
     
  5. Offline

    Hoodiecraft

    Yep that worked khave thatnks
     
    khave likes this.
Thread Status:
Not open for further replies.

Share This Page