Skip to content

Commit

Permalink
Added logging for brushing suspicious blocks (implement #409)
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelli committed Jul 14, 2023
1 parent 36ad620 commit 05aebe7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/coreprotect/bukkit/BukkitAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ public Material getPlantSeeds(Material material) {
}

@Override
public boolean hasGravity(Material scanType) {
return scanType.hasGravity();
public boolean isSuspiciousBlock(Material material) {
return false;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/coreprotect/bukkit/BukkitInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/coreprotect/bukkit/Bukkit_v1_20.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public Material getPlantSeeds(Material material) {
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ protected static void processBlockBreak(Player player, String user, Block block,
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;
boolean topFound = false;
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;
}
Expand Down Expand Up @@ -209,7 +209,7 @@ else if (!isAttached(block, scanBlock, scanMin)) {
}
}
else if (scanMin == 5) {
if (BukkitAdapter.ADAPTER.hasGravity(scanType)) {
if (scanType.hasGravity() || BukkitAdapter.ADAPTER.isSuspiciousBlock(scanType)) {
log = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,17 @@ else if (event.getHand().equals(EquipmentSlot.OFF_HAND) && offHand != null && Bu
}
}
}
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);
}
Expand Down

0 comments on commit 05aebe7

Please sign in to comment.