forked from LogBlock/LogBlock
@ -45,7 +45,8 @@ public enum Logging {
|
|||||||
DRAGONEGGTELEPORT(true),
|
DRAGONEGGTELEPORT(true),
|
||||||
DAYLIGHTDETECTORINTERACT,
|
DAYLIGHTDETECTORINTERACT,
|
||||||
LECTERNBOOKCHANGE(true),
|
LECTERNBOOKCHANGE(true),
|
||||||
SCAFFOLDING(true);
|
SCAFFOLDING(true),
|
||||||
|
SHULKER_BOX_CONTENT;
|
||||||
|
|
||||||
public static final int length = Logging.values().length;
|
public static final int length = Logging.values().length;
|
||||||
private final boolean defaultEnabled;
|
private final boolean defaultEnabled;
|
||||||
|
@ -0,0 +1,85 @@
|
|||||||
|
package de.diddiz.LogBlock.blockstate;
|
||||||
|
|
||||||
|
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
||||||
|
|
||||||
|
import de.diddiz.LogBlock.Logging;
|
||||||
|
import de.diddiz.LogBlock.config.WorldConfig;
|
||||||
|
import de.diddiz.util.BukkitUtils;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.ShulkerBox;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class BlockStateCodecShulkerBox implements BlockStateCodec {
|
||||||
|
@Override
|
||||||
|
public Material[] getApplicableMaterials() {
|
||||||
|
return BukkitUtils.getShulkerBoxBlocks().toArray(new Material[BukkitUtils.getShulkerBoxBlocks().size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public YamlConfiguration serialize(BlockState state) {
|
||||||
|
WorldConfig wcfg = getWorldConfig(state.getWorld());
|
||||||
|
if (wcfg == null || !wcfg.isLogging(Logging.SHULKER_BOX_CONTENT)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (state instanceof ShulkerBox) {
|
||||||
|
ShulkerBox shulkerBox = (ShulkerBox) state;
|
||||||
|
ItemStack[] content = shulkerBox.getSnapshotInventory().getStorageContents();
|
||||||
|
YamlConfiguration conf = new YamlConfiguration();
|
||||||
|
boolean anySlot = false;
|
||||||
|
for (int i = 0; i < content.length; i++) {
|
||||||
|
ItemStack stack = content[i];
|
||||||
|
if (stack != null && stack.getType() != Material.AIR) {
|
||||||
|
conf.set("slot" + i, stack);
|
||||||
|
anySlot = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (anySlot) {
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deserialize(BlockState state, YamlConfiguration conf) {
|
||||||
|
if (state instanceof ShulkerBox) {
|
||||||
|
ShulkerBox shulkerBox = (ShulkerBox) state;
|
||||||
|
if (conf != null) {
|
||||||
|
ItemStack[] content = shulkerBox.getSnapshotInventory().getStorageContents();
|
||||||
|
for (int i = 0; i < content.length; i++) {
|
||||||
|
ItemStack stack = conf.getItemStack("slot" + i);
|
||||||
|
if (stack != null && stack.getType() != Material.AIR) {
|
||||||
|
content[i] = stack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
shulkerBox.getSnapshotInventory().setContents(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(YamlConfiguration conf) {
|
||||||
|
if (conf != null) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("[");
|
||||||
|
boolean anySlot = false;
|
||||||
|
for (String key : conf.getKeys(false)) {
|
||||||
|
if (key.startsWith("slot")) {
|
||||||
|
ItemStack stack = conf.getItemStack(key);
|
||||||
|
if (stack != null && stack.getType() != Material.AIR) {
|
||||||
|
if (anySlot) {
|
||||||
|
sb.append(",");
|
||||||
|
}
|
||||||
|
anySlot = true;
|
||||||
|
sb.append(stack.getAmount()).append("x").append(stack.getType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sb.append("]");
|
||||||
|
return anySlot ? sb.toString() : null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -26,6 +26,7 @@ public class BlockStateCodecs {
|
|||||||
registerCodec(new BlockStateCodecBanner());
|
registerCodec(new BlockStateCodecBanner());
|
||||||
registerCodec(new BlockStateCodecSpawner());
|
registerCodec(new BlockStateCodecSpawner());
|
||||||
registerCodec(new BlockStateCodecLectern());
|
registerCodec(new BlockStateCodecLectern());
|
||||||
|
registerCodec(new BlockStateCodecShulkerBox());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasCodec(Material material) {
|
public static boolean hasCodec(Material material) {
|
||||||
|
@ -40,7 +40,7 @@ public class BlockBreakLogging extends LoggingListener {
|
|||||||
final Block origin = event.getBlock();
|
final Block origin = event.getBlock();
|
||||||
final Material type = origin.getType();
|
final Material type = origin.getType();
|
||||||
|
|
||||||
if (wcfg.isLogging(Logging.CHESTACCESS) && BukkitUtils.getContainerBlocks().contains(type)) {
|
if (wcfg.isLogging(Logging.CHESTACCESS) && BukkitUtils.getContainerBlocks().contains(type) && !BukkitUtils.getShulkerBoxBlocks().contains(type)) {
|
||||||
consumer.queueContainerBreak(actor, origin.getState());
|
consumer.queueContainerBreak(actor, origin.getState());
|
||||||
} else if (type == Material.ICE) {
|
} else if (type == Material.ICE) {
|
||||||
// When in creative mode ice doesn't form water
|
// When in creative mode ice doesn't form water
|
||||||
|
@ -113,7 +113,7 @@ public class ExplosionLogging extends LoggingListener {
|
|||||||
}
|
}
|
||||||
for (final Block block : event.blockList()) {
|
for (final Block block : event.blockList()) {
|
||||||
final Material type = block.getType();
|
final Material type = block.getType();
|
||||||
if (wcfg.isLogging(Logging.CHESTACCESS) && (getContainerBlocks().contains(type))) {
|
if (wcfg.isLogging(Logging.CHESTACCESS) && getContainerBlocks().contains(type) && !BukkitUtils.getShulkerBoxBlocks().contains(type)) {
|
||||||
consumer.queueContainerBreak(actor, block.getState());
|
consumer.queueContainerBreak(actor, block.getState());
|
||||||
} else {
|
} else {
|
||||||
consumer.queueBlockBreak(actor, block.getState());
|
consumer.queueBlockBreak(actor, block.getState());
|
||||||
@ -168,7 +168,7 @@ public class ExplosionLogging extends LoggingListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Material type = block.getType();
|
final Material type = block.getType();
|
||||||
if (wcfg.isLogging(Logging.CHESTACCESS) && (getContainerBlocks().contains(type))) {
|
if (wcfg.isLogging(Logging.CHESTACCESS) && getContainerBlocks().contains(type) && !BukkitUtils.getShulkerBoxBlocks().contains(type)) {
|
||||||
consumer.queueContainerBreak(actor, block.getState());
|
consumer.queueContainerBreak(actor, block.getState());
|
||||||
} else {
|
} else {
|
||||||
consumer.queueBlockBreak(actor, block.getState());
|
consumer.queueBlockBreak(actor, block.getState());
|
||||||
|
@ -55,6 +55,7 @@ public class BukkitUtils {
|
|||||||
|
|
||||||
private static final Set<Material> cropBlocks;
|
private static final Set<Material> cropBlocks;
|
||||||
private static final Set<Material> containerBlocks;
|
private static final Set<Material> containerBlocks;
|
||||||
|
private static final Set<Material> shulkerBoxBlocks;
|
||||||
|
|
||||||
private static final Set<Material> singleBlockPlants;
|
private static final Set<Material> singleBlockPlants;
|
||||||
private static final Set<Material> doublePlants;
|
private static final Set<Material> doublePlants;
|
||||||
@ -316,6 +317,26 @@ public class BukkitUtils {
|
|||||||
cropBlocks.add(Material.POTATO);
|
cropBlocks.add(Material.POTATO);
|
||||||
cropBlocks.add(Material.BEETROOT);
|
cropBlocks.add(Material.BEETROOT);
|
||||||
|
|
||||||
|
// Shulker Boxes
|
||||||
|
shulkerBoxBlocks = EnumSet.noneOf(Material.class);
|
||||||
|
shulkerBoxBlocks.add(Material.SHULKER_BOX);
|
||||||
|
shulkerBoxBlocks.add(Material.BLACK_SHULKER_BOX);
|
||||||
|
shulkerBoxBlocks.add(Material.BLUE_SHULKER_BOX);
|
||||||
|
shulkerBoxBlocks.add(Material.LIGHT_GRAY_SHULKER_BOX);
|
||||||
|
shulkerBoxBlocks.add(Material.BROWN_SHULKER_BOX);
|
||||||
|
shulkerBoxBlocks.add(Material.CYAN_SHULKER_BOX);
|
||||||
|
shulkerBoxBlocks.add(Material.GRAY_SHULKER_BOX);
|
||||||
|
shulkerBoxBlocks.add(Material.GREEN_SHULKER_BOX);
|
||||||
|
shulkerBoxBlocks.add(Material.LIGHT_BLUE_SHULKER_BOX);
|
||||||
|
shulkerBoxBlocks.add(Material.MAGENTA_SHULKER_BOX);
|
||||||
|
shulkerBoxBlocks.add(Material.LIME_SHULKER_BOX);
|
||||||
|
shulkerBoxBlocks.add(Material.ORANGE_SHULKER_BOX);
|
||||||
|
shulkerBoxBlocks.add(Material.PINK_SHULKER_BOX);
|
||||||
|
shulkerBoxBlocks.add(Material.PURPLE_SHULKER_BOX);
|
||||||
|
shulkerBoxBlocks.add(Material.RED_SHULKER_BOX);
|
||||||
|
shulkerBoxBlocks.add(Material.WHITE_SHULKER_BOX);
|
||||||
|
shulkerBoxBlocks.add(Material.YELLOW_SHULKER_BOX);
|
||||||
|
|
||||||
// Container Blocks
|
// Container Blocks
|
||||||
containerBlocks = EnumSet.noneOf(Material.class);
|
containerBlocks = EnumSet.noneOf(Material.class);
|
||||||
containerBlocks.add(Material.CHEST);
|
containerBlocks.add(Material.CHEST);
|
||||||
@ -325,23 +346,7 @@ public class BukkitUtils {
|
|||||||
containerBlocks.add(Material.HOPPER);
|
containerBlocks.add(Material.HOPPER);
|
||||||
containerBlocks.add(Material.BREWING_STAND);
|
containerBlocks.add(Material.BREWING_STAND);
|
||||||
containerBlocks.add(Material.FURNACE);
|
containerBlocks.add(Material.FURNACE);
|
||||||
containerBlocks.add(Material.SHULKER_BOX);
|
containerBlocks.addAll(shulkerBoxBlocks);
|
||||||
containerBlocks.add(Material.BLACK_SHULKER_BOX);
|
|
||||||
containerBlocks.add(Material.BLUE_SHULKER_BOX);
|
|
||||||
containerBlocks.add(Material.LIGHT_GRAY_SHULKER_BOX);
|
|
||||||
containerBlocks.add(Material.BROWN_SHULKER_BOX);
|
|
||||||
containerBlocks.add(Material.CYAN_SHULKER_BOX);
|
|
||||||
containerBlocks.add(Material.GRAY_SHULKER_BOX);
|
|
||||||
containerBlocks.add(Material.GREEN_SHULKER_BOX);
|
|
||||||
containerBlocks.add(Material.LIGHT_BLUE_SHULKER_BOX);
|
|
||||||
containerBlocks.add(Material.MAGENTA_SHULKER_BOX);
|
|
||||||
containerBlocks.add(Material.LIME_SHULKER_BOX);
|
|
||||||
containerBlocks.add(Material.ORANGE_SHULKER_BOX);
|
|
||||||
containerBlocks.add(Material.PINK_SHULKER_BOX);
|
|
||||||
containerBlocks.add(Material.PURPLE_SHULKER_BOX);
|
|
||||||
containerBlocks.add(Material.RED_SHULKER_BOX);
|
|
||||||
containerBlocks.add(Material.WHITE_SHULKER_BOX);
|
|
||||||
containerBlocks.add(Material.YELLOW_SHULKER_BOX);
|
|
||||||
containerBlocks.add(Material.BARREL);
|
containerBlocks.add(Material.BARREL);
|
||||||
containerBlocks.add(Material.BLAST_FURNACE);
|
containerBlocks.add(Material.BLAST_FURNACE);
|
||||||
containerBlocks.add(Material.SMOKER);
|
containerBlocks.add(Material.SMOKER);
|
||||||
@ -586,6 +591,10 @@ public class BukkitUtils {
|
|||||||
return containerBlocks;
|
return containerBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Set<Material> getShulkerBoxBlocks() {
|
||||||
|
return shulkerBoxBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isConcreteBlock(Material m) {
|
public static boolean isConcreteBlock(Material m) {
|
||||||
return concreteBlocks.contains(m);
|
return concreteBlocks.contains(m);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user