diff --git a/docs/api/version/v9.md b/docs/api/version/v9.md index b893867..282e3b7 100644 --- a/docs/api/version/v9.md +++ b/docs/api/version/v9.md @@ -120,11 +120,12 @@ void performPurge(int time) #### CoreProtectPreLogEvent -Fired when a CoreProtect logger is about to log an action. Not cancellable. +Fired when a CoreProtect logger is about to log an action. Cancellable. | Property | Description | Mutable | | --- | --- | --- | | User | The name of the user under which this action will be logged. | Yes | +| Cancelled | If cancelled, the action won't be logged to the database. | Yes | --- diff --git a/src/main/java/net/coreprotect/database/logger/BlockBreakLogger.java b/src/main/java/net/coreprotect/database/logger/BlockBreakLogger.java index 70bf651..1b9f888 100644 --- a/src/main/java/net/coreprotect/database/logger/BlockBreakLogger.java +++ b/src/main/java/net/coreprotect/database/logger/BlockBreakLogger.java @@ -9,6 +9,7 @@ import org.bukkit.Material; import net.coreprotect.CoreProtect; import net.coreprotect.bukkit.BukkitAdapter; +import net.coreprotect.config.Config; import net.coreprotect.config.ConfigHandler; import net.coreprotect.database.statement.BlockStatement; import net.coreprotect.database.statement.UserStatement; @@ -48,7 +49,9 @@ public class BlockBreakLogger { } CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user); - CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + if (Config.getGlobal().API_ENABLED) { + CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + } int userId = UserStatement.getId(preparedStmt, event.getUser(), true); int wid = Util.getWorldId(location.getWorld().getName()); @@ -57,6 +60,11 @@ public class BlockBreakLogger { int y = location.getBlockY(); int z = location.getBlockZ(); CacheHandler.breakCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[] { time, event.getUser(), type }); + + if (event.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 d6f2338..ed49214 100644 --- a/src/main/java/net/coreprotect/database/logger/BlockPlaceLogger.java +++ b/src/main/java/net/coreprotect/database/logger/BlockPlaceLogger.java @@ -9,6 +9,7 @@ import org.bukkit.block.BlockState; import net.coreprotect.CoreProtect; import net.coreprotect.bukkit.BukkitAdapter; +import net.coreprotect.config.Config; import net.coreprotect.config.ConfigHandler; import net.coreprotect.database.statement.BlockStatement; import net.coreprotect.database.statement.UserStatement; @@ -79,7 +80,9 @@ public class BlockPlaceLogger { } CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user); - CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + if (Config.getGlobal().API_ENABLED) { + CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + } int userId = UserStatement.getId(preparedStmt, event.getUser(), true); int wid = Util.getWorldId(block.getWorld().getName()); @@ -89,8 +92,11 @@ public class BlockPlaceLogger { CacheHandler.lookupCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[] { time, event.getUser(), type }); } - int internalType = Util.getBlockId(type.name(), true); + if (event.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/database/logger/CommandLogger.java b/src/main/java/net/coreprotect/database/logger/CommandLogger.java index dcaca2a..759bb31 100644 --- a/src/main/java/net/coreprotect/database/logger/CommandLogger.java +++ b/src/main/java/net/coreprotect/database/logger/CommandLogger.java @@ -6,6 +6,7 @@ import java.util.Locale; import org.bukkit.Location; import net.coreprotect.CoreProtect; +import net.coreprotect.config.Config; import net.coreprotect.config.ConfigHandler; import net.coreprotect.database.statement.CommandStatement; import net.coreprotect.database.statement.UserStatement; @@ -28,7 +29,13 @@ public class CommandLogger { } CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user); - CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + if (Config.getGlobal().API_ENABLED) { + CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + } + + if (event.isCancelled()) { + return; + } int userId = UserStatement.getId(preparedStmt, event.getUser(), true); int wid = Util.getWorldId(location.getWorld().getName()); diff --git a/src/main/java/net/coreprotect/database/logger/ContainerLogger.java b/src/main/java/net/coreprotect/database/logger/ContainerLogger.java index eb80924..11b6e60 100644 --- a/src/main/java/net/coreprotect/database/logger/ContainerLogger.java +++ b/src/main/java/net/coreprotect/database/logger/ContainerLogger.java @@ -14,6 +14,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import net.coreprotect.CoreProtect; +import net.coreprotect.config.Config; import net.coreprotect.config.ConfigHandler; import net.coreprotect.consumer.Queue; import net.coreprotect.database.statement.ContainerStatement; @@ -168,7 +169,13 @@ public class ContainerLogger extends Queue { } CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user); - CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + if (Config.getGlobal().API_ENABLED) { + CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + } + + if (event.isCancelled()) { + return; + } int userId = UserStatement.getId(preparedStmt, event.getUser(), true); int wid = Util.getWorldId(location.getWorld().getName()); diff --git a/src/main/java/net/coreprotect/database/logger/EntityKillLogger.java b/src/main/java/net/coreprotect/database/logger/EntityKillLogger.java index f3f60ac..526d0eb 100644 --- a/src/main/java/net/coreprotect/database/logger/EntityKillLogger.java +++ b/src/main/java/net/coreprotect/database/logger/EntityKillLogger.java @@ -8,6 +8,7 @@ import java.util.Locale; import org.bukkit.block.BlockState; import net.coreprotect.CoreProtect; +import net.coreprotect.config.Config; import net.coreprotect.config.ConfigHandler; import net.coreprotect.database.statement.BlockStatement; import net.coreprotect.database.statement.EntityStatement; @@ -28,7 +29,13 @@ public class EntityKillLogger { } CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user); - CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + if (Config.getGlobal().API_ENABLED) { + CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + } + + if (event.isCancelled()) { + return; + } int userId = UserStatement.getId(preparedStmt, event.getUser(), true); int wid = Util.getWorldId(block.getWorld().getName()); diff --git a/src/main/java/net/coreprotect/database/logger/ItemLogger.java b/src/main/java/net/coreprotect/database/logger/ItemLogger.java index 199eea8..8c68f67 100644 --- a/src/main/java/net/coreprotect/database/logger/ItemLogger.java +++ b/src/main/java/net/coreprotect/database/logger/ItemLogger.java @@ -10,6 +10,7 @@ import org.bukkit.Location; import org.bukkit.inventory.ItemStack; import net.coreprotect.CoreProtect; +import net.coreprotect.config.Config; import net.coreprotect.config.ConfigHandler; import net.coreprotect.database.statement.ItemStatement; import net.coreprotect.database.statement.UserStatement; @@ -125,7 +126,13 @@ public class ItemLogger { } CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user); - CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + if (Config.getGlobal().API_ENABLED) { + CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + } + + if (event.isCancelled()) { + return; + } int userId = UserStatement.getId(preparedStmt, event.getUser(), true); int wid = Util.getWorldId(location.getWorld().getName()); diff --git a/src/main/java/net/coreprotect/database/logger/PlayerInteractLogger.java b/src/main/java/net/coreprotect/database/logger/PlayerInteractLogger.java index 84819b4..f279159 100644 --- a/src/main/java/net/coreprotect/database/logger/PlayerInteractLogger.java +++ b/src/main/java/net/coreprotect/database/logger/PlayerInteractLogger.java @@ -7,6 +7,7 @@ import org.bukkit.Material; import org.bukkit.block.BlockState; import net.coreprotect.CoreProtect; +import net.coreprotect.config.Config; import net.coreprotect.config.ConfigHandler; import net.coreprotect.database.statement.BlockStatement; import net.coreprotect.database.statement.UserStatement; @@ -27,7 +28,13 @@ public class PlayerInteractLogger { } CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user); - CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + if (Config.getGlobal().API_ENABLED) { + CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + } + + if (event.isCancelled()) { + return; + } int userId = UserStatement.getId(preparedStmt, event.getUser(), true); int wid = Util.getWorldId(block.getWorld().getName()); diff --git a/src/main/java/net/coreprotect/database/logger/PlayerKillLogger.java b/src/main/java/net/coreprotect/database/logger/PlayerKillLogger.java index 6807977..fe0fb0b 100644 --- a/src/main/java/net/coreprotect/database/logger/PlayerKillLogger.java +++ b/src/main/java/net/coreprotect/database/logger/PlayerKillLogger.java @@ -6,6 +6,7 @@ import java.util.Locale; import org.bukkit.block.BlockState; import net.coreprotect.CoreProtect; +import net.coreprotect.config.Config; import net.coreprotect.config.ConfigHandler; import net.coreprotect.database.statement.BlockStatement; import net.coreprotect.database.statement.UserStatement; @@ -29,7 +30,13 @@ public class PlayerKillLogger { } CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user); - CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + if (Config.getGlobal().API_ENABLED) { + CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + } + + if (event.isCancelled()) { + return; + } int userId = UserStatement.getId(preparedStmt, event.getUser(), true); int playerId = ConfigHandler.playerIdCache.get(player.toLowerCase(Locale.ROOT)); diff --git a/src/main/java/net/coreprotect/database/logger/SignTextLogger.java b/src/main/java/net/coreprotect/database/logger/SignTextLogger.java index aa4ef06..0572ee8 100644 --- a/src/main/java/net/coreprotect/database/logger/SignTextLogger.java +++ b/src/main/java/net/coreprotect/database/logger/SignTextLogger.java @@ -6,6 +6,7 @@ import java.util.Locale; import org.bukkit.Location; import net.coreprotect.CoreProtect; +import net.coreprotect.config.Config; import net.coreprotect.config.ConfigHandler; import net.coreprotect.database.statement.SignStatement; import net.coreprotect.database.statement.UserStatement; @@ -25,7 +26,13 @@ public class SignTextLogger { } CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user); - CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + if (Config.getGlobal().API_ENABLED) { + CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); + } + + if (event.isCancelled()) { + return; + } int userId = UserStatement.getId(preparedStmt, event.getUser(), true); int wid = Util.getWorldId(location.getWorld().getName()); diff --git a/src/main/java/net/coreprotect/event/CoreProtectPreLogEvent.java b/src/main/java/net/coreprotect/event/CoreProtectPreLogEvent.java index 5517930..f8c3634 100644 --- a/src/main/java/net/coreprotect/event/CoreProtectPreLogEvent.java +++ b/src/main/java/net/coreprotect/event/CoreProtectPreLogEvent.java @@ -6,6 +6,7 @@ import org.bukkit.event.HandlerList; public class CoreProtectPreLogEvent extends Event { private static final HandlerList handlers = new HandlerList(); + private boolean cancelled = false; private String user; public CoreProtectPreLogEvent(String user) { @@ -17,6 +18,14 @@ public class CoreProtectPreLogEvent extends Event { return user; } + public boolean isCancelled() { + return cancelled; + } + + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + public void setUser(String newUser) { if (newUser == null || newUser.isEmpty()) { throw new IllegalArgumentException("Invalid user");