@Override
 public void finish(CastContext context) {
   super.finish(context);
   if (entity != null) {
     entity.remove();
     entity = null;
   }
 }
  @Override
  public void prepare(CastContext context, ConfigurationSection parameters) {
    super.prepare(context, parameters);

    doVelocity = parameters.getBoolean("apply_velocity", true);
    doTeleport = parameters.getBoolean("teleport", true);
    noTarget = parameters.getBoolean("no_target", true);
    orient = parameters.getBoolean("orient", true);
    velocityOffset = ConfigurationUtils.getVector(parameters, "velocity_offset");
    locationOffset = ConfigurationUtils.getVector(parameters, "location_offset");

    try {
      String entityTypeName = parameters.getString("type", "");
      if (!entityTypeName.isEmpty()) {
        entityType = EntityType.valueOf(entityTypeName.toUpperCase());
      }
    } catch (Exception ex) {
      entityType = null;
    }

    if (parameters.contains("spawn_reason")) {
      String reasonText = parameters.getString("spawn_reason").toUpperCase();
      try {
        spawnReason = CreatureSpawnEvent.SpawnReason.valueOf(reasonText);
      } catch (Exception ex) {
        context.getMage().sendMessage("Unknown spawn reason: " + reasonText);
      }
    }

    customName = parameters.getString("name");
    isBaby = parameters.getBoolean("baby", false);
    variantName = parameters.getString("variant");
    if (variantName != null && variantName.isEmpty()) {
      variantName = null;
    }
  }