Drop System buggy as *ELL

Discussion in 'Plugin Development' started by MordorKing78, Feb 7, 2015.

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

    MordorKing78

    So this is so buggy, Somethimes it does work most of the time it doesnt.

    Im trying to stop players from dropping certain stuff when they die
    Code:
    for(Iterator<ItemStack> iterator = e.getDrops().iterator(); iterator.hasNext(); ){
                ItemStack potato = iterator.next();
                if(potato.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Golden Apple")) {
                  iterator.remove();
               }
               if(potato.getItemMeta().getDisplayName().equals("§5Dark Sword")) {
                  iterator.remove();
               }
               if(potato.getItemMeta().getDisplayName().equals("§bIcy Sword")) {
                  iterator.remove();
               }
               if(potato.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Diamond Sword")) {
                  if(!(potato.getEnchantments().size() > 0)){
                      iterator.remove();
                  }
               }
               if(potato.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Bow")) {
                  if(!(potato.getEnchantments().size() > 0)){
                      iterator.remove();
                  }
               }
               if(potato.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Arrow")) {
                  iterator.remove();
               }
               if(potato.getItemMeta().getDisplayName().equals("§6Flame Helmet")) {
                  iterator.remove();
               }
               if(potato.getItemMeta().getDisplayName().equals("§6Flame Chestplate")) {
                  iterator.remove();
               }
               if(potato.getItemMeta().getDisplayName().equals("§6Flame Leggings")) {
                  iterator.remove();
               }
               if(potato.getItemMeta().getDisplayName().equals("§6Flame Boots")) {
                  iterator.remove();
               }
               if(potato.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Diamond Helmet")) {
                  if(!(potato.getEnchantments().size() > 0)){
                      iterator.remove();
                  }
               }
               if(potato.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Diamond Chestplate")) {
                  if(!(potato.getEnchantments().size() > 0)){
                      iterator.remove();
                  }
               }
               if(potato.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Diamond Leggings")) {
                  if(!(potato.getEnchantments().size() > 0)){
                      iterator.remove();
                  }
               }
               if(potato.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Diamond Boots")) {
                  if(!(potato.getEnchantments().size() > 0)){
                      iterator.remove();
                  }
               }
               if(potato.getItemMeta().getDisplayName().equals("§5Dark Helmet")) {
                  iterator.remove();
               }
               if(potato.getItemMeta().getDisplayName().equals("§5Dark Chestplate")) {
                  iterator.remove();
               }
               if(potato.getItemMeta().getDisplayName().equals("§5Dark Leggings")) {
                  iterator.remove();
               }
               if(potato.getItemMeta().getDisplayName().equals("§5Dark Boots")) {
                  iterator.remove();
               }
               if(potato.getItemMeta().getDisplayName().equals("§bIcy Helmet")) {
                  iterator.remove();
               }
               if(potato.getItemMeta().getDisplayName().equals("§bIcy Chestplate")) {
                  iterator.remove();
               }
               if(potato.getItemMeta().getDisplayName().equals("§bIcy Leggings")) {
                  iterator.remove();
               }
               if(potato.getItemMeta().getDisplayName().equals("§bIcy Boots")) {
                  iterator.remove();
               }
               if(potato.getItemMeta().getDisplayName().equals("§bCold Drink")) {
                  iterator.remove();
               }
    
     
    Last edited: Feb 8, 2015
  2. @MordorKing78 Sorry I could not help your issue directly, however a few things came to mind:
    [1] Why does the first line not use the 'name' variable?
    [2] Using a switch statement will make this code really efficient, so you would not have to type 'e.getItemDrop().remove();' about 20 times.
    [3] Use the PlayerDeathEvent to use getDrops() which returns a list of items and checking if that list contains the item (and then removing it from that list)?
     
  3. Offline

    nj2miami

    Many things going on here.... first let's get the ugly out of the way!
    1. Your tab convention leaves much to be desired, so I am taking points away for readability :)
    2. Holy IF statement batman! Throw all those names in a List at least and do a simple .Contains check
    3. What does 'if(!(enchants > 0))' even mean?
    4. Finally, why are you using color codes and not ChatColor?
    Now the bad:
    • What event are you triggering this from or what does your 'e' variable mean?
    and finally, the good!

    Show the whole class and I'll help you out. :)
     
  4. Offline

    MordorKing78

    @nj2miami 1. Ik
    2. Yeh, Ikr. Someone already told me to do is.
    3. if the items doesn't contain an enchantment
    4. Color Codes are so much faster why would I use ChatColor?

    e = event

    PS: I found out the error ( I think ) because in 1 eventhandler this is called:
    ignoreCancelled = true, But if I set this to false than players can (kinda) hurt people in a denied pvp area..
    Maybe do you know how to fix this?
     
  5. Offline

    Techy4198

    @MordorKing78
    1. Keep stuff tidy
    2. Good
    3. There's much better ways to do this. Can't check right now, but someone is bound to say here in the next few hours.
    4. Because ChatColor is compatible with every Bukkit server on pretty much every operating system. The § symbol is not compatible with everything and can result in chat showing things like €ÄcStu€Ä1ff instead of Stuff.
     
  6. Offline

    MordorKing78

    @Techy4198 Okay, But it is still very buggy. Do you know a fix?

    g
    @Techy4198 or do you know a better way to do it?

    I POSTED WRONG CODE:

    Code:
    for(Iterator<ItemStack> iterator = e.getDrops().iterator(); iterator.hasNext(); ){
                ItemStack potato = iterator.next();
                if(potato.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Golden Apple")) {
                     iterator.remove();
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§5Dark Sword")) {
                     iterator.remove();
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§bIcy Sword")) {
                     iterator.remove();
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Diamond Sword")) {
                     if(!(potato.getEnchantments().size() > 0)){
                         iterator.remove();
                     }
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Bow")) {
                     if(!(potato.getEnchantments().size() > 0)){
                         iterator.remove();
                     }
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Arrow")) {
                     iterator.remove();
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§6Flame Helmet")) {
                     iterator.remove();
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§6Flame Chestplate")) {
                     iterator.remove();
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§6Flame Leggings")) {
                     iterator.remove();
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§6Flame Boots")) {
                     iterator.remove();
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Diamond Helmet")) {
                     if(!(potato.getEnchantments().size() > 0)){
                         iterator.remove();
                     }
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Diamond Chestplate")) {
                     if(!(potato.getEnchantments().size() > 0)){
                         iterator.remove();
                     }
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Diamond Leggings")) {
                     if(!(potato.getEnchantments().size() > 0)){
                         iterator.remove();
                     }
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§c[NTPVP]§b Diamond Boots")) {
                     if(!(potato.getEnchantments().size() > 0)){
                         iterator.remove();
                     }
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§5Dark Helmet")) {
                     iterator.remove();
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§5Dark Chestplate")) {
                     iterator.remove();
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§5Dark Leggings")) {
                     iterator.remove();
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§5Dark Boots")) {
                     iterator.remove();
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§bIcy Helmet")) {
                     iterator.remove();
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§bIcy Chestplate")) {
                     iterator.remove();
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§bIcy Leggings")) {
                     iterator.remove();
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§bIcy Boots")) {
                     iterator.remove();
                 }
                 if(potato.getItemMeta().getDisplayName().equals("§bCold Drink")) {
                     iterator.remove();
                 }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  7. Offline

    nj2miami

    To help, you need to provide two things.

    1. The ENTIRE class, not just the snippet.
    2. The error your plugin is producing. (It must be firing a ton of NPE based on that snippet)
    Your entire page of IF's is horrible practice FYI.

    What event are you listening to in order to fire your code?
     
    Last edited: Feb 8, 2015
Thread Status:
Not open for further replies.

Share This Page