mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2026-10-28 09:44:56 +00:00
Fixed Folia death logging crash (fixes #750)
This commit is contained in:
1 parent
4ae0affe4b
commit
2c30ba626a
5 files changed
+44
-14
No files matched your search
@@ -73,6 +73,10 @@ public class Queue {
|
||||
Consumer.consumer_id.put(currentConsumer, new Integer[] { Consumer.consumer_id.get(currentConsumer)[0], 0 });
|
||||
}
|
||||
|
||||
private static Location getBlockLocation(Location location) {
|
||||
return new Location(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
}
|
||||
|
||||
protected static void queueAdvancedBreak(String user, BlockState block, Material type, String blockData, int data, Material breakType, int blockNumber) {
|
||||
int currentConsumer = Consumer.currentConsumer;
|
||||
int consumerId = Consumer.newConsumerId(currentConsumer);
|
||||
@@ -283,7 +287,7 @@ public class Queue {
|
||||
int consumerId = Consumer.newConsumerId(currentConsumer);
|
||||
addConsumer(currentConsumer, new Object[] { consumerId, Process.ENTITY_KILL, null, 0, null, 0, 0 });
|
||||
Consumer.consumerObjectList.get(currentConsumer).put(consumerId, data);
|
||||
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, new Object[] { location.getBlock().getState(), type, null });
|
||||
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, new Object[] { getBlockLocation(location), type, null });
|
||||
}
|
||||
|
||||
protected static void queueEntitySpawn(String user, BlockState block, EntityType type, int data) {
|
||||
@@ -347,7 +351,7 @@ public class Queue {
|
||||
int currentConsumer = Consumer.currentConsumer;
|
||||
int consumerId = Consumer.newConsumerId(currentConsumer);
|
||||
addConsumer(currentConsumer, new Object[] { consumerId, Process.PLAYER_KILL, null, 0, null, 0, 0, null });
|
||||
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, new Object[] { location.getBlock().getState(), player });
|
||||
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, new Object[] { getBlockLocation(location), player });
|
||||
}
|
||||
|
||||
protected static void queuePlayerLogin(Player player, int time, int configSessions, int configUsernames) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.sql.PreparedStatement;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
@@ -16,19 +17,32 @@ class EntityKillProcess {
|
||||
static void process(PreparedStatement preparedStmt, PreparedStatement preparedStmtEntities, int batchCount, int processId, int id, Object object, String user) {
|
||||
if (object instanceof Object[]) {
|
||||
Object[] values = (Object[]) object;
|
||||
if (values.length <= 1 || !(values[0] instanceof BlockState) || !(values[1] instanceof EntityType)) {
|
||||
if (values.length <= 1 || !isLocationData(values[0]) || !(values[1] instanceof EntityType)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockState block = (BlockState) values[0];
|
||||
Location location = getLocation(values[0]);
|
||||
EntityType type = (EntityType) values[1];
|
||||
Map<Integer, List<Object>> objectLists = Consumer.consumerObjectList.get(processId);
|
||||
if (objectLists != null && objectLists.get(id) != null) {
|
||||
List<Object> objectList = objectLists.get(id);
|
||||
int entityId = EntityUtils.getEntityId(type);
|
||||
EntityKillLogger.log(preparedStmt, preparedStmtEntities, batchCount, user, block, objectList, entityId);
|
||||
EntityKillLogger.log(preparedStmt, preparedStmtEntities, batchCount, user, location, objectList, entityId);
|
||||
objectLists.remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isLocationData(Object value) {
|
||||
return value instanceof Location || value instanceof BlockState;
|
||||
}
|
||||
|
||||
private static Location getLocation(Object value) {
|
||||
if (value instanceof Location) {
|
||||
return ((Location) value).clone();
|
||||
}
|
||||
|
||||
BlockState block = (BlockState) value;
|
||||
return new Location(block.getWorld(), block.getX(), block.getY(), block.getZ());
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package net.coreprotect.consumer.process;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
import net.coreprotect.database.logger.PlayerKillLogger;
|
||||
@@ -11,13 +12,26 @@ class PlayerKillProcess {
|
||||
static void process(PreparedStatement preparedStmt, int batchCount, int id, Object object, String user) {
|
||||
if (object instanceof Object[]) {
|
||||
Object[] values = (Object[]) object;
|
||||
if (values.length <= 1 || !(values[0] instanceof BlockState) || !(values[1] instanceof String)) {
|
||||
if (values.length <= 1 || !isLocationData(values[0]) || !(values[1] instanceof String)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockState block = (BlockState) values[0];
|
||||
Location location = getLocation(values[0]);
|
||||
String player = (String) values[1];
|
||||
PlayerKillLogger.log(preparedStmt, batchCount, user, block, player);
|
||||
PlayerKillLogger.log(preparedStmt, batchCount, user, location, player);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isLocationData(Object value) {
|
||||
return value instanceof Location || value instanceof BlockState;
|
||||
}
|
||||
|
||||
private static Location getLocation(Object value) {
|
||||
if (value instanceof Location) {
|
||||
return ((Location) value).clone();
|
||||
}
|
||||
|
||||
BlockState block = (BlockState) value;
|
||||
return new Location(block.getWorld(), block.getX(), block.getY(), block.getZ());
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import net.coreprotect.CoreProtect;
|
||||
@@ -25,7 +24,7 @@ public class EntityKillLogger {
|
||||
throw new IllegalStateException("Database class");
|
||||
}
|
||||
|
||||
public static void log(PreparedStatement preparedStmt, PreparedStatement preparedStmt2, int batchCount, String user, BlockState block, List<Object> data, int type) {
|
||||
public static void log(PreparedStatement preparedStmt, PreparedStatement preparedStmt2, int batchCount, String user, Location location, List<Object> data, int type) {
|
||||
try {
|
||||
if (ConfigHandler.isBlacklisted(user)){
|
||||
return;
|
||||
@@ -42,7 +41,7 @@ public class EntityKillLogger {
|
||||
return;
|
||||
}
|
||||
|
||||
Location initialLocation = new Location(block.getWorld(), block.getX(), block.getY(), block.getZ());
|
||||
Location initialLocation = location.clone();
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, initialLocation, CoreProtectPreLogEvent.Action.ENTITY_KILL, 3, null, checkType, null);
|
||||
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.Locale;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import net.coreprotect.CoreProtect;
|
||||
@@ -22,7 +21,7 @@ public class PlayerKillLogger {
|
||||
throw new IllegalStateException("Database class");
|
||||
}
|
||||
|
||||
public static void log(PreparedStatement preparedStmt, int batchCount, String user, BlockState block, String player) {
|
||||
public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, String player) {
|
||||
try {
|
||||
if (ConfigHandler.isBlacklisted(user)) {
|
||||
return;
|
||||
@@ -32,7 +31,7 @@ public class PlayerKillLogger {
|
||||
UserStatement.loadId(preparedStmt.getConnection(), player, null);
|
||||
}
|
||||
|
||||
Location initialLocation = new Location(block.getWorld(), block.getX(), block.getY(), block.getZ());
|
||||
Location initialLocation = location.clone();
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, initialLocation, CoreProtectPreLogEvent.Action.PLAYER_KILL, 3, null, EntityType.PLAYER, null);
|
||||
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
Reference in new issue
Block a user