TabooLib v.4.325
+ 修复 TConfiguration 失效的问题 + 修复 PathfinderExecutor 工具中部分方法无法使用的问题 + 修复自动更新的问题
This commit is contained in:
parent
bda8fb5ff7
commit
6c42aa3889
@ -13,6 +13,8 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@TConfig(name = "cfg.yml", charset = "GBK")
|
@TConfig(name = "cfg.yml", charset = "GBK")
|
||||||
public class ExampleMain extends JavaPlugin {
|
public class ExampleMain extends JavaPlugin {
|
||||||
|
|
||||||
|
private Property<Boolean> update = Property.of(false);
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
|
MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
|
||||||
System.out.println(bean.getHeapMemoryUsage().toString());
|
System.out.println(bean.getHeapMemoryUsage().toString());
|
||||||
@ -34,8 +36,6 @@ public class ExampleMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Property<Boolean> update = Property.of(false);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
update.addListener(((oldVal, newVal) -> {
|
update.addListener(((oldVal, newVal) -> {
|
||||||
|
@ -779,39 +779,12 @@ public class TabooLibMainCommand extends BaseMainCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (!UpdateTask.isHaveUpdate()) {
|
UpdateTask.updatePlugin(true);
|
||||||
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.UPDATEPLUGIN.UPDATE-NOT-FOUND");
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
File pluginFile = PluginUtils.getPluginFile(Main.getInst());
|
@Override
|
||||||
if (pluginFile == null) {
|
public CommandType getType() {
|
||||||
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.UPDATEPLUGIN.FILE-NOT-FOUND");
|
return CommandType.CONSOLE;
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,7 @@ public class TConfiguration extends YamlConfiguration {
|
|||||||
public void reload() {
|
public void reload() {
|
||||||
try {
|
try {
|
||||||
load(file);
|
load(file);
|
||||||
|
runListener();
|
||||||
} catch (IOException | InvalidConfigurationException e) {
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
TLogger.getGlobalLogger().warn("Cannot load configuration from stream: " + e.toString());
|
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 me.skymc.taboolib.nms.NMSUtils;
|
||||||
import net.minecraft.server.v1_8_R3.*;
|
import net.minecraft.server.v1_8_R3.*;
|
||||||
import org.bukkit.Location;
|
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.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Set;
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 该类仅用作生成 ASM 代码,无任何意义
|
* 该类仅用作生成 ASM 代码,无任何意义
|
||||||
@ -117,7 +115,7 @@ public class InternalPathfinderExecutor extends PathfinderExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public void clearGoalAi(LivingEntity entity) {
|
public void clearGoalAi(LivingEntity entity) {
|
||||||
try {
|
try {
|
||||||
((Set) pathfinderGoalSelectorSet.get(((EntityInsentient) getEntityInsentient(entity)).goalSelector)).clear();
|
((Collection) pathfinderGoalSelectorSet.get(((EntityInsentient) getEntityInsentient(entity)).goalSelector)).clear();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -126,7 +124,7 @@ public class InternalPathfinderExecutor extends PathfinderExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public void clearTargetAi(LivingEntity entity) {
|
public void clearTargetAi(LivingEntity entity) {
|
||||||
try {
|
try {
|
||||||
((Set) pathfinderGoalSelectorSet.get(((EntityInsentient) getEntityInsentient(entity)).targetSelector)).clear();
|
((Collection) pathfinderGoalSelectorSet.get(((EntityInsentient) getEntityInsentient(entity)).targetSelector)).clear();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
package me.skymc.taboolib.fileutils;
|
package me.skymc.taboolib.fileutils;
|
||||||
|
|
||||||
import ch.njol.util.Closeable;
|
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 com.ilummc.tlib.util.IO;
|
||||||
import me.skymc.taboolib.Main;
|
import me.skymc.taboolib.Main;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
@ -405,35 +407,38 @@ public class FileUtils {
|
|||||||
/**
|
/**
|
||||||
* 下载文件
|
* 下载文件
|
||||||
*
|
*
|
||||||
* @param downloadURL 下载地址
|
* @param url 下载地址
|
||||||
* @param file 保存位置
|
* @param file 下载位置
|
||||||
|
* @param async 是否异步
|
||||||
*/
|
*/
|
||||||
public static void download(String downloadURL, File file) {
|
public static void download(String url, File file, boolean async) {
|
||||||
HttpURLConnection conn = null;
|
EagletTask eagletTask = new EagletTask()
|
||||||
InputStream inputStream = null;
|
.url(url)
|
||||||
FileOutputStream fos = null;
|
.file(file)
|
||||||
try {
|
.setThreads(8)
|
||||||
URL url = new URL(downloadURL);
|
.setOnError(event -> {
|
||||||
conn = (HttpURLConnection) url.openConnection();
|
})
|
||||||
conn.setConnectTimeout(5 * 1000);
|
.setOnConnected(event -> TLocale.Logger.info("UTIL.DOWNLOAD-CONNECTED", file.getName(), ProgressEvent.format(event.getContentLength())))
|
||||||
conn.setRequestProperty("User-Agent", "Mozilla/31.0 (compatible; MSIE 10.0; Windows NT; DigExt)");
|
.setOnProgress(event -> TLocale.Logger.info("UTIL.DOWNLOAD-PROGRESS", event.getSpeedFormatted(), event.getPercentageFormatted()))
|
||||||
|
.setOnComplete(event -> {
|
||||||
inputStream = conn.getInputStream();
|
if (event.isSuccess()) {
|
||||||
byte[] data = read(inputStream);
|
TLocale.Logger.info("UTIL.DOWNLOAD-SUCCESS", file.getName());
|
||||||
|
} else {
|
||||||
fos = new FileOutputStream(createNewFile(file));
|
TLocale.Logger.error("UTIL.DOWNLOAD-FAILED", file.getName());
|
||||||
fos.write(data);
|
}
|
||||||
} catch (Exception ignored) {
|
}).start();
|
||||||
} finally {
|
if (!async) {
|
||||||
IOUtils.close(conn);
|
eagletTask.waitUntil();
|
||||||
IOUtils.closeQuietly(fos);
|
|
||||||
IOUtils.closeQuietly(inputStream);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void download(String url, File file) {
|
||||||
|
download(url, file, false);
|
||||||
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void download(String downloadURL, String filename, File saveDir) {
|
public static void download(String url, String filename, File saveDir) {
|
||||||
download(downloadURL, new File(saveDir, filename));
|
download(url, new File(saveDir, filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@ -4,12 +4,17 @@ import com.google.gson.JsonElement;
|
|||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.ilummc.tlib.resources.TLocale;
|
import com.ilummc.tlib.resources.TLocale;
|
||||||
|
import com.ilummc.tlib.util.Strings;
|
||||||
import me.skymc.taboolib.Main;
|
import me.skymc.taboolib.Main;
|
||||||
import me.skymc.taboolib.TabooLib;
|
import me.skymc.taboolib.TabooLib;
|
||||||
import me.skymc.taboolib.fileutils.FileUtils;
|
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.Bukkit;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author sky
|
* @author sky
|
||||||
* @since 2018年2月23日 下午10:39:14
|
* @since 2018年2月23日 下午10:39:14
|
||||||
@ -19,14 +24,6 @@ public class UpdateTask {
|
|||||||
private static boolean haveUpdate = false;
|
private static boolean haveUpdate = false;
|
||||||
private static double newVersion = 0;
|
private static double newVersion = 0;
|
||||||
|
|
||||||
public static boolean isHaveUpdate() {
|
|
||||||
return haveUpdate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getNewVersion() {
|
|
||||||
return newVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UpdateTask() {
|
public UpdateTask() {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
|
|
||||||
@ -35,13 +32,11 @@ public class UpdateTask {
|
|||||||
if (!Main.getInst().getConfig().getBoolean("UPDATE-CHECK")) {
|
if (!Main.getInst().getConfig().getBoolean("UPDATE-CHECK")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String value = FileUtils.getStringFromURL("https://api.github.com/repos/Bkm016/TabooLib/tags", null);
|
String value = FileUtils.getStringFromURL("https://api.github.com/repos/Bkm016/TabooLib/tags", null);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
TLocale.Logger.error("UPDATETASK.VERSION-FAIL");
|
TLocale.Logger.error("UPDATETASK.VERSION-FAIL");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonElement json = new JsonParser().parse(value);
|
JsonElement json = new JsonParser().parse(value);
|
||||||
if (json.isJsonArray()) {
|
if (json.isJsonArray()) {
|
||||||
JsonObject latestObject = json.getAsJsonArray().get(0).getAsJsonObject();
|
JsonObject latestObject = json.getAsJsonArray().get(0).getAsJsonObject();
|
||||||
@ -51,18 +46,39 @@ public class UpdateTask {
|
|||||||
} else {
|
} else {
|
||||||
haveUpdate = true;
|
haveUpdate = true;
|
||||||
TLocale.Logger.info("UPDATETASK.VERSION-OUTDATED", String.valueOf(TabooLib.getPluginVersion()), String.valueOf(newVersion));
|
TLocale.Logger.info("UPDATETASK.VERSION-OUTDATED", String.valueOf(TabooLib.getPluginVersion()), String.valueOf(newVersion));
|
||||||
|
Bukkit.getScheduler().runTask(TabooLib.instance(), () -> updatePlugin(true));
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (Main.getInst().getConfig().getBoolean("UPDATE-DOWNLOAD", false)) {
|
|
||||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "taboolib updatePlugin");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.runTask(Main.getInst());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTaskTimerAsynchronously(Main.getInst(), 100, 20 * 60 * 60 * 6);
|
}.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,8 +159,8 @@ COMMANDS:
|
|||||||
ONLY-STORAGE-SQL: '&8[&3&lTabooLib&8] &4只有启用数据库储存时才能这么做'
|
ONLY-STORAGE-SQL: '&8[&3&lTabooLib&8] &4只有启用数据库储存时才能这么做'
|
||||||
INTERNAL:
|
INTERNAL:
|
||||||
TYPE-ERROR: '&8[&3&lTabooLib&8] &7指令 &f{0} &7只能由 &f{1} &7执行'
|
TYPE-ERROR: '&8[&3&lTabooLib&8] &7指令 &f{0} &7只能由 &f{1} &7执行'
|
||||||
TYPE-PLAYER: 玩家
|
TYPE-PLAYER: '玩家'
|
||||||
TYPE-CONSOLE: 控制台
|
TYPE-CONSOLE: '控制台'
|
||||||
ERROR-USAGE:
|
ERROR-USAGE:
|
||||||
- '&8[&3&lTabooLib&8] &7指令 &f{0} &7参数不足'
|
- '&8[&3&lTabooLib&8] &7指令 &f{0} &7参数不足'
|
||||||
- '&8[&3&lTabooLib&8] &7正确用法:'
|
- '&8[&3&lTabooLib&8] &7正确用法:'
|
||||||
@ -237,10 +237,9 @@ COMMANDS:
|
|||||||
DESCRIPTION: '&4更新插件 &8(谨防非正规途径的插件获取方式)'
|
DESCRIPTION: '&4更新插件 &8(谨防非正规途径的插件获取方式)'
|
||||||
UPDATE-NOT-FOUND: '&8[&3&lTabooLib&8] &7插件已是最新版, 无需更新!'
|
UPDATE-NOT-FOUND: '&8[&3&lTabooLib&8] &7插件已是最新版, 无需更新!'
|
||||||
UPDATE-NOT-SUPPORT: '&8[&3&lTabooLib&8] &4您的服务器不支持在线更新!'
|
UPDATE-NOT-SUPPORT: '&8[&3&lTabooLib&8] &4您的服务器不支持在线更新!'
|
||||||
|
UPDATE-SUCCESS: '&8[&3&lTabooLib&8] &7最新版下载完成, 服务器即将重启!'
|
||||||
FILE-NOT-FOUND: '&8[&3&lTabooLib&8] &4尚未寻找到插件文件'
|
FILE-NOT-FOUND: '&8[&3&lTabooLib&8] &4尚未寻找到插件文件'
|
||||||
PLAYER-ONLINE: '&8[&3&lTabooLib&8] &4服务器有玩家在线无法更新插件.'
|
PLAYER-ONLINE: '&8[&3&lTabooLib&8] &4服务器有玩家在线无法更新插件.'
|
||||||
UPDATE-START: '&8[&3&lTabooLib&8] &7开始下载:&f {0}'
|
|
||||||
UPDATE-SUCCESS: '&8[&3&lTabooLib&8] &7最新版下载完成, 服务器即将重启!'
|
|
||||||
PLAYERTAG:
|
PLAYERTAG:
|
||||||
DESCRIPTION:
|
DESCRIPTION:
|
||||||
DISPLAY: '设置玩家展示名称'
|
DISPLAY: '设置玩家展示名称'
|
||||||
@ -576,3 +575,9 @@ COMMUNICATION:
|
|||||||
CLIENT-QUITED: '§8[§3§lTabooLibClient§8] &7服务器 &f{0} &7退出本地通讯网络.'
|
CLIENT-QUITED: '§8[§3§lTabooLibClient§8] &7服务器 &f{0} &7退出本地通讯网络.'
|
||||||
PACKET-MESSAGE: '§8[§3§lTabooLibClient§8] &7服务器 &f{0} &7发送信息: &f{1}'
|
PACKET-MESSAGE: '§8[§3§lTabooLibClient§8] &7服务器 &f{0} &7发送信息: &f{1}'
|
||||||
PACKET-COMMAND: '§8[§3§lTabooLibClient§8] &7服务器 &f{0} &7运行命令: &f{1}'
|
PACKET-COMMAND: '§8[§3§lTabooLibClient§8] &7服务器 &f{0} &7运行命令: &f{1}'
|
||||||
|
|
||||||
|
UTIL:
|
||||||
|
DOWNLOAD-CONNECTED: '开始下载文件 {0} 大小 {1}'
|
||||||
|
DOWNLOAD-PROGRESS: ' 下载速度 {0} 进度 {1}'
|
||||||
|
DOWNLOAD-SUCCESS: '下载 {0} 完成!'
|
||||||
|
DOWNLOAD-FAILED: '下载 {0} 失败!'
|
Loading…
Reference in New Issue
Block a user