From 05aebe7544814d0d12017fb73c528bb3fda57baf Mon Sep 17 00:00:00 2001 From: Intelli Date: Fri, 14 Jul 2023 14:29:36 -0600 Subject: [PATCH] Added logging for brushing suspicious blocks (implement #409) --- .../java/net/coreprotect/bukkit/BukkitAdapter.java | 4 ++-- .../java/net/coreprotect/bukkit/BukkitInterface.java | 2 +- .../java/net/coreprotect/bukkit/Bukkit_v1_20.java | 4 ++-- .../listener/block/BlockBreakListener.java | 6 +++--- .../listener/player/PlayerInteractListener.java | 11 +++++++++++ 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/coreprotect/bukkit/BukkitAdapter.java b/src/main/java/net/coreprotect/bukkit/BukkitAdapter.java index 489a4e6..f3f2a97 100644 --- a/src/main/java/net/coreprotect/bukkit/BukkitAdapter.java +++ b/src/main/java/net/coreprotect/bukkit/BukkitAdapter.java @@ -208,8 +208,8 @@ public class BukkitAdapter implements BukkitInterface { } @Override - public boolean hasGravity(Material scanType) { - return scanType.hasGravity(); + public boolean isSuspiciousBlock(Material material) { + return false; } @Override diff --git a/src/main/java/net/coreprotect/bukkit/BukkitInterface.java b/src/main/java/net/coreprotect/bukkit/BukkitInterface.java index f94e88e..56941e5 100644 --- a/src/main/java/net/coreprotect/bukkit/BukkitInterface.java +++ b/src/main/java/net/coreprotect/bukkit/BukkitInterface.java @@ -66,7 +66,7 @@ public interface BukkitInterface { public Material getPlantSeeds(Material material); - public boolean hasGravity(Material scanType); + public boolean isSuspiciousBlock(Material material); public boolean isSign(Material material); diff --git a/src/main/java/net/coreprotect/bukkit/Bukkit_v1_20.java b/src/main/java/net/coreprotect/bukkit/Bukkit_v1_20.java index cff153e..a8f635e 100644 --- a/src/main/java/net/coreprotect/bukkit/Bukkit_v1_20.java +++ b/src/main/java/net/coreprotect/bukkit/Bukkit_v1_20.java @@ -112,8 +112,8 @@ public class Bukkit_v1_20 extends Bukkit_v1_19 implements BukkitInterface { } @Override - public boolean hasGravity(Material scanType) { - return scanType.hasGravity() || scanType == Material.SUSPICIOUS_GRAVEL || scanType == Material.SUSPICIOUS_SAND; + public boolean isSuspiciousBlock(Material material) { + return material == Material.SUSPICIOUS_GRAVEL || material == Material.SUSPICIOUS_SAND; } @Override diff --git a/src/main/java/net/coreprotect/listener/block/BlockBreakListener.java b/src/main/java/net/coreprotect/listener/block/BlockBreakListener.java index aa6cf32..b7255ef 100644 --- a/src/main/java/net/coreprotect/listener/block/BlockBreakListener.java +++ b/src/main/java/net/coreprotect/listener/block/BlockBreakListener.java @@ -125,7 +125,7 @@ public final class BlockBreakListener extends Queue implements Listener { Block scanBlock = world.getBlockAt(scanLocation); Material scanType = scanBlock.getType(); if (scanMin == 5) { - if (BukkitAdapter.ADAPTER.hasGravity(scanType)) { + if (scanType.hasGravity() || BukkitAdapter.ADAPTER.isSuspiciousBlock(scanType)) { if (Config.getConfig(world).BLOCK_MOVEMENT) { // log the top-most sand/gravel block as being removed int scanY = y + 2; @@ -133,7 +133,7 @@ public final class BlockBreakListener extends Queue implements Listener { while (!topFound) { Block topBlock = world.getBlockAt(x, scanY, z); Material topMaterial = topBlock.getType(); - if (!BukkitAdapter.ADAPTER.hasGravity(topMaterial)) { + if (!topMaterial.hasGravity() && !BukkitAdapter.ADAPTER.isSuspiciousBlock(topMaterial)) { scanLocation = new Location(world, x, (scanY - 1), z); topFound = true; } @@ -209,7 +209,7 @@ public final class BlockBreakListener extends Queue implements Listener { } } else if (scanMin == 5) { - if (BukkitAdapter.ADAPTER.hasGravity(scanType)) { + if (scanType.hasGravity() || BukkitAdapter.ADAPTER.isSuspiciousBlock(scanType)) { log = true; } } diff --git a/src/main/java/net/coreprotect/listener/player/PlayerInteractListener.java b/src/main/java/net/coreprotect/listener/player/PlayerInteractListener.java index aca6cce..a9e2b66 100755 --- a/src/main/java/net/coreprotect/listener/player/PlayerInteractListener.java +++ b/src/main/java/net/coreprotect/listener/player/PlayerInteractListener.java @@ -751,6 +751,17 @@ public final class PlayerInteractListener extends Queue implements Listener { } } } + else if (BukkitAdapter.ADAPTER.isSuspiciousBlock(type)) { + BlockState blockState = block.getState(); + Scheduler.scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> { + Material newType = block.getType(); + if (type == newType || (type != Material.SAND && type != Material.GRAVEL)) { + return; + } + + Queue.queueBlockPlace(player.getName(), blockState, newType, blockState, newType, -1, 0, null); + }, block.getLocation(), 100); + } else if (type == Material.DRAGON_EGG) { clickedDragonEgg(player, block); }