Java:
ThreadPool.scheduleAtFixedRate(() -> {
List<String> inactivePlayerNames = new ArrayList<>();
// Collect names of inactive players
for (TvTEventTeams team : _teams) {
for (String playerName : team.getParticipatedPlayerNames()) {
if (isPlayerAFK(playerName)) {
inactivePlayerNames.add(playerName);
}
}
}
// Remove inactive players
for (String playerName : inactivePlayerNames) {
removeParticipant(playerName);
Player playerInstance = World.getInstance().getPlayer(playerName);
if (playerInstance != null) {
playerInstance.sendMessage("You have been removed from the TvT event due to inactivity.");
new TvTEventTeleport(playerInstance, Config.TVT_EVENT_BACK_COORDINATES, false, false);
_afkPlayers.remove(playerName);
}
}
}, 60000, 60000); // This runs every 60 seconds
Инициилизируйте переменную
ScheduledFuture<?>
чтоб можно было привязать её к коду выше.
И наверное
stopFight
(вместо resetEvent) нужно добавить
_afkPlayers = new HashSet<>();
и отменять таск, о котором я писал вьіше.