Changed doors and beds to no longer log data as two separate blocks

This commit is contained in:
Intelli 2022-02-23 18:56:00 -07:00
parent f9083053b2
commit 262f27da3e
6 changed files with 106 additions and 170 deletions

View File

@ -11,6 +11,8 @@ import org.bukkit.block.BlockState;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.Bisected.Half;
import org.bukkit.block.data.type.Bed;
import org.bukkit.block.data.type.Bed.Part;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -21,6 +23,7 @@ import net.coreprotect.config.Config;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.consumer.process.Process;
import net.coreprotect.listener.block.BlockUtil;
import net.coreprotect.model.BlockGroup;
import net.coreprotect.utility.Util;
public class Queue {
@ -99,19 +102,29 @@ public class Queue {
CreatureSpawner mobSpawner = (CreatureSpawner) block;
extraData = Util.getSpawnerType(mobSpawner.getSpawnedType());
}
else if (type.equals(Material.SUNFLOWER) || type.equals(Material.LILAC) || type.equals(Material.TALL_GRASS) || type.equals(Material.LARGE_FERN) || type.equals(Material.ROSE_BUSH) || type.equals(Material.PEONY)) { // Double plant
else if (type == Material.IRON_DOOR || BlockGroup.DOORS.contains(type) || type.equals(Material.SUNFLOWER) || type.equals(Material.LILAC) || type.equals(Material.TALL_GRASS) || type.equals(Material.LARGE_FERN) || type.equals(Material.ROSE_BUSH) || type.equals(Material.PEONY)) { // Double plant
if (block.getBlockData() instanceof Bisected) {
if (((Bisected) block.getBlockData()).getHalf().equals(Half.TOP) && !user.startsWith("#")) {
if (((Bisected) block.getBlockData()).getHalf().equals(Half.TOP)) {
if (blockNumber == 5) {
return;
}
if (block.getY() > BukkitAdapter.ADAPTER.getMinHeight(block.getWorld())) {
block = block.getWorld().getBlockAt(block.getX(), block.getY() - 1, block.getZ()).getState();
if (type != block.getType()) {
return;
}
blockData = block.getBlockData().getAsString();
}
}
}
}
else if (type.name().endsWith("_BED") && block.getBlockData() instanceof Bed) {
if (((Bed) block.getBlockData()).getPart().equals(Part.HEAD)) {
return;
}
}
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
@ -136,7 +149,7 @@ public class Queue {
replaceType = blockReplaced.getType();
replaceData = 0;
if ((replaceType.equals(Material.SUNFLOWER) || replaceType.equals(Material.LILAC) || replaceType.equals(Material.TALL_GRASS) || replaceType.equals(Material.LARGE_FERN) || replaceType.equals(Material.ROSE_BUSH) || replaceType.equals(Material.PEONY)) && replaceData >= 8) { // Double plant top half
if ((replaceType == Material.IRON_DOOR || BlockGroup.DOORS.contains(replaceType) || replaceType.equals(Material.SUNFLOWER) || replaceType.equals(Material.LILAC) || replaceType.equals(Material.TALL_GRASS) || replaceType.equals(Material.LARGE_FERN) || replaceType.equals(Material.ROSE_BUSH) || replaceType.equals(Material.PEONY)) && replaceData >= 8) { // Double plant top half
BlockState blockBelow = blockReplaced.getWorld().getBlockAt(blockReplaced.getX(), blockReplaced.getY() - 1, blockReplaced.getZ()).getState();
Material belowType = blockBelow.getType();
Queue.queueBlockBreak(user, blockBelow, belowType, blockBelow.getBlockData().getAsString(), 0);

View File

@ -3,16 +3,12 @@ package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.block.Skull;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.type.Door;
import net.coreprotect.database.logger.BlockBreakLogger;
import net.coreprotect.database.logger.SkullBreakLogger;
import net.coreprotect.model.BlockGroup;
import net.coreprotect.utility.Util;
class BlockBreakProcess {
@ -26,16 +22,6 @@ class BlockBreakProcess {
}
else {
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();
door.setHalf(Bisected.Half.TOP);
blockData = door.getAsString();
Location location = block.getLocation();
location.setY(location.getY() + 1);
BlockBreakLogger.log(preparedStmt, batchCount, user, location, Util.getBlockId(blockType), 0, null, blockData, null);
}
}
}
}
}

View File

@ -726,6 +726,13 @@ public class Rollback extends Queue {
}
}
}
else if (changeBlockData instanceof Bed) {
Bed bed = (Bed) changeBlockData;
if (bed.getPart() == Part.FOOT) {
Block adjacentBlock = block.getRelative(bed.getFacing());
Util.prepareTypeAndData(chunkChanges, adjacentBlock, rowType, null, false);
}
}
Util.prepareTypeAndData(chunkChanges, block, rowType, null, physics);
}
@ -817,83 +824,73 @@ public class Rollback extends Queue {
else if ((rowType == Material.NETHER_PORTAL) && rowAction == 0) {
Util.prepareTypeAndData(chunkChanges, block, Material.FIRE, null, true);
}
else if (rowType == Material.IRON_DOOR || BlockGroup.DOORS.contains(rowType)) {
else if (blockData == null && rowData > 0 && (rowType == Material.IRON_DOOR || BlockGroup.DOORS.contains(rowType))) {
if (countBlock) {
blockCount1++;
}
if (blockData != null) {
Util.prepareTypeAndData(chunkChanges, block, rowType, blockData, false);
block.setType(rowType, false);
Door door = (Door) block.getBlockData();
if (rowData >= 8) {
door.setHalf(Half.TOP);
rowData = rowData - 8;
}
else {
block.setType(rowType, false);
Door door = (Door) block.getBlockData();
if (rowData >= 8) {
door.setHalf(Half.TOP);
rowData = rowData - 8;
}
else {
door.setHalf(Half.BOTTOM);
}
if (rowData >= 4) {
door.setHinge(Hinge.RIGHT);
rowData = rowData - 4;
}
else {
door.setHinge(Hinge.LEFT);
}
BlockFace face = BlockFace.NORTH;
switch (rowData) {
case 0:
face = BlockFace.EAST;
break;
case 1:
face = BlockFace.SOUTH;
break;
case 2:
face = BlockFace.WEST;
break;
}
door.setFacing(face);
door.setOpen(false);
block.setBlockData(door, false);
door.setHalf(Half.BOTTOM);
}
if (rowData >= 4) {
door.setHinge(Hinge.RIGHT);
rowData = rowData - 4;
}
else {
door.setHinge(Hinge.LEFT);
}
BlockFace face = BlockFace.NORTH;
switch (rowData) {
case 0:
face = BlockFace.EAST;
break;
case 1:
face = BlockFace.SOUTH;
break;
case 2:
face = BlockFace.WEST;
break;
}
door.setFacing(face);
door.setOpen(false);
block.setBlockData(door, false);
}
else if (rowType.name().endsWith("_BED")) {
else if (blockData == null && rowData > 0 && (rowType.name().endsWith("_BED"))) {
if (countBlock) {
blockCount1++;
}
if (blockData != null) {
Util.prepareTypeAndData(chunkChanges, block, rowType, blockData, false);
block.setType(rowType, false);
Bed bed = (Bed) block.getBlockData();
BlockFace face = BlockFace.NORTH;
if (rowData > 4) {
bed.setPart(Part.HEAD);
rowData = rowData - 4;
}
else {
block.setType(rowType, false);
Bed bed = (Bed) block.getBlockData();
BlockFace face = BlockFace.NORTH;
if (rowData > 4) {
bed.setPart(Part.HEAD);
rowData = rowData - 4;
}
switch (rowData) {
case 2:
face = BlockFace.WEST;
break;
case 3:
face = BlockFace.EAST;
break;
case 4:
face = BlockFace.SOUTH;
break;
}
bed.setFacing(face);
block.setBlockData(bed, false);
switch (rowData) {
case 2:
face = BlockFace.WEST;
break;
case 3:
face = BlockFace.EAST;
break;
case 4:
face = BlockFace.SOUTH;
break;
}
bed.setFacing(face);
block.setBlockData(bed, false);
}
else if (rowType.name().endsWith("_BANNER")) {
Util.prepareTypeAndData(chunkChanges, block, rowType, blockData, false);
@ -964,6 +961,23 @@ public class Rollback extends Queue {
blockCount1++;
}
}
else if (rowType != Material.AIR && rawBlockData instanceof Bed) {
Bed bed = (Bed) rawBlockData;
if (bed.getPart() == Part.FOOT) {
Block adjacentBlock = block.getRelative(bed.getFacing());
Bed bedData = (Bed) rawBlockData.clone();
bedData.setPart(Part.HEAD);
Util.prepareTypeAndData(chunkChanges, adjacentBlock, rowType, bedData, false);
if (countBlock) {
blockCount1++;
}
}
Util.prepareTypeAndData(chunkChanges, block, rowType, blockData, true);
if (countBlock) {
blockCount1++;
}
}
else {
boolean physics = true;
/*

View File

@ -5,12 +5,7 @@ import java.util.List;
import java.util.Locale;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Bed;
import org.bukkit.block.data.type.Door;
import org.bukkit.block.data.type.Door.Hinge;
import net.coreprotect.CoreProtect;
import net.coreprotect.bukkit.BukkitAdapter;
@ -18,7 +13,6 @@ import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.statement.BlockStatement;
import net.coreprotect.database.statement.UserStatement;
import net.coreprotect.event.CoreProtectPreLogEvent;
import net.coreprotect.model.BlockGroup;
import net.coreprotect.thread.CacheHandler;
import net.coreprotect.utility.Util;
@ -68,97 +62,18 @@ public class BlockPlaceLogger {
int x = block.getX();
int y = block.getY();
int z = block.getZ();
int dx = x;
int dy = y;
int dz = z;
Material doubletype = type;
int doubledata = data;
int logdouble = 0;
if (event.getUser().length() > 0) {
CacheHandler.lookupCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[] { time, event.getUser(), type });
}
String doubleBlockData = null;
if (type.name().endsWith("_BED") || type == Material.IRON_DOOR || BlockGroup.DOORS.contains(type)) { // properly log double blocks (doors/beds)
BlockData blockStateBlockData = block.getBlockData();
if (blockStateBlockData instanceof Bed) {
Bed bed = (Bed) blockStateBlockData;
Bed.Part bedPart = bed.getPart();
BlockFace face = bed.getFacing();
int bedData = 1;
switch (face) {
case WEST:
dx = ((bedPart == Bed.Part.HEAD) ? (x + 1) : (x - 1));
bedData = 2;
break;
case EAST:
dx = ((bedPart == Bed.Part.HEAD) ? (x - 1) : (x + 1));
bedData = 3;
break;
case SOUTH:
dz = ((bedPart == Bed.Part.HEAD) ? (z - 1) : (z + 1));
bedData = 4;
break;
default:
dz = ((bedPart == Bed.Part.HEAD) ? (z + 1) : (z - 1));
break;
}
if (bedPart == Bed.Part.HEAD) {
data = 4 + bedData;
doubledata = bedData;
bed.setPart(Bed.Part.FOOT);
doubleBlockData = bed.getAsString();
}
else {
data = bedData;
doubledata = 4 + bedData;
bed.setPart(Bed.Part.HEAD);
doubleBlockData = bed.getAsString();
}
}
else if (blockStateBlockData instanceof Door) {
Door door = (Door) blockStateBlockData;
BlockFace face = door.getFacing();
Hinge hinge = door.getHinge();
switch (face) {
case EAST:
data = 0;
break;
case SOUTH:
data = 1;
break;
case WEST:
data = 2;
break;
default:
data = 3;
break;
}
if (hinge.equals(Hinge.RIGHT)) {
data = data + 4;
}
if (data < 8) {
dy = y + 1;
doubledata = data + 8;
}
}
logdouble = 1;
}
int internalType = Util.getBlockId(type.name(), true);
int internalDoubleType = Util.getBlockId(doubletype.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);
}
BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, internalType, data, meta, blockData, 1, 0);
if (logdouble == 1) {
BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, dx, dy, dz, internalDoubleType, doubledata, null, doubleBlockData, 1, 0);
}
}
catch (Exception e) {
e.printStackTrace();

View File

@ -22,6 +22,7 @@ import org.bukkit.block.data.MultipleFacing;
import org.bukkit.block.data.Rail;
import org.bukkit.block.data.Rail.Shape;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.block.data.type.Bed;
import org.bukkit.block.data.type.Bell;
import org.bukkit.block.data.type.Lantern;
import org.bukkit.enchantments.Enchantment;
@ -46,8 +47,10 @@ public final class BlockBreakListener extends Queue implements Listener {
if (blockData instanceof Directional && !(blockData instanceof Bisected) && scanMin != BlockUtil.BOTTOM && scanMin != BlockUtil.TOP) {
Directional directional = (Directional) blockData;
BlockFace blockFace = directional.getFacing();
boolean adjacent = scanBlock.getRelative(blockFace.getOppositeFace()).getLocation().equals(block.getLocation());
return adjacent;
if (blockData instanceof Bed) {
blockFace = ((Bed) blockData).getPart() == Bed.Part.FOOT ? blockFace.getOppositeFace() : blockFace;
}
return scanBlock.getRelative(blockFace.getOppositeFace()).getLocation().equals(block.getLocation());
}
else if (blockData instanceof MultipleFacing) {
MultipleFacing multipleFacing = (MultipleFacing) blockData;
@ -119,10 +122,6 @@ public final class BlockBreakListener extends Queue implements Listener {
if (scanMin < 7) {
Location scanLocation = locationMap[scanMin - 1];
if (scanMin == 4 && (type == Material.IRON_DOOR || BlockGroup.DOORS.contains(type))) { // required for doors
scanLocation = locationMap[5];
scanDown = true;
}
Block scanBlock = world.getBlockAt(scanLocation);
Material scanType = scanBlock.getType();
if (scanMin == 5) {

View File

@ -25,6 +25,8 @@ import org.bukkit.block.data.Bisected.Half;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Lightable;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.block.data.type.Bed;
import org.bukkit.block.data.type.Bed.Part;
import org.bukkit.block.data.type.Cake;
import org.bukkit.entity.EnderCrystal;
import org.bukkit.entity.Entity;
@ -88,6 +90,13 @@ public final class PlayerInteractListener extends Queue implements Listener {
checkBlock = world.getBlockAt(checkBlock.getX(), checkBlock.getY() - 1, checkBlock.getZ()).getState();
}
}
/* Check if clicking top half of bed */
if (checkBlockData instanceof Bed) {
Bed bed = (Bed) checkBlockData;
if (bed.getPart().equals(Part.HEAD)) {
checkBlock = event.getClickedBlock().getRelative(bed.getFacing().getOppositeFace()).getState();
}
}
final BlockState blockFinal = checkBlock;
class BasicThread implements Runnable {