Fixed item frames and paintings not logging directional data

This commit is contained in:
Intelli 2022-02-16 19:16:56 -07:00
parent 7398f7dfe6
commit e462e68806
15 changed files with 132 additions and 68 deletions

View File

@ -253,17 +253,17 @@ public class Queue {
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, new Object[] { block, type });
}
protected static void queueHangingRemove(String user, BlockState block, int delay) {
protected static void queueHangingRemove(String user, BlockState block, String blockData, int delay) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.HANGING_REMOVE, null, 0, null, 0, delay, null });
addConsumer(currentConsumer, new Object[] { consumerId, Process.HANGING_REMOVE, null, 0, null, 0, delay, blockData });
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
}
protected static void queueHangingSpawn(String user, BlockState block, Material type, int data, int delay) {
protected static void queueHangingSpawn(String user, BlockState block, Material type, String blockData, int data, int delay) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.HANGING_SPAWN, type, data, null, 0, delay, null });
addConsumer(currentConsumer, new Object[] { consumerId, Process.HANGING_SPAWN, type, data, null, 0, delay, blockData });
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
}
@ -281,7 +281,7 @@ public class Queue {
queueStandardData(consumerId, currentConsumer, new String[] { null, null }, data);
}
protected static void queueNaturalBlockBreak(String user, BlockState block, Block relative, Material type, int data) {
protected static void queueNaturalBlockBreak(String user, BlockState block, Block relative, Material type, String blockData, int data) {
List<BlockState> blockStates = new ArrayList<>();
if (relative != null) {
blockStates.add(relative.getState());
@ -289,7 +289,7 @@ public class Queue {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.NATURAL_BLOCK_BREAK, type, data, null, 0, 0, null });
addConsumer(currentConsumer, new Object[] { consumerId, Process.NATURAL_BLOCK_BREAK, type, data, null, 0, 0, blockData });
Consumer.consumerBlockList.get(currentConsumer).put(consumerId, blockStates);
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
}

View File

@ -25,7 +25,7 @@ class BlockBreakProcess {
SkullBreakLogger.log(preparedStmt, preparedStmtSkulls, batchCount, user, block);
}
else {
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), Util.getBlockId(blockType), blockDataId, meta, block.getBlockData().getAsString());
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), Util.getBlockId(blockType), blockDataId, meta, block.getBlockData().getAsString(), blockData);
if (forceData == 5) { // Fix for doors
if ((blockType == Material.IRON_DOOR || BlockGroup.DOORS.contains(blockType)) && (replaceType != Material.IRON_DOOR && !BlockGroup.DOORS.contains(replaceType))) {
Door door = (Door) block.getBlockData();
@ -33,7 +33,7 @@ class BlockBreakProcess {
blockData = door.getAsString();
Location location = block.getLocation();
location.setY(location.getY() + 1);
BlockBreakLogger.log(preparedStmt, batchCount, user, location, Util.getBlockId(blockType), 0, null, blockData);
BlockBreakLogger.log(preparedStmt, batchCount, user, location, Util.getBlockId(blockType), 0, null, blockData, null);
}
}
}

View File

@ -6,10 +6,10 @@ import net.coreprotect.utility.entity.HangingUtil;
class HangingRemoveProcess {
static void process(Object object, int delay) {
static void process(Object object, String hangingData, int delay) {
if (object instanceof BlockState) {
BlockState block = (BlockState) object;
HangingUtil.removeHanging(block, delay);
HangingUtil.removeHanging(block, hangingData, delay);
}
}
}

View File

@ -7,10 +7,10 @@ import net.coreprotect.utility.entity.HangingUtil;
class HangingSpawnProcess {
static void process(Object object, Material type, int data, int delay) {
static void process(Object object, Material type, int data, String hangingData, int delay) {
if (object instanceof BlockState) {
BlockState block = (BlockState) object;
HangingUtil.spawnHanging(block, type, data, delay);
HangingUtil.spawnHanging(block, type, hangingData, data, delay);
}
}
}

View File

@ -15,7 +15,7 @@ import net.coreprotect.utility.Util;
class NaturalBlockBreakProcess {
static void process(Statement statement, PreparedStatement preparedStmt, int batchCount, int processId, int id, String user, Object object, Material blockType, int blockData) {
static void process(Statement statement, PreparedStatement preparedStmt, int batchCount, int processId, int id, String user, Object object, Material blockType, int blockData, String overrideData) {
if (object instanceof BlockState) {
BlockState block = (BlockState) object;
Map<Integer, List<BlockState>> blockLists = Consumer.consumerBlockList.get(processId);
@ -28,7 +28,7 @@ class NaturalBlockBreakProcess {
}
}
blockLists.remove(id);
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), Util.getBlockId(blockType), blockData, null, block.getBlockData().getAsString());
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), Util.getBlockId(blockType), blockData, null, block.getBlockData().getAsString(), overrideData);
}
}
}

View File

@ -196,13 +196,13 @@ public class Process {
EntitySpawnProcess.process(statement, object, forceData);
break;
case Process.HANGING_REMOVE:
HangingRemoveProcess.process(object, forceData);
HangingRemoveProcess.process(object, (String) data[7], forceData);
break;
case Process.HANGING_SPAWN:
HangingSpawnProcess.process(object, blockType, blockData, forceData);
HangingSpawnProcess.process(object, blockType, blockData, (String) data[7], forceData);
break;
case Process.NATURAL_BLOCK_BREAK:
NaturalBlockBreakProcess.process(statement, preparedStmtBlocks, i, processId, id, user, object, blockType, blockData);
NaturalBlockBreakProcess.process(statement, preparedStmtBlocks, i, processId, id, user, object, blockType, blockData, (String) data[7]);
break;
case Process.MATERIAL_INSERT:
MaterialInsertProcess.process(preparedStmtMaterials, statement, i, object, forceData);

View File

@ -28,7 +28,7 @@ class StructureGrowthProcess {
int count = 0;
for (BlockState blockState : blockStates) {
if (count < replaceBlockCount) {
BlockBreakLogger.log(preparedStmt, batchCount, user, blockState.getLocation(), Util.getBlockId(blockState.getType()), 0, null, blockState.getBlockData().getAsString());
BlockBreakLogger.log(preparedStmt, batchCount, user, blockState.getLocation(), Util.getBlockId(blockState.getType()), 0, null, blockState.getBlockData().getAsString(), null);
}
else {
BlockPlaceLogger.log(preparedStmt, batchCount, user, blockState, 0, 0, null, -1, false, null, null, null);

View File

@ -338,7 +338,7 @@ public class Rollback extends Queue {
}
BlockData blockData = null;
if (blockDataString != null && blockDataString.length() > 0) {
if (blockDataString != null && blockDataString.contains(":")) {
try {
blockData = Bukkit.getServer().createBlockData(blockDataString);
}
@ -564,11 +564,11 @@ public class Rollback extends Queue {
if ((rowType == Material.AIR) && ((BukkitAdapter.ADAPTER.isItemFrame(oldTypeMaterial)) || (oldTypeMaterial == Material.PAINTING))) {
int delay = Util.getHangingDelay(hangingDelay, rowWorldId, rowX, rowY, rowZ);
Queue.queueHangingRemove(rowUser, block.getState(), delay);
Queue.queueHangingRemove(rowUser, block.getState(), blockDataString, delay);
}
else if ((BukkitAdapter.ADAPTER.isItemFrame(rowType)) || (rowType == Material.PAINTING)) {
int delay = Util.getHangingDelay(hangingDelay, rowWorldId, rowX, rowY, rowZ);
Queue.queueHangingSpawn(rowUser, block.getState(), rowType, rowData, delay);
Queue.queueHangingSpawn(rowUser, block.getState(), rowType, blockDataString, rowData, delay);
}
else if ((rowType == Material.ARMOR_STAND)) {
Location location1 = block.getLocation();

View File

@ -8,6 +8,7 @@ import org.bukkit.Location;
import org.bukkit.Material;
import net.coreprotect.CoreProtect;
import net.coreprotect.bukkit.BukkitAdapter;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.statement.BlockStatement;
import net.coreprotect.database.statement.UserStatement;
@ -21,7 +22,7 @@ public class BlockBreakLogger {
throw new IllegalStateException("Database class");
}
public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int type, int data, List<Object> meta, String blockData) {
public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int type, int data, List<Object> meta, String blockData, String overrideData) {
try {
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null || location == null) {
return;
@ -42,6 +43,9 @@ public class BlockBreakLogger {
if (checkType == Material.LECTERN) {
blockData = blockData.replaceFirst("has_book=true", "has_book=false");
}
else if (checkType == Material.PAINTING || BukkitAdapter.ADAPTER.isItemFrame(checkType)) {
blockData = overrideData;
}
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);

View File

@ -36,7 +36,7 @@ public class SkullBreakLogger {
keys.close();
}
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), type, skullKey, null, block.getBlockData().getAsString());
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), type, skullKey, null, block.getBlockData().getAsString(), null);
}
catch (Exception e) {
e.printStackTrace();

View File

@ -119,11 +119,13 @@ public final class HangingBreakByEntityListener extends Queue implements Listene
}
}
String blockData = null;
Material material;
int itemData = 0;
if (entity instanceof ItemFrame) {
material = BukkitAdapter.ADAPTER.getFrameType(entity);
ItemFrame itemframe = (ItemFrame) entity;
blockData = "FACING=" + itemframe.getFacing().name();
if (itemframe.getItem() != null) {
itemData = Util.getBlockId(itemframe.getItem().getType());
@ -132,11 +134,12 @@ public final class HangingBreakByEntityListener extends Queue implements Listene
else {
material = Material.PAINTING;
Painting painting = (Painting) entity;
blockData = "FACING=" + painting.getFacing().name();
itemData = Util.getArtId(painting.getArt().toString(), true);
}
if (!event.isCancelled() && Config.getConfig(blockEvent.getWorld()).BLOCK_BREAK && !inspecting) {
Queue.queueBlockBreak(culprit, blockEvent, material, null, itemData);
Queue.queueBlockBreak(culprit, blockEvent, material, blockData, itemData);
}
}
}

View File

@ -43,11 +43,13 @@ public final class HangingBreakListener extends Queue implements Listener {
attachedBlock = hangingEntity.getLocation().getBlock().getRelative(attached);
}
String blockData = null;
Material material;
int itemData = 0;
if (entity instanceof ItemFrame) {
material = BukkitAdapter.ADAPTER.getFrameType(entity);
ItemFrame itemframe = (ItemFrame) entity;
blockData = "FACING=" + itemframe.getFacing().name();
if (itemframe.getItem() != null) {
itemData = Util.getBlockId(itemframe.getItem().getType());
@ -56,11 +58,12 @@ public final class HangingBreakListener extends Queue implements Listener {
else {
material = Material.PAINTING;
Painting painting = (Painting) entity;
blockData = "FACING=" + painting.getFacing().name();
itemData = Util.getArtId(painting.getArt().toString(), true);
}
if (!event.isCancelled() && Config.getConfig(blockEvent.getWorld()).NATURAL_BREAK) {
Queue.queueNaturalBlockBreak(causeName, blockEvent.getState(), attachedBlock, material, itemData);
Queue.queueNaturalBlockBreak(causeName, blockEvent.getState(), attachedBlock, material, blockData, itemData);
}
}
}

View File

@ -26,16 +26,20 @@ public final class HangingPlaceListener extends Queue implements Listener {
if (entity instanceof ItemFrame || entity instanceof Painting) {
Block blockEvent = event.getEntity().getLocation().getBlock();
String blockData = null;
Material material;
int artId;
if (entity instanceof ItemFrame) {
material = BukkitAdapter.ADAPTER.getFrameType(entity);
ItemFrame itemFrame = (ItemFrame) entity;
blockData = "FACING=" + itemFrame.getFacing().name();
artId = 0;
}
else {
material = Material.PAINTING;
Painting painting = (Painting) entity;
blockData = "FACING=" + painting.getFacing().name();
artId = Util.getArtId(painting.getArt().toString(), true);
}
@ -48,7 +52,7 @@ public final class HangingPlaceListener extends Queue implements Listener {
}
if (!event.isCancelled() && Config.getConfig(blockEvent.getWorld()).BLOCK_PLACE && inspect == 0) {
Queue.queueBlockPlace(player.getName(), blockEvent.getState(), blockEvent.getType(), null, material, artId, 1, null);
Queue.queueBlockPlace(player.getName(), blockEvent.getState(), blockEvent.getType(), null, material, artId, 1, blockData);
}
}
}

View File

@ -451,6 +451,15 @@ public class Util extends Queue {
}
string = String.join(",", blockDataArray);
}
else if (!string.contains(":") && (material == Material.PAINTING || BukkitAdapter.ADAPTER.isItemFrame(material))) {
int id = getBlockdataId(string, true);
if (id > -1) {
string = Integer.toString(id);
}
else {
return result;
}
}
else {
return result;
}
@ -483,7 +492,13 @@ public class Util extends Queue {
blockDataArray.add(block);
}
}
result = NAMESPACE + material.name().toLowerCase(Locale.ROOT) + "[" + String.join(",", blockDataArray) + "]";
if (material == Material.PAINTING || BukkitAdapter.ADAPTER.isItemFrame(material)) {
result = String.join(",", blockDataArray);
}
else {
result = NAMESPACE + material.name().toLowerCase(Locale.ROOT) + "[" + String.join(",", blockDataArray) + "]";
}
}
else {
result = "";

View File

@ -10,6 +10,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Painting;
import org.bukkit.inventory.ItemStack;
@ -26,7 +27,7 @@ public class HangingUtil {
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void spawnHanging(final BlockState blockstate, final Material rowType, final int rowData, int delay) {
public static void spawnHanging(final BlockState blockstate, final Material rowType, final String hangingData, final int rowData, int delay) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
try {
Block block = blockstate.getBlock();
@ -34,51 +35,69 @@ public class HangingUtil {
int y = block.getY();
int z = block.getZ();
BlockFace hangingFace = null;
if (hangingData != null && !hangingData.contains(":") && hangingData.contains("=")) {
try {
hangingFace = BlockFace.valueOf(hangingData.split("=")[1].toUpperCase(Locale.ROOT));
}
catch (Exception e) {
e.printStackTrace();
}
}
for (Entity e : block.getChunk().getEntities()) {
if ((BukkitAdapter.ADAPTER.isItemFrame(rowType) && e instanceof ItemFrame) || (rowType.equals(Material.PAINTING) && e instanceof Painting)) {
Location el = e.getLocation();
if (el.getBlockX() == x && el.getBlockY() == y && el.getBlockZ() == z) {
e.remove();
break;
if (hangingFace == null || ((Hanging) e).getFacing() == hangingFace) {
e.remove();
break;
}
}
}
}
Block c1 = block.getWorld().getBlockAt((x + 1), y, z);
Block c2 = block.getWorld().getBlockAt((x - 1), y, z);
Block c3 = block.getWorld().getBlockAt(x, y, (z + 1));
Block c4 = block.getWorld().getBlockAt(x, y, (z - 1));
BlockFace faceSet = null;
if (!BlockGroup.NON_ATTACHABLE.contains(c1.getType())) {
faceSet = BlockFace.WEST;
block = c1;
}
else if (!BlockGroup.NON_ATTACHABLE.contains(c2.getType())) {
faceSet = BlockFace.EAST;
block = c2;
}
else if (!BlockGroup.NON_ATTACHABLE.contains(c3.getType())) {
faceSet = BlockFace.NORTH;
block = c3;
}
else if (!BlockGroup.NON_ATTACHABLE.contains(c4.getType())) {
faceSet = BlockFace.SOUTH;
block = c4;
}
BlockFace face = null;
if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.EAST)))) {
face = BlockFace.EAST;
if (hangingFace == null) {
Block c1 = block.getWorld().getBlockAt((x + 1), y, z);
Block c2 = block.getWorld().getBlockAt((x - 1), y, z);
Block c3 = block.getWorld().getBlockAt(x, y, (z + 1));
Block c4 = block.getWorld().getBlockAt(x, y, (z - 1));
if (!BlockGroup.NON_ATTACHABLE.contains(c1.getType())) {
faceSet = BlockFace.WEST;
block = c1;
}
else if (!BlockGroup.NON_ATTACHABLE.contains(c2.getType())) {
faceSet = BlockFace.EAST;
block = c2;
}
else if (!BlockGroup.NON_ATTACHABLE.contains(c3.getType())) {
faceSet = BlockFace.NORTH;
block = c3;
}
else if (!BlockGroup.NON_ATTACHABLE.contains(c4.getType())) {
faceSet = BlockFace.SOUTH;
block = c4;
}
if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.EAST)))) {
face = BlockFace.EAST;
}
else if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.NORTH)))) {
face = BlockFace.NORTH;
}
else if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.WEST)))) {
face = BlockFace.WEST;
}
else if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.SOUTH)))) {
face = BlockFace.SOUTH;
}
}
else if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.NORTH)))) {
face = BlockFace.NORTH;
}
else if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.WEST)))) {
face = BlockFace.WEST;
}
else if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.SOUTH)))) {
face = BlockFace.SOUTH;
else {
faceSet = hangingFace;
face = hangingFace;
}
if (faceSet != null && face != null) {
@ -105,8 +124,10 @@ public class HangingUtil {
}
}
}
Block spawnBlock = block.getRelative(face);
Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
Block spawnBlock = hangingFace != null ? block : block.getRelative(face);
if (hangingFace == null) {
Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
}
Painting hanging = null;
try {
hanging = block.getWorld().spawn(spawnBlock.getLocation(), Painting.class);
@ -121,8 +142,10 @@ public class HangingUtil {
}
else if (BukkitAdapter.ADAPTER.isItemFrame(rowType)) {
try {
Block spawnBlock = block.getRelative(face);
Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
Block spawnBlock = hangingFace != null ? block : block.getRelative(face);
if (hangingFace == null) {
Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
}
Class itemFrame = BukkitAdapter.ADAPTER.getFrameClass(rowType);
Entity entity = block.getWorld().spawn(spawnBlock.getLocation(), itemFrame);
if (entity instanceof ItemFrame) {
@ -148,14 +171,26 @@ public class HangingUtil {
}, delay);
}
public static void removeHanging(final BlockState block, int delay) {
public static void removeHanging(final BlockState block, final String hangingData, int delay) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
try {
BlockFace hangingFace = null;
if (hangingData != null && !hangingData.contains(":") && hangingData.contains("=")) {
try {
hangingFace = BlockFace.valueOf(hangingData.split("=")[1].toUpperCase(Locale.ROOT));
}
catch (Exception e) {
e.printStackTrace();
}
}
for (Entity e : block.getChunk().getEntities()) {
if (e instanceof ItemFrame || e instanceof Painting) {
Location el = e.getLocation();
if (el.getBlockX() == block.getX() && el.getBlockY() == block.getY() && el.getBlockZ() == block.getZ()) {
e.remove();
if (hangingFace == null || ((Hanging) e).getFacing() == hangingFace) {
e.remove();
}
}
}
}