Skip to content

Commit

Permalink
Added fail safes against bonus drop meta not being cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
nossr50 committed May 29, 2023
1 parent 44ab8d9 commit e9a0205
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions Changelog.txt
@@ -1,5 +1,6 @@
Version 2.1.221
Fixed blast mining bonus drops not working (Thanks warriiorrrr)
Added fail safes to prevent bonus drops metadata from lingering on blocks

Version 2.1.220
(API) Added TreeFellerBlockBreakEvent class which extends FakeBlockBreakEvent (see notes), this is sent out during Tree Feller processing to allow other plugins to differentiate between Tree Feller and other fake block break events
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/com/gmail/nossr50/listeners/BlockListener.java
Expand Up @@ -140,7 +140,7 @@ public void onBlockPistonExtend(BlockPistonExtendEvent event) {
movedBlock = block.getRelative(direction);

if(BlockUtils.isWithinWorldBounds(movedBlock)) {
mcMMO.getPlaceStore().setTrue(movedBlock);
BlockUtils.setUnnaturalBlock(block);
}
}
}
Expand All @@ -166,12 +166,13 @@ public void onBlockPistonRetract(BlockPistonRetractEvent event) {

//Spigot makes bad things happen in its API
if(BlockUtils.isWithinWorldBounds(movedBlock)) {
mcMMO.getPlaceStore().setTrue(movedBlock);
BlockUtils.setUnnaturalBlock(movedBlock);
}

for (Block block : event.getBlocks()) {
if(BlockUtils.isWithinWorldBounds(block)) {
mcMMO.getPlaceStore().setTrue(block.getRelative(direction));
if(BlockUtils.isWithinWorldBounds(block) && BlockUtils.isWithinWorldBounds(block.getRelative(direction))) {
Block relativeBlock = block.getRelative(direction);
BlockUtils.setUnnaturalBlock(relativeBlock);
}
}
}
Expand All @@ -189,14 +190,13 @@ public void onEntityBlockFormEvent(EntityBlockFormEvent event)
if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld()))
return;


BlockState blockState = event.getNewState();

if(ExperienceConfig.getInstance().isSnowExploitPrevented() && BlockUtils.shouldBeWatched(blockState)) {
Block block = blockState.getBlock();

if(BlockUtils.isWithinWorldBounds(block)) {
mcMMO.getPlaceStore().setTrue(block);
BlockUtils.setUnnaturalBlock(block);
}
}
}
Expand All @@ -217,8 +217,9 @@ public void onBlockFormEvent(BlockFormEvent event)
BlockState newState = event.getNewState();

if(newState.getType() != Material.OBSIDIAN && ExperienceConfig.getInstance().doesBlockGiveSkillXP(PrimarySkillType.MINING, newState.getBlockData())) {
if(BlockUtils.isWithinWorldBounds(newState.getBlock())) {
mcMMO.getPlaceStore().setTrue(newState);
Block block = newState.getBlock();
if(BlockUtils.isWithinWorldBounds(block)) {
BlockUtils.setUnnaturalBlock(block);
}
}
}
Expand All @@ -245,7 +246,7 @@ public void onBlockPlace(BlockPlaceEvent event) {
if(BlockUtils.isWithinWorldBounds(block)) {
//NOTE: BlockMultiPlace has its own logic so don't handle anything that would overlap
if (!(event instanceof BlockMultiPlaceEvent)) {
mcMMO.getPlaceStore().setTrue(blockState);
BlockUtils.setUnnaturalBlock(block);
}
}

Expand Down Expand Up @@ -289,8 +290,8 @@ public void onBlockMultiPlace(BlockMultiPlaceEvent event) {
}

//Track unnatural blocks
for(BlockState replacedStates : event.getReplacedBlockStates()) {
mcMMO.getPlaceStore().setTrue(replacedStates);
for(BlockState replacedState : event.getReplacedBlockStates()) {
BlockUtils.setUnnaturalBlock(replacedState.getBlock());
}
}
}
Expand Down
Expand Up @@ -245,7 +245,7 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {
metaCleanupTask.runTaskTimer(pluginRef, 20, 20*60); //6000 ticks is 5 minutes
}
else if (isTracked) {
mcMMO.getPlaceStore().setTrue(block);
BlockUtils.setUnnaturalBlock(block);
entity.removeMetadata(MetadataConstants.METADATA_KEY_TRAVELING_BLOCK, pluginRef);
}
} else if ((block.getType() == Material.REDSTONE_ORE || block.getType().getKey().getKey().equalsIgnoreCase("deepslate_redstone_ore"))) {
Expand Down
Expand Up @@ -35,7 +35,7 @@ public void run() {
Block nextBlock = b.getRelative(direction);

if (nextBlock.hasMetadata(MetadataConstants.METADATA_KEY_PISTON_TRACKING)) {
mcMMO.getPlaceStore().setTrue(nextBlock);
BlockUtils.setUnnaturalBlock(nextBlock);
nextBlock.removeMetadata(MetadataConstants.METADATA_KEY_PISTON_TRACKING, mcMMO.p);
}
else if (mcMMO.getPlaceStore().isTrue(nextBlock)) {
Expand Down
Expand Up @@ -30,6 +30,6 @@ public void run() {

// The sticky piston actually pulled the block so move the PlaceStore data
mcMMO.getPlaceStore().setFalse(movedBlock.getRelative(direction));
mcMMO.getPlaceStore().setTrue(movedBlock);
BlockUtils.setUnnaturalBlock(movedBlock);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/gmail/nossr50/util/BlockUtils.java
Expand Up @@ -38,6 +38,18 @@ public static void markDropsAsBonus(BlockState blockState, boolean triple) {
blockState.setMetadata(MetadataConstants.METADATA_KEY_BONUS_DROPS, new BonusDropMeta(1, mcMMO.p));
}

/**
* Set up the state for a block to be seen as unnatural and cleanup any unwanted metadata from the block
* @param block target block
*/
public static void setUnnaturalBlock(@NotNull Block block) {
mcMMO.getPlaceStore().setTrue(block);

// Failsafe against lingering metadata
if(block.hasMetadata(MetadataConstants.METADATA_KEY_BONUS_DROPS))
block.removeMetadata(MetadataConstants.METADATA_KEY_BONUS_DROPS, mcMMO.p);
}

/**
* Cleans up some block metadata when a block breaks and the metadata is no longer needed
* This also sets the blocks coords to false in our chunk store
Expand Down

0 comments on commit e9a0205

Please sign in to comment.