diff --git a/src/main/java/com/moulberry/axiom/integration/coreprotect/CoreProtectIntegration.java b/src/main/java/com/moulberry/axiom/integration/coreprotect/CoreProtectIntegration.java index 3bba2e7..60d43ec 100644 --- a/src/main/java/com/moulberry/axiom/integration/coreprotect/CoreProtectIntegration.java +++ b/src/main/java/com/moulberry/axiom/integration/coreprotect/CoreProtectIntegration.java @@ -9,52 +9,21 @@ public class CoreProtectIntegration { public static boolean isEnabled() { return CoreProtectIntegrationImpl.isEnabled(); } - - public static boolean logPlacement(String name, BlockState blockState, CraftWorld world, BlockPos pos) { + + public static void logPlacement(String name, BlockState blockState, CraftWorld world, BlockPos pos) { if (!CoreProtectIntegrationImpl.isEnabled()) { - return false; + return; } - return CoreProtectIntegrationImpl.logPlacement(name, blockState, world, pos); + CoreProtectIntegrationImpl.logPlacement(name, blockState, world, pos); } - public static boolean logPlacement(String name, BlockState blockState, CraftWorld world, int x, int y, int z) { + public static void logRemoval(String name, BlockState blockState, CraftWorld world, BlockPos pos) { if (!CoreProtectIntegrationImpl.isEnabled()) { - return false; - } - - return CoreProtectIntegrationImpl.logPlacement(name, blockState, world, x, y, z); - } - - public static boolean logPlacement(String name, Level level, CraftWorld world, BlockPos pos) { - if (!CoreProtectIntegrationImpl.isEnabled()) { - return false; + return; } - return CoreProtectIntegrationImpl.logPlacement(name, level, world, pos); + CoreProtectIntegrationImpl.logRemoval(name, blockState, world, pos); } - public static boolean logRemoval(String name, BlockState blockState, CraftWorld world, BlockPos pos) { - if (!CoreProtectIntegrationImpl.isEnabled()) { - return false; - } - - return CoreProtectIntegrationImpl.logRemoval(name, blockState, world, pos); - } - - public static boolean logRemoval(String name, BlockState blockState, CraftWorld world, int x, int y, int z) { - if (!CoreProtectIntegrationImpl.isEnabled()) { - return false; - } - - return CoreProtectIntegrationImpl.logRemoval(name, blockState, world, x, y, z); - } - - public static boolean logRemoval(String name, Level level, CraftWorld world, BlockPos pos) { - if (!CoreProtectIntegrationImpl.isEnabled()) { - return false; - } - - return CoreProtectIntegrationImpl.logRemoval(name, level, world, pos); - } -} \ No newline at end of file +} diff --git a/src/main/java/com/moulberry/axiom/integration/coreprotect/CoreProtectIntegrationImpl.java b/src/main/java/com/moulberry/axiom/integration/coreprotect/CoreProtectIntegrationImpl.java index 571d90b..65fc3ec 100644 --- a/src/main/java/com/moulberry/axiom/integration/coreprotect/CoreProtectIntegrationImpl.java +++ b/src/main/java/com/moulberry/axiom/integration/coreprotect/CoreProtectIntegrationImpl.java @@ -4,7 +4,6 @@ import com.moulberry.axiom.AxiomPaper; import net.coreprotect.CoreProtect; import net.coreprotect.CoreProtectAPI; import net.minecraft.core.BlockPos; -import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Bukkit; import org.bukkit.World; @@ -40,12 +39,12 @@ public class CoreProtectIntegrationImpl { private static CoreProtectAPI getCoreProtect() { Plugin plugin = Bukkit.getPluginManager().getPlugin("CoreProtect"); - if (plugin == null || !(plugin instanceof CoreProtect)) { + if (!(plugin instanceof CoreProtect)) { return null; } CoreProtectAPI coreProtect = ((CoreProtect) plugin).getAPI(); - if (coreProtect.isEnabled() == false) { + if (!coreProtect.isEnabled()) { return null; } @@ -58,7 +57,7 @@ public class CoreProtectIntegrationImpl { private static CraftBlockState createCraftBlockState(World world, BlockPos pos, BlockState blockState) { try { - return (CraftBlockState) CRAFT_BLOCK_STATE_CONSTRUCTOR.newInstance(world, pos, blockState); + return CRAFT_BLOCK_STATE_CONSTRUCTOR.newInstance(world, pos, blockState); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { AxiomPaper.PLUGIN.getLogger().warning("Failed to create CraftBlockState for CoreProtect: " + e); return null; @@ -69,31 +68,16 @@ public class CoreProtectIntegrationImpl { return COREPROTECT_ENABLED; } - static boolean logPlacement(String name, BlockState blockState, CraftWorld world, BlockPos pos) { + static void logPlacement(String name, BlockState blockState, CraftWorld world, BlockPos pos) { if (blockState.isAir()) { - return false; + return; } - return COREPROTECT_API.logPlacement(name, createCraftBlockState(world, pos, blockState)); + COREPROTECT_API.logPlacement(name, createCraftBlockState(world, pos, blockState)); } - static boolean logPlacement(String name, BlockState blockState, CraftWorld world, int x, int y, int z) { - return logPlacement(name, blockState, world, new BlockPos(x, y, z)); + static void logRemoval(String name, BlockState blockState, CraftWorld world, BlockPos pos) { + COREPROTECT_API.logRemoval(name, createCraftBlockState(world, pos, blockState)); } - static boolean logPlacement(String name, Level level, CraftWorld world, BlockPos pos) { - return logPlacement(name, level.getBlockState(pos), world, pos); - } - - static boolean logRemoval(String name, BlockState blockState, CraftWorld world, BlockPos pos) { - return COREPROTECT_API.logRemoval(name, createCraftBlockState(world, pos, blockState)); - } - - static boolean logRemoval(String name, BlockState blockState, CraftWorld world, int x, int y, int z) { - return logRemoval(name, blockState, world, new BlockPos(x, y, z)); - } - - static boolean logRemoval(String name, Level level, CraftWorld world, BlockPos pos) { - return logRemoval(name, level.getBlockState(pos), world, pos); - } -} \ No newline at end of file +} diff --git a/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java index 24ef72b..f3aa4df 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java @@ -221,9 +221,6 @@ public class SetBlockBufferPacketListener { BlockState old = section.setBlockState(x, y, z, blockState, true); if (blockState != old) { - CoreProtectIntegration.logRemoval(player.getBukkitEntity().getName(), old, world.getWorld(), bx, by, bz); - CoreProtectIntegration.logPlacement(player.getBukkitEntity().getName(), blockState, world.getWorld(), bx, by, bz); - sectionChanged = true; blockPos.set(bx, by, bz); @@ -291,6 +288,14 @@ public class SetBlockBufferPacketListener { } else if (old.hasBlockEntity()) { chunk.removeBlockEntity(blockPos); } + + if (CoreProtectIntegration.isEnabled() && old != blockState) { + String changedBy = player.getBukkitEntity().getName(); + BlockPos changedPos = new BlockPos(bx, by, bz); + + CoreProtectIntegration.logRemoval(changedBy, old, world.getWorld(), changedPos); + CoreProtectIntegration.logPlacement(changedBy, blockState, world.getWorld(), changedPos); + } } } } diff --git a/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java index e47a694..38052e4 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java @@ -159,7 +159,10 @@ public class SetBlockPacketListener implements PluginMessageListener { continue; } - CoreProtectIntegration.logRemoval(bukkitPlayer.getName(), player.level(), world, blockPos); + if (CoreProtectIntegration.isEnabled()) { + BlockState old = player.level().getBlockState(blockPos); + CoreProtectIntegration.logRemoval(bukkitPlayer.getName(), old, world, blockPos); + } // Place block player.level().setBlock(blockPos, blockState, 3); @@ -225,9 +228,6 @@ public class SetBlockPacketListener implements PluginMessageListener { BlockState old = section.setBlockState(x, y, z, blockState, true); if (blockState != old) { - CoreProtectIntegration.logRemoval(bukkitPlayer.getName(), old, world, blockPos); - CoreProtectIntegration.logPlacement(bukkitPlayer.getName(), blockState, world, blockPos); - Block block = blockState.getBlock(); motionBlocking.update(x, by, z, blockState); motionBlockingNoLeaves.update(x, by, z, blockState); @@ -284,6 +284,14 @@ public class SetBlockPacketListener implements PluginMessageListener { if (oldPoi.isPresent()) level.getPoiManager().remove(blockPos); if (newPoi.isPresent()) level.getPoiManager().add(blockPos, newPoi.get()); } + + if (CoreProtectIntegration.isEnabled()) { + String changedBy = player.getBukkitEntity().getName(); + BlockPos changedPos = new BlockPos(bx, by, bz); + + CoreProtectIntegration.logRemoval(changedBy, old, world, changedPos); + CoreProtectIntegration.logPlacement(changedBy, blockState, world, changedPos); + } } boolean nowHasOnlyAir = section.hasOnlyAir();