From 97f6d012671211eab9cd37ef7f48601fee8f48d2 Mon Sep 17 00:00:00 2001 From: Wakka Date: Thu, 7 Dec 2023 15:30:49 -0600 Subject: [PATCH] add support for proper logging of CustomBlocks, bump version --- build.gradle | 16 +++++- .../database/logger/BlockBreakLogger.java | 11 ++++ .../database/logger/BlockPlaceLogger.java | 10 ++++ .../event/CoreProtectPreLogBlockEvent.java | 52 +++++++++++++++++++ .../worldedit/WorldEditBlockState.java | 2 +- src/main/resources/plugin.yml | 2 +- 6 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 src/main/java/net/coreprotect/event/CoreProtectPreLogBlockEvent.java diff --git a/build.gradle b/build.gradle index 05f8718b..6bdea860 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ plugins { } group = 'net.coreprotect' -String projectVersion = '22.2' +String projectVersion = '22.3.1' String projectBranch = '' version = projectVersion // `version` might be modified, we don't always want that (e.g. plugin.yml) description = 'Provides block protection for your server.' @@ -83,6 +83,20 @@ processResources { }) } +tasks { + compileJava { + options.encoding = "UTF-8" + options.release.set(17) + options.compilerArgs.add("-parameters") + } + + javadoc { options.encoding = "UTF-8" } + + processResources { + filteringCharset = "UTF-8" + } +} + publishing { publications { mavenJava(MavenPublication) { diff --git a/src/main/java/net/coreprotect/database/logger/BlockBreakLogger.java b/src/main/java/net/coreprotect/database/logger/BlockBreakLogger.java index 1b9f888a..95088c41 100644 --- a/src/main/java/net/coreprotect/database/logger/BlockBreakLogger.java +++ b/src/main/java/net/coreprotect/database/logger/BlockBreakLogger.java @@ -3,7 +3,10 @@ import java.sql.PreparedStatement; import java.util.List; import java.util.Locale; +import java.util.concurrent.atomic.AtomicBoolean; +import net.coreprotect.event.CoreProtectPreLogBlockEvent; +import net.coreprotect.event.CoreProtectPreLogBlockEvent.BlockAction; import org.bukkit.Location; import org.bukkit.Material; @@ -65,6 +68,14 @@ else if (checkType == Material.PAINTING || BukkitAdapter.ADAPTER.isItemFrame(che return; } + CoreProtectPreLogBlockEvent blockEvent = new CoreProtectPreLogBlockEvent(user, BlockAction.BREAK, location, checkType, blockData); + if (Config.getGlobal().API_ENABLED) { + CoreProtect.getInstance().getServer().getPluginManager().callEvent(blockEvent); + + if(blockEvent.isCancelled()) + return; + } + BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, type, data, meta, blockData, 0, 0); } catch (Exception e) { diff --git a/src/main/java/net/coreprotect/database/logger/BlockPlaceLogger.java b/src/main/java/net/coreprotect/database/logger/BlockPlaceLogger.java index ed492149..a66405ed 100644 --- a/src/main/java/net/coreprotect/database/logger/BlockPlaceLogger.java +++ b/src/main/java/net/coreprotect/database/logger/BlockPlaceLogger.java @@ -4,6 +4,8 @@ import java.util.List; import java.util.Locale; +import net.coreprotect.event.CoreProtectPreLogBlockEvent; +import net.coreprotect.event.CoreProtectPreLogBlockEvent.BlockAction; import org.bukkit.Material; import org.bukkit.block.BlockState; @@ -96,6 +98,14 @@ else if (type == Material.WATER || type == Material.LAVA) { return; } + CoreProtectPreLogBlockEvent blockEvent = new CoreProtectPreLogBlockEvent(user, BlockAction.PLACE, block.getLocation(), type, blockData); + if (Config.getGlobal().API_ENABLED) { + CoreProtect.getInstance().getServer().getPluginManager().callEvent(blockEvent); + + if(blockEvent.isCancelled()) + return; + } + int internalType = Util.getBlockId(type.name(), true); if (replacedType > 0 && Util.getType(replacedType) != Material.AIR && Util.getType(replacedType) != Material.CAVE_AIR) { BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, replacedType, replacedData, null, replaceBlockData, 0, 0); diff --git a/src/main/java/net/coreprotect/event/CoreProtectPreLogBlockEvent.java b/src/main/java/net/coreprotect/event/CoreProtectPreLogBlockEvent.java new file mode 100644 index 00000000..feeee5f0 --- /dev/null +++ b/src/main/java/net/coreprotect/event/CoreProtectPreLogBlockEvent.java @@ -0,0 +1,52 @@ +package net.coreprotect.event; + +import org.bukkit.Location; +import org.bukkit.Material; + +public class CoreProtectPreLogBlockEvent extends CoreProtectPreLogEvent { + private boolean cancelled = false; + + BlockAction action; + Location location; + Material type; + String blockData; + + public CoreProtectPreLogBlockEvent(String user, BlockAction action, Location location, Material type, String blockData) { + super(user); + this.action = action; + this.location = location; + this.type = type; + this.blockData = blockData; + } + + public BlockAction getAction() { + return action; + } + + public Location getLocation() { + return location; + } + + public Material getType() { + return type; + } + + public String getBlockData() { + return blockData; + } + + public enum BlockAction { + PLACE, + BREAK + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + cancelled = cancel; + } +} diff --git a/src/main/java/net/coreprotect/worldedit/WorldEditBlockState.java b/src/main/java/net/coreprotect/worldedit/WorldEditBlockState.java index c7737ffb..44396e51 100644 --- a/src/main/java/net/coreprotect/worldedit/WorldEditBlockState.java +++ b/src/main/java/net/coreprotect/worldedit/WorldEditBlockState.java @@ -205,7 +205,7 @@ public Collection getDrops(ItemStack tool, Entity entity) { return null; } - @Override + //@Override public BlockState copy() { // TODO Auto-generated method stub return null; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fbb1c9d3..841293e7 100755 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: CoreProtect main: net.coreprotect.CoreProtect version: ${project.version} -branch: ${project.branch} +branch: development api-version: 1.13 folia-supported: true website: http://coreprotect.net