summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authormd_5 <git@md-5.net>2018-08-05 10:04:19 +1000
committermd_5 <git@md-5.net>2018-08-05 10:04:19 +1000
commit5e3082c7d8b6b7b6ef5e7774349e3cb3da0d996c (patch)
tree559f4c7173af959e01dfeff1f7b6d9d21cc365f8 /src
parentec2095d9c6dc466bf9be6b515fc7cc40739f89d8 (diff)
downloadcraftbukkit-5e3082c7d8b6b7b6ef5e7774349e3cb3da0d996c.tar
craftbukkit-5e3082c7d8b6b7b6ef5e7774349e3cb3da0d996c.tar.gz
craftbukkit-5e3082c7d8b6b7b6ef5e7774349e3cb3da0d996c.tar.lz
craftbukkit-5e3082c7d8b6b7b6ef5e7774349e3cb3da0d996c.tar.xz
craftbukkit-5e3082c7d8b6b7b6ef5e7774349e3cb3da0d996c.zip
SPIGOT-4230: Improve legacy block types
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java2
-rw-r--r--src/main/java/org/bukkit/craftbukkit/util/Commodore.java3
-rw-r--r--src/main/java/org/bukkit/craftbukkit/util/CraftEvil.java9
-rw-r--r--src/main/java/org/bukkit/craftbukkit/util/CraftLegacy.java10
4 files changed, 21 insertions, 3 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
index c48b394d..dfddbaf8 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
@@ -45,7 +45,7 @@ public class CraftBlock implements Block {
return getNMS().getBlock();
}
- protected net.minecraft.server.IBlockData getNMS() {
+ public net.minecraft.server.IBlockData getNMS() {
return world.getType(position);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
index c31bb74d..d172a1ae 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
@@ -228,7 +228,8 @@ public class Commodore
if ( EVIL.contains( owner + " " + desc + " " + name )
|| ( owner.startsWith( "org/bukkit/block/" ) && ( desc + " " + name ).equals( "()I getTypeId" ) )
- || ( owner.startsWith( "org/bukkit/block/" ) && ( desc + " " + name ).equals( "(I)Z setTypeId" ) ) )
+ || ( owner.startsWith( "org/bukkit/block/" ) && ( desc + " " + name ).equals( "(I)Z setTypeId" ) )
+ || ( owner.startsWith( "org/bukkit/block/" ) && ( desc + " " + name ).equals( "()Lorg/bukkit/Material; getType" ) ) )
{
Type[] args = Type.getArgumentTypes( desc );
Type[] newArgs = new Type[ args.length + 1 ];
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftEvil.java b/src/main/java/org/bukkit/craftbukkit/util/CraftEvil.java
index 609606e1..db77fbe7 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftEvil.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftEvil.java
@@ -9,6 +9,7 @@ import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.craftbukkit.block.CraftBlockState;
import org.bukkit.inventory.ItemStack;
/**
@@ -34,6 +35,14 @@ public class CraftEvil {
return getId(world.getBlockAt(location).getType());
}
+ public static Material getType(Block block) {
+ return CraftLegacy.toLegacyMaterial(((CraftBlock) block).getNMS());
+ }
+
+ public static Material getType(BlockState block) {
+ return CraftLegacy.toLegacyMaterial(((CraftBlockState) block).getHandle());
+ }
+
public static int getTypeId(Block block) {
return getId(block.getType());
}
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftLegacy.java b/src/main/java/org/bukkit/craftbukkit/util/CraftLegacy.java
index 3a92ac94..83ac79f7 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftLegacy.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftLegacy.java
@@ -134,6 +134,14 @@ public class CraftLegacy {
}
public static byte toLegacyData(IBlockData blockData) {
+ return toLegacy(blockData).getData();
+ }
+
+ public static Material toLegacyMaterial(IBlockData blockData) {
+ return toLegacy(blockData).getItemType();
+ }
+
+ public static MaterialData toLegacy(IBlockData blockData) {
MaterialData mappedData;
// Try exact match first
@@ -143,7 +151,7 @@ public class CraftLegacy {
mappedData = blockToMaterial.get(blockData.getBlock());
}
- return (mappedData == null) ? 0 : mappedData.getData();
+ return (mappedData == null) ? new MaterialData(Material.LEGACY_AIR) : mappedData;
}
public static Material fromLegacy(Material material) {