RuneHive-Game
Loading...
Searching...
No Matches
PlayerSaveEvent.java
Go to the documentation of this file.
1package com.runehive.game.task.impl;
2
3import com.runehive.content.clanchannel.ClanRepository;
4import com.runehive.game.task.Task;
5import com.runehive.game.world.World;
6import com.runehive.game.world.entity.mob.player.Player;
7import com.runehive.game.world.entity.mob.player.persist.PlayerSerializer;
8import org.apache.logging.log4j.LogManager;
9import org.apache.logging.log4j.Logger;
10
11public class PlayerSaveEvent extends Task {
12 private static final Logger logger = LogManager.getLogger(PlayerSaveEvent.class);
13
14 public PlayerSaveEvent() {
15 super(1000);
16 }
17
18 @Override
19 public void execute() {
20 if (World.update.get()) {
21 return;
22 }
23
24 int count = 0;
25 for (Player player : World.getPlayers()) {
26 if (player != null && !player.isBot) {
27 PlayerSerializer.save(player);
28 count++;
29 }
30 }
31
32 if (count != 0) {
33
34 if (count > 10) {
35 // DiscordPlugin.sendSimpleMessage("There are currently " + count + " players online!");
36 }
37
38 logger.info(count + " players were saved.");
40 }
41 }
42}
The repository containing all the clans and their corresponding data.
Task(boolean instant, int delay)
Creates a new Task.
Definition Task.java:41
void execute()
A function representing the unit of work that will be carried out.
Represents the game world.
Definition World.java:46
static final AtomicBoolean update
Definition World.java:72
static MobList< Player > getPlayers()
Definition World.java:544
This class represents a character controlled by a player.
Definition Player.java:125