mirror of
https://github.com/CarmJos/MineSQL.git
synced 2026-06-05 00:48:16 +08:00
修改文件夹名称
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package cc.carm.plugin.easysql;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.plugin.easysql.api.DBConfiguration;
|
||||
import cc.carm.plugin.easysql.api.EasySQLRegistry;
|
||||
import cc.carm.plugin.easysql.command.EasySQLCommand;
|
||||
import cc.carm.plugin.easysql.command.EasySQLHelpFormatter;
|
||||
import co.aikar.commands.CommandManager;
|
||||
import co.aikar.commands.InvalidCommandArgument;
|
||||
import co.aikar.commands.Locales;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public interface EasySQLPluginPlatform {
|
||||
|
||||
@NotNull EasySQLRegistry getRegistry();
|
||||
|
||||
@NotNull Map<String, DBConfiguration> readConfigurations();
|
||||
|
||||
@NotNull Map<String, Properties> readProperties();
|
||||
|
||||
Logger getLogger();
|
||||
|
||||
default void initializeAPI(EasySQLRegistry registry) {
|
||||
EasySQLAPI.initializeAPI(registry);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
default void initializeCommands(CommandManager<?, ?, ?, ?, ?, ?> commandManager) {
|
||||
commandManager.enableUnstableAPI("help");
|
||||
commandManager.setHelpFormatter(new EasySQLHelpFormatter(commandManager));
|
||||
commandManager.getLocales().setDefaultLocale(Locales.SIMPLIFIED_CHINESE);
|
||||
commandManager.getCommandContexts().registerContext(SQLManager.class, c -> {
|
||||
String name = c.popFirstArg();
|
||||
try {
|
||||
return getRegistry().get(name);
|
||||
} catch (NullPointerException exception) {
|
||||
throw new InvalidCommandArgument("不存在名为 " + name + " 的数据库管理器。");
|
||||
}
|
||||
});
|
||||
commandManager.getCommandCompletions().registerCompletion("sql-managers", c -> {
|
||||
if (c.getIssuer().isPlayer()) return ImmutableList.of();
|
||||
else return ImmutableList.copyOf(getRegistry().list().keySet());
|
||||
});
|
||||
commandManager.registerCommand(new EasySQLCommand());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package cc.carm.plugin.easysql;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.lib.easysql.api.SQLQuery;
|
||||
import cc.carm.lib.easysql.manager.SQLManagerImpl;
|
||||
import cc.carm.lib.githubreleases4j.GithubReleases4J;
|
||||
import cc.carm.plugin.easysql.api.DBConfiguration;
|
||||
import cc.carm.plugin.easysql.api.EasySQLRegistry;
|
||||
import cn.beecp.BeeDataSource;
|
||||
import cn.beecp.BeeDataSourceConfig;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class EasySQLRegistryImpl implements EasySQLRegistry {
|
||||
public static final String REPO_OWNER = "CarmJos";
|
||||
public static final String REPO_NAME = "EasySQL-Plugin";
|
||||
|
||||
private static EasySQLRegistryImpl instance;
|
||||
|
||||
protected ExecutorService executorPool;
|
||||
protected EasySQLPluginPlatform platform;
|
||||
private final HashMap<String, SQLManagerImpl> sqlManagerRegistry = new HashMap<>();
|
||||
|
||||
protected EasySQLRegistryImpl(@NotNull EasySQLPluginPlatform platform) {
|
||||
this.platform = platform;
|
||||
EasySQLRegistryImpl.instance = this;
|
||||
this.executorPool = Executors.newFixedThreadPool(2, (r) -> {
|
||||
Thread thread = new Thread(r, "EasySQLRegistry");
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
});
|
||||
Map<String, Properties> dbProperties = platform.readProperties();
|
||||
Map<String, DBConfiguration> dbConfigurations = platform.readConfigurations();
|
||||
|
||||
if (dbProperties.isEmpty() && dbConfigurations.isEmpty()) {
|
||||
platform.getLogger().warning("未检测到任何数据库配置,将不会创建任何SQLManager。");
|
||||
return;
|
||||
}
|
||||
|
||||
dbProperties.forEach((id, properties) -> {
|
||||
try {
|
||||
SQLManagerImpl sqlManager = create(id, properties);
|
||||
this.sqlManagerRegistry.put(id, sqlManager);
|
||||
} catch (Exception exception) {
|
||||
platform.getLogger().warning("初始化SQLManager(#" + id + ") 出错,请检查配置文件.");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
dbConfigurations.forEach((id, configuration) -> {
|
||||
try {
|
||||
SQLManagerImpl sqlManager = create(id, configuration);
|
||||
this.sqlManagerRegistry.put(id, sqlManager);
|
||||
} catch (Exception exception) {
|
||||
platform.getLogger().warning("初始化SQLManager(#" + id + ") 出错,请检查配置文件.");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull SQLManagerImpl get(@Nullable String id) throws NullPointerException {
|
||||
if (!this.sqlManagerRegistry.containsKey(id)) {
|
||||
throw new NullPointerException("并不存在ID为 #" + id + " 的SQLManager.");
|
||||
}
|
||||
return this.sqlManagerRegistry.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Optional<@Nullable SQLManagerImpl> getOptional(@Nullable String name) {
|
||||
try {
|
||||
return Optional.of(get(name));
|
||||
} catch (Exception exception) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Unmodifiable
|
||||
public @NotNull Map<String, SQLManagerImpl> list() {
|
||||
return ImmutableMap.copyOf(this.sqlManagerRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull SQLManagerImpl create(@Nullable String name, @NotNull DBConfiguration configuration) {
|
||||
BeeDataSourceConfig config = new BeeDataSourceConfig();
|
||||
config.setDriverClassName(configuration.getDriverClassName());
|
||||
config.setJdbcUrl(configuration.getUrlPrefix() + configuration.getUrl());
|
||||
Optional.ofNullable(configuration.getUsername()).ifPresent(config::setUsername);
|
||||
Optional.ofNullable(configuration.getPassword()).ifPresent(config::setPassword);
|
||||
|
||||
Optional.ofNullable(configuration.getPoolName()).ifPresent(config::setPoolName);
|
||||
Optional.ofNullable(configuration.getMaxPoolSize()).ifPresent(config::setMaxActive);
|
||||
Optional.ofNullable(configuration.getMaxActive()).ifPresent(config::setMaxActive);
|
||||
|
||||
Optional.ofNullable(configuration.getIdleTimeout()).ifPresent(config::setIdleTimeout);
|
||||
Optional.ofNullable(configuration.getMaxWaitTime()).ifPresent(config::setMaxWait);
|
||||
Optional.ofNullable(configuration.getMaxHoldTime()).ifPresent(config::setHoldTimeout);
|
||||
|
||||
Optional.ofNullable(configuration.getAutoCommit()).ifPresent(config::setDefaultAutoCommit);
|
||||
Optional.ofNullable(configuration.getReadOnly()).ifPresent(config::setDefaultReadOnly);
|
||||
Optional.ofNullable(configuration.getSchema()).ifPresent(config::setDefaultSchema);
|
||||
|
||||
Optional.ofNullable(configuration.getValidationSQL()).ifPresent(config::setValidTestSql);
|
||||
Optional.ofNullable(configuration.getValidationTimeout()).ifPresent(config::setValidTestTimeout);
|
||||
Optional.ofNullable(configuration.getValidationInterval()).ifPresent(config::setValidAssumeTime);
|
||||
|
||||
return create(name, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull SQLManagerImpl create(@Nullable String name, @NotNull Properties properties) {
|
||||
return create(name, new BeeDataSourceConfig(properties));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull SQLManagerImpl create(@Nullable String name, @NotNull String propertyFileName) {
|
||||
return create(name, new BeeDataSourceConfig(propertyFileName));
|
||||
}
|
||||
|
||||
public @NotNull SQLManagerImpl create(@Nullable String name, @NotNull BeeDataSourceConfig configuration) {
|
||||
return new SQLManagerImpl(new BeeDataSource(configuration), name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown(SQLManager manager, @Nullable Consumer<Map<UUID, SQLQuery>> activeQueries) {
|
||||
if (activeQueries != null) activeQueries.accept(manager.getActiveQuery());
|
||||
|
||||
if (manager.getDataSource() instanceof BeeDataSource) {
|
||||
BeeDataSource dataSource = (BeeDataSource) manager.getDataSource();
|
||||
dataSource.close(); //Close bee connection pool
|
||||
}
|
||||
}
|
||||
|
||||
protected HashMap<String, SQLManagerImpl> getManagers() {
|
||||
return sqlManagerRegistry;
|
||||
}
|
||||
|
||||
public ExecutorService getExecutor() {
|
||||
return executorPool;
|
||||
}
|
||||
|
||||
public static EasySQLRegistryImpl getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public EasySQLPluginPlatform getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
public void checkUpdate(String currentVersion) {
|
||||
Logger logger = getInstance().getPlatform().getLogger();
|
||||
getExecutor().execute(() -> {
|
||||
Integer behindVersions = GithubReleases4J.getVersionBehind(REPO_OWNER, REPO_NAME, currentVersion);
|
||||
String downloadURL = GithubReleases4J.getReleasesURL(REPO_OWNER, REPO_NAME);
|
||||
if (behindVersions == null) {
|
||||
logger.severe("检查更新失败,请您定期查看插件是否更新,避免安全问题。");
|
||||
logger.severe("下载地址 " + downloadURL);
|
||||
} else if (behindVersions < 0) {
|
||||
logger.severe("检查更新失败! 当前版本未知,请您使用原生版本以避免安全问题。");
|
||||
logger.severe("最新版下载地址 " + downloadURL);
|
||||
} else if (behindVersions > 0) {
|
||||
logger.warning("发现新版本! 目前已落后 " + behindVersions + " 个版本。");
|
||||
logger.warning("最新版下载地址 " + downloadURL);
|
||||
} else {
|
||||
logger.info("检查完成,当前已是最新版本。");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package cc.carm.plugin.easysql.command;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.lib.easysql.api.SQLQuery;
|
||||
import cc.carm.plugin.easysql.EasySQLRegistryImpl;
|
||||
import cc.carm.plugin.easysql.util.VersionReader;
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.CommandHelp;
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@CommandAlias("EasySQL")
|
||||
@Description("EasySQL-Plugin的主指令,用于开发者进行调试,只允许后台执行。")
|
||||
public class EasySQLCommand extends BaseCommand {
|
||||
|
||||
@HelpCommand
|
||||
@Syntax("&9[页码或子指令名称]")
|
||||
@Description("查看指定数据源的统计信息与当前仍未关闭的查询。")
|
||||
public void help(CommandIssuer issuer, CommandHelp help) {
|
||||
if (issuer.isPlayer()) {
|
||||
issuer.sendMessage("§c只有后台执行才能使用此命令。");
|
||||
return;
|
||||
}
|
||||
help.showHelp();
|
||||
}
|
||||
|
||||
@Subcommand("version")
|
||||
@Description("查看当前插件版本与核心库(EasySQL)版本。")
|
||||
public void version(CommandIssuer issuer) {
|
||||
if (issuer.isPlayer()) {
|
||||
issuer.sendMessage("§c只有后台执行才能使用此命令。");
|
||||
return;
|
||||
}
|
||||
VersionReader reader = new VersionReader();
|
||||
String pluginVersion = reader.get("plugin", null);
|
||||
if (pluginVersion == null) {
|
||||
issuer.sendMessage("§c无法获取当前版本信息,请保证使用原生版本以避免安全问题。");
|
||||
return;
|
||||
}
|
||||
issuer.sendMessage("§r当前插件版本为 §b" + pluginVersion + "§r。 §7(基于 EasySQL &3" + reader.get("api") + "&7)");
|
||||
issuer.sendMessage("§8 - &f连接池依赖 BeeCP §9" + reader.get("beecp"));
|
||||
issuer.sendMessage("§8 - &f数据库驱动 MySQL §9" + reader.get("mysql-driver"));
|
||||
issuer.sendMessage("§8 - &f数据库驱动 MariaDB §9" + reader.get("mariadb-driver"));
|
||||
issuer.sendMessage("§8 - &f数据库驱动 h2-database §9" + reader.get("h2-driver"));
|
||||
|
||||
issuer.sendMessage("§r正在检查插件更新,请稍候...");
|
||||
EasySQLRegistryImpl.getInstance().checkUpdate(pluginVersion);
|
||||
}
|
||||
|
||||
@Subcommand("list")
|
||||
@Description("列出当前所有的数据源管理器与相关信息。")
|
||||
public void list(CommandIssuer issuer) {
|
||||
if (issuer.isPlayer()) {
|
||||
issuer.sendMessage("§c只有后台执行才能使用此命令。");
|
||||
return;
|
||||
}
|
||||
Map<String, ? extends SQLManager> runningManagers = EasySQLRegistryImpl.getInstance().list();
|
||||
if (runningManagers.isEmpty()) {
|
||||
issuer.sendMessage("§r当前无正在运行的数据库管理器。");
|
||||
} else {
|
||||
issuer.sendMessage("§r当前有 §b" + runningManagers.size() + " §r个正在运行的数据库管理器:");
|
||||
runningManagers.forEach(
|
||||
(name, manager) -> issuer.sendMessage("- " + name + " (" + manager.getActiveQuery().size() + " running)")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Subcommand("info")
|
||||
@CommandCompletion("@sql-managers")
|
||||
@Syntax("&9<数据源名称>")
|
||||
@Description("查看指定数据源的统计信息与当前仍未关闭的查询。")
|
||||
public void info(CommandIssuer issuer,
|
||||
@Syntax("&9数据源名称") @Description("数据源管理器名称,一般在配置文件中指定。") SQLManager manager) {
|
||||
if (issuer.isPlayer()) {
|
||||
issuer.sendMessage("§c只有后台执行才能使用此命令。");
|
||||
return;
|
||||
}
|
||||
Map<UUID, SQLQuery> activeQueries = manager.getActiveQuery();
|
||||
if (activeQueries.isEmpty()) {
|
||||
issuer.sendMessage("§r当前暂无活跃查询。");
|
||||
} else {
|
||||
issuer.sendMessage("§r当前有 §b" + activeQueries.size() + " §r个活跃查询:");
|
||||
activeQueries.forEach((uuid, query) -> {
|
||||
issuer.sendMessage("§8#§b " + uuid.toString());
|
||||
issuer.sendMessage("§8-§f " + query.getSQLContent());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package cc.carm.plugin.easysql.command;
|
||||
|
||||
import co.aikar.commands.*;
|
||||
|
||||
public class EasySQLHelpFormatter extends CommandHelpFormatter {
|
||||
|
||||
public EasySQLHelpFormatter(CommandManager manager) {
|
||||
super(manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printHelpHeader(CommandHelp help, CommandIssuer issuer) {
|
||||
issuer.sendMessage("§3§lEasySQL-Plugin §7指令帮助");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printHelpCommand(CommandHelp help, CommandIssuer issuer, HelpEntry entry) {
|
||||
issuer.sendMessage("§8# §f" + entry.getCommand() + " §r" + entry.getParameterSyntax());
|
||||
if (!entry.getDescription().isEmpty()) {
|
||||
issuer.sendMessage("§8- §7" + entry.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printHelpFooter(CommandHelp help, CommandIssuer issuer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printSearchHeader(CommandHelp help, CommandIssuer issuer) {
|
||||
issuer.sendMessage("§3§lEasySQL-Plugin §7指令帮助查询");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printSearchEntry(CommandHelp help, CommandIssuer issuer, HelpEntry entry) {
|
||||
printHelpCommand(help, issuer, entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printSearchFooter(CommandHelp help, CommandIssuer issuer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printDetailedHelpHeader(CommandHelp help, CommandIssuer issuer, HelpEntry entry) {
|
||||
issuer.sendMessage("§3§lEasySQL-Plugin §7指令帮助 §8(§f" + entry.getCommand() + "§8)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printDetailedHelpCommand(CommandHelp help, CommandIssuer issuer, HelpEntry entry) {
|
||||
printHelpCommand(help, issuer, entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printDetailedParameter(CommandHelp help, CommandIssuer issuer, HelpEntry entry, CommandParameter param) {
|
||||
if (param.getDescription() != null) {
|
||||
if (param.getSyntax() != null) {
|
||||
issuer.sendMessage("§8@§r" + param.getSyntax() + "§7 §f" + param.getDescription());
|
||||
} else {
|
||||
issuer.sendMessage("§8@§f" + param.getName() + "§7 §f" + param.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printDetailedHelpFooter(CommandHelp help, CommandIssuer issuer, HelpEntry entry) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cc.carm.plugin.easysql.configuration;
|
||||
|
||||
import cc.carm.plugin.easysql.api.DBConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface PluginConfiguration {
|
||||
|
||||
boolean isDebugEnabled();
|
||||
|
||||
boolean isMetricsEnabled();
|
||||
|
||||
boolean isUpdateCheckerEnabled();
|
||||
|
||||
boolean isPropertiesEnabled();
|
||||
|
||||
String getPropertiesFolder();
|
||||
|
||||
@NotNull Map<String, DBConfiguration> getDBConfigurations();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package cc.carm.plugin.easysql.util;
|
||||
|
||||
import cc.carm.plugin.easysql.util.JarResourceUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
public class DBPropertiesUtil {
|
||||
|
||||
public static Map<String, Properties> readFromFolder(File propertiesFolder) {
|
||||
Map<String, Properties> propertiesMap = new HashMap<>();
|
||||
if (!propertiesFolder.exists() || !propertiesFolder.isDirectory()) return propertiesMap;
|
||||
|
||||
File[] files = propertiesFolder.listFiles();
|
||||
if (files == null || files.length == 0) return propertiesMap;
|
||||
for (File file : files) {
|
||||
if (!validateName(file.getName())) continue;
|
||||
String name = file.getName().substring(0, file.getName().lastIndexOf("."));
|
||||
try (InputStream is = new FileInputStream(file)) {
|
||||
propertiesMap.put(name, read(is));
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
return propertiesMap;
|
||||
}
|
||||
|
||||
public static @NotNull Properties read(InputStream stream) throws IOException {
|
||||
Properties properties = new Properties();
|
||||
properties.load(stream);
|
||||
return properties;
|
||||
}
|
||||
|
||||
public static boolean validateName(String name) {
|
||||
return !name.contains(" ") && !name.startsWith(".") && name.endsWith(".properties");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package cc.carm.plugin.easysql.util;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public class JarResourceUtils {
|
||||
public static final char JAR_SEPARATOR = '/';
|
||||
|
||||
public static @Nullable String[] readResource(@Nullable InputStream resourceStream) {
|
||||
if (resourceStream == null) return null;
|
||||
try (Scanner scanner = new Scanner(resourceStream, "UTF-8")) {
|
||||
List<String> contents = new ArrayList<>();
|
||||
while (scanner.hasNextLine()) {
|
||||
contents.add(scanner.nextLine());
|
||||
}
|
||||
return contents.toArray(new String[0]);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void copyFolderFromJar(String folderName, File destFolder, CopyOption option)
|
||||
throws IOException {
|
||||
copyFolderFromJar(folderName, destFolder, option, null);
|
||||
}
|
||||
|
||||
public static void copyFolderFromJar(String folderName, File destFolder,
|
||||
CopyOption option, PathTrimmer trimmer) throws IOException {
|
||||
if (!destFolder.exists())
|
||||
destFolder.mkdirs();
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
File fullPath;
|
||||
String path = JarResourceUtils.class.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||
if (trimmer != null)
|
||||
path = trimmer.trim(path);
|
||||
try {
|
||||
if (!path.startsWith("file"))
|
||||
path = "file://" + path;
|
||||
|
||||
fullPath = new File(new URI(path));
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
ZipInputStream zis = new ZipInputStream(new FileInputStream(fullPath));
|
||||
|
||||
ZipEntry entry;
|
||||
while ((entry = zis.getNextEntry()) != null) {
|
||||
if (!entry.getName().startsWith(folderName + JAR_SEPARATOR))
|
||||
continue;
|
||||
|
||||
String fileName = entry.getName();
|
||||
|
||||
if (fileName.charAt(fileName.length() - 1) == JAR_SEPARATOR) {
|
||||
File file = new File(destFolder + File.separator + fileName);
|
||||
if (file.isFile()) {
|
||||
file.delete();
|
||||
}
|
||||
file.mkdirs();
|
||||
continue;
|
||||
}
|
||||
|
||||
File file = new File(destFolder + File.separator + fileName);
|
||||
if (option == CopyOption.COPY_IF_NOT_EXIST && file.exists())
|
||||
continue;
|
||||
|
||||
if (!file.getParentFile().exists())
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
if (!file.exists())
|
||||
file.createNewFile();
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
|
||||
int len;
|
||||
while ((len = zis.read(buffer)) > 0) {
|
||||
fos.write(buffer, 0, len);
|
||||
}
|
||||
fos.close();
|
||||
}
|
||||
|
||||
zis.closeEntry();
|
||||
zis.close();
|
||||
}
|
||||
|
||||
public enum CopyOption {
|
||||
COPY_IF_NOT_EXIST, REPLACE_IF_EXIST
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface PathTrimmer {
|
||||
String trim(String original);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package cc.carm.plugin.easysql.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
public class MavenReadUtil {
|
||||
|
||||
public static String getMavenPropertiesPath(@NotNull String groupID, @NotNull String artifactID) {
|
||||
return String.format("/META-INF/maven/%s/%s/pom.properties", groupID, artifactID);
|
||||
}
|
||||
|
||||
public static synchronized @Nullable String getVersion(@NotNull Object provider,
|
||||
@NotNull String groupID,
|
||||
@NotNull String artifactID) {
|
||||
String path = getMavenPropertiesPath(groupID, artifactID);
|
||||
String version = null;
|
||||
// Using maven properties to get the version
|
||||
try (InputStream is = provider.getClass().getResourceAsStream(path)) {
|
||||
if (is != null) {
|
||||
Properties p = new Properties();
|
||||
p.load(is);
|
||||
version = p.getProperty("version", "");
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
if (version != null) return version;
|
||||
|
||||
// Fine, lets try Java API
|
||||
Package pkg = provider.getClass().getPackage();
|
||||
if (pkg != null) {
|
||||
version = pkg.getImplementationVersion();
|
||||
if (version == null) {
|
||||
version = pkg.getSpecificationVersion();
|
||||
}
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package cc.carm.plugin.easysql.util;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
public class VersionReader {
|
||||
|
||||
String versionsFileName;
|
||||
|
||||
|
||||
public VersionReader() {
|
||||
this("versions.properties");
|
||||
}
|
||||
|
||||
public VersionReader(String versionsFileName) {
|
||||
this.versionsFileName = versionsFileName;
|
||||
}
|
||||
|
||||
public synchronized @NotNull String get(@NotNull String artifactID) {
|
||||
return get(artifactID, "unknown");
|
||||
}
|
||||
|
||||
@Contract("_,!null->!null")
|
||||
public synchronized @Nullable String get(@NotNull String artifactID,
|
||||
@Nullable String defaultValue) {
|
||||
try (InputStream is = this.getClass().getResourceAsStream("/" + versionsFileName)) {
|
||||
Properties p = new Properties();
|
||||
p.load(is);
|
||||
return p.getProperty(artifactID, defaultValue);
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
&3 ______ _____ ____ _ &f_____ _ _
|
||||
&3| ____| / ____|/ __ \| | &f| __ \| | (_)
|
||||
&3| |__ __ _ ___ _ _| (___ | | | | | &f| |__) | |_ _ __ _ _ _ __
|
||||
&3| __| / _` / __| | | |\___ \| | | | | &f| ___/| | | | |/ _` | | '_ \
|
||||
&3| |___| (_| \__ \ |_| |____) | |__| | |____ &f| | | | |_| | (_| | | | | |
|
||||
&3|______\__,_|___/\__, |_____/ \___\_\______| &f|_| |_|\__,_|\__, |_|_| |_|
|
||||
&3 __/ | &f __/ |
|
||||
&3 |___/ &f|___/
|
||||
|
||||
&f 查看更多信息请访问项目主页&f https://github.com/CarmJos/EasySQL-Plugin
|
||||
@@ -0,0 +1,41 @@
|
||||
# suppress inspection "UnusedProperty" for whole file
|
||||
#
|
||||
# Copyright (c) 2016-2021 Daniel Ennis (Aikar) - MIT License
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
#
|
||||
acf-core.permission_denied=很抱歉,你没有执行此命令的权限。
|
||||
acf-core.permission_denied_parameter=很抱歉,你没有执行此命令的权限。
|
||||
acf-core.error_generic_logged=很抱歉,插件产生了内部错误。问题已输出在游戏日志中。
|
||||
acf-core.unknown_command=§r您输入了未知的指令,输入 §b/EasySQL help §r获得指令帮助。
|
||||
acf-core.invalid_syntax=§r指令用法 §b{command} {syntax} §r。
|
||||
acf-core.error_prefix=在执行指令时出现了一个错误:\n{message}
|
||||
acf-core.error_performing_command=很抱歉,指令执行中出现了错误。
|
||||
acf-core.info_message=§r{message}
|
||||
acf-core.please_specify_one_of=错误:请输入 <c2>{valid}</c2> 中的某一个。
|
||||
acf-core.must_be_a_number=错误:{num} 必须是数字。
|
||||
acf-core.must_be_min_length=错误:至少需要输入 {min} 个字符。
|
||||
acf-core.must_be_max_length=错误:最多需要输入 {max} 个字符。
|
||||
acf-core.please_specify_at_most=错误:请输入一个不大于 {max} 的值。
|
||||
acf-core.please_specify_at_least=错误:请输入一个不小于 {min} 的值。
|
||||
acf-core.not_allowed_on_console=错误:控制台不能执行此命令。
|
||||
acf-core.could_not_find_player=错误:找不到名叫 <c2>{search}</c2> 的玩家。
|
||||
acf-core.no_command_matched_search=§r抱歉,没有匹配 §b{search} §r的指令。
|
||||
acf-core.help_no_results=§r抱歉,没有相关的指令帮助。
|
||||
@@ -0,0 +1,39 @@
|
||||
# suppress inspection "UnusedProperty" for whole file
|
||||
#
|
||||
# Copyright (c) 2016-2021 Daniel Ennis (Aikar) - MIT License
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
#
|
||||
|
||||
acf-minecraft.invalid_world = 错误:该世界不存在。
|
||||
acf-minecraft.you_must_be_holding_item = 错误:你的主手上必须持有物品。
|
||||
acf-minecraft.player_is_vanished_confirm = \
|
||||
警告:<c2>{vanished}</c2> 已被隐藏。不要暴露他们的身份!\n\
|
||||
如果你确认这么做,请在他们的名字后面加上 <c2>:confirm</c2> 。\n\
|
||||
例如:<c2>{vanished}:confirm</c2>
|
||||
acf-minecraft.username_too_short = 错误:名字太短,请至少输入三个字符。
|
||||
acf-minecraft.is_not_a_valid_name = 错误:<c2>{name}</c2> 不是一个可以用的名字。
|
||||
acf-minecraft.multiple_players_match = 错误:<c2>{search}</c2> 的搜索结果过多<c3>(共计{all}人)</c3>,请再详细一点。
|
||||
acf-minecraft.no_player_found_server = 没有搜索到匹配 <c2>{search}</c2> 的在线玩家。
|
||||
acf-minecraft.no_player_found_offline = 没有搜索到匹配 <c2>{search}</c2> 的在线/离线玩家。
|
||||
acf-minecraft.no_player_found = 没有搜索到匹配 <c2>{search}</c2> 的玩家。
|
||||
acf-minecraft.location_please_specify_world = 错误:请指明世界。例如:<c2>world:x,y,z</c2>。
|
||||
acf-minecraft.location_please_specify_xyz = 错误:请指明坐标x,y和z。例如:<c2>world:x,y,z</c2>。
|
||||
acf-minecraft.location_console_not_relative = 错误:控制台不能使用相对坐标来指明位置。
|
||||
@@ -0,0 +1,44 @@
|
||||
version: ${project.version} #配置文件版本,若与插件版本不同请记得检查配置文件内容
|
||||
|
||||
debug: false
|
||||
|
||||
# 统计数据设定
|
||||
# 改选项用于帮助开发者统计插件版本与使用情况,且绝不会影响性能与使用体验。
|
||||
# 当然,您也可以选择在这里关闭,或在plugins/bStats下的配置文件中关闭。
|
||||
metrics: true
|
||||
|
||||
# 检查更新设定
|
||||
# 该选项用于插件判断是否要检查更新,若您不希望插件检查更新并提示您,可以选择关闭。
|
||||
# 检查更新为异步操作,绝不会影响性能与使用体验。
|
||||
check-update: true
|
||||
|
||||
# 启用 Properties 文件配置
|
||||
# 相关配置介绍(BeeCP) https://github.com/Chris2018998/BeeCP/wiki/Configuration--List#配置列表
|
||||
properties:
|
||||
# 该选项用于启用 Properties 配置读取,若您不希望插件启用 Properties 文件配置,可以选择关闭。
|
||||
enable: true
|
||||
# 文件夹路径,将读取该文件夹下的所有 .properties 文件,并以文件名为数据管理器名称。
|
||||
# 读取时,将排除以 “.” 开头的文件与非 .properties 文件。
|
||||
# 默认为 "db-properties/" 相对路径,指向“plugins/EasySQL-Plugin/db-properties/”;
|
||||
# 该选项也支持绝对路径,但使用绝对路径时,请务必注意权限问题。
|
||||
folder: "db-properties/"
|
||||
|
||||
# 数据库源配置
|
||||
# 目前支持的驱动类型(driver-type)有 mariadb、mysql 与 h2(文件数据库) 。
|
||||
|
||||
databases:
|
||||
|
||||
"example-mariadb": # 数据库源名称 不可包含“.” 以“example-”开头的数据源不会被加载
|
||||
driver-type: mariadb
|
||||
host: 127.0.0.1 # 数据库地址
|
||||
port: 3306 # 数据库端口
|
||||
username: minecraft # 数据库用户名
|
||||
password: password #数据库连接密码
|
||||
database: minecraft #数据库名
|
||||
|
||||
"example-h2": # 数据库源名称 不可包含“.” 以“example-”开头的数据源不会被加载
|
||||
driver-type: h2 #数据库驱动类型,目前支持 mariadb, mysql, h2
|
||||
file: "example.db" #数据库文件路径,相对于“plugins/EasySQL-Plugin/db-files/”
|
||||
username: minecraft # 数据库用户名
|
||||
password: password #数据库连接密码
|
||||
database: minecraft #数据库名
|
||||
@@ -0,0 +1,63 @@
|
||||
# suppress inspection "UnusedProperty" for whole file
|
||||
|
||||
# 该功能一般用于专业开发者使用,若您不了解该功能,请尽量使用config.yml中提供的配置方式,简单便捷,能够满足大多数需求。
|
||||
# 更多帮助详见 BeeCP项目地址 https://github.com/Chris2018998/BeeCP
|
||||
|
||||
#JDBC 用户名
|
||||
username=root
|
||||
#JDBC 密码
|
||||
password=root
|
||||
# JDBC连接URL
|
||||
jdbcUrl=jdbc:mysql://localhost/test
|
||||
# JDBC驱动类名
|
||||
driverClassName=com.mysql.cj.jdbc.Driver
|
||||
# 连接有效性测试SQL语句
|
||||
connectionTestSQL=select 1 from dual
|
||||
# 池名,如果未赋值则会自动产生一个
|
||||
poolName=Pool1
|
||||
# 是否使用公平模式 (竞争模式=false)
|
||||
fairMode=false
|
||||
# 连接池初始大小
|
||||
initialSize=1
|
||||
# 连接池最大个数
|
||||
maxActive=10
|
||||
# 信号量许可大小 min(最大连接数/2,CPU核心数)
|
||||
borrowSemaphoreSize=4
|
||||
# 连接借用等待最大时间(毫秒)
|
||||
maxWait=8000
|
||||
# 连接闲置最大时间(毫秒)
|
||||
idleTimeout=18000
|
||||
# 连接被持有不用最大允许时间(毫秒)
|
||||
holdTimeout=30000
|
||||
# 连接有效性测试SQL语句
|
||||
validTestTimeout=3
|
||||
# 连接测试的间隔时间(毫秒)
|
||||
validAssumeTime=500
|
||||
# 闲置扫描线程间隔时间(毫秒)
|
||||
timerCheckInterval=30000
|
||||
# 在结束时是否直接关闭使用中连接
|
||||
forceCloseUsingOnClear=true
|
||||
# 延迟清理的时候时间(毫秒)
|
||||
delayTimeForNextClear=3000
|
||||
|
||||
# JMX监控支持开关
|
||||
enableJmx=false
|
||||
|
||||
# Catalog默认值
|
||||
defaultCatalog=test1
|
||||
# Schema默认值
|
||||
defaultSchema=test2
|
||||
# ReadOnly默认值
|
||||
defaultReadOnly=true
|
||||
# 自动提交默认值
|
||||
defaultAutoCommit=true
|
||||
|
||||
# 事物隔离代码,未设置时则从第一个连接上读取
|
||||
defaultTransactionIsolationCode=1
|
||||
defaultTransactionIsolationName=TRANSACTION_READ_UNCOMMITTED
|
||||
|
||||
# 额外链接配置
|
||||
connectProperties=cachePrepStmts=true
|
||||
connectProperties.count=2
|
||||
connectProperties.1=prepStmtCacheSize=50
|
||||
connectProperties.2=prepStmtCacheSqlLimit=2048&useServerPrepStmts=true
|
||||
@@ -0,0 +1,11 @@
|
||||
# suppress inspection "SpellCheckingInspection" for whole file
|
||||
|
||||
plugin=${project.version}
|
||||
api=${easysql.version}
|
||||
|
||||
beecp=${beecp.version}
|
||||
|
||||
mysql-driver=${mysql-driver.version}
|
||||
mariadb-driver=${mariadb-driver.version}
|
||||
h2-driver=${h2-driver.version}
|
||||
|
||||
Reference in New Issue
Block a user