Added location to CoreProtectPreLogEvent (implements #709)
This commit is contained in:
parent
6155d4e864
commit
8b3e37774a
13 changed files with 622 additions and 45 deletions
|
|
@ -41,7 +41,7 @@ public class CoreProtectAPI extends Queue {
|
|||
/**
|
||||
* Current version of the API
|
||||
*/
|
||||
private static final int API_VERSION = 10;
|
||||
private static final int API_VERSION = 11;
|
||||
|
||||
public static class ParseResult extends net.coreprotect.api.result.ParseResult {
|
||||
|
||||
|
|
|
|||
|
|
@ -54,17 +54,18 @@ public class BlockBreakLogger {
|
|||
blockData = overrideData;
|
||||
}
|
||||
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, location);
|
||||
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
|
||||
int wid = WorldUtils.getWorldId(location.getWorld().getName());
|
||||
Location eventLocation = event.getLocation();
|
||||
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
int x = eventLocation.getBlockX();
|
||||
int y = eventLocation.getBlockY();
|
||||
int z = eventLocation.getBlockZ();
|
||||
CacheHandler.breakCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[] { time, event.getUser(), type });
|
||||
|
||||
if (event.isCancelled()) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import java.util.Locale;
|
|||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
import net.coreprotect.CoreProtect;
|
||||
|
|
@ -85,15 +86,21 @@ public class BlockPlaceLogger {
|
|||
}
|
||||
}
|
||||
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, block.getLocation());
|
||||
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
|
||||
int wid = WorldUtils.getWorldId(block.getWorld().getName());
|
||||
Location eventLocation = event.getLocation();
|
||||
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
|
||||
// Use event location for subsequent logging
|
||||
x = eventLocation.getBlockX();
|
||||
y = eventLocation.getBlockY();
|
||||
z = eventLocation.getBlockZ();
|
||||
|
||||
if (event.getUser().length() > 0) {
|
||||
CacheHandler.lookupCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[] { time, event.getUser(), type });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class CommandLogger {
|
|||
return;
|
||||
}
|
||||
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, location);
|
||||
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
|
|
@ -39,10 +39,11 @@ public class CommandLogger {
|
|||
}
|
||||
|
||||
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
|
||||
int wid = WorldUtils.getWorldId(location.getWorld().getName());
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
Location eventLocation = event.getLocation();
|
||||
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
|
||||
int x = eventLocation.getBlockX();
|
||||
int y = eventLocation.getBlockY();
|
||||
int z = eventLocation.getBlockZ();
|
||||
CommandStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, message);
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -223,7 +223,7 @@ public class ContainerLogger extends Queue {
|
|||
metadata = null;
|
||||
}
|
||||
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, location);
|
||||
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
|
|
@ -233,11 +233,12 @@ public class ContainerLogger extends Queue {
|
|||
}
|
||||
|
||||
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
|
||||
int wid = WorldUtils.getWorldId(location.getWorld().getName());
|
||||
Location eventLocation = event.getLocation();
|
||||
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
int x = eventLocation.getBlockX();
|
||||
int y = eventLocation.getBlockY();
|
||||
int z = eventLocation.getBlockZ();
|
||||
int typeId = MaterialUtils.getBlockId(item.getType().name(), true);
|
||||
int data = 0;
|
||||
int amount = item.getAmount();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
import net.coreprotect.CoreProtect;
|
||||
|
|
@ -30,7 +31,8 @@ public class EntityKillLogger {
|
|||
return;
|
||||
}
|
||||
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
|
||||
Location initialLocation = new Location(block.getWorld(), block.getX(), block.getY(), block.getZ());
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, initialLocation);
|
||||
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
|
|
@ -40,11 +42,12 @@ public class EntityKillLogger {
|
|||
}
|
||||
|
||||
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
|
||||
int wid = WorldUtils.getWorldId(block.getWorld().getName());
|
||||
Location eventLocation = event.getLocation();
|
||||
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
int x = eventLocation.getBlockX();
|
||||
int y = eventLocation.getBlockY();
|
||||
int z = eventLocation.getBlockZ();
|
||||
int entity_key = 0;
|
||||
|
||||
ResultSet resultSet = EntityStatement.insert(preparedStmt2, time, data);
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ public class ItemLogger {
|
|||
data = null;
|
||||
}
|
||||
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, location);
|
||||
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
|
|
@ -139,11 +139,12 @@ public class ItemLogger {
|
|||
}
|
||||
|
||||
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
|
||||
int wid = WorldUtils.getWorldId(location.getWorld().getName());
|
||||
Location eventLocation = event.getLocation();
|
||||
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L) - offset;
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
int x = eventLocation.getBlockX();
|
||||
int y = eventLocation.getBlockY();
|
||||
int z = eventLocation.getBlockZ();
|
||||
int typeId = MaterialUtils.getBlockId(item.getType().name(), true);
|
||||
int amount = item.getAmount();
|
||||
ItemStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, typeId, data, amount, action);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import java.util.Locale;
|
|||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
import net.coreprotect.CoreProtect;
|
||||
|
|
@ -29,7 +30,7 @@ public class PlayerInteractLogger {
|
|||
return;
|
||||
}
|
||||
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, block.getLocation());
|
||||
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
|
|
@ -39,11 +40,12 @@ public class PlayerInteractLogger {
|
|||
}
|
||||
|
||||
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
|
||||
int wid = WorldUtils.getWorldId(block.getWorld().getName());
|
||||
Location eventLocation = event.getLocation();
|
||||
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
int x = eventLocation.getBlockX();
|
||||
int y = eventLocation.getBlockY();
|
||||
int z = eventLocation.getBlockZ();
|
||||
int data = 0;
|
||||
BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, type, data, null, null, 2, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import java.sql.PreparedStatement;
|
|||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
import net.coreprotect.CoreProtect;
|
||||
|
|
@ -30,7 +31,8 @@ public class PlayerKillLogger {
|
|||
UserStatement.loadId(preparedStmt.getConnection(), player, null);
|
||||
}
|
||||
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
|
||||
Location initialLocation = new Location(block.getWorld(), block.getX(), block.getY(), block.getZ());
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, initialLocation);
|
||||
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
|
|
@ -41,11 +43,12 @@ public class PlayerKillLogger {
|
|||
|
||||
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
|
||||
int playerId = ConfigHandler.playerIdCache.get(player.toLowerCase(Locale.ROOT));
|
||||
int wid = WorldUtils.getWorldId(block.getWorld().getName());
|
||||
Location eventLocation = event.getLocation();
|
||||
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
int x = eventLocation.getBlockX();
|
||||
int y = eventLocation.getBlockY();
|
||||
int z = eventLocation.getBlockZ();
|
||||
BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, 0, playerId, null, null, 3, 0);
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class SignTextLogger {
|
|||
return;
|
||||
}
|
||||
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, location);
|
||||
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
|
|
@ -36,11 +36,12 @@ public class SignTextLogger {
|
|||
}
|
||||
|
||||
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
|
||||
int wid = WorldUtils.getWorldId(location.getWorld().getName());
|
||||
Location eventLocation = event.getLocation();
|
||||
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L) - timeOffset;
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
int x = eventLocation.getBlockX();
|
||||
int y = eventLocation.getBlockY();
|
||||
int z = eventLocation.getBlockZ();
|
||||
|
||||
if (line1.isEmpty() && line2.isEmpty() && line3.isEmpty() && line4.isEmpty()) {
|
||||
line1 = null;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package net.coreprotect.event;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
|
@ -9,16 +10,33 @@ public class CoreProtectPreLogEvent extends Event implements Cancellable {
|
|||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled = false;
|
||||
private String user;
|
||||
private Location location;
|
||||
|
||||
public CoreProtectPreLogEvent(String user, Location location) {
|
||||
super(true); // async
|
||||
this.user = user;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Backwards-compatible constructor for API v10 and earlier.
|
||||
* Defaults location to null; listeners expecting v10 signature can still subscribe.
|
||||
*/
|
||||
@Deprecated
|
||||
public CoreProtectPreLogEvent(String user) {
|
||||
super(true); // async
|
||||
this.user = user;
|
||||
this.location = null;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
|
|
@ -37,6 +55,14 @@ public class CoreProtectPreLogEvent extends Event implements Cancellable {
|
|||
this.user = newUser;
|
||||
}
|
||||
|
||||
public void setLocation(Location newLocation) {
|
||||
if (newLocation == null) {
|
||||
throw new IllegalArgumentException("Invalid location");
|
||||
}
|
||||
|
||||
this.location = newLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue