Create Custom Targets

Using AE's API for Target Registration

To integrate custom targets into the AdvancedEnchantments system, developers must utilize the AEAPI class from the net.advancedplugins.ae.api package. The crucial method in this process is registerTarget, defined in the AEAPI class.

registerTarget Method

/**
 * Register a new target type.
 *
 * @param plugin Plugin that is registering the target type.
 * @param type   Target type to register.
 * @return true if the target type was registered, false if not.
 */
public static boolean registerTarget(JavaPlugin plugin, TargetType type) { }

This method is pivotal for registering new targets. It requires the plugin instance and the custom target as arguments. The method returns a boolean indicating the success or failure of the registration process.

The TargetType Class

To create a custom target, developers must extend the TargetType class. This class serves as the base for all custom targets and provides several constructors and methods to define the targets' behavior.

All you need to do is return the target list. This is how an ADD target would look:

public class AddTarget extends TargetType {

    public AddTarget() {
        super("Add");
    }

    @Override
    public TargetResults getTargets(String effect, String target, ExecutionTask task) {
        double x = Double.parseDouble(classifyTarget(target).getOrDefault(TargetArgument.X, "0.0"));
        double y = Double.parseDouble(classifyTarget(target).getOrDefault(TargetArgument.Y, "0.0"));
        double z = Double.parseDouble(classifyTarget(target).getOrDefault(TargetArgument.Z, "0.0"));

        Location loc = task.getBuilder().getMain().getLocation().clone().add(x, y, z);
        return TargetResults.builder().targetLocations(Collections.singletonList(loc)).build();
    }

}

Do note tht the classifyTarget method will work only for internal parameters. If you want any custom one's you will need to parse the arguments yourself

Last updated

Was this helpful?