Skip to content

Commit

Permalink
Fixed player data not being loaded on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
founderio committed Aug 10, 2016
1 parent 8d527c6 commit 2b07e25
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/net/teamio/gtams/server/DataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ public void addTerminal(Terminal terminal) {
}
}

protected void addPlayerInternal(Player player) {
if(players.containsKey(player.id)) {
throw new DuplicateKeyException("Trying to add duplicate player id " + player.id);
}
players.put(player.id, player);
}

protected abstract void loadCache();

protected abstract void saveTerminal(Terminal terminal);
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/net/teamio/gtams/server/DataStoreJSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,30 @@ public boolean accept(File pathname) {
}
}
}

System.out.println("Loading Players");
dir = new File("data/player");
if(dir.exists()) {
File[] children = dir.listFiles(fileFilter);

for(File file : children) {
System.out.println("Reading data/player/" + file.getName());
Player player;
try {
player = readFile(Player.class, file);

if(player != null && player.id != null) {
addPlayerInternal(player);
}
} catch (GTamsServerException e) {
System.err.println("Error reading player from " + file.getName());
e.printStackTrace();
} catch(DuplicateKeyException e) {
System.err.println("Error reading player from " + file.getName());
e.printStackTrace();
}
}
}
System.out.println("Done loading.");
}

Expand Down

0 comments on commit 2b07e25

Please sign in to comment.