Skip to content

Commit

Permalink
fix: listener should check universal block (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Jan 14, 2025
1 parent 45621bf commit 4e13baf
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
public class StorageCacheUtils {
private static final Set<ADataContainer> loadingData = new HashSet<>();

@ParametersAreNonnullByDefault
public static boolean hasSlimefunBlock(Location l) {
return hasBlock(l) || hasUniversalBlock(l);
}

@ParametersAreNonnullByDefault
public static boolean hasBlock(Location l) {
return getBlock(l) != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ protected void dig(Block b, UniversalMenu menu, Block block) {
}

// We only want to break non-Slimefun blocks
if (!StorageCacheUtils.hasBlock(block.getLocation())
&& !StorageCacheUtils.hasUniversalBlock(block.getLocation())) {
if (!StorageCacheUtils.hasSlimefunBlock(block.getLocation())) {
breakBlock(menu, drops, block);
}
}
Expand All @@ -113,8 +112,7 @@ protected void moveAndDig(Block b, UniversalMenu menu, BlockFace face, Block blo
}

// We only want to break non-Slimefun blocks
if (!StorageCacheUtils.hasBlock(block.getLocation())
&& !StorageCacheUtils.hasUniversalBlock(block.getLocation())) {
if (!StorageCacheUtils.hasSlimefunBlock(block.getLocation())) {
breakBlock(menu, drops, block);
move(b, face, block);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1033,8 +1033,10 @@ protected void move(Block from, BlockFace face, Block to) {
Slimefun.getTickerTask().disableTicker(from.getLocation());

// Bro encountered a ghost 💀
if (StorageCacheUtils.hasBlock(to.getLocation())) {
var data = StorageCacheUtils.getBlock(to.getLocation());
if (StorageCacheUtils.hasSlimefunBlock(to.getLocation())) {
var data = StorageCacheUtils.getBlock(to.getLocation()) == null
? StorageCacheUtils.getBlock(to.getLocation())
: StorageCacheUtils.getUniversalBlock(to);
if (data != null && !data.isPendingRemove()) {
// Since it's a ghost, we just hunt it.
Slimefun.getDatabaseManager().getBlockDataController().removeBlock(to.getLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public BlockUseHandler getItemHandler() {
Block block = b.getRelative(BlockFace.UP);

// Just ignore slimefun block above.
if (StorageCacheUtils.hasBlock(block.getLocation())) return;
if (StorageCacheUtils.hasSlimefunBlock(block.getLocation())) return;

if (craft(p, input)) {
boolean water = Tag.LEAVES.isTagged(input.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,12 @@ public boolean canMine(@Nonnull Block block) {
Material type = block.getType();

if (type == Material.ANCIENT_DEBRIS) {
return canMineAncientDebris.getValue() && !StorageCacheUtils.hasBlock(block.getLocation());
return canMineAncientDebris.getValue() && !StorageCacheUtils.hasSlimefunBlock(block.getLocation());
} else if (version.isAtLeast(MinecraftVersion.MINECRAFT_1_17) && SlimefunTag.DEEPSLATE_ORES.isTagged(type)) {
return canMineDeepslateOres.getValue() && !StorageCacheUtils.hasBlock(block.getLocation());
return canMineDeepslateOres.getValue() && !StorageCacheUtils.hasSlimefunBlock(block.getLocation());
} else {
return SlimefunTag.INDUSTRIAL_MINER_ORES.isTagged(type) && !StorageCacheUtils.hasBlock(block.getLocation());
return SlimefunTag.INDUSTRIAL_MINER_ORES.isTagged(type)
&& !StorageCacheUtils.hasSlimefunBlock(block.getLocation());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private ToolUseHandler onBlockBreak() {
logs.remove(e.getBlock());

for (Block b : logs) {
if (!StorageCacheUtils.hasBlock(b.getLocation())
if (!StorageCacheUtils.hasSlimefunBlock(b.getLocation())
&& Slimefun.getProtectionManager()
.hasPermission(e.getPlayer(), b, Interaction.BREAK_BLOCK)) {
breakLog(b);
Expand All @@ -73,7 +73,7 @@ public ItemUseHandler onItemUse() {
logs.remove(block);

for (Block b : logs) {
if (!StorageCacheUtils.hasBlock(b.getLocation())
if (!StorageCacheUtils.hasSlimefunBlock(b.getLocation())
&& Slimefun.getProtectionManager()
.hasPermission(e.getPlayer(), b, Interaction.BREAK_BLOCK)) {
stripLog(b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public SmeltersPickaxe(ItemGroup itemGroup, SlimefunItemStack item, RecipeType r
Block b = e.getBlock();

if (SlimefunTag.SMELTERS_PICKAXE_BLOCKS.isTagged(b.getType())
&& !StorageCacheUtils.hasBlock(b.getLocation())) {
&& !StorageCacheUtils.hasSlimefunBlock(b.getLocation())) {
Collection<ItemStack> blockDrops = b.getDrops(tool);
List<ItemStack> itemDrops = new ArrayList<>();
for (ItemStack drop : blockDrops) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void onBlockPlaceExisting(BlockPlaceEvent e) {
e.setCancelled(true);
}
}
} else if (StorageCacheUtils.hasBlock(loc)) {
} else if (StorageCacheUtils.hasSlimefunBlock(loc)) {
// If there is no air (e.g. grass) then don't let the block be placed
e.setCancelled(true);
}
Expand Down Expand Up @@ -175,7 +175,7 @@ public void onBlockBreak(BlockBreakEvent e) {

var heldItem = e.getPlayer().getInventory().getItemInMainHand();
var block = e.getBlock();
var blockData = StorageCacheUtils.hasBlock(block.getLocation())
var blockData = StorageCacheUtils.getBlock(block.getLocation()) != null
? StorageCacheUtils.getBlock(block.getLocation())
: StorageCacheUtils.getUniversalBlock(block);
var sfItem = blockData == null ? null : SlimefunItem.getById(blockData.getSfId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ private void callHandler(BlockBreakHandler handler, Block b) {

@EventHandler(ignoreCancelled = true)
public void onPistonExtend(BlockPistonExtendEvent e) {
if (StorageCacheUtils.hasBlock(e.getBlock().getLocation())) {
if (StorageCacheUtils.hasSlimefunBlock(e.getBlock().getLocation())) {
e.setCancelled(true);
} else {
for (Block b : e.getBlocks()) {
if (StorageCacheUtils.hasBlock(b.getLocation())
if (StorageCacheUtils.hasSlimefunBlock(b.getLocation())
|| (b.getRelative(e.getDirection()).getType() == Material.AIR
&& StorageCacheUtils.hasBlock(
&& StorageCacheUtils.hasSlimefunBlock(
b.getRelative(e.getDirection()).getLocation()))) {
e.setCancelled(true);
break;
Expand All @@ -138,13 +138,13 @@ public void onPistonExtend(BlockPistonExtendEvent e) {

@EventHandler(ignoreCancelled = true)
public void onPistonRetract(BlockPistonRetractEvent e) {
if (StorageCacheUtils.hasBlock(e.getBlock().getLocation())) {
if (StorageCacheUtils.hasSlimefunBlock(e.getBlock().getLocation())) {
e.setCancelled(true);
} else if (e.isSticky()) {
for (Block b : e.getBlocks()) {
if (StorageCacheUtils.hasBlock(b.getLocation())
if (StorageCacheUtils.hasSlimefunBlock(b.getLocation())
|| (b.getRelative(e.getDirection()).getType() == Material.AIR
&& StorageCacheUtils.hasBlock(
&& StorageCacheUtils.hasSlimefunBlock(
b.getRelative(e.getDirection()).getLocation()))) {
e.setCancelled(true);
break;
Expand All @@ -161,7 +161,7 @@ public void onLiquidFlow(BlockFromToEvent e) {
// Check if this Material can be destroyed by fluids
if (SlimefunTag.FLUID_SENSITIVE_MATERIALS.isTagged(type)) {
// Check if this Block holds any data
if (StorageCacheUtils.hasBlock(block.getLocation())) {
if (StorageCacheUtils.hasSlimefunBlock(block.getLocation())) {
e.setCancelled(true);
}
return;
Expand All @@ -184,7 +184,7 @@ public void onBucketUse(PlayerBucketEmptyEvent e) {
// Fix for placing water on player heads
Location l = e.getBlockClicked().getRelative(e.getBlockFace()).getLocation();

if (StorageCacheUtils.hasBlock(l)) {
if (StorageCacheUtils.hasSlimefunBlock(l)) {
e.setCancelled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private void onRightClick(Player p, Block b, BlockFace face) {
return;
}

if (StorageCacheUtils.hasBlock(b.getLocation()) || StorageCacheUtils.hasUniversalBlock(b.getLocation())) {
if (StorageCacheUtils.hasSlimefunBlock(b.getLocation())) {
var data = StorageCacheUtils.hasBlock(b.getLocation())
? StorageCacheUtils.getBlock(b.getLocation())
: StorageCacheUtils.getUniversalBlock(b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 pos, T bloc
if (world != null) {
Location l = new Location(world, pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());

if (StorageCacheUtils.hasBlock(l)) {
if (StorageCacheUtils.hasSlimefunBlock(l)) {
Slimefun.getDatabaseManager()
.getBlockDataController()
.removeBlock(l);
Expand Down

0 comments on commit 4e13baf

Please sign in to comment.