EliteEnchantments
  • Home
  • Frequently Asked Questions
  • Support
  • General Information
    • Creating Enchantments
      • Effects
      • Conditions
      • Types
      • Options
    • Web Panel
      • Guide
    • Commands & Permissions
    • Giving Items
    • Developer API
      • Creating Effects
      • Creating Conditions
    • Where to purchase?
  • Addons
    • Gkits
      • Frequently Asked Questions
      • Commands & Permissions
      • Creating GKits
      • Example GKit
Powered by GitBook
On this page

Was this helpful?

  1. General Information
  2. Developer API

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()
            );
        }
    }
PreviousCreating EffectsNextWhere to purchase?

Last updated 2 years ago

Was this helpful?