Creating Conditions

Create your own conditions using the API

You are able to create your own conditions by creating the following:

The following condition will check if the player is gliding

public class ConditionExample extends Condition {
    public ConditionExample(String identifier) {
        super(identifier, "isExample", 1, false);
    }

    @Override
    public boolean parseCondition(String[] args, LivingEntity player, @Nullable LivingEntity target) {
        return player.isGliding();
    }
}

Here is an example of using an event within your condition

public class ConditionBlock extends Condition {
    public ConditionBlock() {
        super("isBlock", "isBlock [BLOCK-TYPE]", 2, true);
    }

    @Override
    public boolean parseCondition(String[] args, LivingEntity player, @Nullable LivingEntity target, Event event) {
        if (!(event instanceof BlockBreakEvent)) return false;

        BlockBreakEvent blockBreakEvent = (BlockBreakEvent) event;
        String block = args[1].trim();

        return blockBreakEvent.getBlock().getType().toString().equalsIgnoreCase(block);
    }
}

Registering the condition

You will then need to add the following to your onEnable (Preferably with a delay) You can register multiple conditions by separating them with a comma as shown below

    @Override
    public void onEnable() {
        if (getServer().getPluginManager().isPluginEnabled("EliteEnchantments")) {
            EliteEnchantmentsAPI.getAPI().registerConditions(
                new ConditionExample(), 
                new ConditionBlock()
            );
        }
    }

Last updated