RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.content.collectionlog.CollectionLogSaving Class Reference

Static Public Member Functions

static CollectionLog load (Player player)
static void save (Player player)

Detailed Description

Definition at line 15 of file CollectionLogSaving.java.

Member Function Documentation

◆ load()

CollectionLog com.runehive.content.collectionlog.CollectionLogSaving.load ( Player player)
static

Definition at line 39 of file CollectionLogSaving.java.

39 {
40 CollectionLog log = new CollectionLog();
41
42 Path path = Paths.get("./data/profile/save/collectionLogs/"+player.getUsername()+".json");
43 File file = path.toFile();
44 if (!file.exists()) {
45 return log;
46 }
47 try (FileReader fileReader = new FileReader(file)) {
48 JsonParser fileParser = new JsonParser();
49 Gson builder = new GsonBuilder().create();
50 JsonObject reader = (JsonObject) fileParser.parse(fileReader);
51 if (reader.has("collectionLog")) {
52 log = builder.fromJson(reader.get("collectionLog"), CollectionLog.class);
53 }
54 } catch (Exception e) {
55 e.printStackTrace();
56 }
57
58 return log;
59 }

References com.runehive.game.world.entity.mob.player.Player.getUsername().

Referenced by com.runehive.game.world.entity.mob.player.PlayerAssistant.login().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save()

void com.runehive.content.collectionlog.CollectionLogSaving.save ( Player player)
static

Definition at line 17 of file CollectionLogSaving.java.

17 {
18 Path path = Paths.get("./data/profile/save/collectionLogs/"+player.getUsername()+".json");
19 File file = path.toFile();
20 file.getParentFile().setWritable(true);
21 if (!file.getParentFile().exists()) {
22 try {
23 file.getParentFile().mkdirs();
24 } catch (SecurityException e) {
25 System.out.println("Unable to create directory for player data!");
26 }
27 }
28 try (FileWriter writer = new FileWriter(file)) {
29 Gson builder = new GsonBuilder().setPrettyPrinting().create();
30 JsonObject object = new JsonObject();
31
32 object.add("collectionLog", builder.toJsonTree(player.getCollectionLog()));
33
34 writer.write(builder.toJson(object));
35 } catch (Exception e) {
36 }
37 }

References com.runehive.game.world.entity.mob.player.Player.getCollectionLog(), and com.runehive.game.world.entity.mob.player.Player.getUsername().

Referenced by com.runehive.content.collectionlog.CollectionLog.logItem(), and com.runehive.game.world.entity.mob.player.Player.unregister().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: