UltimateRewards Wiki
  • Getting started
    • Support
  • Addons
  • Configs
    • Player Levels
    • Referrals
    • Loginstreak
  • USAGE
    • Installation
    • Commands
  • configuration
    • Rewards
      • Creating Reward
      • Reward Types
        • Afk Reward
          • World Afk Reward
          • Area Afk Reward
          • Region Afk Reward
        • Advent Calendar
        • Pickable Reward
        • Time Reward
        • Time Fixed Reward
        • Streak Reward
        • Streak Fixed Reward
        • Vote Reward
        • Renewable Vote Reward
        • Per Vote Reward
        • Streak Vote Reward
        • Play Time Reward
        • Renewable Play Time Reward
        • Referral Reward
        • Renewable Referral Reward
        • Purchasable Reward
        • Re-Purchasable Reward
        • One Time Reward
        • Time Limited Reward
        • Custom Reward
        • Multiple Custom Reward
        • Coupon Reward
        • Discord Reward
      • Reward Settings
      • Reward Actions
      • Reward Features
        • Auto Claim
        • Notifications
        • Reward NPC
        • Discord Support
        • Reward Requirements
        • Reward Variants
        • Selectable Rewards
        • Randomization
          • Execution Chances
          • Random Placeholders
        • AFK Checkers
        • Leaderboards
    • Menus
      • Basics
      • Example of GUIs
      • Setting Menu
    • Schedules & Timers
  • Colors & Models
  • Placeholders
  • API
    • Events
    • Examples
    • Setting up own playtime calculator
  • Policies
    • TOS
Powered by GitBook
On this page
  1. API

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

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

PreviousExamplesNextTOS

Last updated 6 months ago