1package com.runehive.game.world.entity.mob.player.profile;
3import com.google.gson.reflect.TypeToken;
4import com.runehive.game.world.entity.mob.player.Player;
5import com.runehive.util.GsonUtils;
7import java.io.FileReader;
8import java.lang.reflect.Type;
9import java.nio.file.Files;
10import java.nio.file.Path;
11import java.nio.file.StandardCopyOption;
12import java.util.ArrayList;
13import java.util.HashMap;
24 private static final Path
FILE_PATH = Path.of(
"data",
"profile",
"world_profile_list.json");
27 private static Map<String, Profile>
profiles =
new HashMap<>();
30 public static boolean exist(String name) {
41 List<String> list =
new ArrayList<>();
43 for (String host_list :
profile.getHost()) {
44 if (host_list !=
null && host_list.equalsIgnoreCase(host)) {
54 final String name =
profile.getName();
64 public static void load() {
67 final Type type =
new TypeToken<Map<String, Profile>>() {
70 try (
final FileReader reader =
new FileReader(
FILE_PATH.toFile())) {
72 }
catch (
final Exception e) {
78 public static void save() {
79 Thread.startVirtualThread(() -> {
82 Path parent = path.getParent();
84 throw new UnsupportedOperationException(
"Path must have a parent " + path);
86 if (!Files.exists(parent)) {
87 parent = Files.createDirectories(parent);
90 final Path tempFile = Files.createTempFile(parent, path.getFileName().toString(),
".tmp");
93 Files.move(tempFile, path, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
94 }
catch (
final Exception e) {
This class represents a character controlled by a player.
Handles the profile repository, used for gathering important information for all created profiles.
static boolean isFriend(Player player, String other)
Checks if the other player is a friend.
static void load()
Loads all the profiles.
static final Path FILE_PATH
static List< String > getRegistry(String host)
Gets all the registered accounts to a specific host.
static boolean exist(String name)
Checks if a profile is registered to the parameter.
static Map< String, Profile > profiles
The hash map of all the profiles.
static void put(Profile profile)
Puts a profile into the hash map.
static void save()
Saves all the profiles.