Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions src/main/java/fr/openmc/core/features/economy/BankManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;

import java.sql.SQLException;
import java.time.DayOfWeek;
Expand All @@ -46,6 +47,8 @@ public class BankManager extends Feature implements DatabaseFeature {

private static Dao<Bank, String> banksDao;

private static BukkitTask interestTask;

@Override
public void init() {
banks = loadAllBanks();
Expand Down Expand Up @@ -243,18 +246,31 @@ public static void applyAllPlayerInterests() {
}
}

private static void updateInterestTimer() {
if (OMCPlugin.isUnitTestVersion()) return; // Cette méthode bloque totalement le flux des tests. Si
// quelqu'un fait les unit test des banques, merci de le prendre en compte.

Bukkit.getScheduler().runTaskLater(OMCPlugin.getInstance(), () -> {
OMCLogger.info("Applying all player interests...");
applyAllPlayerInterests();
CityBankManager.applyAllCityInterests();
OMCLogger.info("All player interests applied successfully.");
updateInterestTimer();

}, getSecondsUntilInterest() * 20); // 20 ticks per second (ideally)
public static void updateInterestTimer() {
if (OMCPlugin.isUnitTestVersion()) return;

if (interestTask != null) return;

long delay = getSecondsUntilInterest() * 20L;

interestTask = Bukkit.getScheduler().runTaskLater(
OMCPlugin.getInstance(),
() -> {
OMCLogger.info("Applying all player interests...");
applyAllPlayerInterests();
CityBankManager.applyAllCityInterests();
OMCLogger.info("All player interests applied successfully.");

interestTask = null;

Bukkit.getScheduler().runTaskLater(
OMCPlugin.getInstance(),
BankManager::updateInterestTimer,
20L * 10
);
},
delay
);
}

public static long getSecondsUntilInterest() {
Expand Down
Loading