+ fixed TFunction
+ update TCloud System
This commit is contained in:
		@@ -12,6 +12,7 @@ import me.skymc.taboolib.commands.internal.type.CommandArgument;
 | 
			
		||||
import me.skymc.taboolib.commands.internal.type.CommandRegister;
 | 
			
		||||
import me.skymc.taboolib.common.util.SimpleIterator;
 | 
			
		||||
import me.skymc.taboolib.fileutils.FileUtils;
 | 
			
		||||
import me.skymc.taboolib.plugin.PluginUtils;
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
@@ -134,6 +135,8 @@ public class TCloudCommand extends BaseMainCommand {
 | 
			
		||||
            Expansion expansion = TCloudLoader.getExpansion(args[0]);
 | 
			
		||||
            if (expansion == null) {
 | 
			
		||||
                TLocale.sendTo(sender, "COMMANDS.TCLOUD.DOWNLOAD.EXPANSION-NOT-FOUND", args[0]);
 | 
			
		||||
            } else if (!expansion.canUse()) {
 | 
			
		||||
                TLocale.sendTo(sender, "COMMANDS.TCLOUD.DOWNLOAD.EXPANSION-VERSION", args[0], String.valueOf(expansion.getDependVersion()));
 | 
			
		||||
            } else if (TCloudLoader.isExpansionExists(expansion)) {
 | 
			
		||||
                TLocale.sendTo(sender, "COMMANDS.TCLOUD.DOWNLOAD.EXPANSION-EXISTS", args[0]);
 | 
			
		||||
            } else {
 | 
			
		||||
@@ -172,10 +175,12 @@ public class TCloudCommand extends BaseMainCommand {
 | 
			
		||||
                TLocale.sendTo(sender, "COMMANDS.TCLOUD.UPDATE.EXPANSION-NOT-EXISTS", args[0]);
 | 
			
		||||
            } else if (!expansion.canUpdate()) {
 | 
			
		||||
                TLocale.sendTo(sender, "COMMANDS.TCLOUD.UPDATE.EXPANSION-NO-UPDATE", args[0]);
 | 
			
		||||
            } else if (!expansion.canUse()) {
 | 
			
		||||
                TLocale.sendTo(sender, "COMMANDS.TCLOUD.UPDATE.EXPANSION-VERSION", args[0], String.valueOf(expansion.getDependVersion()));
 | 
			
		||||
            } else {
 | 
			
		||||
                Bukkit.getScheduler().runTaskAsynchronously(TabooLib.instance(), () -> {
 | 
			
		||||
                    TLocale.sendTo(sender, "COMMANDS.TCLOUD.UPDATE.UPDATE-START", args[0], expansion.getVersion(), expansion.getLink());
 | 
			
		||||
                    FileUtils.download(expansion.getLink(), expansion.getFile());
 | 
			
		||||
                    FileUtils.download(expansion.getLink(), PluginUtils.getPluginFile(expansion.getName()));
 | 
			
		||||
                    TLocale.sendTo(sender, "COMMANDS.TCLOUD.UPDATE.UPDATE-SUCCESS", args[0]);
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,9 @@ import me.skymc.taboolib.plugin.PluginUtils;
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @Author sky
 | 
			
		||||
@@ -26,8 +28,8 @@ public class TCloudLoader {
 | 
			
		||||
    private static String url = "https://gitee.com/bkm016/TabooLibCloud/raw/master/cloud.json";
 | 
			
		||||
    private static String latestJsonOrigin;
 | 
			
		||||
    private static JsonObject latestJsonObject;
 | 
			
		||||
    private static Map<String, Expansion> expansionPlugins = Maps.newHashMap();
 | 
			
		||||
    private static Map<String, Expansion> expansionInternal = Maps.newHashMap();
 | 
			
		||||
    private static Map<String, Expansion> expansionPlugins = Maps.newTreeMap();
 | 
			
		||||
    private static Map<String, Expansion> expansionInternal = Maps.newTreeMap();
 | 
			
		||||
    private static File expansionInternalFolder;
 | 
			
		||||
 | 
			
		||||
    static void init() {
 | 
			
		||||
@@ -101,11 +103,21 @@ public class TCloudLoader {
 | 
			
		||||
        return expansionInternalFolder;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Expansion getExpansion(String name) {
 | 
			
		||||
        return expansionPlugins.getOrDefault(name, expansionInternal.get(name));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isExpansionExists(Expansion expansion) {
 | 
			
		||||
        return expansion.getType() == ExpansionType.PLUGIN && PluginUtils.isPluginExists(expansion.getName());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Expansion getExpansion(String name) {
 | 
			
		||||
        for (Map.Entry<String, Expansion> stringExpansionEntry : expansionPlugins.entrySet()) {
 | 
			
		||||
            if (stringExpansionEntry.getKey().equalsIgnoreCase(name)) {
 | 
			
		||||
                return stringExpansionEntry.getValue();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        for (Map.Entry<String, Expansion> stringExpansionEntry : expansionInternal.entrySet()) {
 | 
			
		||||
            if (stringExpansionEntry.getKey().equalsIgnoreCase(name)) {
 | 
			
		||||
                return stringExpansionEntry.getValue();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ import com.google.gson.JsonObject;
 | 
			
		||||
import com.ilummc.eagletdl.EagletTask;
 | 
			
		||||
import com.ilummc.eagletdl.ProgressEvent;
 | 
			
		||||
import com.ilummc.tlib.resources.TLocale;
 | 
			
		||||
import me.skymc.taboolib.TabooLib;
 | 
			
		||||
import me.skymc.taboolib.cloud.TCloudLoader;
 | 
			
		||||
import me.skymc.taboolib.fileutils.FileUtils;
 | 
			
		||||
import me.skymc.taboolib.string.ArrayUtils;
 | 
			
		||||
@@ -28,9 +29,10 @@ public class Expansion {
 | 
			
		||||
    private final String lastUpdate;
 | 
			
		||||
    private final String lastUpdateNote;
 | 
			
		||||
    private final String link;
 | 
			
		||||
    private final double dependVersion;
 | 
			
		||||
    private final ExpansionType type;
 | 
			
		||||
 | 
			
		||||
    public Expansion(String name, String[] author, String description, String[] detail, String version, String lastUpdate, String lastUpdateNote, String link, ExpansionType type) {
 | 
			
		||||
    public Expansion(String name, String[] author, String description, String[] detail, String version, String lastUpdate, String lastUpdateNote, String link, double dependVersion, ExpansionType type) {
 | 
			
		||||
        this.name = name;
 | 
			
		||||
        this.author = author;
 | 
			
		||||
        this.description = description;
 | 
			
		||||
@@ -39,6 +41,7 @@ public class Expansion {
 | 
			
		||||
        this.lastUpdate = lastUpdate;
 | 
			
		||||
        this.lastUpdateNote = lastUpdateNote;
 | 
			
		||||
        this.link = link;
 | 
			
		||||
        this.dependVersion = dependVersion;
 | 
			
		||||
        this.type = type;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -50,7 +53,8 @@ public class Expansion {
 | 
			
		||||
        String lastUpdate = object.get("last_update").getAsString();
 | 
			
		||||
        String lastUpdateNote = object.get("last_update_note").getAsString();
 | 
			
		||||
        String link = object.get("link").getAsString();
 | 
			
		||||
        return new Expansion(name, author, description, detail, version, lastUpdate, lastUpdateNote, link, type);
 | 
			
		||||
        double dependVersion = object.has("depend-version") ? object.get("depend-version").getAsDouble() : 0D;
 | 
			
		||||
        return new Expansion(name, author, description, detail, version, lastUpdate, lastUpdateNote, link, dependVersion, type);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String[] toArray(JsonArray json) {
 | 
			
		||||
@@ -89,6 +93,10 @@ public class Expansion {
 | 
			
		||||
        return link;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public double getDependVersion() {
 | 
			
		||||
        return dependVersion;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ExpansionType getType() {
 | 
			
		||||
        return type;
 | 
			
		||||
    }
 | 
			
		||||
@@ -97,6 +105,10 @@ public class Expansion {
 | 
			
		||||
        return type == ExpansionType.INTERNAL ? new File(TCloudLoader.getExpansionInternalFolder(), "[TCLOUD] " + name + ".jar") : new File("plugins/[TCLOUD] " + name + ".jar");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean canUse() {
 | 
			
		||||
        return TabooLib.getPluginVersion() >= dependVersion;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean canUpdate() {
 | 
			
		||||
        if (!TCloudLoader.isExpansionExists(this)) {
 | 
			
		||||
            return false;
 | 
			
		||||
 
 | 
			
		||||
@@ -19,10 +19,9 @@ public class TFunctionLoader implements TabooLibLoader.Loader {
 | 
			
		||||
            TFunction function = pluginClass.getAnnotation(TFunction.class);
 | 
			
		||||
            try {
 | 
			
		||||
                Method method = pluginClass.getDeclaredMethod(function.enable());
 | 
			
		||||
                if (method != null) {
 | 
			
		||||
                    method.setAccessible(true);
 | 
			
		||||
                    method.invoke(null);
 | 
			
		||||
                }
 | 
			
		||||
                method.setAccessible(true);
 | 
			
		||||
                method.invoke(null);
 | 
			
		||||
            } catch (NoSuchMethodException ignore) {
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                TLogger.getGlobalLogger().warn("TFunction load Failed: " + pluginClass.getName());
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
@@ -36,10 +35,9 @@ public class TFunctionLoader implements TabooLibLoader.Loader {
 | 
			
		||||
            TFunction function = pluginClass.getAnnotation(TFunction.class);
 | 
			
		||||
            try {
 | 
			
		||||
                Method method = pluginClass.getDeclaredMethod(function.disable());
 | 
			
		||||
                if (method != null) {
 | 
			
		||||
                    method.setAccessible(true);
 | 
			
		||||
                    method.invoke(null);
 | 
			
		||||
                }
 | 
			
		||||
                method.setAccessible(true);
 | 
			
		||||
                method.invoke(null);
 | 
			
		||||
            } catch (NoSuchMethodException ignore) {
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                TLogger.getGlobalLogger().warn("TFunction unload Failed: " + pluginClass.getName());
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
 
 | 
			
		||||
@@ -33,6 +33,10 @@ public class PluginUtils {
 | 
			
		||||
    PluginUtils() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isPluginExists(String name) {
 | 
			
		||||
        return getPluginFile(name) != null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static File getPluginFile(Plugin plugin) {
 | 
			
		||||
        try {
 | 
			
		||||
            Method method = JavaPlugin.class.getDeclaredMethod("getFile");
 | 
			
		||||
@@ -43,19 +47,19 @@ public class PluginUtils {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isPluginExists(String name) {
 | 
			
		||||
    public static File getPluginFile(String name) {
 | 
			
		||||
        for (File pluginFile : new File("plugins").listFiles()) {
 | 
			
		||||
            if (pluginFile.getName().endsWith(".jar")) {
 | 
			
		||||
                try {
 | 
			
		||||
                    PluginDescriptionFile desc = Main.getInst().getPluginLoader().getPluginDescription(pluginFile);
 | 
			
		||||
                    if (desc.getName().equalsIgnoreCase(name)) {
 | 
			
		||||
                        return true;
 | 
			
		||||
                        return pluginFile;
 | 
			
		||||
                    }
 | 
			
		||||
                } catch (Exception ignored) {
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void enable(Plugin plugin) {
 | 
			
		||||
 
 | 
			
		||||
@@ -593,6 +593,7 @@ COMMANDS:
 | 
			
		||||
        0: '名称'
 | 
			
		||||
      EXPANSION-NOT-FOUND: '&8[&3&lTabooLib&8] &c扩展 &4{0} &c不存在.'
 | 
			
		||||
      EXPANSION-EXISTS: '&8[&3&lTabooLib&8] &c扩展 &4{0} &c已存在.'
 | 
			
		||||
      EXPANSION-VERSION: '&8[&3&lTabooLib&8] &c扩展 &4{0} &c需要 &4TabooLib v{1}&c 版本才可以使用!'
 | 
			
		||||
      DOWNLOAD-START:
 | 
			
		||||
      - '&8[&3&lTabooLib&8] &7扩展 &f{0} &7开始下载:'
 | 
			
		||||
      - '&8[&3&lTabooLib&8] &7地址 &f{1}'
 | 
			
		||||
@@ -604,6 +605,7 @@ COMMANDS:
 | 
			
		||||
      EXPANSION-NOT-FOUND: '&8[&3&lTabooLib&8] &c扩展 &4{0} &c不存在.'
 | 
			
		||||
      EXPANSION-NOT-EXISTS: '&8[&3&lTabooLib&8] &c扩展 &4{0} &c尚未下载.'
 | 
			
		||||
      EXPANSION-NO-UPDATE: '&8[&3&lTabooLib&8] &7扩展 &f{0} &7已是最新版本.'
 | 
			
		||||
      EXPANSION-VERSION: '&8[&3&lTabooLib&8] &c扩展 &4{0} &c需要 &4TabooLib v{1}&c 版本才可以使用!'
 | 
			
		||||
      UPDATE-START:
 | 
			
		||||
      - '&8[&3&lTabooLib&8] &7扩展 &f{0} &7开始更新:'
 | 
			
		||||
      - '&8[&3&lTabooLib&8] &7版本 &f{1}'
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user