//if (!player.hasPermission("vanilla.command.spawn." + clazz.getName().toLowerCase())) {
// throw new CommandException("You do not have permission to spawn a(n) " + clazz.getSimpleName().toLowerCase());
//}
//TODO ServerEntityPrefab!
//How about some client support?
final Entity entity;
if (getEngine() instanceof Client) {
final EntityPrefab prefab = getEngine().getFileSystem().getResource("entity://Vanilla/entities/" + clazz.getSimpleName().toLowerCase() + "/" + clazz.getSimpleName().toLowerCase() + ".sep");
entity = prefab.createEntity(player.getPhysics().getPosition());
} else {
entity = player.getWorld().createEntity(player.getPhysics().getPosition(), clazz);
}
//Optional param was provided (ie the block material for a falling block).
if (args.length() == 2) {
//Now we know its either a living or substance. Lets figure out which.
if (Living.class.isAssignableFrom(clazz)) {
final Living living = entity.get(Living.class);
if (name.equalsIgnoreCase("human")) {
((Human) living).setName(args.popString("disp_name"));
}
} else if (Substance.class.isAssignableFrom(clazz)) {
final Substance substance = entity.get(Substance.class);
switch (ObjectType.valueOf(name.toUpperCase())) {
case ITEM:
Material item = VanillaArgumentTypes.popMaterial("item", args);
((Item) substance).setItemStack(new ItemStack(item, 1));
break;
case FALLING_OBJECT:
Material block = VanillaArgumentTypes.popMaterial("block", args);
if (!(block instanceof BlockMaterial)) {
throw new CommandException("Material " + block.getDisplayName() + " is not a block!");
}
((FallingBlock) substance).setMaterial((BlockMaterial) block);
break;
}
}
}
args.assertCompletelyParsed();
player.getWorld().spawnEntity(entity);
if (child) {
entity.get(Ageable.class).setAge(Ageable.MIN_AGE);
}
}