forked from LogBlock/LogBlock
Update to 1.13 / Logging/Rollbacks work but largely untested
Still missing: Import data from 1.12 and older
This commit is contained in:
@@ -6,11 +6,12 @@ import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.WorldConfig;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.material.*;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -30,7 +31,7 @@ public class LoggingUtil {
|
||||
Block checkBlock = origin.getRelative(BlockFace.UP);
|
||||
int up = 0;
|
||||
final int highestBlock = checkBlock.getWorld().getHighestBlockYAt(checkBlock.getLocation());
|
||||
while (BukkitUtils.getRelativeTopFallables().contains(checkBlock.getType())) {
|
||||
while (checkBlock.getType().hasGravity()) {
|
||||
|
||||
// Record this block as falling
|
||||
consumer.queueBlockBreak(actor, checkBlock.getState());
|
||||
@@ -49,10 +50,10 @@ public class LoggingUtil {
|
||||
// Run this check to avoid false positives
|
||||
if (!BukkitUtils.getFallingEntityKillers().contains(finalLoc.getBlock().getType())) {
|
||||
finalLoc.add(0, up, 0); // Add this here after checking for block breakers
|
||||
if (finalLoc.getBlock().getType() == Material.AIR || BukkitUtils.getRelativeTopFallables().contains(finalLoc.getBlock().getType())) {
|
||||
consumer.queueBlockPlace(actor, finalLoc, checkBlock.getTypeId(), checkBlock.getData());
|
||||
if (finalLoc.getBlock().getType() == Material.AIR) {
|
||||
consumer.queueBlockPlace(actor, finalLoc, checkBlock.getBlockData());
|
||||
} else {
|
||||
consumer.queueBlockReplace(actor, finalLoc, finalLoc.getBlock().getTypeId(), finalLoc.getBlock().getData(), checkBlock.getTypeId(), checkBlock.getData());
|
||||
consumer.queueBlockReplace(actor, finalLoc, finalLoc.getBlock().getBlockData(), checkBlock.getBlockData());
|
||||
}
|
||||
up++;
|
||||
}
|
||||
@@ -73,28 +74,28 @@ public class LoggingUtil {
|
||||
|
||||
Block checkBlock = origin.getRelative(BlockFace.UP);
|
||||
if (BukkitUtils.getRelativeTopBreakabls().contains(checkBlock.getType())) {
|
||||
if (wcfg.isLogging(Logging.SIGNTEXT) && checkBlock.getType() == Material.SIGN_POST) {
|
||||
if (wcfg.isLogging(Logging.SIGNTEXT) && checkBlock.getType() == Material.SIGN) {
|
||||
consumer.queueSignBreak(actor, (Sign) checkBlock.getState());
|
||||
} else if (checkBlock.getType() == Material.IRON_DOOR_BLOCK || checkBlock.getType() == Material.WOODEN_DOOR) {
|
||||
} else if (checkBlock.getType() == Material.IRON_DOOR || Tag.WOODEN_DOORS.isTagged(checkBlock.getType())) {
|
||||
Block doorBlock = checkBlock;
|
||||
// If the doorBlock is the top half a door the player simply punched a door
|
||||
// this will be handled later.
|
||||
if (!BukkitUtils.isTop(doorBlock.getType(), doorBlock.getData())) {
|
||||
if (!BukkitUtils.isTop(doorBlock.getBlockData())) {
|
||||
doorBlock = doorBlock.getRelative(BlockFace.UP);
|
||||
// Fall back check just in case the top half wasn't a door
|
||||
if (doorBlock.getType() == Material.IRON_DOOR_BLOCK || doorBlock.getType() == Material.WOODEN_DOOR) {
|
||||
if (doorBlock.getType() == Material.IRON_DOOR || Tag.WOODEN_DOORS.isTagged(doorBlock.getType())) {
|
||||
consumer.queueBlockBreak(actor, doorBlock.getState());
|
||||
}
|
||||
consumer.queueBlockBreak(actor, checkBlock.getState());
|
||||
}
|
||||
} else if (checkBlock.getType() == Material.DOUBLE_PLANT) {
|
||||
} else if (BukkitUtils.isDoublePlant(checkBlock.getType())) {
|
||||
Block plantBlock = checkBlock;
|
||||
// If the plantBlock is the top half of a double plant the player simply
|
||||
// punched the plant this will be handled later.
|
||||
if (!BukkitUtils.isTop(plantBlock.getType(), plantBlock.getData())) {
|
||||
if (!BukkitUtils.isTop(plantBlock.getBlockData())) {
|
||||
plantBlock = plantBlock.getRelative(BlockFace.UP);
|
||||
// Fall back check just in case the top half wasn't a plant
|
||||
if (plantBlock.getType() == Material.DOUBLE_PLANT) {
|
||||
if (BukkitUtils.isDoublePlant(plantBlock.getType())) {
|
||||
consumer.queueBlockBreak(actor, plantBlock.getState());
|
||||
}
|
||||
consumer.queueBlockBreak(actor, checkBlock.getState());
|
||||
@@ -107,93 +108,45 @@ public class LoggingUtil {
|
||||
List<Location> relativeBreakables = BukkitUtils.getBlocksNearby(origin, BukkitUtils.getRelativeBreakables());
|
||||
if (relativeBreakables.size() != 0) {
|
||||
for (Location location : relativeBreakables) {
|
||||
final Material blockType = location.getBlock().getType();
|
||||
final BlockState blockState = location.getBlock().getState();
|
||||
final MaterialData data = blockState.getData();
|
||||
switch (blockType) {
|
||||
case REDSTONE_TORCH_ON:
|
||||
case REDSTONE_TORCH_OFF:
|
||||
if (blockState.getBlock().getRelative(((RedstoneTorch) data).getAttachedFace()).equals(origin)) {
|
||||
consumer.queueBlockBreak(actor, blockState);
|
||||
Block block = location.getBlock();
|
||||
BlockData blockData = block.getBlockData();
|
||||
if (blockData instanceof Directional) {
|
||||
if (block.getRelative(((Directional) blockData).getFacing()).equals(origin)) {
|
||||
if (wcfg.isLogging(Logging.SIGNTEXT) && block.getType() == Material.WALL_SIGN) {
|
||||
consumer.queueSignBreak(actor, (Sign) block.getState());
|
||||
} else {
|
||||
consumer.queueBlockBreak(actor, block.getState());
|
||||
}
|
||||
break;
|
||||
case TORCH:
|
||||
if (blockState.getBlock().getRelative(((Torch) data).getAttachedFace()).equals(origin)) {
|
||||
consumer.queueBlockBreak(actor, blockState);
|
||||
}
|
||||
break;
|
||||
case COCOA:
|
||||
if (blockState.getBlock().getRelative(((CocoaPlant) data).getAttachedFace().getOppositeFace()).equals(origin)) {
|
||||
consumer.queueBlockBreak(actor, blockState);
|
||||
}
|
||||
break;
|
||||
case LADDER:
|
||||
if (blockState.getBlock().getRelative(((Ladder) data).getAttachedFace()).equals(origin)) {
|
||||
consumer.queueBlockBreak(actor, blockState);
|
||||
}
|
||||
break;
|
||||
case LEVER:
|
||||
if (blockState.getBlock().getRelative(((Lever) data).getAttachedFace()).equals(origin)) {
|
||||
consumer.queueBlockBreak(actor, blockState);
|
||||
}
|
||||
break;
|
||||
case TRIPWIRE_HOOK:
|
||||
if (blockState.getBlock().getRelative(((TripwireHook) data).getAttachedFace()).equals(origin)) {
|
||||
consumer.queueBlockBreak(actor, blockState);
|
||||
}
|
||||
break;
|
||||
case WOOD_BUTTON:
|
||||
case STONE_BUTTON:
|
||||
if (blockState.getBlock().getRelative(((Button) data).getAttachedFace()).equals(origin)) {
|
||||
consumer.queueBlockBreak(actor, blockState);
|
||||
}
|
||||
break;
|
||||
case WALL_SIGN:
|
||||
if (blockState.getBlock().getRelative(((org.bukkit.material.Sign) data).getAttachedFace()).equals(origin)) {
|
||||
if (wcfg.isLogging(Logging.SIGNTEXT)) {
|
||||
consumer.queueSignBreak(actor, (Sign) blockState);
|
||||
} else {
|
||||
consumer.queueBlockBreak(actor, blockState);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TRAP_DOOR:
|
||||
if (blockState.getBlock().getRelative(((TrapDoor) data).getAttachedFace()).equals(origin)) {
|
||||
consumer.queueBlockBreak(actor, blockState);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
consumer.queueBlockBreak(actor, blockState);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Special door check
|
||||
if (origin.getType() == Material.IRON_DOOR_BLOCK || origin.getType() == Material.WOODEN_DOOR) {
|
||||
if (origin.getType() == Material.IRON_DOOR || Tag.WOODEN_DOORS.isTagged(origin.getType())) {
|
||||
Block doorBlock = origin;
|
||||
|
||||
// Up or down?
|
||||
if (!BukkitUtils.isTop(doorBlock.getType(), doorBlock.getData())) {
|
||||
if (!BukkitUtils.isTop(doorBlock.getBlockData())) {
|
||||
doorBlock = doorBlock.getRelative(BlockFace.UP);
|
||||
} else {
|
||||
doorBlock = doorBlock.getRelative(BlockFace.DOWN);
|
||||
}
|
||||
|
||||
if (doorBlock.getType() == Material.IRON_DOOR_BLOCK || doorBlock.getType() == Material.WOODEN_DOOR) {
|
||||
if (doorBlock.getType() == Material.IRON_DOOR || Tag.WOODEN_DOORS.isTagged(doorBlock.getType())) {
|
||||
consumer.queueBlockBreak(actor, doorBlock.getState());
|
||||
}
|
||||
} else if (origin.getType() == Material.DOUBLE_PLANT) { // Special double plant check
|
||||
} else if (BukkitUtils.isDoublePlant(origin.getType())) { // Special double plant check
|
||||
Block plantBlock = origin;
|
||||
|
||||
// Up or down?
|
||||
if (!BukkitUtils.isTop(origin.getType(), origin.getData())) {
|
||||
if (!BukkitUtils.isTop(origin.getBlockData())) {
|
||||
plantBlock = plantBlock.getRelative(BlockFace.UP);
|
||||
} else {
|
||||
plantBlock = plantBlock.getRelative(BlockFace.DOWN);
|
||||
}
|
||||
|
||||
if (plantBlock.getType() == Material.DOUBLE_PLANT) {
|
||||
if (BukkitUtils.isDoublePlant(plantBlock.getType())) {
|
||||
consumer.queueBlockBreak(actor, plantBlock.getState());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user