Disintegrate/Crumble block integrity checks

This commit is contained in:
Esophose 2019-04-30 00:18:45 -06:00
parent 53ba40fb65
commit 90ba6bbf02
5 changed files with 38 additions and 24 deletions

View File

@ -8,6 +8,7 @@ import com.songoda.ultimatetimber.tree.FallingTreeBlock;
import com.songoda.ultimatetimber.tree.ITreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import com.songoda.ultimatetimber.tree.TreeBlockType;
import com.songoda.ultimatetimber.tree.TreeDefinition;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@ -61,6 +62,14 @@ public class TreeAnimationCrumble extends TreeAnimation {
List<ITreeBlock<Block>> partition = treeBlocks.get(0);
for (int i = 0; i < 3 && !partition.isEmpty(); i++) {
ITreeBlock<Block> treeBlock = partition.remove(0);
if (treeBlock.getTreeBlockType().equals(TreeBlockType.LOG)) {
if (td.getLogBlockData().stream().noneMatch(x -> x.isSimilar(treeBlock.getBlock())))
continue;
} else if (treeBlock.getTreeBlockType().equals(TreeBlockType.LEAF)) {
if (td.getLeafBlockData().stream().noneMatch(x -> x.isSimilar(treeBlock.getBlock())))
continue;
}
FallingTreeBlock fallingTreeBlock = TreeAnimationCrumble.this.convertToFallingBlock((TreeBlock)treeBlock);
if (fallingTreeBlock == null)
continue;

View File

@ -7,7 +7,9 @@ import com.songoda.ultimatetimber.manager.TreeDefinitionManager;
import com.songoda.ultimatetimber.tree.DetectedTree;
import com.songoda.ultimatetimber.tree.ITreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockType;
import com.songoda.ultimatetimber.tree.TreeDefinition;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player;
@ -73,6 +75,14 @@ public class TreeAnimationDisintegrate extends TreeAnimation {
versionAdapter.playLandingSound(first);
for (ITreeBlock<Block> treeBlock : toDestroy) {
if (treeBlock.getTreeBlockType().equals(TreeBlockType.LOG)) {
if (td.getLogBlockData().stream().noneMatch(x -> x.isSimilar(treeBlock.getBlock())))
continue;
} else if (treeBlock.getTreeBlockType().equals(TreeBlockType.LEAF)) {
if (td.getLeafBlockData().stream().noneMatch(x -> x.isSimilar(treeBlock.getBlock())))
continue;
}
if (useCustomParticles)
versionAdapter.playFallingParticles(td, treeBlock);
treeDefinitionManager.dropTreeLoot(td, treeBlock, p, hst);

View File

@ -1,17 +1,11 @@
package com.songoda.ultimatetimber.manager;
import com.songoda.ultimatetimber.UltimateTimber;
import com.songoda.ultimatetimber.adapter.IBlockData;
import com.songoda.ultimatetimber.events.TreeFellEvent;
import com.songoda.ultimatetimber.tree.ITreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockType;
import com.songoda.ultimatetimber.tree.TreeDefinition;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -21,31 +15,34 @@ import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.world.StructureGrowEvent;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
public class PlacedBlockManager extends Manager implements Listener {
private List<Location> placedBlocks;
private Set<Location> placedBlocks;
private boolean ignorePlacedBlocks;
private int maxPlacedBlockMemorySize;
public PlacedBlockManager(UltimateTimber ultimateTimber) {
super(ultimateTimber);
this.placedBlocks = new ArrayList<>();
this.ignorePlacedBlocks = true;
this.maxPlacedBlockMemorySize = 10000;
Bukkit.getPluginManager().registerEvents(this, ultimateTimber);
}
@Override
public void reload() {
this.placedBlocks.clear();
this.ignorePlacedBlocks = ConfigurationManager.Setting.IGNORE_PLACED_BLOCKS.getBoolean();
this.maxPlacedBlockMemorySize = ConfigurationManager.Setting.IGNORE_PLACED_BLOCKS_MEMORY_SIZE.getInt();
// Ensures the oldest entry is removed if it exceeds the limit
this.placedBlocks = Collections.newSetFromMap(new LinkedHashMap<Location, Boolean>() {
@Override
protected boolean removeEldestEntry(Map.Entry<Location, Boolean> eldest) {
return this.size() > PlacedBlockManager.this.maxPlacedBlockMemorySize;
}
});
}
@Override
@ -104,8 +101,6 @@ public class PlacedBlockManager extends Manager implements Listener {
return;
this.placedBlocks.add(block.getLocation());
if (this.placedBlocks.size() > this.maxPlacedBlockMemorySize)
this.placedBlocks.remove(0);
} else {
this.placedBlocks.remove(block.getLocation());
}

View File

@ -123,9 +123,9 @@ bonus-loot-multiplier: 2
ignore-placed-blocks: true
# The maximum number of blocks to keep track of in memory at once
# Use a lower number if this starts to take up too much memory
# Default: 10000
ignore-placed-blocks-memory-size: 10000
# Use a lower number if this starts to take up too much memory or trees start taking too long to detect
# Default: 5000
ignore-placed-blocks-memory-size: 5000
# Applies experience when using Jobs/mcMMO
# Only does something if Jobs or mcMMO is installed

View File

@ -124,9 +124,9 @@ bonus-loot-multiplier: 2
ignore-placed-blocks: true
# The maximum number of blocks to keep track of in memory at once
# Use a lower number if this starts to take up too much memory
# Default: 10000
ignore-placed-blocks-memory-size: 10000
# Use a lower number if this starts to take up too much memory or trees start taking too long to detect
# Default: 5000
ignore-placed-blocks-memory-size: 5000
# Applies experience when using Jobs/mcMMO
# Only does something if Jobs or mcMMO is installed