1
mirror of https://github.com/CarmJos/UltraDepository.git synced 2026-06-04 16:48:21 +08:00

Compare commits

..

21 Commits

Author SHA1 Message Date
carm c3fc92abdb [1.3.9] 版本优化
- [R] 采用 Libraries 形式加载插件的部分依赖库,减小插件体积。
- [R] 修改插件入口类,独立API接口类。
2022-03-04 16:55:42 +08:00
carm 5a24db537a 补全插件大标题 2022-03-04 16:48:57 +08:00
carm c6c6b3bc37 更换插件的加载入口 2022-03-04 16:45:08 +08:00
carm 717e313f25 更换成插件入口名 2022-03-04 16:40:58 +08:00
carm 375f4d178a 更换打包配置 2022-03-04 16:33:21 +08:00
carm e35f5ef87e 更换打包配置 2022-03-04 16:31:27 +08:00
carm ccbb5782a6 更换打包配置 2022-03-04 16:25:53 +08:00
carm 8fdd83493b 采用 libraries 形式处理依赖 2022-03-04 16:20:17 +08:00
carm a8dcc99a72 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	pom.xml
2022-03-04 16:19:19 +08:00
carm 5b2eca9ac8 采用 libraries 形式处理依赖 2022-03-04 16:18:23 +08:00
carm 8a5dba9274 修改GithubReleases4J版本 2022-02-07 03:17:28 +08:00
carm 9bd02d1298 修改CI名 2022-02-06 23:57:32 +08:00
carm 7f9ba1c269 修改默认配置 2022-02-06 01:10:28 +08:00
carm 8c44791894 升级依赖版本 2022-02-06 01:10:16 +08:00
carm d52e001e7c [v1.3.8] 修复更新提示类型错误的问题 2022-01-24 01:24:18 +08:00
carm e5efd0d1b2 [v1.3.7] 修复更新提示类型错误的问题 2022-01-24 01:19:53 +08:00
carm 0fcbd1d8f1 [v1.3.6] 修改更新介绍 2022-01-24 01:19:26 +08:00
carm 8f500e3ff0 [v1.3.6] 修改更新介绍 2022-01-23 11:16:54 +08:00
carm baeee39d07 [v1.3.6] 修改更新介绍 2022-01-23 11:16:44 +08:00
carm af82d64ab1 [v1.3.5] 更新GithubReleases4J版本 2022-01-22 15:27:44 +08:00
carm 5d057d2e8e [v1.3.5] 更新GithubReleases4J版本 2022-01-22 14:47:58 +08:00
16 changed files with 674 additions and 407 deletions
+14 -12
View File
@@ -1,30 +1,32 @@
--- ---
name: 问题提交 name: 问题提交
about: 描述问题并提交,帮助我们对其进行检查与修复。 about: 提交并描述问题,帮助我们对其进行检查与修复。
title: '' title: ''
labels: bug labels: bug
assignees: '' assignees: ''
--- ---
### **问题简述** **问题简述**
用简短的话语描述一下大概问题。 <!--用简短的话语描述一下大概问题。-->
### **问题来源** **问题来源**
<!--
描述一下通过哪些操作才发现的问题,如: 描述一下通过哪些操作才发现的问题,如:
1. 打开 '...' 1. 打开 '...'
2. 点击了 '....' 2. 点击了 '....'
3. 出现了报错 '....' 3. 出现了报错 '....'
-->
### **预期结果**(可选) **预期结果**(可选)
如果问题不发生,应该是什么情况 <!--如果问题不发生,应该是什么情况-->
### **问题截图/问题报错** **问题截图/问题报错**
如果有报错或输出,请提供截图。 <!--如果有报错或输出,请提供截图。-->
### *操作环境** **操作环境**
请在后台输入 `version` 并复制相关输出。 <!--请在后台输入 `version` 并复制相关输出。-->
### **其他补充** **其他补充**
如有其他补充,可以在这里描述。 <!--如有其他补充,可以在这里描述。-->
+8 -8
View File
@@ -7,14 +7,14 @@ assignees: ''
--- ---
### **功能简述** **功能简述**
简单的描述一下你想要的功能 <!--简单的描述一下你想要的功能-->
### **需求来源** **需求来源**
简单的描述一下为什么需要这个功能。 <!--简单的描述一下为什么需要这个功能。-->
### **功能参考**(可选) **功能参考**(可选)
如果有相关功能的参考,如文本、截图,请提供给我们。 <!--如果有相关功能的参考,如文本、截图,请提供给我们。-->
### **附加内容** **附加内容**
如果有什么小细节需要重点注意,请在这里告诉我们。 <!--如果有什么小细节需要重点注意,请在这里告诉我们。-->
+8 -4
View File
@@ -1,7 +1,7 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Project Build & Tests name: Build & Tests
on: on:
# 支持手动触发构建 # 支持手动触发构建
@@ -29,10 +29,14 @@ jobs:
env: env:
MAVEN_USERNAME: ${{ github.repository_owner }} MAVEN_USERNAME: ${{ github.repository_owner }}
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}} MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: "Target Stage" - name: "Target Staging"
run: mkdir staging && cp target/*.jar staging run: |
mkdir artifacts
cp -vrf target/ artifacts/target/
cp -vrf asset/*.jar artifacts
- name: "Upload artifact" - name: "Upload artifact"
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
name: Artifact name: Artifact
path: staging path: artifacts
+19 -23
View File
@@ -5,17 +5,20 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <java.version>11</java.version>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding> <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<easyplugin.version>1.3.5</easyplugin.version> <easyplugin.version>1.3.5</easyplugin.version>
<easysql.version>0.3.8</easysql.version>
<ghreleases.version>1.3.1</ghreleases.version>
</properties> </properties>
<groupId>cc.carm.plugin</groupId> <groupId>cc.carm.plugin</groupId>
<artifactId>ultradepository</artifactId> <artifactId>ultradepository</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.3.4</version> <version>1.3.9</version>
<name>UltraDepository</name> <name>UltraDepository</name>
<description>超级仓库插件,支持设定不同物品的存储仓库。</description> <description>超级仓库插件,支持设定不同物品的存储仓库。</description>
@@ -112,14 +115,22 @@
<dependency> <dependency>
<groupId>cc.carm.lib</groupId> <groupId>cc.carm.lib</groupId>
<artifactId>easyplugin-database</artifactId> <artifactId>easysql-beecp</artifactId>
<optional>true</optional> <version>${easysql.version}</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cc.carm.lib</groupId> <groupId>cc.carm.lib</groupId>
<artifactId>githubreleases4j</artifactId> <artifactId>githubreleases4j</artifactId>
<version>1.2.0</version> <version>${ghreleases.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
@@ -137,13 +148,6 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>2.2.1</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>com.github.MilkBowl</groupId> <groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId> <artifactId>VaultAPI</artifactId>
@@ -213,8 +217,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
<configuration> <configuration>
<source>1.8</source> <source>${java.version}</source>
<target>1.8</target> <target>${java.version}</target>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
<compilerArgument>-parameters</compilerArgument> <compilerArgument>-parameters</compilerArgument>
</configuration> </configuration>
@@ -259,18 +263,10 @@
<pattern>org.bstats</pattern> <pattern>org.bstats</pattern>
<shadedPattern>cc.carm.plugin.ultradepository.lib.bstats</shadedPattern> <shadedPattern>cc.carm.plugin.ultradepository.lib.bstats</shadedPattern>
</relocation> </relocation>
<relocation>
<pattern>org.json</pattern>
<shadedPattern>cc.carm.plugin.ultradepository.lib.json</shadedPattern>
</relocation>
<relocation> <relocation>
<pattern>cc.carm.lib.easyplugin</pattern> <pattern>cc.carm.lib.easyplugin</pattern>
<shadedPattern>cc.carm.plugin.ultradepository.lib.easyplugin</shadedPattern> <shadedPattern>cc.carm.plugin.ultradepository.lib.easyplugin</shadedPattern>
</relocation> </relocation>
<relocation>
<pattern>cc.carm.lib.githubreleases4j</pattern>
<shadedPattern>cc.carm.plugin.ultradepository.lib.github</shadedPattern>
</relocation>
</relocations> </relocations>
<filters> <filters>
<filter> <filter>
@@ -0,0 +1,180 @@
package cc.carm.plugin.ultradepository;
import cc.carm.lib.easyplugin.EasyPlugin;
import cc.carm.lib.easyplugin.gui.GUI;
import cc.carm.lib.easyplugin.i18n.EasyPluginMessageProvider;
import cc.carm.lib.easyplugin.utils.MessageUtils;
import cc.carm.plugin.ultradepository.command.DepositoryCommand;
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
import cc.carm.plugin.ultradepository.hooker.GHUpdateChecker;
import cc.carm.plugin.ultradepository.hooker.PAPIExpansion;
import cc.carm.plugin.ultradepository.listener.CollectListener;
import cc.carm.plugin.ultradepository.listener.UserListener;
import cc.carm.plugin.ultradepository.manager.ConfigManager;
import cc.carm.plugin.ultradepository.manager.DepositoryManager;
import cc.carm.plugin.ultradepository.manager.EconomyManager;
import cc.carm.plugin.ultradepository.manager.UserManager;
import cc.carm.plugin.ultradepository.storage.DataStorage;
import cc.carm.plugin.ultradepository.storage.StorageMethod;
import cc.carm.plugin.ultradepository.util.JarResourceUtils;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bstats.charts.SingleLineChart;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import java.util.Optional;
public class Main extends EasyPlugin {
private static Main instance;
private DataStorage storage;
private ConfigManager configManager;
private UserManager userManager;
private EconomyManager economyManager;
private DepositoryManager depositoryManager;
public Main() {
super(new EasyPluginMessageProvider.zh_CN());
}
@Override
protected void load() {
instance = this;
}
@Override
protected boolean initialize() {
log("加载配置文件...");
this.configManager = new ConfigManager(this);
if (!configManager.initialize()) {
log("初始化配置文件失败,放弃加载。");
return false;
}
log("初始化存储方式...");
StorageMethod storageMethod = PluginConfig.STORAGE_METHOD.getOptional().orElse(StorageMethod.YAML);
log(" 正在使用 " + storageMethod.name() + " 进行数据存储");
this.storage = storageMethod.createStorage();
if (!storage.initialize()) {
error("初始化存储失败,请检查配置文件。");
storage.shutdown();
return false;
}
log("加载经济系统...");
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
this.economyManager = new EconomyManager();
if (!economyManager.initialize()) {
error("经济系统初始化失败,关闭出售功能。");
}
} else {
log(" &7[-] 检测到未安装Vault,关闭出售功能。");
}
log("加载仓库管理器...");
this.depositoryManager = new DepositoryManager();
getDepositoryManager().loadDepositories();
log("加载用户系统...");
this.userManager = new UserManager();
log("注册监听器...");
regListener(new UserListener());
regListener(new CollectListener());
GUI.initialize(this);
log("注册指令...");
registerCommand("UltraDepository", new DepositoryCommand());
if (MessageUtils.hasPlaceholderAPI()) {
log("注册变量...");
new PAPIExpansion(this).register();
} else {
log("检测到未安装PlaceholderAPI,跳过变量注册。");
}
if (PluginConfig.METRICS.get()) {
log("启用统计数据...");
Metrics metrics = new Metrics(this, 13777);
metrics.addCustomChart(new SingleLineChart(
"active_depositories",
() -> getDepositoryManager().getDepositories().size())
);
metrics.addCustomChart(new SimplePie("storage_method", storageMethod::name));
metrics.addCustomChart(new SimplePie("economy_enabled", () -> economyManager.isInitialized() ? "YES" : "NO"));
metrics.addCustomChart(new SimplePie("papi_version", () -> {
Plugin plugin = Bukkit.getPluginManager().getPlugin("PlaceholderAPI");
if (plugin == null) return "Not installed";
else return plugin.getDescription().getVersion();
}));
}
if (PluginConfig.CHECK_UPDATE.get()) {
log("开始检查更新...");
GHUpdateChecker checker = new GHUpdateChecker(getLogger(), "CarmJos", "UltraDepository");
getScheduler().runAsync(() -> checker.checkUpdate(getDescription().getVersion()));
} else {
log("已禁用检查更新,跳过。");
}
getUserManager().loadPlayersData();
return true;
}
@Override
protected void shutdown() {
if (!isInitialized()) return;
log("保存现有用户数据...");
getUserManager().saveAll();
getUserManager().getDataCache().clear();
log("释放存储源...");
getStorage().shutdown();
log("卸载监听器...");
Bukkit.getServicesManager().unregisterAll(this);
}
protected DataStorage getStorage() {
return storage;
}
public static Main getInstance() {
return instance;
}
protected UserManager getUserManager() {
return userManager;
}
protected EconomyManager getEconomyManager() {
return economyManager;
}
protected DepositoryManager getDepositoryManager() {
return depositoryManager;
}
protected ConfigManager getConfigManager() {
return configManager;
}
@Override
public boolean isDebugging() {
return PluginConfig.DEBUG.get();
}
@Override
public void outputInfo() {
Optional.ofNullable(JarResourceUtils.readResource(this.getResource("PLUGIN_INFO"))).ifPresent(this::log);
}
}
@@ -1,182 +1,35 @@
package cc.carm.plugin.ultradepository; package cc.carm.plugin.ultradepository;
import cc.carm.lib.easyplugin.EasyPlugin;
import cc.carm.lib.easyplugin.gui.GUI;
import cc.carm.lib.easyplugin.i18n.EasyPluginMessageProvider;
import cc.carm.lib.easyplugin.utils.MessageUtils;
import cc.carm.plugin.ultradepository.command.DepositoryCommand;
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
import cc.carm.plugin.ultradepository.hooker.PAPIExpansion;
import cc.carm.plugin.ultradepository.hooker.UpdateChecker;
import cc.carm.plugin.ultradepository.listener.CollectListener;
import cc.carm.plugin.ultradepository.listener.UserListener;
import cc.carm.plugin.ultradepository.manager.ConfigManager; import cc.carm.plugin.ultradepository.manager.ConfigManager;
import cc.carm.plugin.ultradepository.manager.DepositoryManager; import cc.carm.plugin.ultradepository.manager.DepositoryManager;
import cc.carm.plugin.ultradepository.manager.EconomyManager; import cc.carm.plugin.ultradepository.manager.EconomyManager;
import cc.carm.plugin.ultradepository.manager.UserManager; import cc.carm.plugin.ultradepository.manager.UserManager;
import cc.carm.plugin.ultradepository.storage.DataStorage; import cc.carm.plugin.ultradepository.storage.DataStorage;
import cc.carm.plugin.ultradepository.storage.StorageMethod;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bstats.charts.SingleLineChart;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
public class UltraDepository extends EasyPlugin { public class UltraDepository {
private static UltraDepository instance; public static DataStorage getStorage() {
return Main.getInstance().getStorage();
}
private static DataStorage storage; public static Main getInstance() {
return Main.getInstance();
}
private static UserManager userManager; public static UserManager getUserManager() {
private static EconomyManager economyManager; return Main.getInstance().getUserManager();
private static DepositoryManager depositoryManager; }
public UltraDepository() { public static EconomyManager getEconomyManager() {
super(new EasyPluginMessageProvider.zh_CN()); return Main.getInstance().getEconomyManager();
} }
@Override public static DepositoryManager getDepositoryManager() {
protected void load() { return Main.getInstance().getDepositoryManager();
instance = this; }
}
@Override public static ConfigManager getConfigManager() {
protected boolean initialize() { return Main.getInstance().getConfigManager();
}
log("加载配置文件...");
if (!ConfigManager.initialize()) {
log("初始化配置文件失败,放弃加载。");
return false;
}
log("初始化存储方式...");
StorageMethod storageMethod = PluginConfig.STORAGE_METHOD.getOptional().orElse(StorageMethod.YAML);
log(" 正在使用 " + storageMethod.name() + " 进行数据存储");
storage = storageMethod.createStorage();
if (!storage.initialize()) {
error("初始化存储失败,请检查配置文件。");
storage.shutdown();
return false;
}
log("加载经济系统...");
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
economyManager = new EconomyManager();
if (!economyManager.initialize()) {
error("经济系统初始化失败,关闭出售功能。");
}
} else {
log(" &7[-] 检测到未安装Vault,关闭出售功能。");
}
log("加载仓库管理器...");
depositoryManager = new DepositoryManager();
getDepositoryManager().loadDepositories();
log("加载用户系统...");
userManager = new UserManager();
log("注册监听器...");
regListener(new UserListener());
regListener(new CollectListener());
GUI.initialize(this);
log("注册指令...");
registerCommand("UltraDepository", new DepositoryCommand());
if (MessageUtils.hasPlaceholderAPI()) {
log("注册变量...");
new PAPIExpansion(this).register();
} else {
log("检测到未安装PlaceholderAPI,跳过变量注册。");
}
if (PluginConfig.METRICS.get()) {
log("启用统计数据...");
Metrics metrics = new Metrics(this, 13777);
metrics.addCustomChart(new SingleLineChart(
"active_depositories",
() -> getDepositoryManager().getDepositories().size())
);
metrics.addCustomChart(new SimplePie("storage_method", storageMethod::name));
metrics.addCustomChart(new SimplePie("economy_enabled", () -> economyManager.isInitialized() ? "YES" : "NO"));
metrics.addCustomChart(new SimplePie("papi_version", () -> {
Plugin plugin = Bukkit.getPluginManager().getPlugin("PlaceholderAPI");
if (plugin == null) return "Not installed";
else return plugin.getDescription().getVersion();
}));
}
if (PluginConfig.CHECK_UPDATE.get()) {
log("开始检查更新...");
UpdateChecker.checkUpdate(this);
} else {
log("已禁用检查更新,跳过。");
}
getUserManager().loadPlayersData();
return true;
}
@Override
protected void shutdown() {
if (!isInitialized()) return;
log("保存现有用户数据...");
getUserManager().saveAll();
getUserManager().getDataCache().clear();
log("释放存储源...");
getStorage().shutdown();
log("卸载监听器...");
Bukkit.getServicesManager().unregisterAll(this);
}
public static DataStorage getStorage() {
return storage;
}
public static UltraDepository getInstance() {
return instance;
}
public static UserManager getUserManager() {
return userManager;
}
public static EconomyManager getEconomyManager() {
return economyManager;
}
public static DepositoryManager getDepositoryManager() {
return depositoryManager;
}
@Override
public boolean isDebugging() {
return PluginConfig.DEBUG.get();
}
@Override
public void outputInfo() {
log(" ",
"&6 _ _ _ _ &e _____ _ _ ",
"&6| | | | | | &e| __ \\ (_) | ",
"&6| | | | | |_ _ __ __ _ &e| | | | ___ _ __ ___ ___ _| |_ ___ _ __ _ _ ",
"&6| | | | | __| '__/ _` |&e| | | |/ _ \\ '_ \\ / _ \\/ __| | __/ _ \\| '__| | | |",
"&6| |__| | | |_| | | (_| |&e| |__| | __/ |_) | (_) \\__ \\ | || (_) | | | |_| |",
"&6 \\____/|_|\\__|_| \\__,_|&e|_____/ \\___| .__/ \\___/|___/_|\\__\\___/|_| \\__, |",
"&6 &e| | __/ |",
"&6 &e|_| |___/ ",
"&f请访问项目主页查看详细插件介绍 &8/ &fView GitHub to get more information",
"&8-> &6https://github.com/CarmJos/UltraDepository",
" "
);
}
} }
@@ -6,153 +6,156 @@ import cc.carm.lib.easyplugin.configuration.impl.ConfigSound;
import cc.carm.lib.easyplugin.configuration.message.ConfigMessage; import cc.carm.lib.easyplugin.configuration.message.ConfigMessage;
import cc.carm.lib.easyplugin.configuration.message.ConfigMessageList; import cc.carm.lib.easyplugin.configuration.message.ConfigMessageList;
import cc.carm.lib.easyplugin.configuration.values.ConfigValue; import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
import cc.carm.plugin.ultradepository.manager.ConfigManager; import cc.carm.plugin.ultradepository.UltraDepository;
import cc.carm.plugin.ultradepository.storage.StorageMethod; import cc.carm.plugin.ultradepository.storage.StorageMethod;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
public class PluginConfig { public class PluginConfig {
public static final ConfigValue<Boolean> DEBUG = new ConfigValue<>( public static final ConfigValue<Boolean> DEBUG = new ConfigValue<>(
"debug", Boolean.class, false "debug", Boolean.class, false
); );
public static final ConfigValue<Boolean> METRICS = new ConfigValue<>( public static final ConfigValue<Boolean> METRICS = new ConfigValue<>(
"metrics", Boolean.class, true "metrics", Boolean.class, true
); );
public static final ConfigValue<Boolean> CHECK_UPDATE = new ConfigValue<>( public static final ConfigValue<Boolean> CHECK_UPDATE = new ConfigValue<>(
"check-update", Boolean.class, true "check-update", Boolean.class, true
); );
public static final ConfigStringCast<StorageMethod> STORAGE_METHOD = new ConfigStringCast<>( public static final ConfigStringCast<StorageMethod> STORAGE_METHOD = new ConfigStringCast<>(
"storage.method", StorageMethod::read, StorageMethod.YAML "storage.method", StorageMethod::read, StorageMethod.YAML
); );
/** /**
* 收集配置 * 收集配置
*/ */
public static class Collect { public static class Collect {
public static final ConfigValue<Boolean> PICKUP = new ConfigValue<>( public static final ConfigValue<Boolean> PICKUP = new ConfigValue<>(
"collect.pickup", Boolean.class, true "collect.pickup", Boolean.class, true
); );
public static final ConfigValue<Boolean> KILL = new ConfigValue<>( public static final ConfigValue<Boolean> KILL = new ConfigValue<>(
"collect.kill", Boolean.class, true "collect.kill", Boolean.class, true
); );
public static final ConfigValue<Boolean> BREAK = new ConfigValue<>( public static final ConfigValue<Boolean> BREAK = new ConfigValue<>(
"collect.break", Boolean.class, true "collect.break", Boolean.class, true
); );
} }
public static class Sounds { public static class Sounds {
public static final ConfigSound COLLECT = new ConfigSound("sounds.collect", Sound.ENTITY_VILLAGER_CELEBRATE); public static final ConfigSound COLLECT = new ConfigSound("sounds.collect", Sound.ENTITY_VILLAGER_CELEBRATE);
public static final ConfigSound TAKEOUT = new ConfigSound("sounds.collect"); public static final ConfigSound TAKEOUT = new ConfigSound("sounds.collect");
public static final ConfigSound SELL_SUCCESS = new ConfigSound("sounds.sell-success"); public static final ConfigSound SELL_SUCCESS = new ConfigSound("sounds.sell-success");
public static final ConfigSound SELL_FAIL = new ConfigSound("sounds.sell-fail"); public static final ConfigSound SELL_FAIL = new ConfigSound("sounds.sell-fail");
public static final ConfigSound GUI_CLICK = new ConfigSound("sounds.gui-click"); public static final ConfigSound GUI_CLICK = new ConfigSound("sounds.gui-click");
} }
/** /**
* 通用配置 * 通用配置
*/ */
public static class General { public static class General {
/** /**
* 针对每一件物品的额外介绍 * 针对每一件物品的额外介绍
* 将添加到背包界面内的物品上,避免重复配置 * 将添加到背包界面内的物品上,避免重复配置
*/ */
public static class AdditionalLore { public static class AdditionalLore {
public static final ConfigMessageList AVAILABLE_FOR_SALE = new ConfigMessageList( public static final ConfigMessageList AVAILABLE_FOR_SALE = new ConfigMessageList(
ConfigManager::getPluginConfig, "general.additional-lore.available-for-sale", () -> UltraDepository.getConfigManager().getPluginConfig(),
new String[]{}, "general.additional-lore.available-for-sale",
new String[]{ new String[]{},
"%(item_name)", "%(amount)", "%(price)", "%(sold)", "%(remain)", "%(limit)" new String[]{
}); "%(item_name)", "%(amount)", "%(price)", "%(sold)", "%(remain)", "%(limit)"
});
public static final ConfigMessageList NOT_FOR_SALE = new ConfigMessageList( public static final ConfigMessageList NOT_FOR_SALE = new ConfigMessageList(
ConfigManager::getPluginConfig, "general.additional-lore.not-for-sale", () -> UltraDepository.getConfigManager().getPluginConfig(),
new String[]{}, new String[]{ "general.additional-lore.not-for-sale",
"%(item_name)", "%(amount)" new String[]{}, new String[]{
}); "%(item_name)", "%(amount)"
});
} }
/** /**
* 提示玩家点击行为的介绍 * 提示玩家点击行为的介绍
* 将添加到背包界面内的物品上,避免重复配置 * 将添加到背包界面内的物品上,避免重复配置
*/ */
public static class ClickLore { public static class ClickLore {
public static final ConfigMessageList AVAILABLE_FOR_SALE = new ConfigMessageList( public static final ConfigMessageList AVAILABLE_FOR_SALE = new ConfigMessageList(
ConfigManager::getPluginConfig, () -> UltraDepository.getConfigManager().getPluginConfig(),
"general.click-lore.available-for-sale", "general.click-lore.available-for-sale",
new String[]{}, new String[]{ new String[]{}, new String[]{
"%(item_name)", "%(amount)", "%(price)" "%(item_name)", "%(amount)", "%(price)"
}); });
public static final ConfigMessageList NOT_FOR_SALE = new ConfigMessageList( public static final ConfigMessageList NOT_FOR_SALE = new ConfigMessageList(
ConfigManager::getPluginConfig, "general.click-lore.not-for-sale", () -> UltraDepository.getConfigManager().getPluginConfig(),
new String[]{}, "general.click-lore.not-for-sale",
new String[]{ new String[]{},
"%(item_name)", "%(amount)" new String[]{
}); "%(item_name)", "%(amount)"
} });
}
public static final ConfigMessageList CLICK_LORE = new ConfigMessageList( public static final ConfigMessageList CLICK_LORE = new ConfigMessageList(
ConfigManager::getPluginConfig, () -> UltraDepository.getConfigManager().getPluginConfig(),
"general.click-lore", "general.click-lore",
new String[]{}, new String[]{ new String[]{}, new String[]{
"%(item_name)", "%(amount)", "%(price)" "%(item_name)", "%(amount)", "%(price)"
}); });
/** /**
* 售出界面的配置 * 售出界面的配置
*/ */
public static class SellGUI { public static class SellGUI {
public static final ConfigMessage TITLE = new ConfigMessage( public static final ConfigMessage TITLE = new ConfigMessage(
ConfigManager::getPluginConfig, () -> UltraDepository.getConfigManager().getPluginConfig(),
"general.sell-gui.title", "general.sell-gui.title",
"&a&l出售", new String[]{ "&a&l出售", new String[]{
"%(item_name)", "%(backpack_name)" "%(item_name)", "%(backpack_name)"
} }
); );
public static class Items { public static class Items {
public static final ConfigItem ADD = new ConfigItem( public static final ConfigItem ADD = new ConfigItem(
"general.sell-gui.items.add", "general.sell-gui.items.add",
new String[]{"%(item_name)", "%(amount)"}, new String[]{"%(item_name)", "%(amount)"},
ConfigItem.create(Material.GREEN_STAINED_GLASS_PANE, "&a添加物品 %(amount) 个") ConfigItem.create(Material.GREEN_STAINED_GLASS_PANE, "&a添加物品 %(amount) 个")
); );
public static final ConfigItem REMOVE = new ConfigItem( public static final ConfigItem REMOVE = new ConfigItem(
"general.sell-gui.items.remove", "general.sell-gui.items.remove",
new String[]{"%(item_name)", "%(amount)"}, new String[]{"%(item_name)", "%(amount)"},
ConfigItem.create(Material.RED_STAINED_GLASS_PANE, "&c減少物品 %(amount) 个") ConfigItem.create(Material.RED_STAINED_GLASS_PANE, "&c減少物品 %(amount) 个")
); );
public static final ConfigItem CONFIRM = new ConfigItem( public static final ConfigItem CONFIRM = new ConfigItem(
"general.sell-gui.items.confirm", "general.sell-gui.items.confirm",
new String[]{"%(item_name)", "%(amount)", "%(money)"}, new String[]{"%(item_name)", "%(amount)", "%(money)"},
ConfigItem.create(Material.EMERALD, "&2确认售出") ConfigItem.create(Material.EMERALD, "&2确认售出")
); );
public static final ConfigItem CANCEL = new ConfigItem( public static final ConfigItem CANCEL = new ConfigItem(
"general.sell-gui.items.cancel", "general.sell-gui.items.cancel",
ConfigItem.create(Material.REDSTONE, "&4取消售出") ConfigItem.create(Material.REDSTONE, "&4取消售出")
); );
} }
} }
} }
} }
@@ -0,0 +1,38 @@
package cc.carm.plugin.ultradepository.hooker;
import cc.carm.lib.githubreleases4j.GithubReleases4J;
import java.util.logging.Logger;
public class GHUpdateChecker {
private final Logger logger;
private final String owner;
private final String repo;
public GHUpdateChecker(Logger logger, String owner, String repo) {
this.logger = logger;
this.owner = owner;
this.repo = repo;
}
public void checkUpdate(String currentVersion) {
Integer behindVersions = GithubReleases4J.getVersionBehind(owner, repo, currentVersion);
String downloadURL = GithubReleases4J.getReleasesURL(owner, repo);
if (behindVersions == null) {
logger.severe("检查更新失败,请您定期查看插件是否更新,避免安全问题。");
logger.severe("下载地址 " + downloadURL);
} else if (behindVersions == 0) {
logger.info("检查完成,当前已是最新版本。");
} else if (behindVersions > 0) {
logger.info("发现新版本! 目前已落后 " + behindVersions + " 个版本。");
logger.info("最新版下载地址 " + downloadURL);
} else {
logger.severe("检查更新失败! 当前版本未知,请您使用原生版本以避免安全问题。");
logger.severe("最新版下载地址 " + downloadURL);
}
}
}
@@ -1,42 +1,32 @@
package cc.carm.plugin.ultradepository.hooker; package cc.carm.plugin.ultradepository.hooker;
import cc.carm.lib.githubreleases4j.GithubRelease;
import cc.carm.lib.githubreleases4j.GithubReleases4J; import cc.carm.lib.githubreleases4j.GithubReleases4J;
import cc.carm.plugin.ultradepository.Main;
import cc.carm.plugin.ultradepository.UltraDepository; import cc.carm.plugin.ultradepository.UltraDepository;
import java.util.List;
public class UpdateChecker { public class UpdateChecker {
public static void checkUpdate(UltraDepository plugin) { public static void checkUpdate(Main plugin) {
plugin.getScheduler().runAsync(() -> { plugin.getScheduler().runAsync(() -> {
try { Integer behindVersions = GithubReleases4J.getVersionBehind(
"CarmJos", "UltraDepository",
plugin.getDescription().getVersion()
);
List<GithubRelease> releases = GithubReleases4J.listReleases("CarmJos", "UltraDepository"); String downloadURL = GithubReleases4J.getReleasesURL("CarmJos", "UltraDepository");
if (releases.isEmpty()) throw new NullPointerException(); // 无法获取更新
String currentVersion = plugin.getDescription().getVersion(); if (behindVersions == null) {
int i = 0;
for (GithubRelease release : releases) {
if (release.getTagName().equalsIgnoreCase(currentVersion)) {
break;
}
i++;
}
if (i > 0) {
GithubRelease latestRelease = releases.get(0);
plugin.log("检查更新完成,当前已落后 " + i + " 个版本,最新版本为 &6&l" + latestRelease.getTagName() + " &r。");
plugin.log("最新版本下载地址&e " + latestRelease.getHTMLUrl());
} else {
plugin.log("检查更新完成,当前已是最新版本。");
}
} catch (Exception exception) {
plugin.error("检查更新失败,请您定期查看插件是否更新,避免安全问题。"); plugin.error("检查更新失败,请您定期查看插件是否更新,避免安全问题。");
plugin.error("插件下载地址&e https://github.com/CarmJos/UltraDepository/releases"); plugin.error("下载地址 " + downloadURL);
} else if (behindVersions == 0) {
plugin.log("检查完成,当前已是最新版本。");
} else if (behindVersions > 0) {
plugin.log("发现新版本! 目前已落后 " + behindVersions + " 个版本。");
plugin.log("最新版下载地址 " + downloadURL);
} else {
plugin.error("检查更新失败! 当前版本未知,请您使用原生版本以避免安全问题。");
plugin.error("最新版下载地址 " + downloadURL);
} }
}); });
@@ -7,70 +7,74 @@ import cc.carm.lib.easyplugin.configuration.language.MessagesInitializer;
import cc.carm.plugin.ultradepository.UltraDepository; import cc.carm.plugin.ultradepository.UltraDepository;
import cc.carm.plugin.ultradepository.configuration.PluginMessages; import cc.carm.plugin.ultradepository.configuration.PluginMessages;
import cc.carm.plugin.ultradepository.util.JarUtil; import cc.carm.plugin.ultradepository.util.JarUtil;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
public class ConfigManager { public class ConfigManager {
private static FileConfig pluginConfiguration; private final JavaPlugin plugin;
private static MessagesConfig messageConfiguration; private FileConfig pluginConfiguration;
private MessagesConfig messageConfiguration;
public static boolean initialize() { public ConfigManager(JavaPlugin plugin) {
UltraDepository udPlugin = UltraDepository.getInstance(); this.plugin = plugin;
}
public boolean initialize() {
try { try {
File configFile = new File(udPlugin.getDataFolder(), "config.yml"); File configFile = new File(plugin.getDataFolder(), "config.yml");
if (!configFile.exists()) { if (!configFile.exists()) {
//没找到配置文件,可能是第一次加载此插件 //没找到配置文件,可能是第一次加载此插件
//把一些英文版的东西复制出来,方便英文用户使用。 //把一些英文版的东西复制出来,方便英文用户使用。
UltraDepository.getInstance().log(" 未找到配置文件,生成默认配置..."); UltraDepository.getInstance().log(" 未找到配置文件,生成默认配置...");
JarUtil.copyFolderFromJar( JarUtil.copyFolderFromJar(
"i18n", udPlugin.getDataFolder(), "i18n", plugin.getDataFolder(),
JarUtil.CopyOption.COPY_IF_NOT_EXIST JarUtil.CopyOption.COPY_IF_NOT_EXIST
); );
} }
pluginConfiguration = new FileConfig(udPlugin, "config.yml"); pluginConfiguration = new FileConfig(plugin, "config.yml");
messageConfiguration = new MessagesConfig(udPlugin, "messages.yml"); messageConfiguration = new MessagesConfig(plugin, "messages.yml");
FileConfig.pluginConfiguration = () -> pluginConfiguration; FileConfig.pluginConfiguration = () -> pluginConfiguration;
FileConfig.messageConfiguration = () -> messageConfiguration; FileConfig.messageConfiguration = () -> messageConfiguration;
MessagesInitializer.initialize(messageConfiguration, PluginMessages.class); MessagesInitializer.initialize(messageConfiguration, PluginMessages.class);
return true; return true;
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
return false; return false;
} }
} }
public static FileConfig getPluginConfig() { public FileConfig getPluginConfig() {
return pluginConfiguration; return pluginConfiguration;
} }
public static MessagesConfig getMessageConfig() { public MessagesConfig getMessageConfig() {
return messageConfiguration; return messageConfiguration;
} }
public static void reload() { public void reload() {
try { try {
getPluginConfig().reload(); getPluginConfig().reload();
getMessageConfig().reload(); getMessageConfig().reload();
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
public static void saveConfig() { public void saveConfig() {
try { try {
getPluginConfig().save(); getPluginConfig().save();
getMessageConfig().save(); getMessageConfig().save();
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
} }
@@ -1,12 +1,12 @@
package cc.carm.plugin.ultradepository.storage.impl; package cc.carm.plugin.ultradepository.storage.impl;
import cc.carm.lib.easyplugin.configuration.values.ConfigValue; import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
import cc.carm.lib.easyplugin.database.DatabaseTable; import cc.carm.lib.easysql.EasySQL;
import cc.carm.lib.easyplugin.database.EasySQL; import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easyplugin.database.api.SQLManager; import cc.carm.lib.easysql.api.action.query.PreparedQueryAction;
import cc.carm.lib.easyplugin.database.api.action.query.PreparedQueryAction;
import cc.carm.plugin.ultradepository.UltraDepository; import cc.carm.plugin.ultradepository.UltraDepository;
import cc.carm.plugin.ultradepository.data.UserData; import cc.carm.plugin.ultradepository.data.UserData;
import cc.carm.plugin.ultradepository.util.DatabaseTable;
import cc.carm.plugin.ultradepository.util.DateIntUtil; import cc.carm.plugin.ultradepository.util.DateIntUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -0,0 +1,77 @@
package cc.carm.plugin.ultradepository.util;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateAction;
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateBatchAction;
import cc.carm.lib.easysql.api.builder.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.sql.SQLException;
public class DatabaseTable {
private final @NotNull String tableName;
private final @NotNull String[] columns;
@Nullable String tableSettings;
public DatabaseTable(@NotNull String tableName, @NotNull String[] columns) {
this(tableName, columns, null);
}
public DatabaseTable(@NotNull String tableName, @NotNull String[] columns,
@Nullable String tableSettings) {
this.tableName = tableName;
this.columns = columns;
this.tableSettings = tableSettings;
}
public @NotNull String getTableName() {
return tableName;
}
public @NotNull String[] getColumns() {
return columns;
}
public @Nullable String getTableSettings() {
return tableSettings;
}
public int createTable(SQLManager sqlManager) throws SQLException {
TableCreateBuilder createAction = sqlManager.createTable(getTableName());
createAction.setColumns(getColumns());
if (getTableSettings() != null) createAction.setTableSettings(getTableSettings());
return createAction.build().execute();
}
public TableQueryBuilder createQuery(SQLManager sqlManager) {
return sqlManager.createQuery().inTable(getTableName());
}
public DeleteBuilder createDelete(SQLManager sqlManager) {
return sqlManager.createDelete(getTableName());
}
public UpdateBuilder createUpdate(SQLManager sqlManager) {
return sqlManager.createUpdate(getTableName());
}
public InsertBuilder<PreparedSQLUpdateAction> createInsert(SQLManager sqlManager) {
return sqlManager.createInsert(getTableName());
}
public InsertBuilder<PreparedSQLUpdateBatchAction> createInsertBatch(SQLManager sqlManager) {
return sqlManager.createInsertBatch(getTableName());
}
public ReplaceBuilder<PreparedSQLUpdateAction> createReplace(SQLManager sqlManager) {
return sqlManager.createReplace(getTableName());
}
public ReplaceBuilder<PreparedSQLUpdateBatchAction> createReplaceBatch(SQLManager sqlManager) {
return sqlManager.createReplaceBatch(getTableName());
}
}
@@ -0,0 +1,106 @@
package cc.carm.plugin.ultradepository.util;
import org.jetbrains.annotations.Nullable;
import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
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, StandardCharsets.UTF_8.name())) {
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);
}
}
+10
View File
@@ -0,0 +1,10 @@
&6 _ _ _ _ &e _____ _ _
&6| | | | | | &e| __ \ (_) |
&6| | | | | |_ _ __ __ _&e| | | | ___ _ __ ___ ___ _| |_ ___ _ __ _ _
&6| | | | | __| '__/ _` &e| | | |/ _ \ '_ \ / _ \/ __| | __/ _ \| '__| | | |
&6| |__| | | |_| | | (_| &e| |__| | __/ |_) | (_) \__ \ | || (_) | | | |_| |
&6 \____/|_|\__|_| \__,_&e|_____/ \___| .__/ \___/|___/_|\__\___/|_| \__, |
&6 &e | | __/ |
&6 &e |_| |___/
&f请访问项目主页查看详细插件介绍 &8/ &fView GitHub to get more information
&8-> &6${project.url}
+1 -1
View File
@@ -32,7 +32,7 @@ storage:
# 选择 database 存储方式时的数据库配置 # 选择 database 存储方式时的数据库配置
mysql: mysql:
# 数据库驱动路径 # 数据库驱动路径
driver: "com.mysql.jdbc.Driver" driver: "com.mysql.cj.jdbc.Driver"
url: "jdbc:mysql://127.0.0.1:3306/<db-name>" url: "jdbc:mysql://127.0.0.1:3306/<db-name>"
table: "ud_data" # 插件表名,允许自定义 table: "ud_data" # 插件表名,允许自定义
username: "username" username: "username"
+5 -1
View File
@@ -1,4 +1,4 @@
main: cc.carm.plugin.ultradepository.UltraDepository main: cc.carm.plugin.ultradepository.Main
name: UltraDepository name: UltraDepository
version: ${project.version} version: ${project.version}
@@ -15,6 +15,10 @@ softdepend:
- PlaceholderAPI - PlaceholderAPI
- Vault - Vault
libraries:
- cc.carm.lib:easysql-beecp:${easysql.version}
- cc.carm.lib:githubreleases4j:${ghreleases.version}
commands: commands:
"UltraDepository": "UltraDepository":
description: "超级仓库的主指令" description: "超级仓库的主指令"