RuneHive-Game
Loading...
Searching...
No Matches
ClanUpdateEvent.java
Go to the documentation of this file.
1package com.runehive.game.task.impl;
2
3import com.runehive.content.clanchannel.ClanRepository;
4import com.runehive.content.clanchannel.channel.ClanChannel;
5import com.runehive.game.task.TickableTask;
6import com.runehive.util.GsonUtils;
7
8import java.io.File;
9import java.io.FileWriter;
10import java.nio.file.Paths;
11
12/**
13 * An randomevent which handles updating clan chats.
14 *
15 * @author Daniel | Obey
16 */
17public class ClanUpdateEvent extends TickableTask {
18
19 public ClanUpdateEvent() {
20 super(false, 60);
21 }
22
23 @Override
24 protected void tick() {
25 if (ClanRepository.ACTIVE_CHANNELS.isEmpty()) {
26 return;
27 }
28
30 if (channel.activeSize() <= 0) {
31 continue;
32 }
33
34 channel.forEach(clanMember -> channel.getHandler().updateMemberList(clanMember));
35
36 Thread.startVirtualThread(() -> {
37 final File dir = Paths.get("data", "content", "clan").toFile();
38
39 if (!dir.exists()) {
40 dir.mkdirs();
41 }
42
43 try (FileWriter fw = new FileWriter(dir.toPath().resolve(channel.getOwner() + ".json").toFile())) {
44 fw.write(GsonUtils.JSON_PRETTY_NO_NULLS.get().toJson(channel.toJson()));
45 } catch (final Exception e) {
46 e.printStackTrace();
47 }
48 });
49
50 }
51 }
52
53}
The repository containing all the clans and their corresponding data.
static Set< ClanChannel > ACTIVE_CHANNELS
Set of all active clan chat channels.
void updateMemberList(ClanMember member)
Handles updating the clan channel member list.
void forEach(Consumer< ClanMember > member)
Handles looping through each clan member.
TickableTask(boolean instant, int delay)
static final ThreadLocal< Gson > JSON_PRETTY_NO_NULLS