mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-11-04 11:03:43 +01:00 
			
		
		
		
	Fixed a dupe bug
This commit is contained in:
		@@ -1,3 +1,7 @@
 | 
				
			|||||||
 | 
					Version 2.1.110
 | 
				
			||||||
 | 
					    Fixed a dupe bug
 | 
				
			||||||
 | 
					    Added Lithuanian locale (thanks Vyciokazz)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Version 2.1.109
 | 
					Version 2.1.109
 | 
				
			||||||
    Block Cracker will now correctly crack stone_bricks during Berserk again
 | 
					    Block Cracker will now correctly crack stone_bricks during Berserk again
 | 
				
			||||||
    Added Lily_Of_The_Valley to the Bonus Drops list in config.yml (you'll probably want to add this manually) which enables it to double drop
 | 
					    Added Lily_Of_The_Valley to the Bonus Drops list in config.yml (you'll probably want to add this manually) which enables it to double drop
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -41,7 +41,9 @@ import org.bukkit.event.block.*;
 | 
				
			|||||||
import org.bukkit.inventory.ItemStack;
 | 
					import org.bukkit.inventory.ItemStack;
 | 
				
			||||||
import org.bukkit.metadata.MetadataValue;
 | 
					import org.bukkit.metadata.MetadataValue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.HashSet;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.Set;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class BlockListener implements Listener {
 | 
					public class BlockListener implements Listener {
 | 
				
			||||||
    private final mcMMO plugin;
 | 
					    private final mcMMO plugin;
 | 
				
			||||||
@@ -53,6 +55,20 @@ public class BlockListener implements Listener {
 | 
				
			|||||||
    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 | 
					    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 | 
				
			||||||
    public void onBlockDropItemEvent(BlockDropItemEvent event)
 | 
					    public void onBlockDropItemEvent(BlockDropItemEvent event)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        //Track how many "things" are being dropped
 | 
				
			||||||
 | 
					        HashSet<Material> uniqueMaterials = new HashSet<>();
 | 
				
			||||||
 | 
					        boolean dontRewardTE = false; //If we suspect TEs are mixed in with other things don't reward bonus drops for anything that isn't a block
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for(Item item : event.getItems()) {
 | 
				
			||||||
 | 
					            uniqueMaterials.add(item.getItemStack().getType());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(uniqueMaterials.size() > 1) {
 | 
				
			||||||
 | 
					            //Too many things are dropping, assume tile entities might be duped
 | 
				
			||||||
 | 
					            //Technically this would also prevent something like coal from being bonus dropped if you placed a TE above a coal ore when mining it but that's pretty edge case and this is a good solution for now
 | 
				
			||||||
 | 
					            dontRewardTE = true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for(Item item : event.getItems())
 | 
					        for(Item item : event.getItems())
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            ItemStack is = new ItemStack(item.getItemStack());
 | 
					            ItemStack is = new ItemStack(item.getItemStack());
 | 
				
			||||||
@@ -66,6 +82,13 @@ public class BlockListener implements Listener {
 | 
				
			|||||||
                        && !Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.WOODCUTTING, is.getType()))
 | 
					                        && !Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.WOODCUTTING, is.getType()))
 | 
				
			||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            //If we suspect TEs might be duped only reward block
 | 
				
			||||||
 | 
					            if(dontRewardTE) {
 | 
				
			||||||
 | 
					                if(!is.getType().isBlock()) {
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (event.getBlock().getMetadata(mcMMO.BONUS_DROPS_METAKEY).size() > 0) {
 | 
					            if (event.getBlock().getMetadata(mcMMO.BONUS_DROPS_METAKEY).size() > 0) {
 | 
				
			||||||
                BonusDropMeta bonusDropMeta = (BonusDropMeta) event.getBlock().getMetadata(mcMMO.BONUS_DROPS_METAKEY).get(0);
 | 
					                BonusDropMeta bonusDropMeta = (BonusDropMeta) event.getBlock().getMetadata(mcMMO.BONUS_DROPS_METAKEY).get(0);
 | 
				
			||||||
                int bonusCount = bonusDropMeta.asInt();
 | 
					                int bonusCount = bonusDropMeta.asInt();
 | 
				
			||||||
@@ -80,44 +103,6 @@ public class BlockListener implements Listener {
 | 
				
			|||||||
            event.getBlock().removeMetadata(mcMMO.BONUS_DROPS_METAKEY, plugin);
 | 
					            event.getBlock().removeMetadata(mcMMO.BONUS_DROPS_METAKEY, plugin);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 | 
					 | 
				
			||||||
    public void onBlockDropItemEvent(BlockDropItemEvent event)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        for(Item item : event.getItems())
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            ItemStack is = new ItemStack(item.getItemStack());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if(event.getBlock().getMetadata(mcMMO.doubleDrops).size() > 0)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                List<MetadataValue> metadataValue = event.getBlock().getMetadata(mcMMO.doubleDrops);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                BonusDrops bonusDrops = (BonusDrops) metadataValue.get(0);
 | 
					 | 
				
			||||||
                Collection<ItemStack> potentialDrops = (Collection<ItemStack>) bonusDrops.value();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if(potentialDrops.contains(is))
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    event.getBlock().getState().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                event.getBlock().removeMetadata(mcMMO.doubleDrops, plugin);
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                if(event.getBlock().getMetadata(mcMMO.tripleDrops).size() > 0) {
 | 
					 | 
				
			||||||
                    List<MetadataValue> metadataValue = event.getBlock().getMetadata(mcMMO.tripleDrops);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    BonusDrops bonusDrops = (BonusDrops) metadataValue.get(0);
 | 
					 | 
				
			||||||
                    Collection<ItemStack> potentialDrops = (Collection<ItemStack>) bonusDrops.value();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    if (potentialDrops.contains(is)) {
 | 
					 | 
				
			||||||
                        event.getBlock().getState().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
 | 
					 | 
				
			||||||
                        event.getBlock().getState().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    event.getBlock().removeMetadata(mcMMO.tripleDrops, plugin);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Monitor BlockPistonExtend events.
 | 
					     * Monitor BlockPistonExtend events.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user