> ## Documentation Index
> Fetch the complete documentation index at: https://docs.opai.today/llms.txt
> Use this file to discover all available pages before exploring further.

# 示例

> 示例的开源插件和代码片段

## 可参考的开源插件列表

* [blue-archive-halo](https://github.com/opai-client/blue-archive-halo)
* [BanTracker](https://github.com/opai-client/BanTracker)

## 代码片段示例

```java 自动购买羊毛当你没有足够的时候 theme={null}
public class AutoWool extends ExtensionModule implements EventHandler {
    public AutoWool() {
        super("Auto Wool", "Auto purchase wools when you don't have 64 wools", EnumModuleCategory.MISC);
        setEventHandler(this);
    }

    // // 覆盖了EventHandler中的onPlayerUpdate方法，每个PlayerTick执行一次
    @Override                                                                    
    public void onPlayerUpdate() {
        if(openAPI.getLocalPlayer().isBedWarsShopScreen() &&                     // 判断是否在商店界面
            countWool() < 65 &&                                                  // 是否有足够的羊毛
            openAPI.getLocalPlayer().countResource(EnumResource.IRON) >= 4){     // 是否有4个铁
            openAPI.getLocalPlayer().purchase(EnumShopItem.WOOL);                // 购买羊毛
        }
    }

    private int countWool(){
        int count = 0;
        for (ItemStack itemStack : openAPI.getLocalPlayer().getInventory().getMainInventory()) { // 获得玩家物品栏中的所有物品
            if(itemStack == null) continue;                                                      // 如果物品是空的，则不处理
            if(itemStack.getName().equals("tile.cloth")){                                        // 判断物品是否为羊毛
                count += itemStack.getStackSize();                                               // 添加获取的物品数量
            }
        }
        return count;
    }
}
```
