mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-11-28 12:55:34 +01:00
Fixed double chests not rolling back correctly when each half is in a separate chunk
This commit is contained in:
parent
5d6388fff7
commit
e178ed91ca
@ -1041,8 +1041,11 @@ public class Rollback extends Queue {
|
|||||||
else if (rowType != changeType && (BlockGroup.CONTAINERS.contains(rowType) || BlockGroup.CONTAINERS.contains(changeType))) {
|
else if (rowType != changeType && (BlockGroup.CONTAINERS.contains(rowType) || BlockGroup.CONTAINERS.contains(changeType))) {
|
||||||
block.setType(Material.AIR); // Clear existing container to prevent errors
|
block.setType(Material.AIR); // Clear existing container to prevent errors
|
||||||
|
|
||||||
boolean update = (blockData instanceof Chest);
|
boolean isChest = (blockData instanceof Chest);
|
||||||
Util.setTypeAndData(block, rowType, blockData, update);
|
Util.setTypeAndData(block, rowType, blockData, (isChest));
|
||||||
|
if (isChest) {
|
||||||
|
ChestTool.updateDoubleChest(block, blockData, false);
|
||||||
|
}
|
||||||
|
|
||||||
if (countBlock) {
|
if (countBlock) {
|
||||||
blockCount1++;
|
blockCount1++;
|
||||||
@ -1050,7 +1053,7 @@ public class Rollback extends Queue {
|
|||||||
}
|
}
|
||||||
else if (BlockGroup.UPDATE_STATE.contains(rowType) || rowType.name().contains("CANDLE")) {
|
else if (BlockGroup.UPDATE_STATE.contains(rowType) || rowType.name().contains("CANDLE")) {
|
||||||
Util.setTypeAndData(block, rowType, blockData, true);
|
Util.setTypeAndData(block, rowType, blockData, true);
|
||||||
ChestTool.updateDoubleChest(block, blockData);
|
ChestTool.updateDoubleChest(block, blockData, true);
|
||||||
if (countBlock) {
|
if (countBlock) {
|
||||||
blockCount1++;
|
blockCount1++;
|
||||||
}
|
}
|
||||||
|
@ -3,44 +3,31 @@ package net.coreprotect.utility;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.block.data.Directional;
|
import org.bukkit.block.data.Directional;
|
||||||
import org.bukkit.block.data.type.Chest;
|
import org.bukkit.block.data.type.Chest;
|
||||||
import org.bukkit.inventory.DoubleChestInventory;
|
import org.bukkit.block.data.type.Chest.Type;
|
||||||
|
|
||||||
|
import net.coreprotect.CoreProtect;
|
||||||
|
|
||||||
public class ChestTool {
|
public class ChestTool {
|
||||||
|
|
||||||
public static void updateDoubleChest(Block block, BlockData blockData) {
|
private ChestTool() {
|
||||||
try {
|
throw new IllegalStateException("Utility class");
|
||||||
// modifying existing container, trigger physics update on both sides of double chest
|
|
||||||
if (blockData != null && blockData instanceof Chest) {
|
|
||||||
int chestType = 0;
|
|
||||||
switch (((Chest) blockData).getType()) {
|
|
||||||
case LEFT:
|
|
||||||
chestType = 1;
|
|
||||||
break;
|
|
||||||
case RIGHT:
|
|
||||||
chestType = 2;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chestType > 0) {
|
public static void updateDoubleChest(Block block, BlockData blockData, boolean forceValidation) {
|
||||||
// check that not already a double chest
|
// modifying container, trigger physics update on both sides of double chest
|
||||||
BlockState blockState = block.getState();
|
if (!(blockData instanceof Chest) || ((Chest) blockData).getType() == Type.SINGLE) {
|
||||||
if (blockState instanceof org.bukkit.block.Chest) {
|
|
||||||
org.bukkit.block.Chest chest = (org.bukkit.block.Chest) blockState;
|
|
||||||
if (chest.getInventory() instanceof DoubleChestInventory) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Directional directional = (Directional) blockData;
|
Directional directional = (Directional) blockData;
|
||||||
BlockFace blockFace = directional.getFacing();
|
BlockFace blockFace = directional.getFacing();
|
||||||
BlockFace newFace = null;
|
BlockFace newFace = null;
|
||||||
if (chestType == 1) {
|
|
||||||
|
Type chestType = ((Chest) blockData).getType();
|
||||||
|
if (chestType == Type.LEFT) {
|
||||||
switch (blockFace) {
|
switch (blockFace) {
|
||||||
case NORTH:
|
case NORTH:
|
||||||
newFace = BlockFace.EAST;
|
newFace = BlockFace.EAST;
|
||||||
@ -58,7 +45,7 @@ public class ChestTool {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (chestType == 2) {
|
else if (chestType == Type.RIGHT) {
|
||||||
switch (blockFace) {
|
switch (blockFace) {
|
||||||
case NORTH:
|
case NORTH:
|
||||||
newFace = BlockFace.WEST;
|
newFace = BlockFace.WEST;
|
||||||
@ -77,19 +64,31 @@ public class ChestTool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newFace != null) {
|
if (newFace == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Type newType = (chestType == Type.LEFT) ? Type.RIGHT : Type.LEFT;
|
||||||
Block relativeBlock = block.getRelative(newFace);
|
Block relativeBlock = block.getRelative(newFace);
|
||||||
String relativeBlockData = relativeBlock.getBlockData().getAsString();
|
if (!forceValidation && (relativeBlock.getBlockData() instanceof Chest) && ((Chest) relativeBlock.getBlockData()).getType() == newType) {
|
||||||
String newChestType = (chestType == 1) ? "type=right" : "type=left";
|
return;
|
||||||
relativeBlockData = relativeBlockData.replace("type=single", newChestType);
|
|
||||||
relativeBlock.setBlockData(Bukkit.createBlockData(relativeBlockData), true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
||||||
|
try {
|
||||||
|
BlockData relativeBlockData = relativeBlock.getBlockData();
|
||||||
|
if (!blockData.getAsString().equals(block.getBlockData().getAsString()) || !(relativeBlockData instanceof Chest) || ((Chest) relativeBlockData).getType() == newType) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Chest chestData = (Chest) blockData;
|
||||||
|
chestData.setType(newType);
|
||||||
|
relativeBlock.setBlockData(chestData, true);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user