Fix block tracking logic

This commit is contained in:
nossr50 2021-04-15 09:38:30 -07:00
parent f2357a04ae
commit b9201b89b8
4 changed files with 60 additions and 35 deletions

View File

@ -1,3 +1,6 @@
Version 2.1.191
Fixed a critical bug related to our BlockTracker
Some minor optimizations to our Block events
Version 2.1.190
Fixed a null error in BitSetChunkStore
Version 2.1.189

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.1.190</version>
<version>2.1.191-SNAPSHOT</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<scm>

View File

@ -123,12 +123,16 @@ public class BlockListener implements Listener {
BlockFace direction = event.getDirection();
Block movedBlock;
WorldCompatibilityLayer worldCompatibilityLayer = mcMMO.getCompatibilityManager().getWorldCompatibilityLayer();
for (Block b : event.getBlocks()) {
movedBlock = b.getRelative(direction);
for (Block block : event.getBlocks()) {
movedBlock = block.getRelative(direction);
if(BlockUtils.isWithinWorldBounds(worldCompatibilityLayer, movedBlock)) {
mcMMO.getPlaceStore().setTrue(movedBlock);
}
}
}
/**
* Monitor BlockPistonRetract events.
@ -151,19 +155,15 @@ public class BlockListener implements Listener {
WorldCompatibilityLayer worldCompatibilityLayer = mcMMO.getCompatibilityManager().getWorldCompatibilityLayer();
World world = movedBlock.getWorld();
//Spigot makes bad things happen in its API
if(event.getBlock().getY() < worldCompatibilityLayer.getMaxWorldHeight(world) || event.getBlock().getY() >= worldCompatibilityLayer.getMinWorldHeight(world)) {
if(BlockUtils.isWithinWorldBounds(worldCompatibilityLayer, movedBlock)) {
mcMMO.getPlaceStore().setTrue(movedBlock);
}
for (Block block : event.getBlocks()) {
if(block.getY() < worldCompatibilityLayer.getMaxWorldHeight(world) || block.getY() >= worldCompatibilityLayer.getMinWorldHeight(world)) {
if(BlockUtils.isWithinWorldBounds(worldCompatibilityLayer, block)) {
mcMMO.getPlaceStore().setTrue(block.getRelative(direction));
}
mcMMO.getPlaceStore().setTrue(movedBlock);
}
}
@ -180,11 +180,16 @@ public class BlockListener implements Listener {
if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld()))
return;
BlockState blockState = event.getNewState();
if(ExperienceConfig.getInstance().isSnowExploitPrevented() && BlockUtils.shouldBeWatched(blockState))
{
mcMMO.getPlaceStore().setTrue(blockState.getBlock());
if(ExperienceConfig.getInstance().isSnowExploitPrevented() && BlockUtils.shouldBeWatched(blockState)) {
WorldCompatibilityLayer worldCompatibilityLayer = mcMMO.getCompatibilityManager().getWorldCompatibilityLayer();
Block block = blockState.getBlock();
if(BlockUtils.isWithinWorldBounds(worldCompatibilityLayer, block)) {
mcMMO.getPlaceStore().setTrue(block);
}
}
}
@ -195,26 +200,22 @@ public class BlockListener implements Listener {
public void onBlockFormEvent(BlockFormEvent event)
{
World world = event.getBlock().getWorld();
/* WORLD BLACKLIST CHECK */ {
/* WORLD BLACKLIST CHECK */
if(WorldBlacklist.isWorldBlacklisted(world))
return;
}
BlockState newState = event.getNewState();
if(ExperienceConfig.getInstance().preventStoneLavaFarming()) {
BlockState newState = event.getNewState();
WorldCompatibilityLayer worldCompatibilityLayer = mcMMO.getCompatibilityManager().getWorldCompatibilityLayer();
if(event.getBlock().getY() > worldCompatibilityLayer.getMaxWorldHeight(world) || event.getBlock().getY() < worldCompatibilityLayer.getMinWorldHeight(world)) {
return;
}
if(newState.getType() != Material.OBSIDIAN
&& ExperienceConfig.getInstance().doesBlockGiveSkillXP(PrimarySkillType.MINING, newState.getBlockData())) {
if(newState.getType() != Material.OBSIDIAN && ExperienceConfig.getInstance().doesBlockGiveSkillXP(PrimarySkillType.MINING, newState.getBlockData())) {
if(BlockUtils.isWithinWorldBounds(worldCompatibilityLayer, newState.getBlock())) {
mcMMO.getPlaceStore().setTrue(newState);
}
}
}
}
/**
* Monitor BlockPlace events.
@ -224,16 +225,23 @@ public class BlockListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) {
BlockState blockState = event.getBlock().getState();
Block block = blockState.getBlock();
/* Check if the blocks placed should be monitored so they do not give out XP in the future */
// if (!Tag.LOGS.isTagged(event.getBlockReplacedState().getType()) || !Tag.LOGS.isTagged(event.getBlockPlaced().getType()))
mcMMO.getPlaceStore().setTrue(blockState);
/* WORLD BLACKLIST CHECK */
if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) {
if(WorldBlacklist.isWorldBlacklisted(block.getWorld())) {
return;
}
WorldCompatibilityLayer worldCompatibilityLayer = mcMMO.getCompatibilityManager().getWorldCompatibilityLayer();
if(BlockUtils.isWithinWorldBounds(worldCompatibilityLayer, block)) {
mcMMO.getPlaceStore().setTrue(blockState);
}
Player player = event.getPlayer();
if (!UserManager.hasPlayerDataKey(player)) {
@ -260,18 +268,21 @@ public class BlockListener implements Listener {
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockMultiPlace(BlockMultiPlaceEvent event) {
for (BlockState replacedBlockState : event.getReplacedBlockStates())
{
for (BlockState replacedBlockState : event.getReplacedBlockStates()) {
BlockState blockState = replacedBlockState.getBlock().getState();
Block block = blockState.getBlock();
WorldCompatibilityLayer worldCompatibilityLayer = mcMMO.getCompatibilityManager().getWorldCompatibilityLayer();
/* Check if the blocks placed should be monitored so they do not give out XP in the future */
if(BlockUtils.isWithinWorldBounds(worldCompatibilityLayer, block)) {
mcMMO.getPlaceStore().setTrue(blockState);
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockGrow(BlockGrowEvent event)
{
public void onBlockGrow(BlockGrowEvent event) {
Block block = event.getBlock();
World world = block.getWorld();
@ -280,11 +291,12 @@ public class BlockListener implements Listener {
return;
// Minecraft is dumb, the events still throw when a plant "grows" higher than the max block height. Even though no new block is created
if (block.getY() >= world.getMaxHeight())
return;
WorldCompatibilityLayer worldCompatibilityLayer = mcMMO.getCompatibilityManager().getWorldCompatibilityLayer();
if(BlockUtils.isWithinWorldBounds(worldCompatibilityLayer, block)) {
mcMMO.getPlaceStore().setFalse(block);
}
}
/**
* Monitor BlockBreak events.

View File

@ -7,14 +7,17 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.salvage.Salvage;
import com.gmail.nossr50.util.compat.layers.world.WorldCompatibilityLayer;
import com.gmail.nossr50.util.random.RandomChanceSkill;
import com.gmail.nossr50.util.random.RandomChanceUtil;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.Ageable;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
@ -285,4 +288,11 @@ public final class BlockUtils {
public static boolean isPartOfTree(Block rayCast) {
return hasWoodcuttingXP(rayCast.getState()) || isNonWoodPartOfTree(rayCast.getType());
}
public static boolean isWithinWorldBounds(@NotNull WorldCompatibilityLayer worldCompatibilityLayer, @NotNull Block block) {
World world = block.getWorld();
return block.getY() > worldCompatibilityLayer.getMinWorldHeight(world) || block.getY() < worldCompatibilityLayer.getMaxWorldHeight(world);
}
}