# Custom Conditions

### Create a condition class

For this example, let's create a condition that checks if the players food level is equal to or higher than a given amount. As a result, our condition will look like: `hunger {amount=10}`

```java
import org.bukkit.entity.Player;

import fi.septicuss.tooltips.object.preset.condition.Condition;
import fi.septicuss.tooltips.object.preset.condition.argument.Arguments;
import fi.septicuss.tooltips.object.validation.Validity;

// Checks if players food level is above the given amount
public class Hunger implements Condition {

	// These are the aliases for arguments. 
	// You can yourself decide which aliases can be used.
	private static final String[] AMOUNT = {"amt", "amount"};
	
	// Returns whether this condition is true with the
	// given arguments
	@Override
	public boolean check(Player player, Arguments args) {

		int amount = args.get(AMOUNT).getAsInt();
		int foodLevel = player.getFoodLevel();
		
		return (foodLevel >= amount);
	
	}
	
	
	// This method is triggered, when either the condition is true
	// and more context is needed or when its skipped. So this
	// method may be called if true or not.
	//
	// Put the context that this condition returns
  @Override
  public void writeContext(Player player, Arguments args, Context context) {
		context.put("food", player.getFoodLevel());
  }

		
	// This method is used to check, whether the arguments are valid.
	// Once this check is complete, you can safely use the arguments in the
	// above check method.
	@Override
	public Validity valid(Arguments args) {
		
		if (!args.has(AMOUNT)) {
			return Validity.of(false, "Amount argument is missing!");
		}
		
		if (!args.isNumber(AMOUNT)) {
			return Validity.of(false, "Amount argument must be a number!");
		}
		
		return Validity.TRUE;
		
	}
	
	// Set the conditions ID, which will be used in preset configurations.
  @Override
  public String id() {
  	return "hunger";
  }

}
```

### Register the condition

Register this condition in your plugins `onLoad` like so:

```java
@Override
public void onLoad() {
    TooltipsAPI.addCondition(new Hunger());
}
```

### Restart the server

Once the server loads, your condition should be in Tooltips!

### More examples

For more examples on how to make conditions, check out the code of some official conditions in the [GitHub repository](https://github.com/Septicuss/tooltips/tree/master/src/main/java/fi/septicuss/tooltips/managers/condition/impl).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tooltips.gitbook.io/tooltips/extra/api/custom-conditions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
