From 96388df4b0b29e2691c146de55ea5d07b51443ff Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Mon, 13 Aug 2018 22:29:48 +1000 Subject: [PATCH] Add adapters for EntityType --- .../sk89q/worldedit/bukkit/BukkitAdapter.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java index f1181cf50..faa7e5b57 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java @@ -34,6 +34,8 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; +import com.sk89q.worldedit.world.entity.EntityType; +import com.sk89q.worldedit.world.entity.EntityTypes; import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.item.ItemType; @@ -244,7 +246,7 @@ public class BukkitAdapter { if (!itemType.getId().startsWith("minecraft:")) { throw new IllegalArgumentException("Bukkit only supports Minecraft items"); } - return Material.getMaterial(itemType.getId().replace("minecraft:", "").toUpperCase()); + return Material.getMaterial(itemType.getId().substring(10).toUpperCase()); } /** @@ -258,7 +260,7 @@ public class BukkitAdapter { if (!blockType.getId().startsWith("minecraft:")) { throw new IllegalArgumentException("Bukkit only supports Minecraft blocks"); } - return Material.getMaterial(blockType.getId().replace("minecraft:", "").toUpperCase()); + return Material.getMaterial(blockType.getId().substring(10).toUpperCase()); } /** @@ -272,6 +274,23 @@ public class BukkitAdapter { return GameModes.get(gameMode.name().toLowerCase()); } + /** + * Create a WorldEdit EntityType from a Bukkit one. + * + * @param entityType Bukkit EntityType + * @return WorldEdit EntityType + */ + public static EntityType adapt(org.bukkit.entity.EntityType entityType) { + return EntityTypes.get(entityType.getName().toLowerCase()); + } + + public static org.bukkit.entity.EntityType adapt(EntityType entityType) { + if (!entityType.getId().startsWith("minecraft:")) { + throw new IllegalArgumentException("Bukkit only supports vanilla entities"); + } + return org.bukkit.entity.EntityType.fromName(entityType.getId().substring(10).toLowerCase()); + } + /** * Converts a Material to a BlockType *