Linking effects with an items given name.

Discussion in 'Plugin Development' started by tommyhoogstra, Sep 13, 2013.

Thread Status:
Not open for further replies.
  1. I do, yes :)
    Should I send the address to you in a PM?
     
  2. Offline

    tommyhoogstra

    Yeah, and read my last edit on page 1 :)
    NEVER MIND fixed it

    New Issue: .getview seems to be erroring because its not apart of this event, is there an alternate?[​IMG]
     
  3. just remove the "getView()." and it'll work fine
     
  4. Offline

    tommyhoogstra

    PeterK
    With new features, new problems arise.
    Code:java
    1. @EventHandler
    2. public void onItemHeld(PlayerItemHeldEvent event)
    3. {
    4. Player player = (Player) event.getPlayer();
    5. ItemStack[] playerArmor = player.getInventory().getArmorContents();
    6.  
    7. if( getCustomName(event.getPlayer().getItemInHand()) == "Zeroxes Doombringer" )
    8. {
    9.  
    10. if( getCustomName(playerArmor[3]) != null && getCustomName(playerArmor[3]).equalsIgnoreCase("Zeroxes Bone Visage")
    11. && getCustomName(playerArmor[2]) != null && getCustomName(playerArmor[2]).equalsIgnoreCase("Zeroxes Shadow Plate")
    12. && getCustomName(playerArmor[1]) != null && getCustomName(playerArmor[1]).equalsIgnoreCase("Zeroxes Platelegs")
    13. && getCustomName(playerArmor[0]) != null && getCustomName(playerArmor[0]).equalsIgnoreCase("Zeroxes Moonlanders") )
    14. {
    15. player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, Integer.MAX_VALUE,4));
    16. player.sendMessage("You have equipped the god set of " + ChatColor.AQUA + "Zerox");
    17. }else // Not wearing the kit or not holding item
    18. {
    19. player.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
    20. }
    21. //
    22. // End Zerox Set
    23. //
    24. }
    25.  

    using that code, that you have provided me with (not sure if its meant to be positioned like that), the user doesn't gain the effects at all.
    I tried, dropping the weapon, swapping to it, reequipping my armor, etc. No output at all.
     
  5. what about debug output? Does this part:
    if( getCustomName(event.getPlayer().getItemInHand())=="Zeroxes Doombringer")
    go through?
     
  6. Offline

    tommyhoogstra

    PeterK
    [​IMG]
    Upon scrolling to the first slot in which doombringer was in. No result.

    perhaps an issue here:
    Code:java
    1. public static String getCustomName(ItemStack i)
    2. {
    3. if( i == null ) return null;
    4. if( i.hasItemMeta() && i.getItemMeta().hasDisplayName() ) {
    5. return ChatColor.stripColor(i.getItemMeta().getDisplayName());
    6. }
    7. return null;
    8. }
     
  7. hm instead of this:
    Code:
    event.getPlayer().getItemInHand()
    use this:
    Code:
    event.getPlayer().getInventory().getItem(event.getNewSlot())
     
  8. Offline

    tommyhoogstra

  9. there's one bracket missing after event.getNewSlot()
     
  10. Offline

    tommyhoogstra

    PeterK nothing is outputted still, after my embarrassing mistake with one bracket -.-.
    Code:
        if( getCustomName(event.getPlayer().getInventory().getItem(event.getNewSlot())) == "Zeroxes Doombringer" )
            {
            player.sendMessage("Test");
     
  11. Code:
    event.getPlayer().sendMessage(getCustomName(event.getPlayer().getInventory().getItem(event.getNewSlot())));
    put this above the if-statement
     
    tommyhoogstra likes this.
  12. Offline

    tommyhoogstra

    Works! so it must be the if statement itself?
     
  13. so that outputs the name correctly?
    if that's the case, change the if-statement to this:
    Code:java
    1.  
    2. if( getCustomName(event.getPlayer().getInventory().getItem(event.getNewSlot())) != null && getCustomName(event.getPlayer().getInventory().getItem(event.getNewSlot())).equalsIgnoreCase("itemname") )
    3.  
     
  14. Offline

    tommyhoogstra

    PeterK
    Have my babies, works now!

    Quick question with that
    Will that work with multiple names, e.g. "itemname" || "itemname2"
    Not that I have to do that, just might be a future thing.
     
  15. yes, it should work. just add multiple comparisons like this:
    Code:
    if( getCustomName(someItem) != null && (getCustomName(someItem).equalsIgnoreCase("option1") || getCustomName(someItem).equalsIgnoreCase("option2")) )
    {
    ...
    }
     
  16. Offline

    tommyhoogstra

    Sweet.

    With the new event it only detects scrolling of items, if a user were to open there inventory and move another item it, it doesn't trigger the even't. This will probably be a whole different public void right?
     
  17. You can keep listening to the inventoryclosevent to avoid this:
    Code:java
    1.  
    2. @EventHandler
    3. public void onInventoryClose( InventoryClosEvent event )
    4. {
    5. if( getCustomName(event.getPlayer().getItemInHand()) != null && getCustomName(event.getPlayer().getItemInHand()).equalsIgnoreCase("Zeroxes Doombringer") )
    6. {
    7. if( getCustomName(playerArmor[3]) != null && getCustomName(playerArmor[3]).equalsIgnoreCase("Zeroxes Bone Visage")
    8. && getCustomName(playerArmor[2]) != null && getCustomName(playerArmor[2]).equalsIgnoreCase("Zeroxes Shadow Plate")
    9. && getCustomName(playerArmor[1]) != null && getCustomName(playerArmor[1]).equalsIgnoreCase("Zeroxes Platelegs")
    10. && getCustomName(playerArmor[0]) != null && getCustomName(playerArmor[0]).equalsIgnoreCase("Zeroxes Moonlanders") )
    11. {
    12. player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, Integer.MAX_VALUE,4));
    13. player.sendMessage("You have equipped the god set of " + ChatColor.AQUA + "Zerox");
    14. }
    15. else // Not wearing the kit or not holding item
    16. {
    17. player.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
    18. }
    19. //
    20. // End Zerox Set
    21. //
    22. }
    23. else
    24. {
    25. player.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
    26. }
    27. }
    28.  
     
    tommyhoogstra likes this.
  18. Offline

    tommyhoogstra

    So just by adding that for each set will prevent people abusing shit like mad :)
     
  19. yes, keep in mind the code from above is untested, though ;P

    The ItemStack you need is here: event.getItem().getItemStack();
    Just check if the dropped item is one of your special ones and apply/remove effects

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

    tommyhoogstra


    So under the drop event I would check if that item stack was dropped

    Also, upon scrolling off the weapon, the effect remains.
     
  21. Add an else-statement in line 25 of that code, removing the effect.

    GTG, You'll have to take care of yourself for now ;P If you run into any problems, just post them here, I'll check back later.

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

    tommyhoogstra

    PeterK
    Fixed it, supposedly I had inventory set to strength and itemheld set to speed!
    I feel bad now :(

    Edit: All i have left now is to work on a Pickup event for each god, and to work out the drop event.

    Code:java
    1. public void onItemPickup( PlayerPickupItemEvent event){
    2. Player player = (Player) event.getPlayer();
    3. ItemStack[] playerArmor = player.getInventory().getArmorContents();
    4.  
    5. if( getCustomName(event.getPlayer().getItemInHand()) != null && getCustomName(event.getPlayer().getItemInHand()).equalsIgnoreCase("Zeroxes Doombringer") )
    6. {
    7. if( getCustomName(playerArmor[3]) != null && getCustomName(playerArmor[3]).equalsIgnoreCase("Zeroxes Bone Visage")
    8. && getCustomName(playerArmor[2]) != null && getCustomName(playerArmor[2]).equalsIgnoreCase("Zeroxes Shadow Plate")
    9. && getCustomName(playerArmor[1]) != null && getCustomName(playerArmor[1]).equalsIgnoreCase("Zeroxes Platelegs")
    10. && getCustomName(playerArmor[0]) != null && getCustomName(playerArmor[0]).equalsIgnoreCase("Zeroxes Moonlanders") )
    11. {
    12. player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, Integer.MAX_VALUE,4));
    13. player.sendMessage("You have equipped the god set of " + ChatColor.AQUA + "Zerox");
    14. }
    15. else // Not wearing the kit or not holding item
    16. {
    17. player.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
    18. }
    19.  
    20. //
    21. // End Zerox Set
    22. //
    23. }
    24. else{ player.removePotionEffect(PotionEffectType.INCREASE_DAMAGE); }
    25. }
    26.  
    27.  


    I honestly don't see why that doesn't work, it should check the item you're holding upon picking an item up, right?
     
  23. Hm. When the event is called, the player is not yet holding the item. Get the first empty slot of their Inventory and check if that's their currently selected hotbar slot to see if the picked up item goes in their hand immediately:
    player.getInventory().firstEmpty == player.getInventory().getHeldItemSlot()
     
  24. Offline

    tommyhoogstra

    That would work, So it would be at the very start of the event? before the if statement if im correct.
     
  25. Offline

    tommyhoogstra

    PeterK
    [​IMG]
    Tried adding () at end of firstEmpty, thought the first side was a variable.
    I can tell i'm doing something wrong here :S

    thanks
     
  26. whoa whoa, that was meant to be an if-statement :p And Yea, forgot the brackets there, sorry.
    Code:java
    1.  
    2. // If the item will not land in hand, stop handling.
    3. if( player.getInventory().firstEmpty() != player.getInventory().getHeldItemSlot() ) return;
    4.  
     
  27. Offline

    tommyhoogstra

    Aha, and you changed that a bit as well, cheater! Will try it out now, thanks.

    PeterK
    I am officially confused, is this meant for the pickup event right?
    I just inserted it at the top under the itemstack[] playerArmor variable.
    Code:java
    1. @EventHandler
    2. public void onItemPickup(PlayerPickupItemEvent event){
    3. Player player = (Player) event.getPlayer();
    4. ItemStack[] playerArmor = player.getInventory().getArmorContents();
    5. if( player.getInventory().firstEmpty() != player.getInventory().getHeldItemSlot() ) return;
    6. if( getCustomName(event.getPlayer().getItemInHand()) != null && getCustomName(event.getPlayer().getItemInHand()).equalsIgnoreCase("Zeroxes Doombringer") )
    7. {
    8. if( getCustomName(playerArmor[3]) != null && getCustomName(playerArmor[3]).equalsIgnoreCase("Zeroxes Bone Visage")
    9. && getCustomName(playerArmor[2]) != null && getCustomName(playerArmor[2]).equalsIgnoreCase("Zeroxes Shadow Plate")
    10. && getCustomName(playerArmor[1]) != null && getCustomName(playerArmor[1]).equalsIgnoreCase("Zeroxes Platelegs")
    11. && getCustomName(playerArmor[0]) != null && getCustomName(playerArmor[0]).equalsIgnoreCase("Zeroxes Battle Boots") )
    12. {
    13. player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, Integer.MAX_VALUE,1));
    14. player.sendMessage(ChatColor.YELLOW + "You have equipped the god set of " + ChatColor.AQUA + "Zerox");
    15. }
    16. else // Not wearing the kit or not holding item
    17. {
    18. player.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
    19. }
    20.  
    21.  
    22. }
    23. else{ player.removePotionEffect(PotionEffectType.INCREASE_DAMAGE); }
    24. //
    25. // End Zerox Set
    26. //
    27. if( getCustomName(event.getPlayer().getItemInHand()) != null && getCustomName(event.getPlayer().getItemInHand()).equalsIgnoreCase("Tathalyns Windshear") ) {
    28.  
    29. if( getCustomName(playerArmor[3]) != null &&
    30. getCustomName(playerArmor[3]).equalsIgnoreCase("Tathalyns Hawk eye")
    31. && getCustomName(playerArmor[2]) != null &&
    32. getCustomName(playerArmor[2]).equalsIgnoreCase("Tathalyns Fleece")
    33. && getCustomName(playerArmor[1]) != null &&
    34. getCustomName(playerArmor[1]).equalsIgnoreCase("Tathalyns Spiked Stockings")
    35. && getCustomName(playerArmor[0]) != null &&
    36. getCustomName(playerArmor[0]).equalsIgnoreCase("Tathalyns Boots of Mobility") )
    37. {
    38. player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE,0));
    39. player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE,0));
    40. player.sendMessage(ChatColor.YELLOW + "You have equipped the god set of " + ChatColor.AQUA + "Tathalyn");
    41. }
    42. else // Not wearing the kit
    43. {
    44. player.removePotionEffect(PotionEffectType.SPEED);
    45. player.removePotionEffect(PotionEffectType.JUMP);
    46. }
    47. }
    48. else{
    49. player.removePotionEffect(PotionEffectType.SPEED);
    50. player.removePotionEffect(PotionEffectType.JUMP);
    51. }
    52. //
    53. // End Mazurel Set
    54. //
    55. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  28. Okay, that's step one. Now you need to replace the player.getItemInHand() part with the ItemStack being picked up. Try this: event.getItem().getItemStack()
     
  29. Offline

    tommyhoogstra

    PeterK inside that new if statement?
     
Thread Status:
Not open for further replies.

Share This Page