Search in sources :

Example 11 with User

use of kml.auth.user.User in project Krothium-Launcher by DarkLBP.

the class MainFX method fetchAds.

/**
 * Fetches any advertisement available for the logged user
 */
private void fetchAds() {
    User user = kernel.getAuthentication().getSelectedUser();
    if (user.getType() != UserType.MOJANG) {
        String profileID = user.getSelectedProfile();
        String adsCheck = "https://mc.krothium.com/ads.php?profileID=" + profileID;
        String response = Utils.readURL(adsCheck);
        if (!response.isEmpty()) {
            String[] chunks = response.split(":");
            String firstChunk = Utils.fromBase64(chunks[0]);
            urlPrefix = firstChunk == null ? "" : firstChunk;
            if (chunks.length == 2) {
                String secondChunk = Utils.fromBase64(response.split(":")[1]);
                String adsURL = secondChunk == null ? "" : secondChunk;
                kernel.getBrowser().loadWebsite(adsURL);
                kernel.getBrowser().show(mainScene);
            }
            console.print("Ads loaded.");
        } else {
            console.print("Ads info not available.");
        }
    } else {
        console.print("Ads not available for Mojang user.");
    }
}
Also used : User(kml.auth.user.User)

Aggregations

User (kml.auth.user.User)11 JSONObject (org.json.JSONObject)6 Authentication (kml.auth.Authentication)5 AuthenticationException (kml.exceptions.AuthenticationException)5 IOException (java.io.IOException)3 UserProfile (kml.auth.user.UserProfile)3 UserType (kml.auth.user.UserType)2 GameLauncherException (kml.exceptions.GameLauncherException)2 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1 FXMLLoader (javafx.fxml.FXMLLoader)1 Parent (javafx.scene.Parent)1 Scene (javafx.scene.Scene)1 Image (javafx.scene.image.Image)1 Stage (javafx.stage.Stage)1 DownloaderException (kml.exceptions.DownloaderException)1 Profile (kml.game.profile.Profile)1 Version (kml.game.version.Version)1