Treat CAVE_AIR and VOID_AIR the same as AIR

This commit is contained in:
Brokkonaut
2018-07-27 17:19:15 +02:00
parent 905c25a943
commit 0a7ea8e747
11 changed files with 39 additions and 28 deletions

View File

@ -74,14 +74,14 @@ public class BlockChange implements LookupCacheElement {
msg.append(actor.getName()).append(" ");
}
if (signtext != null) {
final String action = type.getMaterial() == Material.AIR ? "destroyed " : "created ";
final String action = BukkitUtils.isEmpty(type.getMaterial()) ? "destroyed " : "created ";
if (!signtext.contains("\0")) {
msg.append(action).append(signtext);
} else {
msg.append(action).append((type.getMaterial() != Material.AIR ? type : replaced).getMaterial().name()).append(" [").append(signtext.replace("\0", "] [")).append("]");
msg.append(action).append((!BukkitUtils.isEmpty(type.getMaterial()) ? type : replaced).getMaterial().name()).append(" [").append(signtext.replace("\0", "] [")).append("]");
}
} else if (type.equals(replaced)) {
if (type.getMaterial() == Material.AIR) {
if (BukkitUtils.isEmpty(type.getMaterial())) {
msg.append("did an unspecified action");
} else if (ca != null) {
if (ca.itemStack == null) {
@ -109,9 +109,9 @@ public class BlockChange implements LookupCacheElement {
} else if (type.getMaterial() == Material.TRIPWIRE) {
msg.append("ran into ").append(type.getMaterial().name());
}
} else if (type.getMaterial() == Material.AIR) {
} else if (BukkitUtils.isEmpty(type.getMaterial())) {
msg.append("destroyed ").append(replaced.getMaterial().name());
} else if (replaced.getMaterial() == Material.AIR) {
} else if (BukkitUtils.isEmpty(replaced.getMaterial())) {
msg.append("created ").append(type.getMaterial().name());
} else {
msg.append("replaced ").append(replaced.getMaterial().name()).append(" with ").append(type.getMaterial().name());

View File

@ -67,7 +67,7 @@ public class Consumer extends TimerTask {
}
/**
* Logs a block break. The type afterwards is assumed to be 0 (air).
* Logs a block break. The type afterwards is assumed to be air.
*
* @param actor
* Actor responsible for breaking the block
@ -79,7 +79,7 @@ public class Consumer extends TimerTask {
}
/**
* Logs a block break. The block type afterwards is assumed to be 0 (air).
* Logs a block break. The block type afterwards is assumed to be air.
*
* @param actor
* Actor responsible for the block break
@ -95,7 +95,7 @@ public class Consumer extends TimerTask {
}
/**
* Logs a block place. The block type before is assumed to be 0 (air).
* Logs a block place. The block type before is assumed to be air.
*
* @param actor
* Actor responsible for placing the block
@ -107,7 +107,7 @@ public class Consumer extends TimerTask {
}
/**
* Logs a block place. The block type before is assumed to be 0 (air).
* Logs a block place. The block type before is assumed to be air.
*
* @param actor
* Actor responsible for placing the block
@ -215,7 +215,7 @@ public class Consumer extends TimerTask {
}
/**
* Logs a container block break. The block type before is assumed to be o (air). All content is assumed to be taken.
* Logs a container block break. The block type before is assumed to be air. All content is assumed to be taken.
*
* @param actor
* The actor breaking the container
@ -230,7 +230,7 @@ public class Consumer extends TimerTask {
}
/**
* Logs a container block break. The block type before is assumed to be o (air). All content is assumed to be taken.
* Logs a container block break. The block type before is assumed to be air. All content is assumed to be taken.
*
* @param actor
* The actor responsible for breaking the container

View File

@ -1,6 +1,8 @@
package de.diddiz.LogBlock;
import de.diddiz.LogBlock.config.Config;
import de.diddiz.util.BukkitUtils;
import org.bukkit.Location;
import org.bukkit.Material;
@ -57,7 +59,7 @@ public class Kill implements LookupCacheElement {
}
public String prettyItemName(Material t) {
if (t == null || t == Material.AIR) {
if (t == null || BukkitUtils.isEmpty(t)) {
return "fist";
}
return t.toString().replace('_', ' ').toLowerCase();

View File

@ -20,6 +20,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import de.diddiz.util.BukkitUtils;
import java.io.File;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
@ -167,7 +169,7 @@ public class WorldEditor implements Runnable {
return PerformResult.BLACKLISTED;
}
final Block block = loc.getBlock();
if (replacedBlock.getMaterial() == Material.AIR && block.getType() == Material.AIR) {
if (BukkitUtils.isEmpty(replacedBlock.getMaterial()) && BukkitUtils.isEmpty(block.getType())) {
return PerformResult.NO_ACTION;
}
final BlockState state = block.getState();
@ -175,7 +177,7 @@ public class WorldEditor implements Runnable {
world.loadChunk(block.getChunk());
}
if (setBlock.equals(replacedBlock)) {
if (setBlock.getMaterial() == Material.AIR) {
if (BukkitUtils.isEmpty(setBlock.getMaterial())) {
block.setType(Material.AIR);
} else if (ca != null) {
if (state instanceof InventoryHolder) {

View File

@ -2,6 +2,8 @@ package de.diddiz.LogBlock.events;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.ChestAccess;
import de.diddiz.util.BukkitUtils;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -85,10 +87,10 @@ public class BlockChangePreLogEvent extends PreLogEvent {
private boolean isValidSign() {
if ((typeAfter.getMaterial() == Material.SIGN || typeAfter.getMaterial() == Material.WALL_SIGN) && typeBefore.getMaterial() == Material.AIR) {
if ((typeAfter.getMaterial() == Material.SIGN || typeAfter.getMaterial() == Material.WALL_SIGN) && BukkitUtils.isEmpty(typeBefore.getMaterial())) {
return true;
}
if ((typeBefore.getMaterial() == Material.SIGN || typeBefore.getMaterial() == Material.WALL_SIGN) && typeAfter.getMaterial() == Material.AIR) {
if ((typeBefore.getMaterial() == Material.SIGN || typeBefore.getMaterial() == Material.WALL_SIGN) && BukkitUtils.isEmpty(typeAfter.getMaterial())) {
return true;
}
if ((typeAfter.getMaterial() == Material.SIGN || typeAfter.getMaterial() == Material.WALL_SIGN) && typeBefore.equals(typeAfter)) {

View File

@ -37,7 +37,7 @@ public class BlockPlaceLogging extends LoggingListener {
if (type.hasGravity()) {
// Catch placed blocks overwriting something
if (before.getType() != Material.AIR) {
if (!BukkitUtils.isEmpty(before.getType())) {
consumer.queueBlockBreak(actor, before);
}
@ -46,7 +46,7 @@ public class BlockPlaceLogging extends LoggingListener {
int y = loc.getBlockY();
int z = loc.getBlockZ();
// Blocks only fall if they have a chance to start a velocity
if (event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR) {
if (BukkitUtils.isEmpty(event.getBlock().getRelative(BlockFace.DOWN).getType())) {
while (y > 0 && BukkitUtils.canFall(loc.getWorld(), x, (y - 1), z)) {
y--;
}
@ -56,7 +56,7 @@ public class BlockPlaceLogging extends LoggingListener {
Location finalLoc = new Location(loc.getWorld(), x, y, z);
// Run this check to avoid false positives
if (!BukkitUtils.getFallingEntityKillers().contains(finalLoc.getBlock().getType())) {
if (finalLoc.getBlock().getType() == Material.AIR || finalLoc.equals(event.getBlock().getLocation())) {
if (BukkitUtils.isEmpty(finalLoc.getBlock().getType()) || finalLoc.equals(event.getBlock().getLocation())) {
consumer.queueBlockPlace(actor, finalLoc, event.getBlock().getBlockData());
} else {
consumer.queueBlockReplace(actor, finalLoc, finalLoc.getBlock().getBlockData(), event.getBlock().getBlockData());
@ -75,7 +75,7 @@ public class BlockPlaceLogging extends LoggingListener {
LogBlock.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(LogBlock.getInstance(), new Runnable() {
@Override
public void run() {
if (before.getType() == Material.AIR) {
if (BukkitUtils.isEmpty(before.getType())) {
consumer.queueBlockPlace(actor, after);
} else {
consumer.queueBlockReplace(actor, before, after);

View File

@ -32,7 +32,7 @@ public class FluidFlowLogging extends LoggingListener {
final Block to = event.getToBlock();
final Material typeTo = to.getType();
final boolean canFlow = typeTo == Material.AIR || BukkitUtils.getNonFluidProofBlocks().contains(typeTo);
final boolean canFlow = BukkitUtils.isEmpty(typeTo) || BukkitUtils.getNonFluidProofBlocks().contains(typeTo);
if (typeFrom == Material.LAVA) {
Levelled levelledFrom = (Levelled)blockDataFrom;
if (canFlow && wcfg.isLogging(Logging.LAVAFLOW)) {
@ -41,7 +41,7 @@ public class FluidFlowLogging extends LoggingListener {
} else {
Levelled newBlock = (Levelled) blockDataFrom.clone();
newBlock.setLevel(levelledFrom.getLevel() + 1);
if (typeTo == Material.AIR) {
if (BukkitUtils.isEmpty(typeTo)) {
consumer.queueBlockPlace(new Actor("LavaFlow"), to.getLocation(), newBlock);
} else {
consumer.queueBlockReplace(new Actor("LavaFlow"), to.getState(), newBlock);
@ -58,7 +58,7 @@ public class FluidFlowLogging extends LoggingListener {
Levelled levelledFrom = (Levelled)blockDataFrom;
Levelled newBlock = (Levelled) blockDataFrom.clone();
newBlock.setLevel(levelledFrom.getLevel() + 1);
if (typeTo == Material.AIR) {
if (BukkitUtils.isEmpty(typeTo)) {
consumer.queueBlockPlace(new Actor("WaterFlow"), to.getLocation(), newBlock);
} else if (BukkitUtils.getNonFluidProofBlocks().contains(typeTo)) {
consumer.queueBlockReplace(new Actor("WaterFlow"), to.getState(), newBlock);
@ -70,7 +70,7 @@ public class FluidFlowLogging extends LoggingListener {
consumer.queueBlockReplace(new Actor("WaterFlow"), to.getState(), Material.STONE.createBlockData());
}
}
if (typeTo == Material.AIR || BukkitUtils.getNonFluidProofBlocks().contains(typeTo)) {
if (BukkitUtils.isEmpty(typeTo) || BukkitUtils.getNonFluidProofBlocks().contains(typeTo)) {
for (final BlockFace face : new BlockFace[]{BlockFace.DOWN, BlockFace.NORTH, BlockFace.WEST, BlockFace.EAST, BlockFace.SOUTH}) {
final Block lower = to.getRelative(face);
if (lower.getType() == Material.LAVA) {

View File

@ -487,4 +487,8 @@ public class BukkitUtils {
public static boolean isDoublePlant(Material m) {
return doublePlants.contains(m);
}
public static boolean isEmpty(Material m) {
return m == Material.AIR || m == Material.CAVE_AIR || m == Material.VOID_AIR;
}
}

View File

@ -50,7 +50,7 @@ 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) {
if (BukkitUtils.isEmpty(finalLoc.getBlock().getType())) {
consumer.queueBlockPlace(actor, finalLoc, checkBlock.getBlockData());
} else {
consumer.queueBlockReplace(actor, finalLoc, finalLoc.getBlock().getBlockData(), checkBlock.getBlockData());

View File

@ -16,7 +16,6 @@ import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.bukkit.Material;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
@ -239,7 +238,7 @@ public class Utils {
}
public static byte[] saveItemStack(ItemStack stack) {
if (stack == null || stack.getType() == Material.AIR) {
if (stack == null || BukkitUtils.isEmpty(stack.getType())) {
return null;
}
try {

View File

@ -15,6 +15,8 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.Config;
import de.diddiz.util.BukkitUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -109,7 +111,7 @@ public class WorldEditLoggingHook {
plugin.getConsumer().queueBlockBreak(lbActor, location, origin.getBlockData());
}
BlockData newBlock = BukkitAdapter.adapt(block);
if (newBlock != null && newBlock.getMaterial() != Material.AIR) {
if (newBlock != null && !BukkitUtils.isEmpty(newBlock.getMaterial())) {
plugin.getConsumer().queueBlockPlace(lbActor, location, newBlock);
}
}