Search in sources :

Example 1 with Account

use of com.github.games647.changeskin.core.model.auth.Account in project ChangeSkin by games647.

the class UploadCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length == 0) {
        plugin.sendMessage(sender, "upload-noargs");
    } else {
        String url = args[0];
        if (url.startsWith("http://") || url.startsWith("https://")) {
            List<Account> accounts = plugin.getCore().getUploadAccounts();
            if (accounts.isEmpty()) {
                plugin.sendMessage(sender, "no-accounts");
            } else {
                Account uploadAccount = accounts.get(0);
                Runnable skinUploader = new SkinUploader(plugin, sender, uploadAccount, url);
                Bukkit.getScheduler().runTaskAsynchronously(plugin, skinUploader);
            }
        } else {
            plugin.sendMessage(sender, "no-valid-url");
        }
    }
    return true;
}
Also used : Account(com.github.games647.changeskin.core.model.auth.Account) SkinUploader(com.github.games647.changeskin.bukkit.task.SkinUploader)

Example 2 with Account

use of com.github.games647.changeskin.core.model.auth.Account in project ChangeSkin by games647.

the class UploadCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) {
    String url = args.<String>getOne("url").get();
    if (url.startsWith("http://") || url.startsWith("https://")) {
        List<Account> accounts = plugin.getCore().getUploadAccounts();
        if (accounts.isEmpty()) {
            plugin.sendMessage(src, "no-accounts");
        } else {
            Account uploadAccount = accounts.get(0);
            Runnable skinUploader = new SkinUploader(plugin, src, uploadAccount, url);
            Task.builder().async().execute(skinUploader).submit(plugin);
        }
    } else {
        plugin.sendMessage(src, "no-valid-url");
    }
    return CommandResult.success();
}
Also used : Account(com.github.games647.changeskin.core.model.auth.Account) SkinUploader(com.github.games647.changeskin.sponge.task.SkinUploader)

Example 3 with Account

use of com.github.games647.changeskin.core.model.auth.Account in project ChangeSkin by games647.

the class UploadCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    if (args.length == 0) {
        plugin.sendMessage(sender, "upload-noargs");
    } else {
        String url = args[0];
        if (url.startsWith("http://") || url.startsWith("https://")) {
            List<Account> accounts = plugin.getCore().getUploadAccounts();
            if (accounts.isEmpty()) {
                plugin.sendMessage(sender, "no-accounts");
            } else {
                Account uploadAccount = accounts.get(0);
                Runnable skinUploader = new SkinUploader(plugin, sender, uploadAccount, url);
                ProxyServer.getInstance().getScheduler().runAsync(plugin, skinUploader);
            }
        } else {
            plugin.sendMessage(sender, "no-valid-url");
        }
    }
}
Also used : Account(com.github.games647.changeskin.core.model.auth.Account) SkinUploader(com.github.games647.changeskin.bungee.task.SkinUploader)

Example 4 with Account

use of com.github.games647.changeskin.core.model.auth.Account in project ChangeSkin by games647.

the class MojangAuthApi method authenticate.

public Optional<Account> authenticate(String email, String password) {
    try {
        HttpURLConnection httpConnection = CommonUtil.getConnection(AUTH_URL);
        httpConnection.setRequestMethod("POST");
        httpConnection.setDoOutput(true);
        try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(httpConnection.getOutputStream(), StandardCharsets.UTF_8))) {
            writer.append(gson.toJson(new AuthRequest(email, password)));
        }
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream(), StandardCharsets.UTF_8))) {
            AuthResponse authResponse = gson.fromJson(reader, AuthResponse.class);
            return Optional.of(new Account(authResponse.getSelectedProfile(), authResponse.getAccessToken()));
        }
    } catch (IOException ex) {
        logger.error("Failed to authenticate user: {}", email, ex);
    }
    return Optional.empty();
}
Also used : AuthRequest(com.github.games647.changeskin.core.model.auth.AuthRequest) Account(com.github.games647.changeskin.core.model.auth.Account) HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) AuthResponse(com.github.games647.changeskin.core.model.auth.AuthResponse)

Aggregations

Account (com.github.games647.changeskin.core.model.auth.Account)4 SkinUploader (com.github.games647.changeskin.bukkit.task.SkinUploader)1 SkinUploader (com.github.games647.changeskin.bungee.task.SkinUploader)1 AuthRequest (com.github.games647.changeskin.core.model.auth.AuthRequest)1 AuthResponse (com.github.games647.changeskin.core.model.auth.AuthResponse)1 SkinUploader (com.github.games647.changeskin.sponge.task.SkinUploader)1 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 HttpURLConnection (java.net.HttpURLConnection)1