mirror of
https://github.com/CarmJos/UltraDepository.git
synced 2026-06-05 00:58:22 +08:00
Compare commits
74 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f590d29d7 | |||
| 84e1be3975 | |||
| 114d029579 | |||
| 7b49e56b69 | |||
| 4334e13d63 | |||
| f6187340fd | |||
| 9507ddd09a | |||
| b76074873c | |||
| 833ebdd675 | |||
| c490f32e26 | |||
| 3fae967c2c | |||
| cc60dca3f3 | |||
| d925bf55eb | |||
| cc6a092fbf | |||
| 2127ff6421 | |||
| a9d1699233 | |||
| 61f0bd1afa | |||
| d4817d6438 | |||
| 6be058153b | |||
| 66b9160a01 | |||
| e5b501b92d | |||
| aa253b0ffd | |||
| 2e2b0772fc | |||
| da86663667 | |||
| 1777bfd8cb | |||
| 5ed483088d | |||
| 849fc6a1c4 | |||
| b867b2d761 | |||
| be8b9fde82 | |||
| 252c91bf94 | |||
| ab744b6eb9 | |||
| bb2577aed3 | |||
| d0d188b399 | |||
| 443f04c55c | |||
| dcd0e114dd | |||
| f019019c48 | |||
| 1fc6e47c46 | |||
| f5d74e0bca | |||
| f8a3a35790 | |||
| 93c5fc09fb | |||
| ee76419d6d | |||
| 0e4568d646 | |||
| 62a76ef7b1 | |||
| e6c4a77a18 | |||
| a6d70a7e22 | |||
| e192a896b7 | |||
| c3fc92abdb | |||
| 5a24db537a | |||
| c6c6b3bc37 | |||
| 717e313f25 | |||
| 375f4d178a | |||
| e35f5ef87e | |||
| ccbb5782a6 | |||
| 8fdd83493b | |||
| a8dcc99a72 | |||
| 5b2eca9ac8 | |||
| 8a5dba9274 | |||
| 9bd02d1298 | |||
| 7f9ba1c269 | |||
| 8c44791894 | |||
| d52e001e7c | |||
| e5efd0d1b2 | |||
| 0fcbd1d8f1 | |||
| 8f500e3ff0 | |||
| baeee39d07 | |||
| af82d64ab1 | |||
| 5d057d2e8e | |||
| a427db36e9 | |||
| afd62a493d | |||
| c841a7b1b3 | |||
| dc57e822b5 | |||
| 54cc9c070b | |||
| fa07564548 | |||
| 7138d20357 |
@@ -17,18 +17,18 @@
|
||||
|
||||
## 预设配置截图
|
||||
|
||||
### 渔夫仓库 ([fishman.yml](files/fishman.yml))
|
||||
### 渔夫仓库 ([fishman.yml](../../src/main/resources/depositories/fishman.yml))
|
||||
|
||||

|
||||
|
||||
### 矿工仓库 ([miner.yml](files/miner.yml))
|
||||
### 矿工仓库 ([miner.yml](../../src/main/resources/depositories/miner.yml))
|
||||
|
||||

|
||||
|
||||
### 农夫仓库 ([farmer.yml](files/farmer.yml))
|
||||
### 农夫仓库 ([farmer.yml](../../src/main/resources/depositories/farmer.yml))
|
||||
|
||||

|
||||
|
||||
### 猎人仓库 ([hunter.yml](files/hunter.yml))
|
||||
### 猎人仓库 ([hunter.yml](../../src/main/resources/depositories/hunter.yml))
|
||||
|
||||

|
||||
@@ -1,30 +1,32 @@
|
||||
---
|
||||
name: 问题提交
|
||||
about: 描述问题并提交,帮助我们对其进行检查与修复。
|
||||
about: 提交并描述问题,帮助我们对其进行检查与修复。
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### **问题简述**
|
||||
用简短的话语描述一下大概问题。
|
||||
**问题简述**
|
||||
<!--用简短的话语描述一下大概问题。-->
|
||||
|
||||
### **问题来源**
|
||||
**问题来源**
|
||||
<!--
|
||||
描述一下通过哪些操作才发现的问题,如:
|
||||
1. 打开 '...'
|
||||
2. 点击了 '....'
|
||||
3. 出现了报错 '....'
|
||||
-->
|
||||
|
||||
### **预期结果**(可选)
|
||||
如果问题不发生,应该是什么情况
|
||||
**预期结果**(可选)
|
||||
<!--如果问题不发生,应该是什么情况-->
|
||||
|
||||
### **问题截图/问题报错**
|
||||
如果有报错或输出,请提供截图。
|
||||
**问题截图/问题报错**
|
||||
<!--如果有报错或输出,请提供截图。-->
|
||||
|
||||
### *操作环境**
|
||||
请在后台输入 `version` 并复制相关输出。
|
||||
**操作环境**
|
||||
<!--请在后台输入 `version` 并复制相关输出。-->
|
||||
|
||||
|
||||
### **其他补充**
|
||||
如有其他补充,可以在这里描述。
|
||||
**其他补充**
|
||||
<!--如有其他补充,可以在这里描述。-->
|
||||
|
||||
@@ -7,14 +7,14 @@ assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### **功能简述**
|
||||
简单的描述一下你想要的功能
|
||||
**功能简述**
|
||||
<!--简单的描述一下你想要的功能-->
|
||||
|
||||
### **需求来源**
|
||||
简单的描述一下为什么需要这个功能。
|
||||
**需求来源**
|
||||
<!--简单的描述一下为什么需要这个功能。-->
|
||||
|
||||
### **功能参考**(可选)
|
||||
如果有相关功能的参考,如文本、截图,请提供给我们。
|
||||
**功能参考**(可选)
|
||||
<!--如果有相关功能的参考,如文本、截图,请提供给我们。-->
|
||||
|
||||
### **附加内容**
|
||||
如果有什么小细节需要重点注意,请在这里告诉我们。
|
||||
**附加内容**
|
||||
<!--如果有什么小细节需要重点注意,请在这里告诉我们。-->
|
||||
|
||||
@@ -38,11 +38,11 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v6
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
uses: github/codeql-action/init@v4
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
@@ -53,7 +53,7 @@ jobs:
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
uses: github/codeql-action/autobuild@v4
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
@@ -67,4 +67,4 @@ jobs:
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
uses: github/codeql-action/analyze@v4
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# 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
|
||||
|
||||
name: Project Deploy
|
||||
name: Deploy & Upload
|
||||
|
||||
on:
|
||||
# 支持手动触发构建
|
||||
@@ -16,9 +16,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v6
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v2
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
@@ -27,13 +27,23 @@ jobs:
|
||||
server-username: MAVEN_USERNAME
|
||||
server-password: MAVEN_TOKEN
|
||||
|
||||
- name: "Maven Deploy With Javadoc"
|
||||
- name: "Maven Deploy"
|
||||
run: mvn -B deploy --file pom.xml -DskipTests
|
||||
env:
|
||||
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||
|
||||
- name: "Copy Javadoc to Location"
|
||||
- name: "Release Asset Upload"
|
||||
id: upload-release-asset
|
||||
uses: shogo82148/actions-upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ github.event.release.upload_url }}
|
||||
asset_path: asset/*.jar
|
||||
asset_content_type: application/java-archive
|
||||
|
||||
- name: "Javadoc Deploy Staging"
|
||||
run: |
|
||||
rm -rf docs
|
||||
mkdir -vp docs
|
||||
@@ -44,10 +54,10 @@ jobs:
|
||||
id: sitemap
|
||||
uses: cicirello/generate-sitemap@v1
|
||||
with:
|
||||
base-url-path: https://carmjos.github.io/EasySQL
|
||||
base-url-path: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}
|
||||
path-to-root: docs
|
||||
|
||||
- name: "Output stats"
|
||||
- name: "Output Javadoc stats"
|
||||
run: |
|
||||
echo "sitemap-path = ${{ steps.sitemap.outputs.sitemap-path }}"
|
||||
echo "url-count = ${{ steps.sitemap.outputs.url-count }}"
|
||||
@@ -65,11 +75,11 @@ jobs:
|
||||
git config --global user.name 'CarmJos'
|
||||
git config --global user.email 'carm@carm.cc'
|
||||
|
||||
- name: "Commit documentations"
|
||||
- name: "Commit Javadocs"
|
||||
run: |
|
||||
cd docs
|
||||
git init
|
||||
git remote add origin git@github.com:CarmJos/UltraDepository.git
|
||||
git remote add origin git@github.com:${{ github.repository }}.git
|
||||
git checkout -b gh-pages
|
||||
git add -A
|
||||
git commit -m "API Document generated."
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# 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
|
||||
|
||||
name: Project Build & Tests
|
||||
name: Build & Tests
|
||||
|
||||
on:
|
||||
# 支持手动触发构建
|
||||
@@ -14,9 +14,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v6
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v2
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
@@ -29,10 +29,15 @@ jobs:
|
||||
env:
|
||||
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||
- name: "Target Stage"
|
||||
run: mkdir staging && cp target/*.jar staging
|
||||
|
||||
- name: "Upload artifact"
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: Artifact
|
||||
path: staging
|
||||
name: artifact
|
||||
path: target
|
||||
|
||||
- name: "Upload assets"
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: assets
|
||||
path: asset
|
||||
@@ -2,3 +2,4 @@
|
||||
/target/
|
||||
./*.iml
|
||||
*.iml
|
||||
asset/
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
进入仓库后的物品玩家可以选择拿出或直接按量出售,且每日的出售数量上限和每件物品的价格可以自定义。
|
||||
|
||||
插件支持针对不同的权限配置仓库的容量,由此可以制作付费享用的”农业仓库“、”战斗仓库“、”伐木仓库“...
|
||||
插件支持针对不同的权限配置仓库的容量,由此可以制作付费享用的”作物仓库“、”药剂师仓库“、”伐木仓库“...
|
||||
|
||||
综上,该插件不但提供了一种功能特权,对其合理配置之后也将大大为玩家带来便利。
|
||||
|
||||
@@ -218,7 +218,7 @@
|
||||
|
||||
文件名即仓库的ID,**强烈推荐使用纯英文**。以`.`开头的仓库配置不会被加载。部分符号可能会影响正常读取,请避免使用。
|
||||
|
||||
随本项目预设了几个常用的仓库类型,可以 [在这里](.examples/depositories) 找到您需要的仓库配置加以修改后使用。
|
||||
随本项目预设了几个常用的仓库类型,可以 [在这里](.examples/depositories) 直接下载您需要的仓库配置加以修改后使用。
|
||||
|
||||
您也可以 [点击这里](src/main/resources/depositories/.example-depository.yml) 查看一份*详细的仓库配置示例*,以制作您自己的仓库。
|
||||
|
||||
|
||||
@@ -5,17 +5,20 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<java.version>11</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
<easyplugin.version>1.3.5</easyplugin.version>
|
||||
<easyplugin.version>1.5.14</easyplugin.version>
|
||||
<easysql.version>0.4.7</easysql.version>
|
||||
<ghreleases.version>1.3.2</ghreleases.version>
|
||||
</properties>
|
||||
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<artifactId>ultradepository</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.2.5</version>
|
||||
<version>1.3.9</version>
|
||||
|
||||
<name>UltraDepository</name>
|
||||
<description>超级仓库插件,支持设定不同物品的存储仓库。</description>
|
||||
@@ -112,35 +115,43 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-database</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.16.3-R0.1-SNAPSHOT</version>
|
||||
<artifactId>easysql-beecp</artifactId>
|
||||
<version>${easysql.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.10.9</version>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>githubreleases4j</artifactId>
|
||||
<version>${ghreleases.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<version>3.2.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.19-R0.1-20220725.090125-47</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.12.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<version>1.7.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -172,7 +183,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.1</version>
|
||||
<version>3.5.6</version>
|
||||
<configuration>
|
||||
<useSystemClassLoader>false</useSystemClassLoader>
|
||||
</configuration>
|
||||
@@ -180,7 +191,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.12.0</version>
|
||||
<configuration>
|
||||
<classifier>javadoc</classifier>
|
||||
<links>
|
||||
@@ -204,10 +215,10 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.15.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
<compilerArgument>-parameters</compilerArgument>
|
||||
</configuration>
|
||||
@@ -215,12 +226,12 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.5.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.4.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -233,7 +244,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<version>3.6.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -244,6 +255,8 @@
|
||||
</executions>
|
||||
|
||||
<configuration>
|
||||
<finalName>${project.name}-${project.version}</finalName>
|
||||
<outputDirectory>${project.basedir}/asset/</outputDirectory>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<relocations>
|
||||
<relocation>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:recommended"
|
||||
],
|
||||
"packageRules": [
|
||||
{
|
||||
"matchUpdateTypes": ["minor", "patch"],
|
||||
"matchCurrentVersion": "!/^0/",
|
||||
"automerge": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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,169 +1,35 @@
|
||||
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.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 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 {
|
||||
|
||||
private static UltraDepository instance;
|
||||
|
||||
private static DataStorage storage;
|
||||
|
||||
private static UserManager userManager;
|
||||
private static EconomyManager economyManager;
|
||||
private static DepositoryManager depositoryManager;
|
||||
|
||||
public UltraDepository() {
|
||||
super(new EasyPluginMessageProvider.zh_CN());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean initialize() {
|
||||
|
||||
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("加载用户系统...");
|
||||
userManager = new UserManager();
|
||||
|
||||
log("加载经济系统...");
|
||||
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
|
||||
economyManager = new EconomyManager();
|
||||
if (!economyManager.initialize()) {
|
||||
error("经济系统初始化失败,关闭出售功能。");
|
||||
}
|
||||
} else {
|
||||
log(" &7[-] 检测到未安装Vault,关闭出售功能。");
|
||||
}
|
||||
|
||||
log("加载仓库管理器...");
|
||||
depositoryManager = new DepositoryManager();
|
||||
getDepositoryManager().loadDepositories();
|
||||
GUI.initialize(this);
|
||||
|
||||
log("注册监听器...");
|
||||
regListener(new UserListener());
|
||||
regListener(new CollectListener());
|
||||
|
||||
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();
|
||||
}));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutdown() {
|
||||
if (!isInitialized()) return;
|
||||
|
||||
log("保存现有用户数据...");
|
||||
getUserManager().saveAll();
|
||||
getUserManager().getDataCache().clear();
|
||||
|
||||
log("释放存储源...");
|
||||
getStorage().shutdown();
|
||||
|
||||
log("卸载监听器...");
|
||||
Bukkit.getServicesManager().unregisterAll(this);
|
||||
}
|
||||
public class UltraDepository {
|
||||
|
||||
public static DataStorage getStorage() {
|
||||
return storage;
|
||||
return Main.getInstance().getStorage();
|
||||
}
|
||||
|
||||
public static UltraDepository getInstance() {
|
||||
return instance;
|
||||
public static Main getInstance() {
|
||||
return Main.getInstance();
|
||||
}
|
||||
|
||||
public static UserManager getUserManager() {
|
||||
return userManager;
|
||||
return Main.getInstance().getUserManager();
|
||||
}
|
||||
|
||||
public static EconomyManager getEconomyManager() {
|
||||
return economyManager;
|
||||
return Main.getInstance().getEconomyManager();
|
||||
}
|
||||
|
||||
public static DepositoryManager getDepositoryManager() {
|
||||
return depositoryManager;
|
||||
return Main.getInstance().getDepositoryManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugging() {
|
||||
return PluginConfig.DEBUG.get();
|
||||
public static ConfigManager getConfigManager() {
|
||||
return Main.getInstance().getConfigManager();
|
||||
}
|
||||
|
||||
@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,7 +6,7 @@ import cc.carm.lib.easyplugin.configuration.impl.ConfigSound;
|
||||
import cc.carm.lib.easyplugin.configuration.message.ConfigMessage;
|
||||
import cc.carm.lib.easyplugin.configuration.message.ConfigMessageList;
|
||||
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 org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
@@ -21,6 +21,10 @@ public class PluginConfig {
|
||||
"metrics", Boolean.class, true
|
||||
);
|
||||
|
||||
public static final ConfigValue<Boolean> CHECK_UPDATE = new ConfigValue<>(
|
||||
"check-update", Boolean.class, true
|
||||
);
|
||||
|
||||
public static final ConfigStringCast<StorageMethod> STORAGE_METHOD = new ConfigStringCast<>(
|
||||
"storage.method", StorageMethod::read, StorageMethod.YAML
|
||||
);
|
||||
@@ -65,14 +69,16 @@ public class PluginConfig {
|
||||
public static class AdditionalLore {
|
||||
|
||||
public static final ConfigMessageList AVAILABLE_FOR_SALE = new ConfigMessageList(
|
||||
ConfigManager::getPluginConfig, "general.additional-lore.available-for-sale",
|
||||
() -> UltraDepository.getConfigManager().getPluginConfig(),
|
||||
"general.additional-lore.available-for-sale",
|
||||
new String[]{},
|
||||
new String[]{
|
||||
"%(item_name)", "%(amount)", "%(price)", "%(sold)", "%(remain)", "%(limit)"
|
||||
});
|
||||
|
||||
public static final ConfigMessageList NOT_FOR_SALE = new ConfigMessageList(
|
||||
ConfigManager::getPluginConfig, "general.additional-lore.not-for-sale",
|
||||
() -> UltraDepository.getConfigManager().getPluginConfig(),
|
||||
"general.additional-lore.not-for-sale",
|
||||
new String[]{}, new String[]{
|
||||
"%(item_name)", "%(amount)"
|
||||
});
|
||||
@@ -85,14 +91,15 @@ public class PluginConfig {
|
||||
*/
|
||||
public static class ClickLore {
|
||||
public static final ConfigMessageList AVAILABLE_FOR_SALE = new ConfigMessageList(
|
||||
ConfigManager::getPluginConfig,
|
||||
() -> UltraDepository.getConfigManager().getPluginConfig(),
|
||||
"general.click-lore.available-for-sale",
|
||||
new String[]{}, new String[]{
|
||||
"%(item_name)", "%(amount)", "%(price)"
|
||||
});
|
||||
|
||||
public static final ConfigMessageList NOT_FOR_SALE = new ConfigMessageList(
|
||||
ConfigManager::getPluginConfig, "general.click-lore.not-for-sale",
|
||||
() -> UltraDepository.getConfigManager().getPluginConfig(),
|
||||
"general.click-lore.not-for-sale",
|
||||
new String[]{},
|
||||
new String[]{
|
||||
"%(item_name)", "%(amount)"
|
||||
@@ -101,7 +108,7 @@ public class PluginConfig {
|
||||
|
||||
|
||||
public static final ConfigMessageList CLICK_LORE = new ConfigMessageList(
|
||||
ConfigManager::getPluginConfig,
|
||||
() -> UltraDepository.getConfigManager().getPluginConfig(),
|
||||
"general.click-lore",
|
||||
new String[]{}, new String[]{
|
||||
"%(item_name)", "%(amount)", "%(price)"
|
||||
@@ -114,7 +121,7 @@ public class PluginConfig {
|
||||
|
||||
|
||||
public static final ConfigMessage TITLE = new ConfigMessage(
|
||||
ConfigManager::getPluginConfig,
|
||||
() -> UltraDepository.getConfigManager().getPluginConfig(),
|
||||
"general.sell-gui.title",
|
||||
"&a&l出售", new String[]{
|
||||
"%(item_name)", "%(backpack_name)"
|
||||
|
||||
@@ -95,4 +95,8 @@ public class PluginMessages extends MessagesRoot {
|
||||
"&f数目输入错误,请输入正确的数字!"
|
||||
);
|
||||
|
||||
public static final EasyMessage LOAD_FAILED = new EasyMessage(
|
||||
"&c您的背包数据未被正确加载,请重新进入!"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package cc.carm.plugin.ultradepository.hooker;
|
||||
|
||||
import cc.carm.lib.githubreleases4j.GithubReleases4J;
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
|
||||
public class UpdateChecker {
|
||||
|
||||
public static void checkUpdate(Main plugin) {
|
||||
plugin.getScheduler().runAsync(() -> {
|
||||
|
||||
Integer behindVersions = GithubReleases4J.getVersionBehind(
|
||||
"CarmJos", "UltraDepository",
|
||||
plugin.getDescription().getVersion()
|
||||
);
|
||||
|
||||
String downloadURL = GithubReleases4J.getReleasesURL("CarmJos", "UltraDepository");
|
||||
|
||||
if (behindVersions == null) {
|
||||
plugin.error("检查更新失败,请您定期查看插件是否更新,避免安全问题。");
|
||||
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);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package cc.carm.plugin.ultradepository.listener;
|
||||
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.configuration.PluginMessages;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -19,15 +20,13 @@ public class UserListener implements Listener {
|
||||
if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
||||
return;
|
||||
}
|
||||
UUID uuid = event.getUniqueId();
|
||||
UltraDepository.getInstance().debug("尝试加载玩家 " + event.getName() + " 的数据...");
|
||||
UltraDepository.getUserManager().getDataCache().put(uuid, UltraDepository.getUserManager().loadData(uuid));
|
||||
UltraDepository.getUserManager().loadDataCache(event.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPreLoginMonitor(AsyncPlayerPreLoginEvent event) {
|
||||
if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
||||
UltraDepository.getUserManager().getDataCache().remove(event.getUniqueId());
|
||||
UltraDepository.getUserManager().removeDataCache(event.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +35,7 @@ public class UserListener implements Listener {
|
||||
UserData data = UltraDepository.getUserManager().getData(e.getPlayer().getUniqueId());
|
||||
if (data == null) {
|
||||
e.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
e.setKickMessage(UltraDepository.getInstance().getName() + " 数据未被正确加载,请重新进入。");
|
||||
e.setKickMessage(PluginMessages.LOAD_FAILED.get(e.getPlayer()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +43,8 @@ public class UserListener implements Listener {
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
UltraDepository.getInstance().getScheduler().runAsync(() -> UltraDepository.getUserManager().unloadData(playerUUID, true));
|
||||
UltraDepository.getInstance().getScheduler()
|
||||
.runAsync(() -> UltraDepository.getUserManager().unloadData(playerUUID, true));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,33 +7,37 @@ import cc.carm.lib.easyplugin.configuration.language.MessagesInitializer;
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.configuration.PluginMessages;
|
||||
import cc.carm.plugin.ultradepository.util.JarUtil;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
private static FileConfig pluginConfiguration;
|
||||
private static MessagesConfig messageConfiguration;
|
||||
private final JavaPlugin plugin;
|
||||
private FileConfig pluginConfiguration;
|
||||
private MessagesConfig messageConfiguration;
|
||||
|
||||
public static boolean initialize() {
|
||||
UltraDepository udPlugin = UltraDepository.getInstance();
|
||||
public ConfigManager(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public boolean initialize() {
|
||||
|
||||
try {
|
||||
File configFile = new File(udPlugin.getDataFolder(), "config.yml");
|
||||
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
if (!configFile.exists()) {
|
||||
//没找到配置文件,可能是第一次加载此插件
|
||||
//把一些英文版的东西复制出来,方便英文用户使用。
|
||||
UltraDepository.getInstance().log(" 未找到配置文件,生成默认配置...");
|
||||
JarUtil.copyFolderFromJar(
|
||||
"i18n", udPlugin.getDataFolder(),
|
||||
"i18n", plugin.getDataFolder(),
|
||||
JarUtil.CopyOption.COPY_IF_NOT_EXIST
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
pluginConfiguration = new FileConfig(udPlugin, "config.yml");
|
||||
messageConfiguration = new MessagesConfig(udPlugin, "messages.yml");
|
||||
pluginConfiguration = new FileConfig(plugin, "config.yml");
|
||||
messageConfiguration = new MessagesConfig(plugin, "messages.yml");
|
||||
|
||||
FileConfig.pluginConfiguration = () -> pluginConfiguration;
|
||||
FileConfig.messageConfiguration = () -> messageConfiguration;
|
||||
@@ -47,15 +51,15 @@ public class ConfigManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static FileConfig getPluginConfig() {
|
||||
public FileConfig getPluginConfig() {
|
||||
return pluginConfiguration;
|
||||
}
|
||||
|
||||
public static MessagesConfig getMessageConfig() {
|
||||
public MessagesConfig getMessageConfig() {
|
||||
return messageConfiguration;
|
||||
}
|
||||
|
||||
public static void reload() {
|
||||
public void reload() {
|
||||
try {
|
||||
getPluginConfig().reload();
|
||||
getMessageConfig().reload();
|
||||
@@ -64,7 +68,7 @@ public class ConfigManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveConfig() {
|
||||
public void saveConfig() {
|
||||
try {
|
||||
getPluginConfig().save();
|
||||
getMessageConfig().save();
|
||||
|
||||
@@ -6,6 +6,7 @@ import cc.carm.plugin.ultradepository.configuration.PluginMessages;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.Depository;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.DepositoryItem;
|
||||
import cc.carm.plugin.ultradepository.event.DepositoryCollectItemEvent;
|
||||
import cc.carm.plugin.ultradepository.util.JarUtil;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@@ -18,6 +19,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -46,9 +48,13 @@ public class DepositoryManager {
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
|
||||
UltraDepository.getInstance().saveResource(
|
||||
"depositories/.example-depository.yml", false
|
||||
try {
|
||||
JarUtil.copyFolderFromJar(
|
||||
"depositories", UltraDepository.getInstance().getDataFolder(),
|
||||
JarUtil.CopyOption.COPY_IF_NOT_EXIST
|
||||
);
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
|
||||
} else if (folder.isDirectory()) {
|
||||
folder.delete();
|
||||
|
||||
@@ -4,6 +4,7 @@ import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import cc.carm.plugin.ultradepository.storage.DataStorage;
|
||||
import cc.carm.plugin.ultradepository.util.DateIntUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -20,6 +21,27 @@ public class UserManager {
|
||||
return dataCache;
|
||||
}
|
||||
|
||||
public void loadPlayersData() {
|
||||
if (Bukkit.getOnlinePlayers().size() < 1) return;
|
||||
|
||||
UltraDepository.getInstance().log("加载当前在线玩家数据...");
|
||||
// 用于热加载时重载玩家数据。
|
||||
Bukkit.getOnlinePlayers().forEach(player -> loadDataCache(player.getUniqueId()));
|
||||
}
|
||||
|
||||
public @NotNull UserData loadDataCache(@NotNull UUID userUUID) {
|
||||
UserData data = loadData(userUUID);
|
||||
UltraDepository.getUserManager().getDataCache().put(userUUID, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
public boolean removeDataCache(@NotNull UUID userUUID) {
|
||||
boolean contains = getDataCache().containsKey(userUUID);
|
||||
getDataCache().remove(userUUID);
|
||||
return contains;
|
||||
}
|
||||
|
||||
public @Nullable UserData getData(@NotNull UUID userUUID) {
|
||||
return getDataCache().get(userUUID);
|
||||
}
|
||||
@@ -32,7 +54,7 @@ public class UserManager {
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
DataStorage storage = UltraDepository.getStorage();
|
||||
UltraDepository.getInstance().debug("正通过 " + storage.getClass().getSimpleName() + " 加载 " + userUUID + " 的用户数据...");
|
||||
UltraDepository.getInstance().debug("正通过 " + storage.getClass().getSimpleName() + " 加载 " + userUUID + " 的用户数据...(" + System.currentTimeMillis() + ")");
|
||||
UserData data = UltraDepository.getStorage().loadData(userUUID);
|
||||
|
||||
if (data == null) {
|
||||
@@ -56,7 +78,7 @@ public class UserManager {
|
||||
UserData data = getData(uuid);
|
||||
if (data == null) return;
|
||||
if (save) saveData(data);
|
||||
dataCache.remove(uuid);
|
||||
removeDataCache(uuid);
|
||||
}
|
||||
|
||||
public void saveData(UserData data) {
|
||||
@@ -64,7 +86,7 @@ public class UserManager {
|
||||
long start = System.currentTimeMillis();
|
||||
DataStorage storage = UltraDepository.getStorage();
|
||||
|
||||
UltraDepository.getInstance().debug("正通过 " + storage.getClass().getSimpleName() + " 保存 " + data.getUserUUID() + " 的用户数据...");
|
||||
UltraDepository.getInstance().debug("正通过 " + storage.getClass().getSimpleName() + " 保存 " + data.getUserUUID() + " 的用户数据...(" + System.currentTimeMillis() + ")");
|
||||
storage.saveUserData(data);
|
||||
|
||||
UltraDepository.getInstance().debug("通过 " + storage.getClass().getSimpleName() + " 保存 " + data.getUserUUID() + " 的用户数据完成," +
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cc.carm.plugin.ultradepository.storage;
|
||||
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import cc.carm.plugin.ultradepository.manager.UserManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -8,14 +9,38 @@ import java.util.UUID;
|
||||
|
||||
public interface DataStorage {
|
||||
|
||||
|
||||
/**
|
||||
* 在插件加载存储源时执行。
|
||||
*
|
||||
* @return 是否初始化成功
|
||||
*/
|
||||
boolean initialize();
|
||||
|
||||
/**
|
||||
* 在插件被卸载时执行。
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* 用于加载用户数据的方法。<b>该方法将会被异步运行!</b>
|
||||
* <br>该方法一般无需自行执行,见 {@link UserManager#loadData(UUID)}
|
||||
* <br>
|
||||
* <br>若不存在该用户的数据,请返回 null 。
|
||||
* <br>若加载出现任何错误,请抛出异常。
|
||||
*
|
||||
* @param uuid 用户UUID
|
||||
* @throws Exception 当出现任何错误时抛出
|
||||
*/
|
||||
@Nullable
|
||||
UserData loadData(@NotNull UUID uuid) throws Exception;
|
||||
|
||||
/**
|
||||
* 用于保存用户数据的方法。 <b>该方法将会被异步运行!</b>
|
||||
* <br>该方法一般无需自行执行,见 {@link UserManager#saveData(UserData)}
|
||||
*
|
||||
* @param data 用户数据
|
||||
* @throws Exception 当出现任何错误时抛出
|
||||
*/
|
||||
void saveUserData(@NotNull UserData data) throws Exception;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package cc.carm.plugin.ultradepository.storage.impl;
|
||||
|
||||
import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
|
||||
import cc.carm.lib.easyplugin.database.DatabaseTable;
|
||||
import cc.carm.lib.easyplugin.database.EasySQL;
|
||||
import cc.carm.lib.easyplugin.database.api.SQLManager;
|
||||
import cc.carm.lib.easyplugin.database.api.action.query.PreparedQueryAction;
|
||||
import cc.carm.lib.easysql.EasySQL;
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.lib.easysql.api.action.query.PreparedQueryAction;
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import cc.carm.plugin.ultradepository.util.DatabaseTable;
|
||||
import cc.carm.plugin.ultradepository.util.DateIntUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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}
|
||||
@@ -11,6 +11,11 @@ debug: false
|
||||
# 当然,您也可以选择在这里关闭,或在plugins/bStats下的配置文件中关闭。
|
||||
metrics: true
|
||||
|
||||
# 检查更新设定
|
||||
# 该选项用于插件判断是否要检查更新,若您不希望插件检查更新并提示您,可以选择关闭。
|
||||
# 检查更新为异步操作,绝不会影响性能与使用体验。
|
||||
check-update: true
|
||||
|
||||
# 存储相关配置
|
||||
# 注意:存储配置不会通过重载指令生效,如有修改请重新启动服务器。
|
||||
storage:
|
||||
@@ -27,7 +32,7 @@ storage:
|
||||
# 选择 database 存储方式时的数据库配置
|
||||
mysql:
|
||||
# 数据库驱动路径
|
||||
driver: "com.mysql.jdbc.Driver"
|
||||
driver: "com.mysql.cj.jdbc.Driver"
|
||||
url: "jdbc:mysql://127.0.0.1:3306/<db-name>"
|
||||
table: "ud_data" # 插件表名,允许自定义
|
||||
username: "username"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
main: cc.carm.plugin.ultradepository.UltraDepository
|
||||
main: cc.carm.plugin.ultradepository.Main
|
||||
name: UltraDepository
|
||||
|
||||
version: ${project.version}
|
||||
@@ -15,6 +15,10 @@ softdepend:
|
||||
- PlaceholderAPI
|
||||
- Vault
|
||||
|
||||
libraries:
|
||||
- cc.carm.lib:easysql-beecp:${easysql.version}
|
||||
- cc.carm.lib:githubreleases4j:${ghreleases.version}
|
||||
|
||||
commands:
|
||||
"UltraDepository":
|
||||
description: "超级仓库的主指令"
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import cc.carm.lib.githubreleases4j.GithubRelease;
|
||||
import cc.carm.lib.githubreleases4j.GithubReleases4J;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ReleasesTest {
|
||||
|
||||
@Test
|
||||
public void onTest() {
|
||||
|
||||
List<GithubRelease> releases = GithubReleases4J.listReleases("CarmJos", "UltraDepository");
|
||||
|
||||
for (GithubRelease release : releases) {
|
||||
System.out.println("#" + release.getID() + " (:" + release.getTagName() + ")" + " " + release.getName());
|
||||
System.out.println("- " + release.getHTMLUrl());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user