• Trong thời gian này, bạn không thể tạo bài mới, đăng comment, hay tạo tài nguyên mới để diễn đàn dọn dẹp nội dung.
    Diễn đàn sẽ sớm mở trở lại, chi tiết hãy theo dõi tại Discord
acayr1n

Hướng dẫn Updater.java - update plugin qua web

Trạng thái
Không mở trả lời sau này.

acayr1n

DEVELOPER
WIBU
Class để Update plugin tự động

Mã:
import java.io.*;

public void onEnable() {
       if(Updater.check(this.getDescription().getVersion())) {
           Bukkit.log("A new version detected v" + Updater.ver());
           if(!this.getFile().delete()) Bukkit.log("An error occured while removing old version");
           Updater.update(new File("./plugins/MyPlugin-" + Updater.ver() + ".jar"));
           Bukkit.log("Update completed");
       }
}

Mã:
ver$1.0.0
url$http://my.domain.org/plugin.jar

Mã:
package acayrin.updater;

import java.io.*;
import java.net.*;

public class Updater {
    protected static String toGET = "http://my.domain.org/plugin.txt";

    public static boolean check(String ver) {
        String chk = ver();
        if(ver.equals(chk)) return false;
        return true;
    }

    public static void update(File file) {
        try {
            URL link = new URL(url());
            InputStream input = link.openStream();
            if (file.exists()) {
                if (file.isDirectory())
                    throw new IOException("File '" + file + "' is a directory");

                if (!file.canWrite())
                    throw new IOException("File '" + file + "' cannot be written");
            } else {
                File parent = file.getParentFile();
                if ((parent != null) && (!parent.exists()) && (!parent.mkdirs())) {
                    throw new IOException("File '" + file + "' could not be created");
                }
            }

            FileOutputStream output = new FileOutputStream(file);

            byte[] buffer = new byte[4096];
            int n = 0;
            while (-1 != (n = input.read(buffer))) {
                output.write(buffer, 0, n);
            }

            input.close();
            output.close();
        }
        catch(IOException e) {
            e.printStackTrace();
        }
    }

    public static String ver() {
        String ver = null;
        try {
            URL url = new URL(toGET);
            URLConnection conn = url.openConnection();
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(conn.getInputStream()));

            String line;
            while ((line = br.readLine()) != null) {
                if(line.contains("ver")) ver = line.replace("ver$", "");
            }
            br.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ver;
    }

    public static String url() {
        String res = null;
        try {
            URL url = new URL(toGET);
            URLConnection conn = url.openConnection();
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(conn.getInputStream()));

            String line;
            while ((line = br.readLine()) != null) {
                if(line.contains("url")) res = line.replace("url$", "");
            }
            br.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return res;
    }
}
 
Ai như tui không, nhìn hông ...
12bf5532f5599a838441ce875b6d8cc55e0f2db83614611ffde18c8f3c36dc46.gif
 
Làm qua socket dc ko nhỉ :3
 
SPammmmmm kìa report mau :3
 
Trạng thái
Không mở trả lời sau này.
Nội dung tương tự Xem nhiều nhất Xem thêm

Thống kê nội dung

Tạo
acayr1n,
Trả lời lần cuối từ
InfiGamez,
Trả lời
17
Lượt xem
1,867
Quay lại
Trên cùng