Search in sources :

Example 1 with PlayerAttributes

use of com.rs.entity.player.PlayerAttributes in project runesource by PureCS.

the class JsonPlayerFileHandler method load.

@Override
public LoadResponse load(Player player) throws Exception {
    // Checking if file exists
    File file = new File(getStorageDirectory() + player.getAttributes().getUsername() + ".json");
    if (!file.exists()) {
        return LoadResponse.NOT_FOUND;
    }
    // Reading file
    JsonReader reader = new JsonReader(new FileInputStream(file));
    PlayerAttributes attributes = (PlayerAttributes) reader.readObject();
    reader.close();
    // Checking password
    if (!attributes.getPassword().equals(player.getAttributes().getPassword())) {
        return LoadResponse.INVALID_CREDENTIALS;
    }
    player.setAttributes(attributes);
    return LoadResponse.SUCCESS;
}
Also used : PlayerAttributes(com.rs.entity.player.PlayerAttributes) JsonReader(com.cedarsoftware.util.io.JsonReader) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

JsonReader (com.cedarsoftware.util.io.JsonReader)1 PlayerAttributes (com.rs.entity.player.PlayerAttributes)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1