TabooLib v.4.325
+ 修复 TConfiguration 失效的问题 + 修复 PathfinderExecutor 工具中部分方法无法使用的问题 + 修复自动更新的问题
This commit is contained in:
@@ -779,39 +779,12 @@ public class TabooLibMainCommand extends BaseMainCommand {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!UpdateTask.isHaveUpdate()) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.UPDATEPLUGIN.UPDATE-NOT-FOUND");
|
||||
return;
|
||||
}
|
||||
UpdateTask.updatePlugin(true);
|
||||
}
|
||||
|
||||
File pluginFile = PluginUtils.getPluginFile(Main.getInst());
|
||||
if (pluginFile == null) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.UPDATEPLUGIN.FILE-NOT-FOUND");
|
||||
return;
|
||||
}
|
||||
|
||||
new BukkitRunnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (PlayerUtils.getOnlinePlayers().size() > 0) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.UPDATEPLUGIN.PLAYER-ONLINE");
|
||||
return;
|
||||
}
|
||||
|
||||
String url = Strings.replaceWithOrder("https://github.com/Bkm016/TabooLib/releases/download/{0}/TabooLib-{0}.jar", UpdateTask.getNewVersion());
|
||||
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.UPDATEPLUGIN.UPDATE-START", url);
|
||||
|
||||
File file = new File("plugins/update");
|
||||
if (file.exists()) {
|
||||
FileUtils.download(url, new File(file, pluginFile.getName()));
|
||||
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.UPDATEPLUGIN.UPDATE-SUCCESS");
|
||||
} else {
|
||||
FileUtils.download(url, pluginFile);
|
||||
Bukkit.shutdown();
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(Main.getInst());
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return CommandType.CONSOLE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ public class TConfiguration extends YamlConfiguration {
|
||||
public void reload() {
|
||||
try {
|
||||
load(file);
|
||||
runListener();
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
TLogger.getGlobalLogger().warn("Cannot load configuration from stream: " + e.toString());
|
||||
}
|
||||
|
||||
@@ -6,14 +6,12 @@ import me.skymc.taboolib.common.pathfinder.SimpleAiSelector;
|
||||
import me.skymc.taboolib.nms.NMSUtils;
|
||||
import net.minecraft.server.v1_8_R3.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Set;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 该类仅用作生成 ASM 代码,无任何意义
|
||||
@@ -117,7 +115,7 @@ public class InternalPathfinderExecutor extends PathfinderExecutor {
|
||||
@Override
|
||||
public void clearGoalAi(LivingEntity entity) {
|
||||
try {
|
||||
((Set) pathfinderGoalSelectorSet.get(((EntityInsentient) getEntityInsentient(entity)).goalSelector)).clear();
|
||||
((Collection) pathfinderGoalSelectorSet.get(((EntityInsentient) getEntityInsentient(entity)).goalSelector)).clear();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -126,7 +124,7 @@ public class InternalPathfinderExecutor extends PathfinderExecutor {
|
||||
@Override
|
||||
public void clearTargetAi(LivingEntity entity) {
|
||||
try {
|
||||
((Set) pathfinderGoalSelectorSet.get(((EntityInsentient) getEntityInsentient(entity)).targetSelector)).clear();
|
||||
((Collection) pathfinderGoalSelectorSet.get(((EntityInsentient) getEntityInsentient(entity)).targetSelector)).clear();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package me.skymc.taboolib.fileutils;
|
||||
|
||||
import ch.njol.util.Closeable;
|
||||
import com.ilummc.eagletdl.EagletTask;
|
||||
import com.ilummc.eagletdl.ProgressEvent;
|
||||
import com.ilummc.tlib.resources.TLocale;
|
||||
import com.ilummc.tlib.util.IO;
|
||||
import me.skymc.taboolib.Main;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
@@ -405,35 +407,38 @@ public class FileUtils {
|
||||
/**
|
||||
* 下载文件
|
||||
*
|
||||
* @param downloadURL 下载地址
|
||||
* @param file 保存位置
|
||||
* @param url 下载地址
|
||||
* @param file 下载位置
|
||||
* @param async 是否异步
|
||||
*/
|
||||
public static void download(String downloadURL, File file) {
|
||||
HttpURLConnection conn = null;
|
||||
InputStream inputStream = null;
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
URL url = new URL(downloadURL);
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setConnectTimeout(5 * 1000);
|
||||
conn.setRequestProperty("User-Agent", "Mozilla/31.0 (compatible; MSIE 10.0; Windows NT; DigExt)");
|
||||
|
||||
inputStream = conn.getInputStream();
|
||||
byte[] data = read(inputStream);
|
||||
|
||||
fos = new FileOutputStream(createNewFile(file));
|
||||
fos.write(data);
|
||||
} catch (Exception ignored) {
|
||||
} finally {
|
||||
IOUtils.close(conn);
|
||||
IOUtils.closeQuietly(fos);
|
||||
IOUtils.closeQuietly(inputStream);
|
||||
public static void download(String url, File file, boolean async) {
|
||||
EagletTask eagletTask = new EagletTask()
|
||||
.url(url)
|
||||
.file(file)
|
||||
.setThreads(8)
|
||||
.setOnError(event -> {
|
||||
})
|
||||
.setOnConnected(event -> TLocale.Logger.info("UTIL.DOWNLOAD-CONNECTED", file.getName(), ProgressEvent.format(event.getContentLength())))
|
||||
.setOnProgress(event -> TLocale.Logger.info("UTIL.DOWNLOAD-PROGRESS", event.getSpeedFormatted(), event.getPercentageFormatted()))
|
||||
.setOnComplete(event -> {
|
||||
if (event.isSuccess()) {
|
||||
TLocale.Logger.info("UTIL.DOWNLOAD-SUCCESS", file.getName());
|
||||
} else {
|
||||
TLocale.Logger.error("UTIL.DOWNLOAD-FAILED", file.getName());
|
||||
}
|
||||
}).start();
|
||||
if (!async) {
|
||||
eagletTask.waitUntil();
|
||||
}
|
||||
}
|
||||
|
||||
public static void download(String url, File file) {
|
||||
download(url, file, false);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void download(String downloadURL, String filename, File saveDir) {
|
||||
download(downloadURL, new File(saveDir, filename));
|
||||
public static void download(String url, String filename, File saveDir) {
|
||||
download(url, new File(saveDir, filename));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
||||
@@ -4,12 +4,17 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.ilummc.tlib.resources.TLocale;
|
||||
import com.ilummc.tlib.util.Strings;
|
||||
import me.skymc.taboolib.Main;
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import me.skymc.taboolib.fileutils.FileUtils;
|
||||
import me.skymc.taboolib.player.PlayerUtils;
|
||||
import me.skymc.taboolib.plugin.PluginUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
* @since 2018年2月23日 下午10:39:14
|
||||
@@ -19,14 +24,6 @@ public class UpdateTask {
|
||||
private static boolean haveUpdate = false;
|
||||
private static double newVersion = 0;
|
||||
|
||||
public static boolean isHaveUpdate() {
|
||||
return haveUpdate;
|
||||
}
|
||||
|
||||
public static double getNewVersion() {
|
||||
return newVersion;
|
||||
}
|
||||
|
||||
public UpdateTask() {
|
||||
new BukkitRunnable() {
|
||||
|
||||
@@ -35,13 +32,11 @@ public class UpdateTask {
|
||||
if (!Main.getInst().getConfig().getBoolean("UPDATE-CHECK")) {
|
||||
return;
|
||||
}
|
||||
|
||||
String value = FileUtils.getStringFromURL("https://api.github.com/repos/Bkm016/TabooLib/tags", null);
|
||||
if (value == null) {
|
||||
TLocale.Logger.error("UPDATETASK.VERSION-FAIL");
|
||||
return;
|
||||
}
|
||||
|
||||
JsonElement json = new JsonParser().parse(value);
|
||||
if (json.isJsonArray()) {
|
||||
JsonObject latestObject = json.getAsJsonArray().get(0).getAsJsonObject();
|
||||
@@ -51,18 +46,39 @@ public class UpdateTask {
|
||||
} else {
|
||||
haveUpdate = true;
|
||||
TLocale.Logger.info("UPDATETASK.VERSION-OUTDATED", String.valueOf(TabooLib.getPluginVersion()), String.valueOf(newVersion));
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (Main.getInst().getConfig().getBoolean("UPDATE-DOWNLOAD", false)) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "taboolib updatePlugin");
|
||||
}
|
||||
}
|
||||
}.runTask(Main.getInst());
|
||||
Bukkit.getScheduler().runTask(TabooLib.instance(), () -> updatePlugin(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(Main.getInst(), 100, 20 * 60 * 60 * 6);
|
||||
}
|
||||
|
||||
public static boolean isHaveUpdate() {
|
||||
return haveUpdate;
|
||||
}
|
||||
|
||||
public static double getNewVersion() {
|
||||
return newVersion;
|
||||
}
|
||||
|
||||
public static void updatePlugin(boolean shutdown) {
|
||||
if (!UpdateTask.isHaveUpdate()) {
|
||||
TLocale.Logger.info("COMMANDS.TABOOLIB.UPDATEPLUGIN.UPDATE-NOT-FOUND");
|
||||
return;
|
||||
}
|
||||
if (PlayerUtils.getOnlinePlayers().size() > 0) {
|
||||
TLocale.Logger.info("COMMANDS.TABOOLIB.UPDATEPLUGIN.PLAYER-ONLINE");
|
||||
return;
|
||||
}
|
||||
File pluginFile = PluginUtils.getPluginFile(Main.getInst());
|
||||
if (pluginFile == null) {
|
||||
TLocale.Logger.info("COMMANDS.TABOOLIB.UPDATEPLUGIN.FILE-NOT-FOUND");
|
||||
return;
|
||||
}
|
||||
FileUtils.download(Strings.replaceWithOrder("https://github.com/Bkm016/TabooLib/releases/download/{0}/TabooLib-{0}.jar", UpdateTask.getNewVersion()), pluginFile);
|
||||
TLocale.Logger.info("COMMANDS.TABOOLIB.UPDATEPLUGIN.UPDATE-SUCCESS");
|
||||
if (shutdown) {
|
||||
Bukkit.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user