Hot Summer Deals are Here!
Celebrate with up to 99% off on 17,100 resources
03
Days
12
Hours
24
Mins
19
Secs
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Paceski

Performance & Content Technician
Supreme
Feedback score
4
Posts
126
Reactions
54
Resources
0
I don't know about this one honstly.

I use uLicense and that's how I log my version.

On Spigot there is a method to do this, not sure about MCMarket.


Code:
package dev.pace.staffchat.updatechecker;

import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Scanner;
import java.util.function.Consumer;

/**
 * Created by Pace
 * No part of this publication may be reproduced, disturbed, or transmitted in any form or any means.
 */

public class UpdateChecker {

    private final JavaPlugin plugin;
    private final int resourceId;

    public UpdateChecker(JavaPlugin plugin, int resourceId) {
        this.plugin = plugin;
        this.resourceId = resourceId;
    }

    public void getVersion(final Consumer<String> consumer) {
        Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
            try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream(); Scanner scanner = new Scanner(inputStream)) {
                if (scanner.hasNext()) {
                    consumer.accept(scanner.next());
                }
            } catch (IOException exception) {
                this.plugin.getLogger().info("Cannot look for updates: " + exception.getMessage());
            }
        });
    }
}
 
Last edited:
Top