# Setting up own playtime calculator

The Custom Playtime Calculator Registration API allows you to integrate your own playtime calculation logic into the UltimateReward plugin.

#### Usage

1. **Implement Your Playtime Calculator**

   To create a custom playtime calculator, inherit from the `PlayTimeCalculator` interface and implement the `calculatePlayTime(Player player)` method. This method should contain your custom logic to calculate the playtime of the given player.<br>

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

   public class MyOwnPlayTimeCalculator implements PlayTimeCalculator {
       @Override
       public float calculatePlayTime(OfflinePlayer player) {
           // Your custom logic to calculate player's playtime
       }
   }
   ```
2. **Register Your Calculator**

   After implementing your custom playtime calculator, register it with the UltimateReward plugin using the `registerPlayTimeCalculator()` method. This ensures that your custom logic is integrated into the playtime tracking system.

   ```java
   UltimateReward.registerPlayTimeCalculator(new MyOwnPlayTimeCalculator());
   ```

{% hint style="warning" %}
Method must return the play-time in **minutes**
{% endhint %}

**Example**

Here's a practical example demonstrating how to register a custom playtime calculator:

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

public class MyOwnPlayTimeCalculator implements PlayTimeCalculator {
    @Override
    public float calculatePlayTime(OfflinePlayer player) {
        // Example: return playtime in minutes
        return player.getStatistic(Statistic.PLAY_ONE_TICK) / 60.0 / 20.0; // Convert ticks to minutes
    }
}

// Register the custom playtime calculator
UltimateReward.registerPlayTimeCalculator(new MyOwnPlayTimeCalculator());
```

In this example, `MyOwnPlayTimeCalculator` calculates playtime based on Minecraft's built-in statistics, converting total playtime from ticks to minutes.


---

# 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://ultimaterewards.athelion.eu/api/setting-up-own-playtime-calculator.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.
