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 Version 2.1.190
Fixed a null error in BitSetChunkStore Fixed a null error in BitSetChunkStore
Version 2.1.189 Version 2.1.189

View File

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

View File

@ -123,12 +123,16 @@ public class BlockListener implements Listener {
BlockFace direction = event.getDirection(); BlockFace direction = event.getDirection();
Block movedBlock; Block movedBlock;
WorldCompatibilityLayer worldCompatibilityLayer = mcMMO.getCompatibilityManager().getWorldCompatibilityLayer();
for (Block b : event.getBlocks()) { for (Block block : event.getBlocks()) {
movedBlock = b.getRelative(direction); movedBlock = block.getRelative(direction);
if(BlockUtils.isWithinWorldBounds(worldCompatibilityLayer, movedBlock)) {
mcMMO.getPlaceStore().setTrue(movedBlock); mcMMO.getPlaceStore().setTrue(movedBlock);
} }
} }
}
/** /**
* Monitor BlockPistonRetract events. * Monitor BlockPistonRetract events.
@ -151,19 +155,15 @@ public class BlockListener implements Listener {
WorldCompatibilityLayer worldCompatibilityLayer = mcMMO.getCompatibilityManager().getWorldCompatibilityLayer(); WorldCompatibilityLayer worldCompatibilityLayer = mcMMO.getCompatibilityManager().getWorldCompatibilityLayer();
World world = movedBlock.getWorld();
//Spigot makes bad things happen in its API //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); mcMMO.getPlaceStore().setTrue(movedBlock);
} }
for (Block block : event.getBlocks()) { 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(block.getRelative(direction));
} }
mcMMO.getPlaceStore().setTrue(movedBlock);
} }
} }
@ -180,11 +180,16 @@ public class BlockListener implements Listener {
if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld()))
return; return;
BlockState blockState = event.getNewState(); BlockState blockState = event.getNewState();
if(ExperienceConfig.getInstance().isSnowExploitPrevented() && BlockUtils.shouldBeWatched(blockState)) if(ExperienceConfig.getInstance().isSnowExploitPrevented() && BlockUtils.shouldBeWatched(blockState)) {
{ WorldCompatibilityLayer worldCompatibilityLayer = mcMMO.getCompatibilityManager().getWorldCompatibilityLayer();
mcMMO.getPlaceStore().setTrue(blockState.getBlock()); 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) public void onBlockFormEvent(BlockFormEvent event)
{ {
World world = event.getBlock().getWorld(); World world = event.getBlock().getWorld();
/* WORLD BLACKLIST CHECK */ {
/* WORLD BLACKLIST CHECK */
if(WorldBlacklist.isWorldBlacklisted(world)) if(WorldBlacklist.isWorldBlacklisted(world))
return; return;
}
BlockState newState = event.getNewState();
if(ExperienceConfig.getInstance().preventStoneLavaFarming()) { if(ExperienceConfig.getInstance().preventStoneLavaFarming()) {
BlockState newState = event.getNewState();
WorldCompatibilityLayer worldCompatibilityLayer = mcMMO.getCompatibilityManager().getWorldCompatibilityLayer(); WorldCompatibilityLayer worldCompatibilityLayer = mcMMO.getCompatibilityManager().getWorldCompatibilityLayer();
if(event.getBlock().getY() > worldCompatibilityLayer.getMaxWorldHeight(world) || event.getBlock().getY() < worldCompatibilityLayer.getMinWorldHeight(world)) { if(newState.getType() != Material.OBSIDIAN && ExperienceConfig.getInstance().doesBlockGiveSkillXP(PrimarySkillType.MINING, newState.getBlockData())) {
return; if(BlockUtils.isWithinWorldBounds(worldCompatibilityLayer, newState.getBlock())) {
}
if(newState.getType() != Material.OBSIDIAN
&& ExperienceConfig.getInstance().doesBlockGiveSkillXP(PrimarySkillType.MINING, newState.getBlockData())) {
mcMMO.getPlaceStore().setTrue(newState); mcMMO.getPlaceStore().setTrue(newState);
} }
} }
} }
}
/** /**
* Monitor BlockPlace events. * Monitor BlockPlace events.
@ -224,16 +225,23 @@ public class BlockListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
BlockState blockState = event.getBlock().getState(); 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 */ /* 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())) // if (!Tag.LOGS.isTagged(event.getBlockReplacedState().getType()) || !Tag.LOGS.isTagged(event.getBlockPlaced().getType()))
mcMMO.getPlaceStore().setTrue(blockState);
/* WORLD BLACKLIST CHECK */ /* WORLD BLACKLIST CHECK */
if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) { if(WorldBlacklist.isWorldBlacklisted(block.getWorld())) {
return; return;
} }
WorldCompatibilityLayer worldCompatibilityLayer = mcMMO.getCompatibilityManager().getWorldCompatibilityLayer();
if(BlockUtils.isWithinWorldBounds(worldCompatibilityLayer, block)) {
mcMMO.getPlaceStore().setTrue(blockState);
}
Player player = event.getPlayer(); Player player = event.getPlayer();
if (!UserManager.hasPlayerDataKey(player)) { if (!UserManager.hasPlayerDataKey(player)) {
@ -260,18 +268,21 @@ public class BlockListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockMultiPlace(BlockMultiPlaceEvent event) { public void onBlockMultiPlace(BlockMultiPlaceEvent event) {
for (BlockState replacedBlockState : event.getReplacedBlockStates()) for (BlockState replacedBlockState : event.getReplacedBlockStates()) {
{
BlockState blockState = replacedBlockState.getBlock().getState(); 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 */ /* 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); mcMMO.getPlaceStore().setTrue(blockState);
} }
} }
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockGrow(BlockGrowEvent event) public void onBlockGrow(BlockGrowEvent event) {
{
Block block = event.getBlock(); Block block = event.getBlock();
World world = block.getWorld(); World world = block.getWorld();
@ -280,11 +291,12 @@ public class BlockListener implements Listener {
return; 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 // 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()) WorldCompatibilityLayer worldCompatibilityLayer = mcMMO.getCompatibilityManager().getWorldCompatibilityLayer();
return;
if(BlockUtils.isWithinWorldBounds(worldCompatibilityLayer, block)) {
mcMMO.getPlaceStore().setFalse(block); mcMMO.getPlaceStore().setFalse(block);
} }
}
/** /**
* Monitor BlockBreak events. * 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.mcMMO;
import com.gmail.nossr50.skills.repair.Repair; import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.salvage.Salvage; 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.RandomChanceSkill;
import com.gmail.nossr50.util.random.RandomChanceUtil; import com.gmail.nossr50.util.random.RandomChanceUtil;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.data.Ageable; import org.bukkit.block.data.Ageable;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet; import java.util.HashSet;
@ -285,4 +288,11 @@ public final class BlockUtils {
public static boolean isPartOfTree(Block rayCast) { public static boolean isPartOfTree(Block rayCast) {
return hasWoodcuttingXP(rayCast.getState()) || isNonWoodPartOfTree(rayCast.getType()); 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);
}
} }