diff --git a/lib/PlaceholderAPI.jar b/lib/PlaceholderAPI.jar
new file mode 100644
index 0000000..01da9ea
Binary files /dev/null and b/lib/PlaceholderAPI.jar differ
diff --git a/pom.xml b/pom.xml
index 8d382c5..03814bb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -55,7 +55,7 @@
http://ci.citycraft.cn:8080
- 1
+ Debug
UTF-8
@@ -81,5 +81,12 @@
jar
1.0
+
+ me.clip
+ PlaceholderAPI
+ 1.8.6
+ system
+ ${project.basedir}/lib/PlaceholderAPI.jar
+
\ No newline at end of file
diff --git a/src/main/java/cn/citycraft/DataStorage/DataStorage.java b/src/main/java/cn/citycraft/DataStorage/DataStorage.java
index c8fd019..5da3f5b 100644
--- a/src/main/java/cn/citycraft/DataStorage/DataStorage.java
+++ b/src/main/java/cn/citycraft/DataStorage/DataStorage.java
@@ -1,21 +1,98 @@
package cn.citycraft.DataStorage;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.PluginHelper.config.FileConfig;
+import cn.citycraft.PluginHelper.pluginapi.PluginAPI;
import cn.citycraft.PluginHelper.sql.DataBase;
+import cn.citycraft.PluginHelper.sql.KeyValue;
+import cn.citycraft.PluginHelper.sql.MySQLCore;
+import cn.citycraft.PluginHelper.sql.SQLiteCore;
public class DataStorage extends JavaPlugin {
FileConfig config;
DataBase db;
+ String kfields = "key";
+ String tableName;
+ String vfields = "value";
+
+ @Override
+ public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
+ if (args.length > 1) {
+ final String subcmd = args[0];
+ final String key = args[1];
+ final KeyValue kv = new KeyValue(kfields, key);
+ int value = 0;
+ int dbValue = 0;
+ try {
+ value = Integer.valueOf(args[2]);
+ dbValue = Integer.valueOf(db.dbSelectFirst(tableName, vfields, kv));
+ } catch (final Exception e) {
+ }
+ if (args.length > 2 && value != 0) {
+ switch (subcmd) {
+ case "add":
+ db.dbUpdate(tableName, new KeyValue(vfields, value + dbValue), kv);
+ return true;
+ case "del":
+ db.dbUpdate(tableName, new KeyValue(vfields, dbValue - value), kv);
+ return true;
+ case "create":
+ db.dbInsert(tableName, kv.add(vfields, value));
+ return true;
+ }
+ }
+ if (args.length > 1) {
+ db.dbDelete(tableName, kv);
+ return true;
+ }
+ }
+ final String[] help = new String[] { "§6dd add key value 键key的值添加value!", "§6dd del key value 键key的值减少value!", "§6dd add key value 创建键key设置值为value!", "§6dd remove key 移除key!" };
+ sender.sendMessage(help);
+ return true;
+ }
@Override
public void onDisable() {
+ if (db != null) {
+ db.close();
+ }
}
@Override
public void onEnable() {
-
+ final ConfigurationSection cfg = config.getConfigurationSection("Data.MySQL");
+ if (config.getMessage("Data.FileSystem").equalsIgnoreCase("MySQL")) {
+ db = new DataBase(new MySQLCore(cfg));
+ } else {
+ db = new DataBase(new SQLiteCore(this, cfg));
+ }
+ tableName = config.getMessage("Data.MySQL.tablename");
+ if (db.testConnect()) {
+ this.getLogger().info("数据库连接成功,检查数据表是否存在...");
+ if (!db.isTableExists(tableName)) {
+ this.getLogger().info("数据表不存在,新建表" + tableName + "...");
+ if (!db.createTables(tableName, new KeyValue(kfields, "VARCHAR(30) PRIMARY KEY").add(vfields, "INT"), "UNIQUE (`key`)")) {
+ this.getLogger().info("数据表" + tableName + "创建失败,请尝试手动创建并重启服务器...");
+ }
+ }
+ } else {
+ this.getLogger().warning("数据库连接失败!");
+ this.getServer().getPluginManager().disablePlugin(this);
+ }
+ final boolean result = PluginAPI.PlaceholderHook("dd", new me.clip.placeholderapi.PlaceholderHook() {
+ @Override
+ public String onPlaceholderRequest(final Player arg0, final String arg1) {
+ return db.dbSelectFirst(tableName, vfields, new KeyValue(kfields, arg1));
+ }
+ });
+ if (result) {
+ this.getLogger().info("发现 PlaceholderAPI 已关联...");
+ }
}
@Override
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
new file mode 100644
index 0000000..c061f52
--- /dev/null
+++ b/src/main/resources/config.yml
@@ -0,0 +1,13 @@
+Data:
+ #数据保存方式 [sqlite|MySQL]
+ FileSystem: sqlite
+ #MySQL数据库配置 只有当FileSystem配置为MySQL时有效
+ MySQL:
+ #数据库需要自行建立
+ database: minecraft
+ #数据表需要自行建立
+ tablename: datastorage
+ username: root
+ password:
+ ip: localhost
+ port: 3306
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
new file mode 100644
index 0000000..7f2fde4
--- /dev/null
+++ b/src/main/resources/plugin.yml
@@ -0,0 +1,19 @@
+name: ${project.artifactId}
+description: ${project.description}
+main: ${project.groupId}.${project.artifactId}.${project.artifactId}
+version: ${project.version}-Build#${env.BUILD_NUMBER}
+author: 喵♂呜
+website: ${jenkins.url}/job/${project.artifactId}/
+commands:
+ ${project.artifactId}:
+ description: ${project.artifactId} - ${project.description}
+ aliases:
+ - dd
+ - ds
+ usage: §b使用/${project.artifactId} help 查看帮助!
+ permission: ${project.artifactId}.use
+ permission-message: §c你没有 的权限来执行此命令!
+permissions:
+ ${project.artifactId}.use:
+ description: ${project.artifactId} 使用!
+ default: op
\ No newline at end of file