> For the complete documentation index, see [llms.txt](https://ultimaterewards.athelion.eu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ultimaterewards.athelion.eu/api/setting-up-own-playtime-calculator.md).

# 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.
