Add adapters for EntityType

This commit is contained in:
Matthew Miller 2018-08-13 22:29:48 +10:00
parent e0e7778536
commit 96388df4b0

View File

@ -34,6 +34,8 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; 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.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
@ -244,7 +246,7 @@ public class BukkitAdapter {
if (!itemType.getId().startsWith("minecraft:")) { if (!itemType.getId().startsWith("minecraft:")) {
throw new IllegalArgumentException("Bukkit only supports Minecraft items"); 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:")) { if (!blockType.getId().startsWith("minecraft:")) {
throw new IllegalArgumentException("Bukkit only supports Minecraft blocks"); 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()); 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 * Converts a Material to a BlockType
* *