add CoreProtectBlockBreakPreLogEvent
- called before logging block breaking - can fetch the location is being logged - can modify username as CoreProtectPreLogEvent
This commit is contained in:
parent
8dd263e839
commit
feb36b03a2
|
@ -13,6 +13,7 @@ import net.coreprotect.config.Config;
|
|||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.BlockStatement;
|
||||
import net.coreprotect.database.statement.UserStatement;
|
||||
import net.coreprotect.event.CoreProtectBlockBreakPreLogEvent;
|
||||
import net.coreprotect.event.CoreProtectPreLogEvent;
|
||||
import net.coreprotect.thread.CacheHandler;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
@ -52,20 +53,28 @@ public class BlockBreakLogger {
|
|||
blockData = overrideData;
|
||||
}
|
||||
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
|
||||
// call events and fetch changed username, all other properties are readonly for now
|
||||
CoreProtectPreLogEvent coreProtectPreLogEvent = new CoreProtectPreLogEvent(user);
|
||||
if (Config.getGlobal().API_ENABLED) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(coreProtectPreLogEvent);
|
||||
}
|
||||
user = coreProtectPreLogEvent.getUser();
|
||||
|
||||
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
|
||||
CoreProtectBlockBreakPreLogEvent coreProtectBlockBreakPreLogEvent = new CoreProtectBlockBreakPreLogEvent(user, location);
|
||||
if (Config.getGlobal().API_ENABLED) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(coreProtectBlockBreakPreLogEvent);
|
||||
}
|
||||
user = coreProtectBlockBreakPreLogEvent.getUser();
|
||||
|
||||
int userId = UserStatement.getId(preparedStmt, user, true);
|
||||
int wid = Util.getWorldId(location.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
CacheHandler.breakCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[] { time, event.getUser(), type });
|
||||
CacheHandler.breakCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[]{time, user, type});
|
||||
|
||||
if (event.isCancelled()) {
|
||||
if (coreProtectPreLogEvent.isCancelled() || coreProtectBlockBreakPreLogEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package net.coreprotect.event;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class CoreProtectBlockBreakPreLogEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String user;
|
||||
private final Location location;
|
||||
private boolean cancelled = false;
|
||||
|
||||
public CoreProtectBlockBreakPreLogEvent(String user, Location location) {
|
||||
super(true); // async
|
||||
this.user = user;
|
||||
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean b) {
|
||||
cancelled = b;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String newUser) {
|
||||
if (newUser == null || newUser.isEmpty()) {
|
||||
throw new IllegalArgumentException("Invalid user");
|
||||
}
|
||||
|
||||
this.user = newUser;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue