1
mirror of https://github.com/CarmJos/MineSQL.git synced 2024-09-19 20:25:45 +00:00

新增通用接口与指令

This commit is contained in:
Carm Jos 2022-02-22 02:59:18 +08:00
parent 67bd7a4141
commit 108442ad43
14 changed files with 246 additions and 66 deletions

View File

@ -6,7 +6,7 @@ public class EasySQLAPI {
protected static EasySQLRegistry api;
protected static void init(EasySQLRegistry api) {
protected static void initializeAPI(EasySQLRegistry api) {
EasySQLAPI.api = api;
}

View File

@ -30,6 +30,13 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-core</artifactId>
<version>0.5.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.chris2018998</groupId>
<artifactId>beecp</artifactId>

View File

@ -1,6 +1,7 @@
package cc.carm.plugin.easysql;
import cc.carm.plugin.easysql.api.DBConfiguration;
import cc.carm.plugin.easysql.api.EasySQLRegistry;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
@ -9,7 +10,7 @@ import java.util.logging.Logger;
public interface EasySQLPluginPlatform {
@NotNull EasySQLRegistry getRegistry();
@NotNull Map<String, DBConfiguration> readConfigurations();
@ -17,4 +18,8 @@ public interface EasySQLPluginPlatform {
Logger getLogger();
default void initializeAPI(EasySQLRegistry registry) {
EasySQLAPI.initializeAPI(registry);
}
}

View File

@ -0,0 +1,11 @@
package cc.carm.plugin.easysql.command;
import co.aikar.commands.BaseCommand;
public class EasySQLCommand extends BaseCommand {
}

View File

@ -0,0 +1,27 @@
package cc.carm.plugin.easysql.util;
import org.jetbrains.annotations.Nullable;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class ResourceReadUtil {
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;
}
}
}

View File

@ -24,7 +24,6 @@
<name>EasySQL-Plugin-Bukkit</name>
<dependencies>
<dependency>
@ -37,6 +36,8 @@
<dependency>
<groupId>cc.carm.lib</groupId>
<artifactId>easyplugin-main</artifactId>
<version>${easyplugin.version}</version>
<optional>true</optional>
<scope>compile</scope>
</dependency>
@ -50,9 +51,19 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>2.2.1</version>
<version>3.0.0</version>
<optional>true</optional>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-paper</artifactId>
<version>0.5.1-SNAPSHOT</version>
<optional>true</optional>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
@ -87,6 +98,14 @@
<pattern>cc.carm.lib.easyplugin</pattern>
<shadedPattern>cc.carm.plugin.easysql.lib.easyplugin</shadedPattern>
</relocation>
<relocation>
<pattern>co.aikar.commands</pattern>
<shadedPattern>cc.carm.plugin.easysql.lib.acf</shadedPattern> <!-- Replace this -->
</relocation>
<relocation>
<pattern>co.aikar.locales</pattern>
<shadedPattern>cc.carm.plugin.easysql.lib.locales</shadedPattern> <!-- Replace this -->
</relocation>
</relocations>
<filters>
<filter>

View File

@ -1,54 +0,0 @@
package cc.carm.plugin.easysql;
import cc.carm.lib.easyplugin.EasyPlugin;
import cc.carm.lib.easyplugin.i18n.EasyPluginMessageProvider;
import cc.carm.plugin.easysql.api.DBConfiguration;
import cc.carm.plugin.easysql.util.PropertiesUtil;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class EasySQLBukkit extends EasyPlugin implements EasySQLPluginPlatform {
public EasySQLBukkit() {
super(new EasyPluginMessageProvider.zh_CN());
}
@Override
protected void load() {
}
@Override
protected boolean initialize() {
return false;
}
@Override
public @NotNull Map<String, DBConfiguration> readConfigurations() {
return new HashMap<>();
}
@Override
public @NotNull Map<String, Properties> readProperties() {
return PropertiesUtil.readDBProperties(new File(getDataFolder(), "properties"));
}
@Override
public void outputInfo() {
log("\n" +
"&5&l ______ _____ ____ _ &d&l_____ _ _ \n" +
"&5&l| ____| / ____|/ __ \\| | &d&l| __ \\| | (_) \n" +
"&5&l| |__ __ _ ___ _ _| (___ | | | | | &d&l| |__) | |_ _ __ _ _ _ __ \n" +
"&5&l| __| / _` / __| | | |\\___ \\| | | | | &d&l| ___/| | | | |/ _` | | '_ \\ \n" +
"&5&l| |___| (_| \\__ \\ |_| |____) | |__| | |____ &d&l| | | | |_| | (_| | | | | |\n" +
"&5&l|______\\__,_|___/\\__, |_____/ \\___\\_\\______| &d&l|_| |_|\\__,_|\\__, |_|_| |_|\n" +
"&5&l __/ | &d&l __/ | \n" +
"&5&l |___/ &d&l|___/ "
);
}
}

View File

@ -0,0 +1,78 @@
package cc.carm.plugin.easysql.bukkit;
import cc.carm.lib.easyplugin.EasyPlugin;
import cc.carm.lib.easyplugin.i18n.EasyPluginMessageProvider;
import cc.carm.plugin.easysql.EasySQLPluginPlatform;
import cc.carm.plugin.easysql.EasySQLRegistryImpl;
import cc.carm.plugin.easysql.api.DBConfiguration;
import cc.carm.plugin.easysql.util.PropertiesUtil;
import cc.carm.plugin.easysql.util.ResourceReadUtil;
import co.aikar.commands.PaperCommandManager;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
public class EasySQLBukkit extends EasyPlugin implements EasySQLPluginPlatform {
public EasySQLBukkit() {
super(new EasyPluginMessageProvider.zh_CN());
}
protected static EasySQLBukkit instance;
protected PaperCommandManager commandManager;
protected EasySQLRegistryImpl registry;
@Override
protected void load() {
EasySQLBukkit.instance = this;
this.commandManager = new PaperCommandManager(this);
initializeAPI(getRegistry());
}
@Override
protected boolean initialize() {
//TODO COMMANDS
return true;
}
@Override
@NotNull
public EasySQLRegistryImpl getRegistry() {
return this.registry;
}
@Override
public @NotNull
Map<String, DBConfiguration> readConfigurations() {
return new HashMap<>();
}
@Override
public @NotNull
Map<String, Properties> readProperties() {
return PropertiesUtil.readDBProperties(new File(getDataFolder(), "properties"));
}
@Override
public void outputInfo() {
Optional.ofNullable(ResourceReadUtil.readResource(this.getResource("info.txt"))).ifPresent(this::log);
}
public static EasySQLBukkit getInstance() {
return EasySQLBukkit.instance;
}
protected PaperCommandManager getCommandManager() {
return commandManager;
}
}

View File

@ -0,0 +1,21 @@
main: cc.carm.plugin.easysql.bukkit.EasySQLBukkit
version: ${project.version}
name: EasySQL-Plugin-Bukkit
load: STARTUP
website: ${project.url}
description: ${project.description}
authors:
- CarmJos
- GhostChu
api-version: 1.13
prefix: EasySQL
commands:
"EasySQLBukkit":
usage: "/EasySQLBukkit help"
description: "EasySQL独立插件的主指令只允许后台运行。"
aliases:
- "EasySQL"

View File

@ -26,10 +26,12 @@
<repositories>
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
<dependencies>
@ -60,7 +62,16 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bungeecord</artifactId>
<version>2.2.1</version>
<version>3.0.0</version>
<optional>true</optional>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-bungee</artifactId>
<version>0.5.1-SNAPSHOT</version>
<optional>true</optional>
<scope>compile</scope>
</dependency>
@ -110,6 +121,24 @@
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>cc.carm.plugin.easysql.lib.bstats</shadedPattern>
</relocation>
<relocation>
<pattern>org.json</pattern>
<shadedPattern>cc.carm.plugin.easysql.lib.json</shadedPattern>
</relocation>
<relocation>
<pattern>co.aikar.commands</pattern>
<shadedPattern>cc.carm.plugin.easysql.lib.acf</shadedPattern> <!-- Replace this -->
</relocation>
<relocation>
<pattern>co.aikar.locales</pattern>
<shadedPattern>cc.carm.plugin.easysql.lib.locales</shadedPattern> <!-- Replace this -->
</relocation>
</relocations>
</configuration>
</plugin>
</plugins>

View File

@ -1,6 +1,7 @@
package cc.carm.plugin.easysql;
import cc.carm.plugin.easysql.api.DBConfiguration;
import cc.carm.plugin.easysql.api.EasySQLRegistry;
import cc.carm.plugin.easysql.util.PropertiesUtil;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
@ -68,6 +69,11 @@ public class EasySQLBungee extends Plugin implements EasySQLPluginPlatform {
getLogger().info("Shutting down...");
}
@Override
public @NotNull EasySQLRegistry getRegistry() {
return null;
}
@Override
public @NotNull Map<String, DBConfiguration> readConfigurations() {
return new HashMap<>();

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>easysql-plugin</artifactId>
<groupId>cc.carm.plugin</groupId>
<version>0.0.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>easysql-plugin-sponge</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
</project>

View File

@ -52,10 +52,21 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-velocity</artifactId>
<version>2.2.1</version>
<version>3.0.0</version>
<optional>true</optional>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-velocity</artifactId>
<version>0.5.1-SNAPSHOT</version>
<optional>true</optional>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

12
pom.xml
View File

@ -26,6 +26,7 @@
<module>platforms/easysql-plugin-bukkit</module>
<module>platforms/easysql-plugin-bungee</module>
<module>platforms/easysql-plugin-velocity</module>
<module>platforms/easysql-plugin-sponge</module>
</modules>
<name>EasySQL-Plugin</name>
@ -88,6 +89,11 @@
<url>https://repo.carm.cc/repository/maven-public/</url>
</repository>
<repository>
<id>aikar</id>
<url>https://repo.aikar.co/content/groups/aikar/</url>
</repository>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
@ -148,12 +154,6 @@
<version>${easysql.version}</version>
</dependency>
<dependency>
<groupId>cc.carm.lib</groupId>
<artifactId>easyplugin-main</artifactId>
<version>${easyplugin.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>