> For the complete documentation index, see [llms.txt](https://mo-mi.gitbook.io/xiaomomi-plugins/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mo-mi.gitbook.io/xiaomomi-plugins/customfishing/plugin-wiki/customfishing/api/basic-operations.md).

# Basic Operations

### Create context

```java
Player player = Bukkit.getPlayer("player");
Context<Player> context = Context.player(player);
// You can create it with null, but please be careful not to use it in any place 
// where a player is needed, such as checking permissions, sending messages
Context<Player> context = Context.player(null);
```

### Get plugin instance

```java
BukkitCustomFishingPlugin api = BukkitCustomFishingPlugin.getInstance()
```

### Build an item instance

```java
ItemStack itemStack = api.getItemManager().buildInternal(context, "rubbish");
```

### Get effect modifier

```java
Optional<EffectModifier> optional = api.getEffectManager().getEffectModifier("beginner_rod", MechanicType.ROD);
if (optional.isPresent()) {
    EffectModifier modifier = optional.get();
}
```

### Create new effect instance

```java
Effect effect = Effect.newInstance();
```

### Apply the modifier

```java
// There are three stages in total
// CAST: Determines what fishing mechanics are available (such as lava fishing)
// LOOT: Affects the weight of the next loot
// FISHING: Determines loot-related properties, such as size, score, and game difficulty
modifier.apply(effect, FishingEffectApplyEvent.Stage.CAST, context);
```

### Get the loot at a certain location

```java
context.arg(ContextKeys.LOCATION, player.getLocation()); // sets the player location
context.arg(ContextKeys.OTHER_LOCATION, custom_location); // sets the custom location, in most cases, it's the hook's
context.arg(ContextKeys.SURROUNDING, "water");
Loot loot = api.getLootManager().getNextLoot(effect, context); 
```

### Convert loot into an itemStack

```java
if (loot.type() == LootType.ITEM) {
    ItemStack itemStack = api.getItemManager().buildInternal(context, loot.id());
}
```

### Get the itemStack from FishingLootSpawnEvent

```java
@EventHandler
public void onLootSpawn(FishingLootSpawnEvent event) {
    if (event.getEntity() instanceof Item item) {
        ItemStack itemStack = item.getItemStack();
    }
}
```
