package com.laytonsmith.abstraction.bukkit;

import com.laytonsmith.abstraction.blocks.MCBlockState;
import com.laytonsmith.abstraction.MCBlockStateMeta;
import org.bukkit.block.BlockState;
import org.bukkit.inventory.meta.BlockStateMeta;

public class BukkitMCBlockStateMeta extends BukkitMCItemMeta implements MCBlockStateMeta {

	BlockStateMeta bsm;

	public BukkitMCBlockStateMeta(BlockStateMeta meta) {
		super(meta);
		this.bsm = meta;
	}

	@Override
	public MCBlockState getBlockState() {
		try {
			return BukkitConvertor.BukkitGetCorrectBlockState(bsm.getBlockState());
		} catch (IllegalStateException | NullPointerException ex) {
			// BlockStateMeta that cannot get a BlockState
			// or a broken implementation
			return null;
		}
	}

	@Override
	public void setBlockState(MCBlockState state) {
		bsm.setBlockState((BlockState) state.getHandle());
	}
}

@@ -147,16 +147,52 @@
 teMeta;%0A
+import com.laytonsmith.core.Static;%0A
 import o
@@ -269,16 +269,49 @@
 eMeta;%0A%0A
+import java.util.logging.Level;%0A%0A
 public c
@@ -564,67 +564,39 @@
 %7B%0A%09%09
-try %7B%0A%09%09%09return BukkitConvertor.BukkitGetCorrectBlockState(
+BlockState bs;%0A%09%09try %7B%0A%09%09%09bs = 
 bsm.
@@ -610,17 +610,16 @@
 kState()
-)
 ;%0A%09%09%7D ca
@@ -627,97 +627,153 @@
 ch (
-IllegalStateException %7C NullPointerException ex) %7B%0A%09%09%09// BlockStateMeta that cannot
+Exception ex) %7B%0A%09%09%09// Broken server implementation.%0A%09%09%09Static.getLogger().log(Level.WARNING, ex.getMessage() + %22 when%22%0A%09%09%09%09%09+ %22 trying to
  get 
-a
+the
  Blo
@@ -783,61 +783,111 @@
 tate
-%0A%09%09%09// or a broken implementation%0A%09%09%09return null;%0A%09%09%7D
+ from %22 + bsm.toString());%0A%09%09%09return null;%0A%09%09%7D%0A%09%09return BukkitConvertor.BukkitGetCorrectBlockState(bs);
 %0A%09%7D%0A

Add better logging when getting a broken BlockState from item meta