Skip to content

Commit

Permalink
Additional dupe failsafes
Browse files Browse the repository at this point in the history
  • Loading branch information
nossr50 committed Oct 18, 2019
1 parent 335d708 commit 76ca7cc
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions src/main/java/com/gmail/nossr50/listeners/BlockListener.java
Expand Up @@ -58,9 +58,15 @@ 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
int blockCount = 0;

for(Item item : event.getItems()) {
//Track unique materials
uniqueMaterials.add(item.getItemStack().getType());

//Count blocks as a second failsafe
if(item.getItemStack().getType().isBlock())
blockCount++;
}

if(uniqueMaterials.size() > 1) {
Expand All @@ -69,32 +75,35 @@ public void onBlockDropItemEvent(BlockDropItemEvent event)
dontRewardTE = true;
}

for(Item item : event.getItems())
{
ItemStack is = new ItemStack(item.getItemStack());
//If there are more than one block in the item list we can't really trust it and will back out of rewarding bonus drops
if(blockCount <= 1) {
for(Item item : event.getItems())
{
ItemStack is = new ItemStack(item.getItemStack());

if(is.getAmount() <= 0)
continue;
if(is.getAmount() <= 0)
continue;

//TODO: Ignore this abomination its rewritten in 2.2
if(!Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.MINING, is.getType())
&& !Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.HERBALISM, is.getType())
//TODO: Ignore this abomination its rewritten in 2.2
if(!Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.MINING, is.getType())
&& !Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.HERBALISM, is.getType())
&& !Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.WOODCUTTING, is.getType()))
continue;

//If we suspect TEs might be duped only reward block
if(dontRewardTE) {
if(!is.getType().isBlock()) {
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) {
BonusDropMeta bonusDropMeta = (BonusDropMeta) event.getBlock().getMetadata(mcMMO.BONUS_DROPS_METAKEY).get(0);
int bonusCount = bonusDropMeta.asInt();
if (event.getBlock().getMetadata(mcMMO.BONUS_DROPS_METAKEY).size() > 0) {
BonusDropMeta bonusDropMeta = (BonusDropMeta) event.getBlock().getMetadata(mcMMO.BONUS_DROPS_METAKEY).get(0);
int bonusCount = bonusDropMeta.asInt();

for (int i = 0; i < bonusCount; i++) {
event.getBlock().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
for (int i = 0; i < bonusCount; i++) {
event.getBlock().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
}
}
}
}
Expand Down

0 comments on commit 76ca7cc

Please sign in to comment.