10 Material Group
alexcrea edited this page 2024-07-15 22:19:39 +02:00

Material Group

A material group is a named collection of bukkit material that can accept other material group to be "added" to the group policy.
It is used in enchantment conflict


Actual Implementation of Material Group

The 2 implementation of material groups are IncludeGroup and ExcludeGroup.
It is recommended to use only IncludeGroup as it can be edited by admin at runtime via the gui.

  • IncludeGroup policy is to include given materials and groups. It starts with an empty group.
  • ExcludeGroup policy is to remove given materials and groups. It starts containing every material.

Include group is useful for most use case, while exclude group can be used as a "use every item excluding theses" and a "everything" group.
Adding a group to another group is not impacted by the type of group. For example, adding an empty exclude group ("everything group") to an include group will create an include group containing everything.


Creating and Registering a Material Group

Here is an example of you could create some material group

@EventHandler
public void onConfigReady(CAConfigReadyEvent event){
    // Create group of zombie drops
    IncludeGroup zombieGroup = new IncludeGroup("zombieDrop");
    zombieGroup.addToPolicy(Material.ROTTEN_FLESH) // Please note "addToPolicy would be "exclude from group" for ExcludeGroup
            .addToPolicy(Material.ZOMBIE_HEAD)
            .addToPolicy(Material.IRON_INGOT)
            .addToPolicy(Material.POTATO)
            .addToPolicy(Material.CARROT);

    // Create group of skeleton drops
    IncludeGroup skeletonGroup = new IncludeGroup("skeletonDrop");
    skeletonGroup.addToPolicy(Material.BONE)
            .addToPolicy(Material.ARROW)
            .addToPolicy(Material.SKELETON_SKULL);

    // Create group of overworld undead drops
    IncludeGroup undeadGroup = new IncludeGroup("overworldUndeadDrop");
    undeadGroup.addToPolicy(zombieGroup).addToPolicy(skeletonGroup);

    // Register groups
    MaterialGroupApi.addMaterialGroup(zombieGroup);
    MaterialGroupApi.addMaterialGroup(skeletonGroup);
    MaterialGroupApi.addMaterialGroup(undeadGroup);

    // Create conflict (see appropriate doc)
    // ...

}

Material group can also be registered after the event is triggered. But not before. It will be triggered almost instantly after every plugin have initialized.


Removing a Material Group.

You may want to remove a material group via MaterialGroupApi. But it is not recommended and current implementation: If the group is not in use everything should be fine, but if not the case then it is unspecified behavior. (but probably will still be used until restart by the required conflict and group)
A better version of these function will be implemented in the incoming update.