mirror of
https://e.coding.net/circlecloud/DataStorage.git
synced 2024-12-04 04:08:53 +00:00
添加Lib 添加配置文件...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
d545b09f5f
commit
448020a1de
BIN
lib/PlaceholderAPI.jar
Normal file
BIN
lib/PlaceholderAPI.jar
Normal file
Binary file not shown.
9
pom.xml
9
pom.xml
@ -55,7 +55,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
|
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
|
||||||
<update.description></update.description>
|
<update.description></update.description>
|
||||||
<env.BUILD_NUMBER>1</env.BUILD_NUMBER>
|
<env.BUILD_NUMBER>Debug</env.BUILD_NUMBER>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
<repositories>
|
<repositories>
|
||||||
@ -81,5 +81,12 @@
|
|||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.clip</groupId>
|
||||||
|
<artifactId>PlaceholderAPI</artifactId>
|
||||||
|
<version>1.8.6</version>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${project.basedir}/lib/PlaceholderAPI.jar</systemPath>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -1,21 +1,98 @@
|
|||||||
package cn.citycraft.DataStorage;
|
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 org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||||
|
import cn.citycraft.PluginHelper.pluginapi.PluginAPI;
|
||||||
import cn.citycraft.PluginHelper.sql.DataBase;
|
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 {
|
public class DataStorage extends JavaPlugin {
|
||||||
FileConfig config;
|
FileConfig config;
|
||||||
DataBase db;
|
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
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
if (db != null) {
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
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
|
@Override
|
||||||
|
13
src/main/resources/config.yml
Normal file
13
src/main/resources/config.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
Data:
|
||||||
|
#数据保存方式 [sqlite|MySQL]
|
||||||
|
FileSystem: sqlite
|
||||||
|
#MySQL数据库配置 只有当FileSystem配置为MySQL时有效
|
||||||
|
MySQL:
|
||||||
|
#数据库需要自行建立
|
||||||
|
database: minecraft
|
||||||
|
#数据表需要自行建立
|
||||||
|
tablename: datastorage
|
||||||
|
username: root
|
||||||
|
password:
|
||||||
|
ip: localhost
|
||||||
|
port: 3306
|
19
src/main/resources/plugin.yml
Normal file
19
src/main/resources/plugin.yml
Normal file
@ -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你没有 <permission> 的权限来执行此命令!
|
||||||
|
permissions:
|
||||||
|
${project.artifactId}.use:
|
||||||
|
description: ${project.artifactId} 使用!
|
||||||
|
default: op
|
Loading…
Reference in New Issue
Block a user