PlayerDeathEvent Help

Status
This thread has been locked.

vPixelZ

Feedback score
0
Posts
316
Reactions
101
Resources
0
So basically, I want this plugin to not drop any unenchanted armor on a players death. It works well unless the armor piece are damaged. Un-damaged armor pieces won't drop. Which is supposed to be like that. Damaged armor drops however. Which was not my intention at all. If someone could fix my code up that'd be awesome!

My code:
Code:
      @EventHandler[/COLOR][/FONT]
[FONT=Droid Sans][COLOR=rgb(44, 44, 44)]      public void onPlayerDeath(PlayerDeathEvent e)
      {
        for (ItemStack item : e.getDrops())
        {
          Material mat = item.getType();
          if (((mat == Material.DIAMOND_HELMET) || (mat == Material.DIAMOND_CHESTPLATE) || (mat == Material.DIAMOND_LEGGINGS) || (mat == Material.DIAMOND_BOOTS) || (mat == Material.DIAMOND_SWORD)) &&
            (item.getEnchantments().isEmpty())) {
            item.setType(Material.AIR);
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Lacroix

creativity at its finest!
Supreme
Feedback score
40
Posts
1,663
Reactions
771
Resources
0
So basically, I want this plugin to not drop any unenchanted armor on a players death. It works well unless the armor piece are damaged. Un-damaged armor pieces won't drop. Which is supposed to be like that. Damaged armor drops however. Which was not my intention at all. If someone could fix my code up that'd be awesome!

My code:
Code:
      @EventHandler[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT]
[FONT=Droid Sans][COLOR=rgb(44, 44, 44)][FONT=Georgia][COLOR=rgb(20, 20, 20)][FONT=Droid Sans][COLOR=rgb(44, 44, 44)]      public void onPlayerDeath(PlayerDeathEvent e)
      {
        for (ItemStack item : e.getDrops())
        {
          Material mat = item.getType();
          if (((mat == Material.DIAMOND_HELMET) || (mat == Material.DIAMOND_CHESTPLATE) || (mat == Material.DIAMOND_LEGGINGS) || (mat == Material.DIAMOND_BOOTS) || (mat == Material.DIAMOND_SWORD)) &&
            (item.getEnchantments().isEmpty())) {
            item.setType(Material.AIR);
Why don't you make it so it doesnt drop items period?[DOUBLEPOST=1457063067][/DOUBLEPOST]And that code will be.
@EventHandler
public void onPlayerDeath(PlayerDeathEvent e) {
e.setDroppedExp(1);

e.getDrops().clear();
e.getDrops().add(new ItemStack(Material.AIR,
 

DrPiggy

Deactivated
Feedback score
0
Posts
99
Reactions
32
Resources
0
Why don't you make it so it doesnt drop items period?[DOUBLEPOST=1457063067]
[/DOUBLEPOST]And that code will be.
@EventHandler
public void onPlayerDeath(PlayerDeathEvent e) {
e.setDroppedExp(1);

e.getDrops().clear();
e.getDrops().add(new ItemStack(Material.AIR,
Instead of doing the exact oposit of what he aaked for, maybe try to help?
So basically, I want this plugin to not drop any unenchanted armor on a players death. It works well unless the armor piece are damaged. Un-damaged armor pieces won't drop. Which is supposed to be like that. Damaged armor drops however. Which was not my intention at all. If someone could fix my code up that'd be awesome!

My code:
Code:
      @EventHandler[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT]
[FONT=Droid Sans][COLOR=rgb(44, 44, 44)][FONT=Georgia][COLOR=rgb(20, 20, 20)][FONT=Droid Sans][COLOR=rgb(44, 44, 44)]      public void onPlayerDeath(PlayerDeathEvent e)
      {
        for (ItemStack item : e.getDrops())
        {
          Material mat = item.getType();
          if (((mat == Material.DIAMOND_HELMET) || (mat == Material.DIAMOND_CHESTPLATE) || (mat == Material.DIAMOND_LEGGINGS) || (mat == Material.DIAMOND_BOOTS) || (mat == Material.DIAMOND_SWORD)) &&
            (item.getEnchantments().isEmpty())) {
            item.setType(Material.AIR);
I think it would be a better idea to clear() the list and add only the enchanted back. I think it would fix the problem ☺
 

Tyler

Developer
Supreme
Feedback score
14
Posts
2,589
Reactions
2,238
Resources
0
If the damage is a problem, maybe check the durability of the item being dropped.
 

7rory768

Feedback score
3
Posts
27
Reactions
8
Resources
0
getDrops returns a collection of item entities. Ofcourse you can use a FOR loop but it's not efficient for when a lot of players die.
I agree you should first check if they have at least one piece of diamond armour before looping
 
Status
This thread has been locked.
Top