Search in sources :

Example 1 with JsonReader

use of com.cedarsoftware.util.io.JsonReader in project runesource by PureCS.

the class Settings method load.

public static Settings load(String fileName) throws Exception {
    // Checking if file exists
    File file = new File(fileName);
    if (!file.exists()) {
        throw new FileNotFoundException("The settings file was not found");
    }
    // Reading file
    JsonReader reader = new JsonReader(new FileInputStream(file));
    Settings settings = (Settings) reader.readObject();
    reader.close();
    return settings;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) JsonReader(com.cedarsoftware.util.io.JsonReader) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with JsonReader

use of com.cedarsoftware.util.io.JsonReader 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)

Example 3 with JsonReader

use of com.cedarsoftware.util.io.JsonReader in project runesource by PureCS.

the class EquipmentHelper method loadWeaponDefinitions.

@SuppressWarnings("unchecked")
public static void loadWeaponDefinitions(String fileName) throws FileNotFoundException {
    // Checking if file exists
    File file = new File(fileName);
    if (!file.exists()) {
        throw new FileNotFoundException("The weapon definitions file was not found");
    }
    // Reading file
    JsonReader reader = new JsonReader(new FileInputStream(file));
    WEAPONS = ((ArrayList<WeaponDefinition>) reader.readObject()).toArray(new WeaponDefinition[0]);
    reader.close();
}
Also used : FileNotFoundException(java.io.FileNotFoundException) JsonReader(com.cedarsoftware.util.io.JsonReader) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

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