private final HashMap<Player, Double> playerEnergy = new HashMap<>();
private static final int CALCULATION_INTERVAL_MINUTES = 5; // The interval for calculations in minutes
private static final double DECREASE_PERCENTAGE = 0.0024; // 0.24% decrease per interval
private void calculateOffTime(Player player) {
long currentTime = System.currentTimeMillis();
Long lastUpdateTime = Manager.getLong(player.getUniqueId(), "energy_offtime", Mongo.rpg);
// Calculate the time difference in minutes
long timeDifferenceMinutes = (currentTime - lastUpdateTime) / (1000 * 60);
// Calculate the number of 5-minute intervals that have passed
int intervalsPassed = (int) (timeDifferenceMinutes / CALCULATION_INTERVAL_MINUTES);
// Calculate the new energy value
double oldValue = playerEnergy.get(player);
double decreasePercentage = DECREASE_PERCENTAGE * intervalsPassed;
double newValue = oldValue * (1 - decreasePercentage);
newValue = Math.max(0, Math.min(newValue, 100)); // Ensure value is within 0 to 100
playerEnergy.put(player, newValue);
String formattedValue = formatEnergyValue(newValue);
player.sendMessage("Calculations for energy loss completed! New energy level: " + formattedValue);
}