mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-11-25 12:25:37 +01:00
Made PreLogEvent cancellable (implements #325)
This commit is contained in:
parent
e7a6f21d88
commit
1a06e6a6bf
@ -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 |
|
||||
|
||||
---
|
||||
|
||||
|
@ -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);
|
||||
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) {
|
||||
|
@ -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);
|
||||
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);
|
||||
}
|
||||
|
@ -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);
|
||||
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());
|
||||
|
@ -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);
|
||||
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());
|
||||
|
@ -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);
|
||||
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());
|
||||
|
@ -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);
|
||||
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());
|
||||
|
@ -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);
|
||||
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());
|
||||
|
@ -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);
|
||||
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));
|
||||
|
@ -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);
|
||||
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());
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user