Fix dependency download
This commit is contained in:
parent
0f55e50417
commit
429ceaeca6
@ -24,10 +24,10 @@ ITEM-UTILS:
|
||||
FAIL-SAVE-EXISTS: '无法载入载入物品 &4{0}&c, 因为它已经存在了'
|
||||
|
||||
MYSQL-HIKARI:
|
||||
CREATE-SUCCESS: '&7插件 &f{0}&7 注册新的数据库连接: &f{1}'
|
||||
CREATE-EXISTS: '&7插件 &f{0}&7 引用插件 &f{1}&7 注册的数据库连接'
|
||||
CLOSE-SUCCESS: '&7插件 &f{0} &7注册的数据库连接 &f{1} &7已被注销!'
|
||||
CLOSE-FAIL: '&7插件 &f{0} &7注册的数据库连接正在被 &f{1} &7个插件使用, 无法注销!'
|
||||
CREATE-SUCCESS: '&7插件 &f{0} &7注册新的连接池: &f{1}'
|
||||
CREATE-EXISTS: '&7插件 &f{0} &7引用插件 &f{1} &7注册的连接池.'
|
||||
CLOSE-SUCCESS: '&7插件 &f{0} &7注册的连接池 &f{1} &7已被注销.'
|
||||
CLOSE-FAIL: '&7插件 &f{0} &7注册的连接池正在被 &f{1} &7个插件使用, 无法注销!'
|
||||
|
||||
COMMANDS:
|
||||
GLOBAL:
|
||||
|
@ -5,6 +5,7 @@ import io.izzel.taboolib.Version;
|
||||
import io.izzel.taboolib.module.db.local.Local;
|
||||
import io.izzel.taboolib.module.db.local.LocalPlayer;
|
||||
import io.izzel.taboolib.module.inject.TListener;
|
||||
import io.izzel.taboolib.module.locale.TLocale;
|
||||
import io.izzel.taboolib.module.locale.logger.TLogger;
|
||||
import io.izzel.taboolib.module.tellraw.TellrawJson;
|
||||
import io.izzel.taboolib.util.item.Items;
|
||||
@ -19,6 +20,22 @@ import org.bukkit.event.server.ServerCommandEvent;
|
||||
@TListener
|
||||
public class ListenerPlayerCommand implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void cmd(PlayerCommandPreprocessEvent e) {
|
||||
if (e.getMessage().equalsIgnoreCase("/tabooLib")) {
|
||||
e.setCancelled(true);
|
||||
TLocale.Display.sendTitle(e.getPlayer(), "§fTabooLib", "§7TabooLib is enabled.");
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("/tellrawTest") && e.getPlayer().hasPermission("taboolib.tellraw")) {
|
||||
e.setCancelled(true);
|
||||
TellrawJson.create()
|
||||
.append("§8[§3§lTabooLib§8] §7TellrawJson Test: §f[")
|
||||
.append(Items.getName(e.getPlayer().getItemInHand())).hoverItem(e.getPlayer().getItemInHand())
|
||||
.append("§f]")
|
||||
.send(e.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void cmd(ServerCommandEvent e) {
|
||||
if (e.getCommand().equalsIgnoreCase("saveFiles")) {
|
||||
@ -41,16 +58,4 @@ public class ListenerPlayerCommand implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void cmd(PlayerCommandPreprocessEvent e) {
|
||||
if (e.getMessage().equals("/tellrawTest") && e.getPlayer().hasPermission("taboolib.tellraw")) {
|
||||
e.setCancelled(true);
|
||||
TellrawJson.create()
|
||||
.append("§8[§3§lTabooLib§8] §7TellrawJson Test: §f[")
|
||||
.append(Items.getName(e.getPlayer().getItemInHand())).hoverItem(e.getPlayer().getItemInHand())
|
||||
.append("§f]")
|
||||
.send(e.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ import java.util.stream.Collectors;
|
||||
public class SQLHost extends IHost {
|
||||
|
||||
private String host;
|
||||
private String user;
|
||||
private String port;
|
||||
private String user;
|
||||
private String password;
|
||||
private String database;
|
||||
private List<String> flags = Arrays.asList("characterEncoding=utf-8", "useSSL=false");
|
||||
@ -28,23 +28,18 @@ public class SQLHost extends IHost {
|
||||
}
|
||||
|
||||
public SQLHost(ConfigurationSection section, Plugin plugin, boolean autoClose) {
|
||||
this(section.getString("host", "localhost"), section.getString("user", "root"), section.getString("port", "3306"), section.getString("password", ""), section.getString("database", "test"), plugin);
|
||||
this(section.getString("host", "localhost"), section.getString("port", "3306"), section.getString("user", "root"), section.getString("password", ""), section.getString("database", "test"), plugin);
|
||||
}
|
||||
|
||||
public SQLHost(String host, int port, String user, String password, String database, Plugin plugin) {
|
||||
this(host, user, String.valueOf(port), password, database, plugin, false);
|
||||
public SQLHost(String host, String port, String user, String password, String database, Plugin plugin) {
|
||||
this(host, port, user, password, database, plugin, false);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SQLHost(String host, String user, String port, String password, String database, Plugin plugin) {
|
||||
this(host, user, port, password, database, plugin, false);
|
||||
}
|
||||
|
||||
public SQLHost(String host, String user, String port, String password, String database, Plugin plugin, boolean autoClose) {
|
||||
public SQLHost(String host, String port, String user, String password, String database, Plugin plugin, boolean autoClose) {
|
||||
super(plugin, autoClose);
|
||||
this.host = host;
|
||||
this.user = user;
|
||||
this.port = port;
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
this.database = database;
|
||||
}
|
||||
|
@ -58,7 +58,6 @@ public class TDependency {
|
||||
|
||||
private static boolean downloadMaven(String url, String groupId, String artifactId, String version, File target, String dl) {
|
||||
TLocale.Logger.info("DEPENDENCY.DOWNLOAD-START", target.getName());
|
||||
Files.toFile(Files.readFromURL(dl.length() == 0 ? url + "/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".jar" : dl, ""), Files.file(target));
|
||||
return target.length() > 0;
|
||||
return Files.downloadFile(dl.length() == 0 ? url + "/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".jar" : dl, Files.file(target));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.izzel.taboolib.module.dependency;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
@ -15,7 +16,7 @@ public class TDependencyLoader {
|
||||
try {
|
||||
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(plugin.getClass().getClassLoader(), url);
|
||||
method.invoke(Bukkit.class.getClassLoader(), url);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -26,15 +26,15 @@ public abstract class ChannelExecutor {
|
||||
|
||||
public void addPlayerChannel(Player player) {
|
||||
addChannelService.submit(() -> {
|
||||
getPlayerChannel(player).pipeline().addBefore("packet_handler", "taboolib_packet_handler", new ChannelHandler(player));
|
||||
getPlayerChannel(player).pipeline().addBefore("packet_handler", "taboolib5_packet_handler", new ChannelHandler(player));
|
||||
});
|
||||
}
|
||||
|
||||
public void removePlayerChannel(Player player) {
|
||||
removeChannelService.submit(() -> {
|
||||
Channel playerChannel = getPlayerChannel(player);
|
||||
if (playerChannel.pipeline().get("taboolib_packet_handler") != null) {
|
||||
playerChannel.pipeline().remove("taboolib_packet_handler");
|
||||
if (playerChannel.pipeline().get("taboolib5_packet_handler") != null) {
|
||||
playerChannel.pipeline().remove("taboolib5_packet_handler");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.jar.JarFile;
|
||||
@ -70,9 +71,9 @@ public class Files {
|
||||
}
|
||||
|
||||
public static InputStream getCanonicalResource(Plugin plugin, String filename) {
|
||||
File file = Files.file(new File("plugins/TabooLib/temp/" + UUID.randomUUID()));
|
||||
File file = file(new File("plugins/TabooLib/temp/" + UUID.randomUUID()));
|
||||
try {
|
||||
ZipFile zipFile = new ZipFile(Files.toFile(plugin.getClass().getProtectionDomain().getCodeSource().getLocation().openStream(), file));
|
||||
ZipFile zipFile = new ZipFile(toFile(plugin.getClass().getProtectionDomain().getCodeSource().getLocation().openStream(), file));
|
||||
ZipEntry entry = zipFile.getEntry(filename);
|
||||
if (entry != null) {
|
||||
return zipFile.getInputStream(entry);
|
||||
@ -88,7 +89,7 @@ public class Files {
|
||||
if (!file.exists() || replace) {
|
||||
try (InputStream inputStream = getCanonicalResource(plugin, (plugin instanceof InternalPlugin ? "__resources__/" : "") + path)) {
|
||||
if (inputStream != null) {
|
||||
toFile(inputStream, Files.file(file));
|
||||
toFile(inputStream, file(file));
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
@ -120,6 +121,16 @@ public class Files {
|
||||
return file;
|
||||
}
|
||||
|
||||
public static boolean downloadFile(String in, File file) {
|
||||
try (InputStream inputStream = new URL(in).openStream(); BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream)) {
|
||||
toFile(bufferedInputStream, file);
|
||||
return true;
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static File file(File path, String filePath) {
|
||||
return file(new File(path, filePath));
|
||||
}
|
||||
@ -161,18 +172,15 @@ public class Files {
|
||||
return file;
|
||||
}
|
||||
|
||||
public static void deepDelete(File file) {
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
public static void copy(File file1, File file2) {
|
||||
try (FileInputStream fileIn = new FileInputStream(file1);
|
||||
FileOutputStream fileOut = new FileOutputStream(file2);
|
||||
FileChannel channelIn = fileIn.getChannel();
|
||||
FileChannel channelOut = fileOut.getChannel()) {
|
||||
channelIn.transferTo(0, channelIn.size(), channelOut);
|
||||
} catch (IOException t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
if (file.isFile()) {
|
||||
file.delete();
|
||||
return;
|
||||
}
|
||||
for (File file1 : Objects.requireNonNull(file.listFiles())) {
|
||||
deepDelete(file1);
|
||||
}
|
||||
file.delete();
|
||||
}
|
||||
|
||||
public static void deepCopy(String originFileName, String targetFileName) {
|
||||
@ -190,23 +198,26 @@ public class Files {
|
||||
if (file.isDirectory()) {
|
||||
deepCopy(file.getAbsolutePath(), targetFileName + "/" + file.getName());
|
||||
} else {
|
||||
weekCopy(file, new File(targetFileName + "/" + file.getName()));
|
||||
copy(file, new File(targetFileName + "/" + file.getName()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
weekCopy(originFile, targetFile);
|
||||
copy(originFile, targetFile);
|
||||
}
|
||||
}
|
||||
|
||||
public static void weekCopy(File file1, File file2) {
|
||||
try (FileInputStream fileIn = new FileInputStream(file1);
|
||||
FileOutputStream fileOut = new FileOutputStream(file2);
|
||||
FileChannel channelIn = fileIn.getChannel();
|
||||
FileChannel channelOut = fileOut.getChannel()) {
|
||||
channelIn.transferTo(0, channelIn.size(), channelOut);
|
||||
} catch (IOException t) {
|
||||
t.printStackTrace();
|
||||
public static void deepDelete(File file) {
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
if (file.isFile()) {
|
||||
file.delete();
|
||||
return;
|
||||
}
|
||||
for (File file1 : Objects.requireNonNull(file.listFiles())) {
|
||||
deepDelete(file1);
|
||||
}
|
||||
file.delete();
|
||||
}
|
||||
|
||||
public static String readFromURL(String url, String def) {
|
||||
@ -222,7 +233,15 @@ public class Files {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String readFromFile(File file, int size, String encode) {
|
||||
public static String readFromFile(File file) {
|
||||
return readFromFile(file, 1024, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static String readFromFile(File file, int size) {
|
||||
return readFromFile(file, size, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static String readFromFile(File file, int size, Charset encode) {
|
||||
try (FileInputStream fin = new FileInputStream(file); BufferedInputStream bin = new BufferedInputStream(fin)) {
|
||||
return readFromStream(fin, size, encode);
|
||||
} catch (IOException e) {
|
||||
@ -231,7 +250,15 @@ public class Files {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String readFromStream(InputStream in, int size, String encode) {
|
||||
public static String readFromStream(InputStream in) {
|
||||
return readFromStream(in, 1024, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static String readFromStream(InputStream in, int size) {
|
||||
return readFromStream(in, size, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static String readFromStream(InputStream in, int size, Charset encode) {
|
||||
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
|
||||
byte[] b = new byte[size];
|
||||
int i;
|
||||
@ -258,15 +285,12 @@ public class Files {
|
||||
}
|
||||
|
||||
public static YamlConfiguration loadYaml(File file) {
|
||||
YamlConfiguration configuration = new YamlConfiguration();
|
||||
try {
|
||||
String yaml = com.google.common.io.Files.toString(file, Charset.forName("utf-8"));
|
||||
configuration.loadFromString(yaml);
|
||||
return configuration;
|
||||
return YamlConfiguration.loadConfiguration(file);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return configuration;
|
||||
return new YamlConfiguration();
|
||||
}
|
||||
|
||||
private static Class getCaller(Class<?> obj) {
|
||||
|
Loading…
Reference in New Issue
Block a user