use of com.elmakers.mine.bukkit.mob.GoalConfiguration 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);
}
use of com.elmakers.mine.bukkit.mob.GoalConfiguration in project MagicPlugin by elBukkit.
the class MobUtils method getGoals.
private List<Goal> getGoals(Entity entity, Mob mob, ConfigurationSection config, String logContext) {
List<Goal> goals = new ArrayList<>();
List<GoalConfiguration> goalConfigurations = GoalConfiguration.fromList(config, "goals", platform.getLogger(), logContext);
if (goalConfigurations != null) {
Collections.sort(goalConfigurations);
for (GoalConfiguration goalConfig : goalConfigurations) {
try {
Goal goal = getGoal(goalConfig.getGoalType(), entity, mob, goalConfig.getConfiguration());
if (goal != null) {
goals.add(goal);
}
} catch (Exception ex) {
platform.getLogger().log(Level.WARNING, "Error creating goal: " + goalConfig.getGoalType() + " on mob " + entity.getType(), ex);
}
}
}
if (goals.isEmpty()) {
goals.add(new IdleGoal());
}
return goals;
}
use of com.elmakers.mine.bukkit.mob.GoalConfiguration in project MagicPlugin by elBukkit.
the class MobUtils method getGoals.
private List<Goal> getGoals(Entity entity, Mob mob, ConfigurationSection config, String logContext) {
List<Goal> goals = new ArrayList<>();
List<GoalConfiguration> goalConfigurations = GoalConfiguration.fromList(config, "goals", platform.getLogger(), logContext);
if (goalConfigurations != null) {
Collections.sort(goalConfigurations);
for (GoalConfiguration goalConfig : goalConfigurations) {
try {
Goal goal = getGoal(goalConfig.getGoalType(), entity, mob, goalConfig.getConfiguration());
if (goal != null) {
goals.add(goal);
}
} catch (Exception ex) {
platform.getLogger().log(Level.WARNING, "Error creating goal: " + goalConfig.getGoalType() + " on mob " + entity.getType(), ex);
}
}
}
if (goals.isEmpty()) {
goals.add(new IdleGoal());
}
return goals;
}
use of com.elmakers.mine.bukkit.mob.GoalConfiguration in project MagicPlugin by elBukkit.
the class MobUtils method getGoals.
private List<Goal> getGoals(Entity entity, Mob mob, ConfigurationSection config, String logContext) {
List<Goal> goals = new ArrayList<>();
List<GoalConfiguration> goalConfigurations = GoalConfiguration.fromList(config, "goals", platform.getLogger(), logContext);
if (goalConfigurations != null) {
Collections.sort(goalConfigurations);
for (GoalConfiguration goalConfig : goalConfigurations) {
try {
Goal goal = getGoal(goalConfig.getGoalType(), entity, mob, goalConfig.getConfiguration());
if (goal != null) {
goals.add(goal);
}
} catch (Exception ex) {
platform.getLogger().log(Level.WARNING, "Error creating goal: " + goalConfig.getGoalType() + " on mob " + entity.getType(), ex);
}
}
}
if (goals.isEmpty()) {
goals.add(new IdleGoal());
}
return goals;
}
use of com.elmakers.mine.bukkit.mob.GoalConfiguration in project MagicPlugin by elBukkit.
the class MobUtils method getGoals.
private List<Goal> getGoals(Entity entity, Mob mob, ConfigurationSection config, String logContext) {
List<Goal> goals = new ArrayList<>();
List<GoalConfiguration> goalConfigurations = GoalConfiguration.fromList(config, "goals", platform.getLogger(), logContext);
if (goalConfigurations != null) {
Collections.sort(goalConfigurations);
for (GoalConfiguration goalConfig : goalConfigurations) {
try {
Goal goal = getGoal(goalConfig.getGoalType(), entity, mob, goalConfig.getConfiguration());
if (goal != null) {
goals.add(goal);
}
} catch (Exception ex) {
platform.getLogger().log(Level.WARNING, "Error creating goal: " + goalConfig.getGoalType() + " on mob " + entity.getType(), ex);
}
}
}
if (goals.isEmpty()) {
goals.add(new IdleGoal());
}
return goals;
}
Aggregations