Untitled
plain_text
a month ago
1.5 kB
3
Indexable
Never
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 energyOffTime = Manager.getLong(player.getUniqueId(), "energy_offtime", Mongo.rpg); logoutTimes.put(player, energyOffTime); long lastUpdateTime = logoutTimes.get(player); // 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); // Player is online, reset the logoutTime logoutTimes.put(player, null); String formattedValue = formatEnergyValue(newValue); player.sendMessage("Calculations for energy loss completed! New energy level: " + formattedValue); }