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;
}
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;
}
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();
}
Aggregations