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.

    import org.bukkit.entity.Player;
    
    public class MyOwnPlayTimeCalculator implements PlayTimeCalculator {
        @Override
        public float calculatePlayTime(Player 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.

    UltimateReward.registerPlayTimeCalculator(new MyOwnPlayTimeCalculator());

Method must return the play-time in minutes

Example

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

import org.bukkit.entity.Player;

public class MyOwnPlayTimeCalculator implements PlayTimeCalculator {
    @Override
    public float calculatePlayTime(Player 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.

Last updated