Comparing one ItemStack to another one being stored in an object

Discussion in 'Plugin Development' started by r0llingthund3r, Jan 16, 2014.

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

    r0llingthund3r

    So I have an object called an ability. Abilities take an ItemStack as a parameter. I also have a playerInteract listener to listen for people who click with the item in hand to "activate" their abilities. The problem is I don't know how to check if the item in their hand is the same item being stored in the ability object. Any help is much appreciated.
     
  2. Offline

    xTrollxDudex

    r0llingthund3r
    Don't you have a getter for the ItemStack in Ablility?
     
  3. Offline

    r0llingthund3r

    Well here's my code.
    Code:java
    1. public class Ability {
    2. String name;
    3. String lore;
    4. Material m;
    5. ItemStack is;
    6.  
    7. public Ability(Material m, String name, String lore){
    8. this.name = name;
    9. this.lore = lore;
    10. this.m = m;
    11. this.is = new ItemStack(m, 1);
    12. String[] aLore = new String[1];
    13. aLore[0] = lore;
    14. ItemMeta im = is.getItemMeta();
    15. im.setDisplayName(name);
    16. im.setLore(Arrays.asList(aLore));
    17. is.setItemMeta(im);
    18. }
    19.  
    20. public ItemStack getItem(){
    21. return is;
    22. }
    23.  
    24. public String getLore(){
    25. return lore;
    26. }
    27.  
    28. public String getName(){
    29. return name;
    30. }
    31. }
    32.  

    Code:java
    1. public class AbilityListener {
    2. public AbilityListener(ThunderSuite plugin) {
    3. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    4. }
    5.  
    6. @EventHandler
    7. public void onAbilityUse(PlayerInteractEvent e) {
    8.  
    9. Player p = e.getPlayer();
    10.  
    11. if (e.getAction().equals(Action.RIGHT_CLICK_AIR)
    12. || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    13.  
    14. if (e.getItem().equals(a.getItem())) {
    15.  
    16. }
    17. }
    18. }
    19. }


    xTrollxDudex Since I don't have an ability specified when the PlayerInteractEvent fires I don't I think I can use that method. Am I going about this entirely wrong?

    I can't seem to get the code to format correctly sorry about that.
     
  4. Offline

    xTrollxDudex

    r0llingthund3r
    Set your IDE to use spaces instead of tabs.

    Anyways, you can use the getItem method, how do you store the Ablity object? In a list?
     
  5. Offline

    r0llingthund3r

  6. Offline

    r0llingthund3r

Thread Status:
Not open for further replies.

Share This Page