Fix dependency download

This commit is contained in:
坏黑 2019-07-08 21:23:49 +08:00
parent 0f55e50417
commit 429ceaeca6
7 changed files with 88 additions and 64 deletions

View File

@ -24,10 +24,10 @@ ITEM-UTILS:
FAIL-SAVE-EXISTS: '无法载入载入物品 &4{0}&c, 因为它已经存在了' FAIL-SAVE-EXISTS: '无法载入载入物品 &4{0}&c, 因为它已经存在了'
MYSQL-HIKARI: MYSQL-HIKARI:
CREATE-SUCCESS: '&7插件 &f{0}&7 注册新的数据库连接: &f{1}' CREATE-SUCCESS: '&7插件 &f{0} &7注册新的连接: &f{1}'
CREATE-EXISTS: '&7插件 &f{0}&7 引用插件 &f{1}&7 注册的数据库连接' CREATE-EXISTS: '&7插件 &f{0} &7引用插件 &f{1} &7注册的连接池.'
CLOSE-SUCCESS: '&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个插件使用, 无法注销!' CLOSE-FAIL: '&7插件 &f{0} &7注册的连接正在被 &f{1} &7个插件使用, 无法注销!'
COMMANDS: COMMANDS:
GLOBAL: GLOBAL:

View File

@ -5,6 +5,7 @@ import io.izzel.taboolib.Version;
import io.izzel.taboolib.module.db.local.Local; import io.izzel.taboolib.module.db.local.Local;
import io.izzel.taboolib.module.db.local.LocalPlayer; import io.izzel.taboolib.module.db.local.LocalPlayer;
import io.izzel.taboolib.module.inject.TListener; 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.locale.logger.TLogger;
import io.izzel.taboolib.module.tellraw.TellrawJson; import io.izzel.taboolib.module.tellraw.TellrawJson;
import io.izzel.taboolib.util.item.Items; import io.izzel.taboolib.util.item.Items;
@ -19,6 +20,22 @@ import org.bukkit.event.server.ServerCommandEvent;
@TListener @TListener
public class ListenerPlayerCommand implements Listener { 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 @EventHandler
public void cmd(ServerCommandEvent e) { public void cmd(ServerCommandEvent e) {
if (e.getCommand().equalsIgnoreCase("saveFiles")) { 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());
}
}
} }

View File

@ -17,8 +17,8 @@ import java.util.stream.Collectors;
public class SQLHost extends IHost { public class SQLHost extends IHost {
private String host; private String host;
private String user;
private String port; private String port;
private String user;
private String password; private String password;
private String database; private String database;
private List<String> flags = Arrays.asList("characterEncoding=utf-8", "useSSL=false"); 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) { 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) { public SQLHost(String host, String port, String user, String password, String database, Plugin plugin) {
this(host, user, String.valueOf(port), password, database, plugin, false); this(host, port, user, password, database, plugin, false);
} }
@Deprecated public SQLHost(String host, String port, String user, String password, String database, Plugin plugin, boolean autoClose) {
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) {
super(plugin, autoClose); super(plugin, autoClose);
this.host = host; this.host = host;
this.user = user;
this.port = port; this.port = port;
this.user = user;
this.password = password; this.password = password;
this.database = database; this.database = database;
} }

View File

@ -58,7 +58,6 @@ public class TDependency {
private static boolean downloadMaven(String url, String groupId, String artifactId, String version, File target, String dl) { private static boolean downloadMaven(String url, String groupId, String artifactId, String version, File target, String dl) {
TLocale.Logger.info("DEPENDENCY.DOWNLOAD-START", target.getName()); 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 Files.downloadFile(dl.length() == 0 ? url + "/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".jar" : dl, Files.file(target));
return target.length() > 0;
} }
} }

View File

@ -1,5 +1,6 @@
package io.izzel.taboolib.module.dependency; package io.izzel.taboolib.module.dependency;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import java.io.File; import java.io.File;
@ -15,7 +16,7 @@ public class TDependencyLoader {
try { try {
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
method.setAccessible(true); method.setAccessible(true);
method.invoke(plugin.getClass().getClassLoader(), url); method.invoke(Bukkit.class.getClassLoader(), url);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -26,15 +26,15 @@ public abstract class ChannelExecutor {
public void addPlayerChannel(Player player) { public void addPlayerChannel(Player player) {
addChannelService.submit(() -> { 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) { public void removePlayerChannel(Player player) {
removeChannelService.submit(() -> { removeChannelService.submit(() -> {
Channel playerChannel = getPlayerChannel(player); Channel playerChannel = getPlayerChannel(player);
if (playerChannel.pipeline().get("taboolib_packet_handler") != null) { if (playerChannel.pipeline().get("taboolib5_packet_handler") != null) {
playerChannel.pipeline().remove("taboolib_packet_handler"); playerChannel.pipeline().remove("taboolib5_packet_handler");
} }
}); });
} }

View File

@ -13,6 +13,7 @@ import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.jar.JarFile; import java.util.jar.JarFile;
@ -70,9 +71,9 @@ public class Files {
} }
public static InputStream getCanonicalResource(Plugin plugin, String filename) { 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 { 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); ZipEntry entry = zipFile.getEntry(filename);
if (entry != null) { if (entry != null) {
return zipFile.getInputStream(entry); return zipFile.getInputStream(entry);
@ -88,7 +89,7 @@ public class Files {
if (!file.exists() || replace) { if (!file.exists() || replace) {
try (InputStream inputStream = getCanonicalResource(plugin, (plugin instanceof InternalPlugin ? "__resources__/" : "") + path)) { try (InputStream inputStream = getCanonicalResource(plugin, (plugin instanceof InternalPlugin ? "__resources__/" : "") + path)) {
if (inputStream != null) { if (inputStream != null) {
toFile(inputStream, Files.file(file)); toFile(inputStream, file(file));
} }
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
@ -120,6 +121,16 @@ public class Files {
return file; 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) { public static File file(File path, String filePath) {
return file(new File(path, filePath)); return file(new File(path, filePath));
} }
@ -161,18 +172,15 @@ public class Files {
return file; return file;
} }
public static void deepDelete(File file) { public static void copy(File file1, File file2) {
if (!file.exists()) { try (FileInputStream fileIn = new FileInputStream(file1);
return; 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) { public static void deepCopy(String originFileName, String targetFileName) {
@ -190,23 +198,26 @@ public class Files {
if (file.isDirectory()) { if (file.isDirectory()) {
deepCopy(file.getAbsolutePath(), targetFileName + "/" + file.getName()); deepCopy(file.getAbsolutePath(), targetFileName + "/" + file.getName());
} else { } else {
weekCopy(file, new File(targetFileName + "/" + file.getName())); copy(file, new File(targetFileName + "/" + file.getName()));
} }
} }
} else { } else {
weekCopy(originFile, targetFile); copy(originFile, targetFile);
} }
} }
public static void weekCopy(File file1, File file2) { public static void deepDelete(File file) {
try (FileInputStream fileIn = new FileInputStream(file1); if (!file.exists()) {
FileOutputStream fileOut = new FileOutputStream(file2); return;
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 String readFromURL(String url, String def) { public static String readFromURL(String url, String def) {
@ -222,7 +233,15 @@ public class Files {
return null; 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)) { try (FileInputStream fin = new FileInputStream(file); BufferedInputStream bin = new BufferedInputStream(fin)) {
return readFromStream(fin, size, encode); return readFromStream(fin, size, encode);
} catch (IOException e) { } catch (IOException e) {
@ -231,7 +250,15 @@ public class Files {
return null; 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()) { try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
byte[] b = new byte[size]; byte[] b = new byte[size];
int i; int i;
@ -258,15 +285,12 @@ public class Files {
} }
public static YamlConfiguration loadYaml(File file) { public static YamlConfiguration loadYaml(File file) {
YamlConfiguration configuration = new YamlConfiguration();
try { try {
String yaml = com.google.common.io.Files.toString(file, Charset.forName("utf-8")); return YamlConfiguration.loadConfiguration(file);
configuration.loadFromString(yaml);
return configuration;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return configuration; return new YamlConfiguration();
} }
private static Class getCaller(Class<?> obj) { private static Class getCaller(Class<?> obj) {