Search in sources :

Example 1 with GoalType

use of com.elmakers.mine.bukkit.mob.GoalType in project MagicPlugin by elBukkit.

the class EntityData method applyBrain.

private void applyBrain(Entity entity) {
    if (brain == null)
        return;
    // See if there are any custom goals
    MobUtils mobUtils = CompatibilityLib.getMobUtils();
    Collection<GoalConfiguration> goals = GoalConfiguration.fromList(brain, "goals", controller.getLogger(), "mob " + getKey());
    // Remove any existing goals first
    boolean removeDefaultGoals = brain.getBoolean("remove_default_goals", goals != null && !goals.isEmpty());
    if (removeDefaultGoals) {
        if (!mobUtils.removeGoals(entity)) {
            // This indicates we don't have support for goals, so just stop here.
            return;
        }
    }
    List<String> removeGoals = ConfigurationUtils.getStringList(brain, "remove_goals");
    if (removeGoals != null) {
        for (String goalKey : removeGoals) {
            GoalType goalType;
            try {
                goalType = GoalType.valueOf(goalKey.toUpperCase());
            } catch (Exception ex) {
                controller.getLogger().info("Invalid goal type in remove_goals of mob " + getKey() + ": " + goalKey);
                continue;
            }
            mobUtils.removeGoal(entity, goalType);
        }
    }
    // Apply custom goals
    applyGoals(entity, goals);
    // Now look for target goals
    Collection<GoalConfiguration> targets = GoalConfiguration.fromList(brain, "targets", controller.getLogger(), "mob " + getKey());
    // Remove any existing goals first
    boolean removeDefaultTargets = brain.getBoolean("remove_default_targets", targets != null && !targets.isEmpty());
    if (removeDefaultTargets) {
        if (!mobUtils.removeTargetGoals(entity)) {
            // This indicates we don't have support for goals, so just stop here.
            return;
        }
    }
    List<String> removeTargets = ConfigurationUtils.getStringList(brain, "remove_targets");
    if (removeTargets != null) {
        for (String goalKey : removeTargets) {
            GoalType goalType;
            try {
                goalType = GoalType.valueOf(goalKey.toUpperCase());
            } catch (Exception ex) {
                controller.getLogger().info("Invalid goal type in remove_targets of mob " + getKey() + ": " + goalKey);
                continue;
            }
            mobUtils.removeTargetGoal(entity, goalType);
        }
    }
    // Apply custom goals
    applyTargetGoals(entity, targets);
}
Also used : GoalConfiguration(com.elmakers.mine.bukkit.mob.GoalConfiguration) GoalType(com.elmakers.mine.bukkit.mob.GoalType) MobUtils(com.elmakers.mine.bukkit.utility.platform.MobUtils)

Aggregations

GoalConfiguration (com.elmakers.mine.bukkit.mob.GoalConfiguration)1 GoalType (com.elmakers.mine.bukkit.mob.GoalType)1 MobUtils (com.elmakers.mine.bukkit.utility.platform.MobUtils)1