mirror of
https://github.com/CarmJos/UltraDepository.git
synced 2026-06-05 00:58:22 +08:00
Compare commits
49 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| afd62a493d | |||
| c841a7b1b3 | |||
| dc57e822b5 | |||
| 54cc9c070b | |||
| fa07564548 | |||
| 7138d20357 | |||
| 379068b440 | |||
| 23e900cf3f | |||
| 9b25c8574e | |||
| 23161a48bd | |||
| 7153661f86 | |||
| 19a26cb9b8 | |||
| c2eeddedcb | |||
| 8538aa2be8 | |||
| f001ac0010 | |||
| 988fe600ce | |||
| 52df1863f4 | |||
| 4c46af55d0 | |||
| 123ae0b039 | |||
| dd5793427a | |||
| 6bf8e261d0 | |||
| fcdda893f1 | |||
| 27ad14c7ab | |||
| b6a6502713 | |||
| d8d589ba76 | |||
| 52a0d28249 | |||
| 2f0a3d283b | |||
| 725ea4b4ee | |||
| e256278453 | |||
| 66dafb39b5 | |||
| 4640a8098d | |||
| 62c8350b8b | |||
| d0361c260d | |||
| fe256dc916 | |||
| 976d9c32ff | |||
| 64acb25bfc | |||
| e01aa6207e | |||
| 8766b3a45e | |||
| 1894761f7c | |||
| 6a014cca48 | |||
| 1ee70b2794 | |||
| 3a5e5e8fc4 | |||
| 6aa5c40c3f | |||
| f98a7ce025 | |||
| c5230c0fbd | |||
| 56aba62ffc | |||
| affe047789 | |||
| 6662ae35fb | |||
| e95ca412f8 |
@@ -11,6 +11,72 @@
|
||||
|
||||
# UltraDepository 帮助介绍文档
|
||||
|
||||
## 插件介绍目录
|
||||
|
||||
- 使用示例
|
||||
- [仓库配置文件预设示例](../.examples/depositories)
|
||||
- [用户数据示例](../.examples/userdata)
|
||||
- [YAML格式](../.examples/userdata/uuid.yml)
|
||||
- [JSON格式](../.examples/userdata/uuid.json)
|
||||
- [MySQL格式](../.examples/userdata/database.sql)
|
||||
- [开发](develop)
|
||||
- [自定义存储源](develop/use-custome-storage.md)
|
||||
|
||||
|
||||
## [开发文档](JAVADOC-README.md)
|
||||
|
||||
基于 [Github Pages](https://pages.github.com/) 搭建,请访问 [JavaDoc](https://carmjos.github.io/UltraDepository) 。
|
||||
|
||||
## 依赖方式
|
||||
|
||||
### Maven 依赖
|
||||
|
||||
```xml
|
||||
|
||||
<project>
|
||||
<repositories>
|
||||
|
||||
<repository>
|
||||
<!--采用github依赖库,安全稳定,但需要配置 (推荐)-->
|
||||
<id>UltraDepository</id>
|
||||
<name>GitHub Packages</name>
|
||||
<url>https://maven.pkg.github.com/CarmJos/UltraDepository</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<!--采用我的私人依赖库,简单方便,但可能因为变故而无法使用-->
|
||||
<id>carm-repo</id>
|
||||
<name>Carm's Repo</name>
|
||||
<url>https://repo.carm.cc/repository/maven-public/</url>
|
||||
</repository>
|
||||
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<artifactId>ultradepository</artifactId>
|
||||
<version>[LATEST RELEASE]</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
```
|
||||
|
||||
### Gradle 依赖
|
||||
|
||||
```groovy
|
||||
repositories {
|
||||
// 采用github依赖库,安全稳定,但需要配置 (推荐)
|
||||
maven { url 'https://maven.pkg.github.com/CarmJos/EasyPlugin' }
|
||||
|
||||
// 采用我的私人依赖库,简单方便,但可能因为变故而无法使用
|
||||
maven { url 'https://repo.carm.cc/repository/maven-public/' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly "cc.carm.plugin:ultradepository:[LATEST RELEASE]"
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,105 @@
|
||||
# 开发 - 自定义存储源
|
||||
|
||||
在某些情况下,插件提供的几种存储方式并不能满足您的需求,此时您可以选择在您自己的插件中自定义本插件的存储源。
|
||||
|
||||
## 1. 修改 plugin.yml
|
||||
|
||||
您需要在您自己的插件中声明依赖了本插件,即在 `plugin.yml` 中添加以下内容:
|
||||
|
||||
```yaml
|
||||
softdepend:
|
||||
- UltraDepository
|
||||
```
|
||||
|
||||
添加后,Bukkit会让您的插件在本插件之后加载,此时您就可以应用您的存储源。
|
||||
|
||||
## 2. 依赖本插件
|
||||
|
||||
请依据 [开发指南](../README.md) 中的依赖介绍部分完成对本插件的依赖。
|
||||
|
||||
## 3. 实现 DataStorage
|
||||
|
||||
您需要在您的插件中实现 DataStorage 类,并实现其中的功能,他看起来像是这样的:
|
||||
|
||||
```java
|
||||
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import cc.carm.plugin.ultradepository.storage.DataStorage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class CustomStorage implements DataStorage {
|
||||
|
||||
@Override
|
||||
public boolean initialize() {
|
||||
//初始化存储,在这里可进行连接数据库、创建表等操作。
|
||||
|
||||
return true; //返回true代表初始化成功,若失败则插件将不再加载
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
// 插件卸载时触发,一般用于释放连接池。
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable UserData loadData(@NotNull UUID uuid) throws Exception {
|
||||
// 加载玩家数据部分
|
||||
// 若抛出错误,则视为加载出错,会采用临时玩家数据的形式保证插件继续运行,同时在后台提示检查。
|
||||
// 返回空则代表暂无该玩家数据,会自动视作新数据
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUserData(@NotNull UserData data) throws Exception {
|
||||
// 保存玩家数据部分
|
||||
// 若抛出错误,则视为保存出错,将在后台提示检查。
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
您也可以 [点击这里](../../src/main/java/cc/carm/plugin/ultradepository/storage/impl) 参考本插件提供的其他已实现的存储方式,并在此基础上开发您的自定义存储。
|
||||
|
||||
> 若您需要JSON格式存储,可以直接继承 [`JSONStorage`](../../src/main/java/cc/carm/plugin/ultradepository/storage/impl/JSONStorage.java) ,并重写相关方法。
|
||||
|
||||
## 4. 应用您的存储
|
||||
|
||||
您需要在插件加载(`onLoad()`)时,应用您的自定义存储。
|
||||
|
||||
```java
|
||||
|
||||
import cc.carm.plugin.ultradepository.storage.DataStorage;
|
||||
import cc.carm.plugin.ultradepository.storage.StorageMethod;
|
||||
import cc.carm.plugin.ultradepository.storage.impl.CustomStorage;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class YourPlugin extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
|
||||
// 应用您的存储方式
|
||||
StorageMethod.CUSTOM.setStorageSupplier(new Supplier<DataStorage>() {
|
||||
@Override
|
||||
public DataStorage get() {
|
||||
return new CustomStorage();
|
||||
}
|
||||
});
|
||||
|
||||
// 简化后大概长这样(lamda)
|
||||
StorageMethod.CUSTOM.setStorageSupplier(CustomStorage::new);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 5. 修改本插件的 config.yml
|
||||
|
||||
您需要修改本插件的 `config.yml` 中的 `storage.method` 为 **CUSTOM** 。
|
||||
|
||||
修改完成后,在插件下次启动时就将应用您实现的 **DataStorage** 从而完成自定义存储源。
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
## 详细示例
|
||||
|
||||
您可以 [点击这里](full-example.yml) 查看一份详细的示例。
|
||||
您可以 [点击这里](../../src/main/resources/depositories/.example-depository.yml) 查看一份详细的示例。
|
||||
|
||||
## 使用须知
|
||||
|
||||
预设配置基于 MineCraft 1.16 实现,更低版本可能无法使用。
|
||||
预设配置基于 MineCraft 1.16 实现,理论上支持更高版本使用。
|
||||
|
||||
## 如何使用?
|
||||
|
||||
@@ -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))
|
||||
|
||||

|
||||
@@ -0,0 +1,2 @@
|
||||
INSERT INTO `ub_data`(`uuid`, `data`, `day`)
|
||||
VALUES ('<UUID>', '{"date":20220103,"depositories":{"miner":{"DIAMOND:0":{"sold":102,"amount":399}}}}', '20220103');
|
||||
@@ -1,41 +1 @@
|
||||
{
|
||||
"farmer": {},
|
||||
"hunter": {
|
||||
"CHICKEN:0": {
|
||||
"amount": 3
|
||||
},
|
||||
"FEATHER:0": {
|
||||
"amount": 2
|
||||
}
|
||||
},
|
||||
"miner": {
|
||||
"COAL:0": {
|
||||
"amount": 9,
|
||||
"sold": 10
|
||||
},
|
||||
"LAPIS_LAZULI:0": {
|
||||
"amount": 9
|
||||
},
|
||||
"REDSTONE:0": {
|
||||
"sold": 129
|
||||
},
|
||||
"COBBLESTONE:0": {
|
||||
"amount": 12
|
||||
},
|
||||
"CLAY_BALL:0": {
|
||||
"amount": 112
|
||||
},
|
||||
"DIAMOND:0": {
|
||||
"amount": 975,
|
||||
"sold": 1500
|
||||
}
|
||||
},
|
||||
"fishman": {
|
||||
"COD:0": {
|
||||
"amount": 3
|
||||
},
|
||||
"PUFFERFISH:0": {
|
||||
"amount": 64
|
||||
}
|
||||
}
|
||||
}
|
||||
{"date":20220103,"depositories":{"miner":{"DIAMOND:0":{"sold":102,"amount":399}}}}
|
||||
@@ -1,30 +1,30 @@
|
||||
---
|
||||
name: 问题提交
|
||||
about: 提交并描述问题,帮助我们对其进行检查与修复。
|
||||
about: 描述问题并提交,帮助我们对其进行检查与修复。
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**问题简述**
|
||||
### **问题简述**
|
||||
用简短的话语描述一下大概问题。
|
||||
|
||||
**问题来源**
|
||||
### **问题来源**
|
||||
描述一下通过哪些操作才发现的问题,如:
|
||||
1. 打开 '...'
|
||||
2. 点击了 '....'
|
||||
3. 出现了报错 '....'
|
||||
|
||||
**预期结果**(可选)
|
||||
### **预期结果**(可选)
|
||||
如果问题不发生,应该是什么情况
|
||||
|
||||
**问题截图/问题报错**
|
||||
### **问题截图/问题报错**
|
||||
如果有报错或输出,请提供截图。
|
||||
|
||||
**操作环境**
|
||||
### *操作环境**
|
||||
请在后台输入 `version` 并复制相关输出。
|
||||
|
||||
|
||||
**其他补充**
|
||||
### **其他补充**
|
||||
如有其他补充,可以在这里描述。
|
||||
|
||||
@@ -7,14 +7,14 @@ assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**功能简述**
|
||||
### **功能简述**
|
||||
简单的描述一下你想要的功能
|
||||
|
||||
**需求来源**
|
||||
### **需求来源**
|
||||
简单的描述一下为什么需要这个功能。
|
||||
|
||||
**功能参考**(可选)
|
||||
### **功能参考**(可选)
|
||||
如果有相关功能的参考,如文本、截图,请提供给我们。
|
||||
|
||||
**附加内容**
|
||||
### **附加内容**
|
||||
如果有什么小细节需要重点注意,请在这里告诉我们。
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
name: "CodeQL Analysis"
|
||||
|
||||
on:
|
||||
push:
|
||||
|
||||
@@ -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: Deploy
|
||||
name: Deploy & Upload
|
||||
|
||||
on:
|
||||
# 支持手动触发构建
|
||||
@@ -26,8 +26,65 @@ jobs:
|
||||
server-id: github
|
||||
server-username: MAVEN_USERNAME
|
||||
server-password: MAVEN_TOKEN
|
||||
- name: "Deploy"
|
||||
|
||||
- name: "Maven Deploy"
|
||||
run: mvn -B deploy --file pom.xml -DskipTests
|
||||
env:
|
||||
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||
|
||||
- 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
|
||||
cp -vrf target/apidocs/* docs/
|
||||
cp -vrf .documentation/JAVADOC-README.md docs/README.md
|
||||
|
||||
- name: "Generate the Javadoc sitemap"
|
||||
id: sitemap
|
||||
uses: cicirello/generate-sitemap@v1
|
||||
with:
|
||||
base-url-path: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}
|
||||
path-to-root: docs
|
||||
|
||||
- name: "Output Javadoc stats"
|
||||
run: |
|
||||
echo "sitemap-path = ${{ steps.sitemap.outputs.sitemap-path }}"
|
||||
echo "url-count = ${{ steps.sitemap.outputs.url-count }}"
|
||||
echo "excluded-count = ${{ steps.sitemap.outputs.excluded-count }}"
|
||||
|
||||
- name: "Configure Git"
|
||||
env:
|
||||
DEPLOY_PRI: ${{secrets.DEPLOY_PRI}}
|
||||
run: |
|
||||
sudo timedatectl set-timezone "Asia/Shanghai"
|
||||
mkdir -p ~/.ssh/
|
||||
echo "$DEPLOY_PRI" > ~/.ssh/id_rsa
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
ssh-keyscan github.com >> ~/.ssh/known_hosts
|
||||
git config --global user.name 'CarmJos'
|
||||
git config --global user.email 'carm@carm.cc'
|
||||
|
||||
- name: "Commit Javadocs"
|
||||
run: |
|
||||
cd docs
|
||||
git init
|
||||
git remote add origin git@github.com:${{ github.repository }}.git
|
||||
git checkout -b gh-pages
|
||||
git add -A
|
||||
git commit -m "API Document generated."
|
||||
|
||||
- name: "Push javadocs"
|
||||
run: |
|
||||
cd docs
|
||||
git push origin HEAD:gh-pages --force
|
||||
@@ -1,73 +0,0 @@
|
||||
# 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: Javadoc
|
||||
|
||||
on:
|
||||
# 支持手动触发构建
|
||||
workflow_dispatch:
|
||||
release:
|
||||
# 创建release的时候触发
|
||||
types: [ published ]
|
||||
|
||||
jobs:
|
||||
api-website:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout the repo
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set up the Java JDK
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
|
||||
- name: Generate docs
|
||||
run: mvn clean package -DskipTests
|
||||
|
||||
- name: Copy to Location
|
||||
run: |
|
||||
rm -rf docs
|
||||
mkdir -vp docs
|
||||
cp -vrf target/apidocs/* docs/
|
||||
cp -vrf .documentation/JAVADOC-README.md docs/README.md
|
||||
|
||||
- name: Generate the sitemap
|
||||
id: sitemap
|
||||
uses: cicirello/generate-sitemap@v1
|
||||
with:
|
||||
base-url-path: https://carmjos.github.io/UltraDepository
|
||||
path-to-root: docs
|
||||
|
||||
- name: Output stats
|
||||
run: |
|
||||
echo "sitemap-path = ${{ steps.sitemap.outputs.sitemap-path }}"
|
||||
echo "url-count = ${{ steps.sitemap.outputs.url-count }}"
|
||||
echo "excluded-count = ${{ steps.sitemap.outputs.excluded-count }}"
|
||||
|
||||
- name: Configure Git
|
||||
env:
|
||||
DEPLOY_PRI: ${{secrets.DEPLOY_PRI}}
|
||||
run: |
|
||||
sudo timedatectl set-timezone "Asia/Shanghai"
|
||||
mkdir -p ~/.ssh/
|
||||
echo "$DEPLOY_PRI" > ~/.ssh/id_rsa
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
ssh-keyscan github.com >> ~/.ssh/known_hosts
|
||||
git config --global user.name 'CarmJos'
|
||||
git config --global user.email 'carm@carm.cc'
|
||||
|
||||
- name: Commit documentation changes
|
||||
run: |
|
||||
cd docs
|
||||
git init
|
||||
git remote add origin git@github.com:CarmJos/UltraDepository.git
|
||||
git checkout -b gh-pages
|
||||
git add -A
|
||||
git commit -m "API Document generated."
|
||||
- name: Push javadocs
|
||||
run: |
|
||||
cd docs
|
||||
git push origin HEAD:gh-pages --force
|
||||
|
||||
@@ -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: Build
|
||||
name: Project Build & Tests
|
||||
|
||||
on:
|
||||
# 支持手动触发构建
|
||||
|
||||
@@ -2,3 +2,4 @@
|
||||
/target/
|
||||
./*.iml
|
||||
*.iml
|
||||
asset/
|
||||
@@ -15,14 +15,26 @@
|
||||
[](https://opensource.org/licenses/GPL-3.0)
|
||||
[](https://github.com/CarmJos/UltraDepository/actions/workflows/maven.yml)
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
超级仓库插件,支持设定不同物品的存储仓库。
|
||||
|
||||
本插件基于Spigot实现,**理论上支持全版本**。
|
||||
本插件基于 Spigot(1.16.3) 实现,**理论上支持1.16后的全部版本**。
|
||||
|
||||
本插件由 [墨豆Mordo](https://www.zimrs.cn) 赞助本人开发,经过授权后开源。
|
||||
本插件由 [墨豆Mordo](https://www.mordo.cn)、[子墨Zimrs](https://www.zimrs.cn) 资助本人开发,经过授权后开源。
|
||||
|
||||
> 本插件已发布于 [MCBBS](https://www.mcbbs.net/forum.php?mod=viewthread&tid=1292631) 和 [SpigotMC]() 。
|
||||
|
||||
## 功能介绍
|
||||
|
||||
本插件允许配置多个不同功能的仓库,玩家通过 击杀生物/挖掘方块/捡起收集 获得的原版物品可以自动被放入仓库中。
|
||||
|
||||
进入仓库后的物品玩家可以选择拿出或直接按量出售,且每日的出售数量上限和每件物品的价格可以自定义。
|
||||
|
||||
插件支持针对不同的权限配置仓库的容量,由此可以制作付费享用的”作物仓库“、”药剂师仓库“、”伐木仓库“...
|
||||
|
||||
综上,该插件不但提供了一种功能特权,对其合理配置之后也将大大为玩家带来便利。
|
||||
|
||||
## 效果预览
|
||||
|
||||
@@ -50,7 +62,8 @@
|
||||
|
||||
## 插件依赖
|
||||
|
||||
- **[必须]** 插件本体基于 [Spigot-API](https://hub.spigotmc.org/stash/projects/SPIGOT)、[BukkitAPI](http://bukkit.org/) 实现。
|
||||
- **[必须]** 插件本体基于 [Spigot-API](https://hub.spigotmc.org/stash/projects/SPIGOT) 、 [BukkitAPI](http://bukkit.org/) 实现。
|
||||
- **[自带]** 插件功能基于 [EasyPlugin](https://github.com/CarmJos/EasyPlugin) 实现。
|
||||
- **[自带]** 数据部分基于 [EasySQL](https://github.com/CarmJos/EasySQL) 实现。
|
||||
- 本插件连接池使用 [BeeCP](https://github.com/Chris2018998/BeeCP) ,更轻量、快速。
|
||||
- **[推荐]** 变量部分基于 [PlaceholderAPI](https://www.spigotmc.org/resources/6245/) 实现。
|
||||
@@ -161,7 +174,6 @@
|
||||
<summary>展开查看所有权限</summary>
|
||||
|
||||
```text
|
||||
|
||||
# UltraDepository.use
|
||||
- 超级仓库的基本使用权限 (默认所有人都有)
|
||||
|
||||
@@ -176,11 +188,16 @@
|
||||
|
||||
# UltraDepository.auto.enable
|
||||
- 用于判断是否启用了自动收集功能
|
||||
- 若玩家有"UltraDepository.auto"权限,且玩家有该权限,则会开始为玩家自动收集物品。
|
||||
- 若玩家缺失该权限或“UltraDepository.auto”权限,则自动收集物品功能不会启用。
|
||||
- 您可以自己使用GUI创建一个按钮,后通过给玩家添加/删除该权限决定玩家是否开启自动收集。
|
||||
|
||||
# UltraDepository.silent
|
||||
- 拥有该权限将不再接收到放入背包的提示。
|
||||
- 您可以自己使用GUI创建一个按钮,后通过给玩家添加/删除该权限决定玩家是否开启收集提示。
|
||||
|
||||
# UltraDepository.admin
|
||||
- "超级仓库的管理权限"
|
||||
|
||||
```
|
||||
|
||||
</details>
|
||||
@@ -191,19 +208,27 @@
|
||||
|
||||
详见源文件。
|
||||
|
||||
### 消息配置文件 ([messages.yml](src/main/resources/messages.yml))
|
||||
### 消息配置文件 ([messages.yml](src/main/java/cc/carm/plugin/ultradepository/configuration/PluginMessages.java))
|
||||
|
||||
详见源文件。
|
||||
详见代码文件中默认值,相关文件将在首次运行时创建。
|
||||
|
||||
### 仓库配置文件 ([depositories/<仓库ID>.yml](.examples/depositories/full-example.yml))
|
||||
### 仓库配置文件 ([depositories/<仓库ID>.yml](src/main/resources/depositories/.example-depository.yml))
|
||||
|
||||
所有仓库配置均为单独的配置文件,存放于 `插件配置目录/depositories` 下,便于管理。
|
||||
|
||||
文件名即仓库的ID,**强烈推荐使用纯英文**,部分符号可能会影响正常读取,请避免使用。
|
||||
文件名即仓库的ID,**强烈推荐使用纯英文**。以`.`开头的仓库配置不会被加载。部分符号可能会影响正常读取,请避免使用。
|
||||
|
||||
随本项目预设了几个常用的仓库类型,可以 [在这里](.examples/depositories) 找到您需要的直接使用或加以修改后使用。
|
||||
随本项目预设了几个常用的仓库类型,可以 [在这里](.examples/depositories) 直接下载您需要的仓库配置加以修改后使用。
|
||||
|
||||
您也可以 [点击这里](.examples/depositories/full-example.yml) 查看一份*详细的仓库配置示例*,以制作您自己的仓库。
|
||||
您也可以 [点击这里](src/main/resources/depositories/.example-depository.yml) 查看一份*详细的仓库配置示例*,以制作您自己的仓库。
|
||||
|
||||
## 开发
|
||||
|
||||
详细开发介绍请 [点击这里](.documentation/README.md) , JavaDoc(最新Release) 请 [点击这里](https://carmjos.github.io/UltraDepository) 。
|
||||
|
||||
## 使用统计
|
||||
|
||||
[](https://bstats.org/plugin/bukkit/UltraDepository/13777)
|
||||
|
||||
## 支持与捐赠
|
||||
|
||||
|
||||
@@ -9,12 +9,13 @@
|
||||
<maven.compiler.target>11</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>
|
||||
</properties>
|
||||
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<artifactId>ultradepository</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.1.2</version>
|
||||
<version>1.3.3</version>
|
||||
|
||||
<name>UltraDepository</name>
|
||||
<description>超级仓库插件,支持设定不同物品的存储仓库。</description>
|
||||
@@ -28,6 +29,16 @@
|
||||
<url>https://www.carm.cc</url>
|
||||
<roles>
|
||||
<role>Main Developer</role>
|
||||
<role>Designer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>zimrs</id>
|
||||
<name>Zimrs</name>
|
||||
<email>zimrs@kar.red</email>
|
||||
<url>https://www.zimrs.cn</url>
|
||||
<roles>
|
||||
<role>Product Manager</role>
|
||||
</roles>
|
||||
</developer>
|
||||
</developers>
|
||||
@@ -60,17 +71,6 @@
|
||||
|
||||
<repositories>
|
||||
|
||||
<repository>
|
||||
<id>EasySQL</id>
|
||||
<url>https://maven.pkg.github.com/CarmJos/EasySQL</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>github</id>
|
||||
<name>GitHub Packages</name>
|
||||
<url>https://maven.pkg.github.com/CarmJos/UltraDepository</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>central</id>
|
||||
<url>https://repo1.maven.org/maven2/</url>
|
||||
@@ -83,8 +83,9 @@
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>nexus</id>
|
||||
<url>https://mvn.lumine.io/repository/maven-public/</url>
|
||||
<id>github</id>
|
||||
<name>GitHub Packages</name>
|
||||
<url>https://maven.pkg.github.com/CarmJos/*</url>
|
||||
</repository>
|
||||
|
||||
</repositories>
|
||||
@@ -93,15 +94,32 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easysql-beecp</artifactId>
|
||||
<version>0.2.3</version>
|
||||
<scope>compile</scope>
|
||||
<artifactId>easyplugin-main</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-configuration</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-gui</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<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.17-R0.1-SNAPSHOT</version>
|
||||
<version>1.16.3-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -112,6 +130,13 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
@@ -128,6 +153,20 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-bom</artifactId>
|
||||
<version>${easyplugin.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@@ -201,12 +240,23 @@
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
|
||||
<configuration>
|
||||
<finalName>${project.name}-${project.version}</finalName>
|
||||
<outputDirectory>${project.basedir}/asset/</outputDirectory>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>cc.carm.plugin.ultradepository.lib.bstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>cc.carm.lib.easyplugin</pattern>
|
||||
<shadedPattern>cc.carm.plugin.ultradepository.lib.easyplugin</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
|
||||
@@ -1,190 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository;
|
||||
|
||||
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.FileStorage;
|
||||
import cc.carm.plugin.ultradepository.storage.MySQLStorage;
|
||||
import cc.carm.plugin.ultradepository.util.ColorParser;
|
||||
import cc.carm.plugin.ultradepository.util.MessageUtil;
|
||||
import cc.carm.plugin.ultradepository.util.SchedulerUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
|
||||
private static Main instance;
|
||||
private static SchedulerUtils scheduler;
|
||||
|
||||
private static DataStorage storage;
|
||||
|
||||
private static UserManager userManager;
|
||||
private static EconomyManager economyManager;
|
||||
private static DepositoryManager depositoryManager;
|
||||
|
||||
boolean initialized = false;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
scheduler = new SchedulerUtils(this);
|
||||
outputPlugin();
|
||||
log(getName() + " " + getDescription().getVersion() + " &7开始加载...");
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
log("加载配置文件...");
|
||||
ConfigManager.initConfig();
|
||||
|
||||
log("初始化存储方式...");
|
||||
if (PluginConfig.STORAGE_METHOD.get().equalsIgnoreCase("mysql")) {
|
||||
log(" 正在使用 MySQL 进行数据存储");
|
||||
storage = new MySQLStorage();
|
||||
} else {
|
||||
log(" 正在使用 文件 进行数据存储");
|
||||
storage = new FileStorage();
|
||||
}
|
||||
|
||||
if (!storage.initialize()) {
|
||||
error("存储初始化失败,请检查配置文件。");
|
||||
setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
log("注册监听器...");
|
||||
regListener(new UserListener());
|
||||
regListener(new CollectListener());
|
||||
|
||||
log("注册指令...");
|
||||
registerCommand("UltraDepository", new DepositoryCommand(), new DepositoryCommand());
|
||||
|
||||
if (MessageUtil.hasPlaceholderAPI()) {
|
||||
log("注册变量...");
|
||||
new PAPIExpansion(this).register();
|
||||
} else {
|
||||
log("检测到未安装PlaceholderAPI,跳过变量注册。");
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
log("加载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (!initialized) return;
|
||||
outputPlugin();
|
||||
log(getName() + " " + getDescription().getVersion() + " 开始卸载...");
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
log("保存现有用户数据...");
|
||||
getUserManager().saveAll();
|
||||
|
||||
log("释放存储源...");
|
||||
getStorage().shutdown();
|
||||
|
||||
log("卸载监听器...");
|
||||
Bukkit.getServicesManager().unregisterAll(this);
|
||||
|
||||
log("卸载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
||||
}
|
||||
|
||||
public static DataStorage getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
public static SchedulerUtils getScheduler() {
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
public static UserManager getUserManager() {
|
||||
return userManager;
|
||||
}
|
||||
|
||||
public static EconomyManager getEconomyManager() {
|
||||
return economyManager;
|
||||
}
|
||||
|
||||
public static DepositoryManager getDepositoryManager() {
|
||||
return depositoryManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册监听器
|
||||
*
|
||||
* @param listener 监听器
|
||||
*/
|
||||
public static void regListener(@NotNull Listener listener) {
|
||||
Bukkit.getPluginManager().registerEvents(listener, getInstance());
|
||||
}
|
||||
|
||||
public static void log(@Nullable String message) {
|
||||
Bukkit.getConsoleSender().sendMessage(ColorParser.parse("[" + getInstance().getName() + "] " + message));
|
||||
}
|
||||
|
||||
public static void error(String message) {
|
||||
log("&c[ERROR] &r" + message);
|
||||
}
|
||||
|
||||
public static void debug(@Nullable String message) {
|
||||
if (PluginConfig.DEBUG.get()) log("[DEBUG] " + message);
|
||||
}
|
||||
|
||||
public static Main getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void registerCommand(String commandName,
|
||||
@NotNull CommandExecutor executor) {
|
||||
registerCommand(commandName, executor, null);
|
||||
}
|
||||
|
||||
public static void registerCommand(String commandName,
|
||||
@NotNull CommandExecutor executor,
|
||||
@Nullable TabCompleter tabCompleter) {
|
||||
PluginCommand command = Bukkit.getPluginCommand(commandName);
|
||||
if (command == null) return;
|
||||
command.setExecutor(executor);
|
||||
if (tabCompleter != null) command.setTabCompleter(tabCompleter);
|
||||
}
|
||||
|
||||
public static void outputPlugin() {
|
||||
log(" _ _ _ _ _____ _ _ ");
|
||||
log("| | | | | | | __ \\ (_) | ");
|
||||
log("| | | | | |_ _ __ __ _| | | | ___ _ __ ___ ___ _| |_ ___ _ __ _ _ ");
|
||||
log("| | | | | __| '__/ _` | | | |/ _ \\ '_ \\ / _ \\/ __| | __/ _ \\| '__| | | |");
|
||||
log("| |__| | | |_| | | (_| | |__| | __/ |_) | (_) \\__ \\ | || (_) | | | |_| |");
|
||||
log(" \\____/|_|\\__|_| \\__,_|_____/ \\___| .__/ \\___/|___/_|\\__\\___/|_| \\__, |");
|
||||
log(" | | __/ |");
|
||||
log(" |_| |___/ ");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
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("加载经济系统...");
|
||||
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();
|
||||
}));
|
||||
}
|
||||
|
||||
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",
|
||||
" "
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package cc.carm.plugin.ultradepository.command;
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
|
||||
import cc.carm.plugin.ultradepository.configuration.PluginMessages;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.Depository;
|
||||
@@ -9,8 +11,6 @@ import cc.carm.plugin.ultradepository.data.DepositoryData;
|
||||
import cc.carm.plugin.ultradepository.data.DepositoryItemData;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import cc.carm.plugin.ultradepository.ui.DepositoryGUI;
|
||||
import cc.carm.plugin.ultradepository.util.ColorParser;
|
||||
import cc.carm.plugin.ultradepository.util.MessageUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@@ -30,12 +30,12 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
|
||||
private boolean helpConsole(CommandSender sender) {
|
||||
PluginMessages.HELP_CONSOLE.send(sender);
|
||||
PluginMessages.Usages.CONSOLE.send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean helpPlayer(Player player) {
|
||||
PluginMessages.HELP_PLAYER.send(player);
|
||||
PluginMessages.Usages.PLAYER.send(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
return false;
|
||||
}
|
||||
if (args.length < 2) return helpPlayer(player);
|
||||
Depository depository = Main.getDepositoryManager().getDepository(args[1]);
|
||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
|
||||
if (depository == null) {
|
||||
PluginMessages.NO_DEPOSITORY.send(player);
|
||||
return true;
|
||||
@@ -64,13 +64,13 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
if (!player.hasPermission("UltraDepository.Command.Sell")) {
|
||||
return false;
|
||||
}
|
||||
if (!Main.getEconomyManager().isInitialized()) {
|
||||
if (!UltraDepository.getEconomyManager().isInitialized()) {
|
||||
PluginConfig.Sounds.SELL_FAIL.play(player);
|
||||
PluginMessages.NO_ECONOMY.send(player);
|
||||
return true;
|
||||
}
|
||||
if (args.length < 4) return helpPlayer(player);
|
||||
Depository depository = Main.getDepositoryManager().getDepository(args[1]);
|
||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
|
||||
if (depository == null) {
|
||||
PluginConfig.Sounds.SELL_FAIL.play(player);
|
||||
PluginMessages.NO_DEPOSITORY.send(player);
|
||||
@@ -95,7 +95,7 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
return true;
|
||||
}
|
||||
|
||||
UserData userData = Main.getUserManager().getData(player);
|
||||
UserData userData = UltraDepository.getUserManager().getData(player);
|
||||
DepositoryItemData itemData = userData.getItemData(item);
|
||||
int limit = item.getLimit();
|
||||
int sold = itemData.getSold();
|
||||
@@ -113,26 +113,26 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
return true;
|
||||
}
|
||||
|
||||
Main.getEconomyManager().sellItem(player, userData, itemData, amount);
|
||||
UltraDepository.getEconomyManager().sellItem(player, userData, item, amount);
|
||||
return true;
|
||||
}
|
||||
case "sellall": {
|
||||
if (!player.hasPermission("UltraDepository.Command.SellAll")) {
|
||||
return false;
|
||||
}
|
||||
if (!Main.getEconomyManager().isInitialized()) {
|
||||
if (!UltraDepository.getEconomyManager().isInitialized()) {
|
||||
PluginConfig.Sounds.SELL_FAIL.play(player);
|
||||
PluginMessages.NO_ECONOMY.send(player);
|
||||
return true;
|
||||
}
|
||||
UserData userData = Main.getUserManager().getData(player);
|
||||
UserData userData = UltraDepository.getUserManager().getData(player);
|
||||
|
||||
String depositoryID = args.length >= 2 ? args[1] : null;
|
||||
String itemID = args.length >= 3 ? args[2] : null;
|
||||
|
||||
Depository depository = null;
|
||||
if (depositoryID != null) {
|
||||
depository = Main.getDepositoryManager().getDepository(depositoryID);
|
||||
depository = UltraDepository.getDepositoryManager().getDepository(depositoryID);
|
||||
if (depository == null) {
|
||||
PluginConfig.Sounds.SELL_FAIL.play(player);
|
||||
PluginMessages.NO_DEPOSITORY.send(player);
|
||||
@@ -141,7 +141,7 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
if (depository == null) {
|
||||
Main.getEconomyManager().sellAllItem(player, userData);
|
||||
UltraDepository.getEconomyManager().sellAllItem(player, userData);
|
||||
sender.sendMessage("Success! " + player.getName() + "'s items had been sold.");
|
||||
return true;
|
||||
}
|
||||
@@ -157,11 +157,11 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
Main.getEconomyManager().sellAllItem(player, userData, userData.getDepositoryData(depositoryID));
|
||||
UltraDepository.getEconomyManager().sellAllItem(player, userData, depository);
|
||||
return true;
|
||||
}
|
||||
|
||||
Main.getEconomyManager().sellAllItem(player, userData, userData.getItemData(item));
|
||||
UltraDepository.getEconomyManager().sellAllItem(player, userData, item);
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
@@ -177,14 +177,14 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
sender.sendMessage("Player does not exist.");
|
||||
return false;
|
||||
}
|
||||
UserData userData = Main.getUserManager().getData(player);
|
||||
UserData userData = UltraDepository.getUserManager().getData(player);
|
||||
|
||||
String depositoryID = args.length >= 3 ? args[2] : null;
|
||||
String itemID = args.length >= 4 ? args[3] : null;
|
||||
|
||||
Depository depository = null;
|
||||
if (depositoryID != null) {
|
||||
depository = Main.getDepositoryManager().getDepository(depositoryID);
|
||||
depository = UltraDepository.getDepositoryManager().getDepository(depositoryID);
|
||||
if (depository == null) {
|
||||
PluginMessages.NO_DEPOSITORY.send(player);
|
||||
return true;
|
||||
@@ -193,12 +193,12 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
sender.sendMessage(ColorParser.parse("&fInfo &6" + player.getName() + " &f:"));
|
||||
if (depository == null) {
|
||||
userData.getDepositories().values().forEach(depositoryData -> {
|
||||
MessageUtil.send(sender, "&8# &e" + depositoryData.getIdentifier());
|
||||
MessageUtils.send(sender, "&8# &e" + depositoryData.getIdentifier());
|
||||
depositoryData.getContents().values().forEach(itemData -> {
|
||||
String typeID = itemData.getSource().getTypeID();
|
||||
int amount = itemData.getAmount();
|
||||
int sold = itemData.getSold();
|
||||
MessageUtil.send(sender, "&8- &f" + typeID + " &7[&f " + amount + "&8|&f " + sold + "&7]");
|
||||
MessageUtils.send(sender, "&8- &f" + typeID + " &7[&f " + amount + "&8|&f " + sold + "&7]");
|
||||
});
|
||||
});
|
||||
return true;
|
||||
@@ -215,12 +215,12 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
if (item == null) {
|
||||
DepositoryData depositoryData = userData.getDepositoryData(depository);
|
||||
MessageUtil.send(sender, "&8# &e" + depositoryData.getIdentifier());
|
||||
MessageUtils.send(sender, "&8# &e" + depositoryData.getIdentifier());
|
||||
depositoryData.getContents().values().forEach(itemData -> {
|
||||
String typeID = itemData.getSource().getTypeID();
|
||||
int amount = itemData.getAmount();
|
||||
int sold = itemData.getSold();
|
||||
MessageUtil.send(sender, "&8- &f" + typeID + " &7[&f " + amount + "&8|&f " + sold + "&7]");
|
||||
MessageUtils.send(sender, "&8- &f" + typeID + " &7[&f " + amount + "&8|&f " + sold + "&7]");
|
||||
});
|
||||
return true;
|
||||
}
|
||||
@@ -230,8 +230,8 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
int amount = itemData.getAmount();
|
||||
int sold = itemData.getSold();
|
||||
|
||||
MessageUtil.send(sender, "&8# &e" + depository.getIdentifier());
|
||||
MessageUtil.send(sender, "&8- &f" + typeID + " &7[&f " + amount + "&8|&f " + sold + "&7]");
|
||||
MessageUtils.send(sender, "&8# &e" + depository.getIdentifier());
|
||||
MessageUtils.send(sender, "&8- &f" + typeID + " &7[&f " + amount + "&8|&f " + sold + "&7]");
|
||||
return true;
|
||||
}
|
||||
case "add": {
|
||||
@@ -242,7 +242,7 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
return false;
|
||||
}
|
||||
|
||||
Depository depository = Main.getDepositoryManager().getDepository(args[2]);
|
||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[2]);
|
||||
if (depository == null) {
|
||||
PluginMessages.NO_DEPOSITORY.send(sender);
|
||||
return true;
|
||||
@@ -264,7 +264,7 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
return true;
|
||||
}
|
||||
|
||||
Integer after = Main.getUserManager().getData(player)
|
||||
Integer after = UltraDepository.getUserManager().getData(player)
|
||||
.addItemAmount(depository.getIdentifier(), item.getTypeID(), amount);
|
||||
|
||||
if (after != null) {
|
||||
@@ -283,7 +283,7 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
return false;
|
||||
}
|
||||
|
||||
Depository depository = Main.getDepositoryManager().getDepository(args[2]);
|
||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[2]);
|
||||
if (depository == null) {
|
||||
PluginMessages.NO_DEPOSITORY.send(sender);
|
||||
return true;
|
||||
@@ -305,7 +305,7 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
return true;
|
||||
}
|
||||
|
||||
UserData userData = Main.getUserManager().getData(player);
|
||||
UserData userData = UltraDepository.getUserManager().getData(player);
|
||||
if (amount != null) {
|
||||
Integer after = userData.removeItemAmount(depository.getIdentifier(), item.getTypeID(), amount);
|
||||
if (after != null) {
|
||||
@@ -331,17 +331,17 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
Depository depository = null;
|
||||
if (depositoryID != null) {
|
||||
depository = Main.getDepositoryManager().getDepository(depositoryID);
|
||||
depository = UltraDepository.getDepositoryManager().getDepository(depositoryID);
|
||||
if (depository == null) {
|
||||
PluginMessages.NO_DEPOSITORY.send(sender);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
UserData userData = Main.getUserManager().getData(player);
|
||||
UserData userData = UltraDepository.getUserManager().getData(player);
|
||||
|
||||
if (depository == null) {
|
||||
Main.getEconomyManager().sellAllItem(player, userData);
|
||||
UltraDepository.getEconomyManager().sellAllItem(player, userData);
|
||||
sender.sendMessage("Success! " + player.getName() + "'s items had been sold.");
|
||||
return true;
|
||||
}
|
||||
@@ -355,7 +355,7 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
}
|
||||
if (item == null) {
|
||||
Main.getEconomyManager().sellAllItem(player, userData, userData.getDepositoryData(depository));
|
||||
UltraDepository.getEconomyManager().sellAllItem(player, userData, depository);
|
||||
sender.sendMessage("Success! " + player.getName() + "'s " + depository.getIdentifier() + " had been sold.");
|
||||
return true;
|
||||
}
|
||||
@@ -374,7 +374,7 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
if (amount == null) {
|
||||
Main.getEconomyManager().sellAllItem(player, userData, userData.getItemData(item));
|
||||
UltraDepository.getEconomyManager().sellAllItem(player, userData, item);
|
||||
sender.sendMessage("Success! " + player.getName() + "'s " + item.getTypeID() + " had been sold.");
|
||||
return true;
|
||||
}
|
||||
@@ -395,7 +395,7 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
return true;
|
||||
}
|
||||
|
||||
Main.getEconomyManager().sellItem(player, userData, userData.getItemData(item), amount);
|
||||
UltraDepository.getEconomyManager().sellItem(player, userData, item, amount);
|
||||
sender.sendMessage("Success! " + player.getName() + "'s " + amount + " " + item.getTypeID() + " had been sold.");
|
||||
return true;
|
||||
}
|
||||
@@ -430,7 +430,7 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
&& player.hasPermission("UltraDepository.Command.Sell"))
|
||||
|| (aim.equalsIgnoreCase("sellAll")
|
||||
&& player.hasPermission("UltraDepository.Command.SellAll"))) {
|
||||
allCompletes.addAll(Main.getDepositoryManager().getDepositories().keySet());
|
||||
allCompletes.addAll(UltraDepository.getDepositoryManager().getDepositories().keySet());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -441,7 +441,7 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
&& player.hasPermission("UltraDepository.Command.Sell"))
|
||||
|| (aim.equalsIgnoreCase("sellAll")
|
||||
&& player.hasPermission("UltraDepository.Command.SellAll"))) {
|
||||
Depository depository = Main.getDepositoryManager().getDepository(depositoryID);
|
||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(depositoryID);
|
||||
if (depository != null) {
|
||||
allCompletes.addAll(depository.getItems().keySet());
|
||||
}
|
||||
@@ -465,11 +465,11 @@ public class DepositoryCommand implements CommandExecutor, TabCompleter {
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
allCompletes.addAll(Main.getDepositoryManager().getDepositories().keySet());
|
||||
allCompletes.addAll(UltraDepository.getDepositoryManager().getDepositories().keySet());
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
Depository depository = Main.getDepositoryManager().getDepository(args[2]);
|
||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[2]);
|
||||
if (depository != null) {
|
||||
allCompletes.addAll(depository.getItems().keySet());
|
||||
}
|
||||
|
||||
@@ -1,21 +1,28 @@
|
||||
package cc.carm.plugin.ultradepository.configuration;
|
||||
|
||||
import cc.carm.plugin.ultradepository.configuration.message.ConfigMessage;
|
||||
import cc.carm.plugin.ultradepository.configuration.message.ConfigMessageList;
|
||||
import cc.carm.plugin.ultradepository.configuration.values.ConfigSound;
|
||||
import cc.carm.plugin.ultradepository.configuration.values.ConfigStringCast;
|
||||
import cc.carm.plugin.ultradepository.configuration.values.ConfigValue;
|
||||
import cc.carm.lib.easyplugin.configuration.cast.ConfigStringCast;
|
||||
import cc.carm.lib.easyplugin.configuration.impl.ConfigItem;
|
||||
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.storage.StorageMethod;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
|
||||
public class PluginConfig {
|
||||
|
||||
public static final ConfigValue<Boolean> DEBUG = new ConfigValue<>(
|
||||
"debug", Boolean.class
|
||||
"debug", Boolean.class, false
|
||||
);
|
||||
|
||||
public static final ConfigValue<String> STORAGE_METHOD = new ConfigValue<>(
|
||||
"storage.method", String.class
|
||||
public static final ConfigValue<Boolean> METRICS = new ConfigValue<>(
|
||||
"metrics", Boolean.class, true
|
||||
);
|
||||
|
||||
public static final ConfigStringCast<StorageMethod> STORAGE_METHOD = new ConfigStringCast<>(
|
||||
"storage.method", StorageMethod::read, StorageMethod.YAML
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -39,7 +46,8 @@ public class PluginConfig {
|
||||
|
||||
public static class Sounds {
|
||||
|
||||
public static final ConfigSound COLLECT = new ConfigSound("sounds.collect");
|
||||
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 SELL_SUCCESS = new ConfigSound("sounds.sell-success");
|
||||
public static final ConfigSound SELL_FAIL = new ConfigSound("sounds.sell-fail");
|
||||
public static final ConfigSound GUI_CLICK = new ConfigSound("sounds.gui-click");
|
||||
@@ -49,22 +57,53 @@ public class PluginConfig {
|
||||
* 通用配置
|
||||
*/
|
||||
public static class General {
|
||||
|
||||
/**
|
||||
* 针对每一件物品的额外介绍
|
||||
* 将添加到背包界面内的物品上,避免重复配置
|
||||
*/
|
||||
public static final ConfigMessageList ADDITIONAL_LORE = new ConfigMessageList(
|
||||
ConfigManager.getPluginConfig(), "general.additional-lore", new String[]{},
|
||||
public static class AdditionalLore {
|
||||
|
||||
public static final ConfigMessageList AVAILABLE_FOR_SALE = new ConfigMessageList(
|
||||
ConfigManager::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",
|
||||
new String[]{}, new String[]{
|
||||
"%(item_name)", "%(amount)"
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 提示玩家点击行为的介绍
|
||||
* 将添加到背包界面内的物品上,避免重复配置
|
||||
*/
|
||||
public static class ClickLore {
|
||||
public static final ConfigMessageList AVAILABLE_FOR_SALE = new ConfigMessageList(
|
||||
ConfigManager::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",
|
||||
new String[]{},
|
||||
new String[]{
|
||||
"%(item_name)", "%(amount)"
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static final ConfigMessageList CLICK_LORE = new ConfigMessageList(
|
||||
ConfigManager.getPluginConfig(), "general.click-lore", new String[]{}, new String[]{
|
||||
ConfigManager::getPluginConfig,
|
||||
"general.click-lore",
|
||||
new String[]{}, new String[]{
|
||||
"%(item_name)", "%(amount)", "%(price)"
|
||||
});
|
||||
|
||||
@@ -75,7 +114,8 @@ public class PluginConfig {
|
||||
|
||||
|
||||
public static final ConfigMessage TITLE = new ConfigMessage(
|
||||
ConfigManager.getPluginConfig(), "general.sell-gui.title",
|
||||
ConfigManager::getPluginConfig,
|
||||
"general.sell-gui.title",
|
||||
"&a&l出售", new String[]{
|
||||
"%(item_name)", "%(backpack_name)"
|
||||
}
|
||||
@@ -83,116 +123,27 @@ public class PluginConfig {
|
||||
|
||||
public static class Items {
|
||||
|
||||
public static class Add {
|
||||
|
||||
public static final ConfigStringCast<Material> TYPE = new ConfigStringCast<>(
|
||||
"general.sell-gui.items.add.type",
|
||||
Material::matchMaterial, Material.STONE
|
||||
public static final ConfigItem ADD = new ConfigItem(
|
||||
"general.sell-gui.items.add",
|
||||
new String[]{"%(item_name)", "%(amount)"},
|
||||
ConfigItem.create(Material.GREEN_STAINED_GLASS_PANE, "&a添加物品 %(amount) 个")
|
||||
);
|
||||
|
||||
|
||||
public static final ConfigValue<Integer> DATA = new ConfigValue<>(
|
||||
"general.sell-gui.items.add.data", Integer.class, 0
|
||||
public static final ConfigItem REMOVE = new ConfigItem(
|
||||
"general.sell-gui.items.remove",
|
||||
new String[]{"%(item_name)", "%(amount)"},
|
||||
ConfigItem.create(Material.RED_STAINED_GLASS_PANE, "&c減少物品 %(amount) 个")
|
||||
);
|
||||
|
||||
|
||||
public static final ConfigMessage NAME = new ConfigMessage(
|
||||
ConfigManager.getPluginConfig(), "general.sell-gui.items.add.name",
|
||||
"&a添加物品 %(amount) 个", new String[]{
|
||||
"%(item_name)", "%(amount)"
|
||||
}
|
||||
public static final ConfigItem CONFIRM = new ConfigItem(
|
||||
"general.sell-gui.items.confirm",
|
||||
new String[]{"%(item_name)", "%(amount)", "%(money)"},
|
||||
ConfigItem.create(Material.EMERALD, "&2确认售出")
|
||||
);
|
||||
|
||||
|
||||
public static final ConfigMessageList LORE = new ConfigMessageList(
|
||||
ConfigManager.getPluginConfig(), "general.sell-gui.items.add.lore",
|
||||
new String[]{}, new String[]{
|
||||
"%(item_name)", "%(amount)"
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static class Remove {
|
||||
|
||||
public static final ConfigStringCast<Material> TYPE = new ConfigStringCast<>(
|
||||
"general.sell-gui.items.remove.type",
|
||||
Material::matchMaterial, Material.STONE
|
||||
);
|
||||
|
||||
|
||||
public static final ConfigValue<Integer> DATA = new ConfigValue<>(
|
||||
"general.sell-gui.items.remove.data", Integer.class, 0
|
||||
);
|
||||
|
||||
|
||||
public static final ConfigMessage NAME = new ConfigMessage(
|
||||
ConfigManager.getPluginConfig(), "general.sell-gui.items.remove.name",
|
||||
"&c減少物品 %(amount) 个", new String[]{
|
||||
"%(item_name)", "%(amount)"
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
public static final ConfigMessageList LORE = new ConfigMessageList(
|
||||
ConfigManager.getPluginConfig(), "general.sell-gui.items.remove.lore",
|
||||
new String[]{}, new String[]{
|
||||
"%(item_name)", "%(amount)"
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static class Confirm {
|
||||
|
||||
public static final ConfigStringCast<Material> TYPE = new ConfigStringCast<>(
|
||||
"general.sell-gui.items.confirm.type",
|
||||
Material::matchMaterial, Material.EMERALD
|
||||
);
|
||||
|
||||
|
||||
public static final ConfigValue<Integer> DATA = new ConfigValue<>(
|
||||
"general.sell-gui.items.confirm.data", Integer.class, 0
|
||||
);
|
||||
|
||||
|
||||
public static final ConfigMessage NAME = new ConfigMessage(
|
||||
ConfigManager.getPluginConfig(), "general.sell-gui.items.confirm.name",
|
||||
"&2确认售出", new String[]{
|
||||
"%(item_name)", "%(amount)", "%(money)"
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
public static final ConfigMessageList LORE = new ConfigMessageList(
|
||||
ConfigManager.getPluginConfig(), "general.sell-gui.items.confirm.lore",
|
||||
new String[]{}, new String[]{
|
||||
"%(item_name)", "%(amount)", "%(money)"
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static class Cancel {
|
||||
|
||||
public static final ConfigStringCast<Material> TYPE = new ConfigStringCast<>(
|
||||
"general.sell-gui.items.cancel.type",
|
||||
Material::matchMaterial, Material.REDSTONE
|
||||
);
|
||||
|
||||
|
||||
public static final ConfigValue<Integer> DATA = new ConfigValue<>(
|
||||
"general.sell-gui.items.cancel.data", Integer.class, 0
|
||||
);
|
||||
|
||||
|
||||
public static final ConfigMessage NAME = new ConfigMessage(
|
||||
ConfigManager.getPluginConfig(), "general.sell-gui.items.cancel.name",
|
||||
"&4取消售出", null
|
||||
);
|
||||
|
||||
public static final ConfigMessageList LORE = new ConfigMessageList(
|
||||
ConfigManager.getPluginConfig(), "general.sell-gui.items.cancel.lore", new String[0], new String[0]
|
||||
public static final ConfigItem CANCEL = new ConfigItem(
|
||||
"general.sell-gui.items.cancel",
|
||||
ConfigItem.create(Material.REDSTONE, "&4取消售出")
|
||||
);
|
||||
|
||||
}
|
||||
@@ -200,7 +151,4 @@ public class PluginConfig {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,46 +1,102 @@
|
||||
package cc.carm.plugin.ultradepository.configuration;
|
||||
|
||||
|
||||
import cc.carm.plugin.ultradepository.configuration.message.ConfigMessageList;
|
||||
import cc.carm.lib.easyplugin.configuration.language.EasyMessage;
|
||||
import cc.carm.lib.easyplugin.configuration.language.EasyMessageList;
|
||||
import cc.carm.lib.easyplugin.configuration.language.MessagesRoot;
|
||||
import cc.carm.lib.easyplugin.configuration.language.MessagesSection;
|
||||
|
||||
public class PluginMessages {
|
||||
public class PluginMessages extends MessagesRoot {
|
||||
|
||||
public static final ConfigMessageList HELP_CONSOLE = new ConfigMessageList("help.console");
|
||||
@MessagesSection("help")
|
||||
public static class Usages {
|
||||
|
||||
public static final ConfigMessageList HELP_PLAYER = new ConfigMessageList("help.player");
|
||||
public static final EasyMessageList CONSOLE = new EasyMessageList(
|
||||
"&6&l超级仓库 &f后台指令帮助",
|
||||
"&8#&f info &6<玩家> &e[仓库ID] &e[物品ID]",
|
||||
"&8-&7 得到玩家的相关物品信息。",
|
||||
"&8#&f add &6<玩家> &6<仓库ID> &6<物品ID> &6<数量>",
|
||||
"&8-&7 为玩家添加对应仓库中对于物品的数量。",
|
||||
"&8#&f remove &6<玩家> &6<仓库ID> &6<物品ID> &e[数量]",
|
||||
"&8-&7 为玩家减少对应仓库中对于物品的数量。",
|
||||
"&8-&7 若不填写数量,则清空对应仓库的对应物品。",
|
||||
"&8#&f sell &6<玩家> &e[仓库ID] &e[物品ID] &e[数量]",
|
||||
"&8-&7 为玩家售出相关物品。",
|
||||
"&8-&7 若不填写数量,则售出所有对应仓库的对应物品。",
|
||||
"&8-&7 若不填写物品,则售出对应仓库内所有物品。",
|
||||
"&8-&7 若不填写仓库,则售出所有仓库内所有物品。",
|
||||
"&8-&7 该指令受到玩家每日售出数量的限制。"
|
||||
);
|
||||
|
||||
public static final EasyMessageList PLAYER = new EasyMessageList(
|
||||
"&6&l超级仓库 &f玩家指令帮助",
|
||||
"&8#&f open &e[仓库ID]",
|
||||
"&8-&7 打开对应仓库的界面。",
|
||||
"&8#&f sell &6<仓库ID> &6<物品ID> &6<数量>",
|
||||
"&8-&7 售出对应数量的对应物品。",
|
||||
"&8-&7 该指令受到玩家每日售出数量的限制。",
|
||||
"&8#&f sellAll &e[仓库ID] &e[物品ID]",
|
||||
"&8-&7 该指令受到玩家每日售出数量的限制。"
|
||||
);
|
||||
|
||||
public static final ConfigMessageList SOLD = new ConfigMessageList(
|
||||
"item-sold", new String[0], new String[]{
|
||||
"%(item)", "%(amount)", "%(money)"
|
||||
});
|
||||
}
|
||||
|
||||
public static final ConfigMessageList PICKUP = new ConfigMessageList(
|
||||
"item-pickup", new String[0], new String[]{
|
||||
"%(item)", "%(amount)"
|
||||
});
|
||||
public static final EasyMessageList ITEM_SOLD = new EasyMessageList(
|
||||
new String[]{"&f您出售了 &r%(item)&7x%(amount) &f,共赚取 &6%(money) &f元。"},
|
||||
new String[]{"%(item)", "%(amount)", "%(money)"}
|
||||
);
|
||||
|
||||
public static final ConfigMessageList COLLECTED = new ConfigMessageList(
|
||||
"item-collected", new String[0], new String[]{
|
||||
"%(item)", "%(amount)", "%(depository)"
|
||||
});
|
||||
public static final EasyMessageList ITEM_SOLD_LIMIT = new EasyMessageList(
|
||||
new String[]{"&f该物品今日剩余可出售额度为 &a%(amount)&8/%(limit) &f个。"},
|
||||
new String[]{"%(amount)", "%(limit)"}
|
||||
);
|
||||
|
||||
public static final EasyMessageList ITEM_PICKUP = new EasyMessageList(
|
||||
new String[]{"&f您拾取了 &r%(item)&7x%(amount) &f,已自动放入到您的仓库中。"},
|
||||
new String[]{"%(item)", "%(amount)"}
|
||||
);
|
||||
|
||||
public static final ConfigMessageList NO_ECONOMY = new ConfigMessageList("no-economy");
|
||||
public static final EasyMessageList ITEM_TAKEOUT = new EasyMessageList(
|
||||
new String[]{"&f您从仓库中拿取了 &r%(item)&7x%(amount) &f放入到您的背包中。"},
|
||||
new String[]{"%(item)", "%(amount)"}
|
||||
);
|
||||
|
||||
public static final ConfigMessageList NO_SPACE = new ConfigMessageList("no-space");
|
||||
public static final EasyMessageList ITEM_COLLECT = new EasyMessageList(
|
||||
new String[]{"&f您收集了 &r%(item)&7x%(amount) &f,已自动放入到您的 &6%(depository) &f中。"},
|
||||
new String[]{"%(item)", "%(amount)", "%(depository)"}
|
||||
);
|
||||
|
||||
public static final ConfigMessageList NO_DEPOSITORY = new ConfigMessageList("no-depository");
|
||||
public static final EasyMessage ITEM_COLLECT_ACTIONBAR = new EasyMessage(
|
||||
"&r%(item)&7x%(amount) &f-> &6%(depository)",
|
||||
new String[]{"%(item)", "%(amount)", "%(depository)"}
|
||||
);
|
||||
|
||||
public static final ConfigMessageList NO_ITEM = new ConfigMessageList("no-item");
|
||||
public static final EasyMessageList NO_SPACE = new EasyMessageList(
|
||||
"&f您背包内没有足够的空间取出物品!"
|
||||
);
|
||||
|
||||
public static final ConfigMessageList NO_ENOUGH_ITEM = new ConfigMessageList("no-enough-item");
|
||||
public static final EasyMessageList NO_ECONOMY = new EasyMessageList(
|
||||
"&f本服务器暂未启用出售功能。"
|
||||
);
|
||||
|
||||
public static final EasyMessageList NO_DEPOSITORY = new EasyMessageList(
|
||||
"&f不存在该仓库,请检查仓库ID是否正确。"
|
||||
);
|
||||
|
||||
public static final ConfigMessageList ITEM_SOLD_LIMIT = new ConfigMessageList(
|
||||
"item-sold-limit", new String[0], new String[]{
|
||||
"%(amount)", "%(limit)"
|
||||
});
|
||||
public static final EasyMessageList NO_ITEM = new EasyMessageList(
|
||||
"&f仓库中不存在该物品,请检查物品ID是否正确。"
|
||||
);
|
||||
|
||||
public static final EasyMessageList NO_ENOUGH_ITEM = new EasyMessageList(
|
||||
"&f仓库中不存在足够的物品。"
|
||||
);
|
||||
|
||||
public static final EasyMessageList WRONG_NUMBER = new EasyMessageList(
|
||||
"&f数目输入错误,请输入正确的数字!"
|
||||
);
|
||||
|
||||
public static final EasyMessage LOAD_FAILED = new EasyMessage(
|
||||
"&c您的背包数据未被正确加载,请重新进入!"
|
||||
);
|
||||
|
||||
public static final ConfigMessageList WRONG_NUMBER = new ConfigMessageList("wrong-number");
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package cc.carm.plugin.ultradepository.configuration.depository;
|
||||
|
||||
import cc.carm.plugin.ultradepository.configuration.gui.GUIConfiguration;
|
||||
import cc.carm.lib.easyplugin.gui.configuration.GUIConfiguration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
+15
-6
@@ -3,7 +3,6 @@ package cc.carm.plugin.ultradepository.configuration.depository;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -43,11 +42,21 @@ public class DepositoryCapacity {
|
||||
}
|
||||
|
||||
public int getPlayerCapacity(Player player) {
|
||||
return getPermissions().entrySet().stream()
|
||||
.filter(entry -> player.hasPermission(entry.getKey()))
|
||||
.map(Map.Entry::getValue)
|
||||
.min(Comparator.comparingInt(Integer::intValue))
|
||||
.orElse(defaultCapacity);
|
||||
if (defaultCapacity == -1) return -1;
|
||||
|
||||
int capacity = defaultCapacity;
|
||||
for (Map.Entry<String, Integer> entry : getPermissions().entrySet()) {
|
||||
if (player.hasPermission(entry.getKey())) {
|
||||
int value = entry.getValue();
|
||||
if (value == -1) {
|
||||
return -1;
|
||||
} else if (value > capacity) {
|
||||
capacity = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return capacity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,7 +1,7 @@
|
||||
package cc.carm.plugin.ultradepository.configuration.depository;
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import cc.carm.plugin.ultradepository.util.ItemStackFactory;
|
||||
import cc.carm.lib.easyplugin.utils.ItemStackFactory;
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -45,7 +45,7 @@ public class DepositoryItem {
|
||||
}
|
||||
|
||||
public @NotNull String getTypeID() {
|
||||
return getMaterial().name() + ":" + getData();
|
||||
return UltraDepository.getDepositoryManager().getItemTypeID(getMaterial(), getData());
|
||||
}
|
||||
|
||||
public @NotNull Material getMaterial() {
|
||||
@@ -116,15 +116,15 @@ public class DepositoryItem {
|
||||
return new DepositoryItem(
|
||||
depository, material, data,
|
||||
section.getInt("slot", 0),
|
||||
section.getDouble("price", 0),
|
||||
section.getInt("limit", 0),
|
||||
section.getDouble("price", -1),
|
||||
section.getInt("limit", -1),
|
||||
section.getString("name", material.name()),
|
||||
section.getStringList("lore")
|
||||
);
|
||||
|
||||
} catch (Exception ex) {
|
||||
Main.error("没有与 " + typeID + " 匹配的物品!");
|
||||
Main.error("No match material of " + typeID + " !");
|
||||
UltraDepository.getInstance().error("没有与 " + typeID + " 匹配的物品!");
|
||||
UltraDepository.getInstance().error("No match material of " + typeID + " !");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.configuration.file;
|
||||
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FileConfig {
|
||||
|
||||
private long updateTime;
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
private final String fileName;
|
||||
|
||||
|
||||
private File file;
|
||||
private FileConfiguration config;
|
||||
|
||||
public FileConfig(final JavaPlugin plugin) {
|
||||
this(plugin, "config.yml");
|
||||
}
|
||||
|
||||
public FileConfig(final JavaPlugin plugin, final String name) {
|
||||
this.plugin = plugin;
|
||||
this.fileName = name;
|
||||
initFile();
|
||||
}
|
||||
|
||||
private void initFile() {
|
||||
this.updateTime = System.currentTimeMillis();
|
||||
this.file = new File(plugin.getDataFolder(), fileName);
|
||||
if (!this.file.exists()) {
|
||||
if (!this.file.getParentFile().exists()) {
|
||||
boolean success = this.file.getParentFile().mkdirs();
|
||||
}
|
||||
plugin.saveResource(fileName, true);
|
||||
}
|
||||
this.config = YamlConfiguration.loadConfiguration(this.file);
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
try {
|
||||
getConfig().save(getFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
this.updateTime = System.currentTimeMillis();
|
||||
if (getFile().exists()) {
|
||||
this.config = YamlConfiguration.loadConfiguration(getFile());
|
||||
} else {
|
||||
initFile();
|
||||
}
|
||||
}
|
||||
|
||||
public long getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public boolean isExpired(long time) {
|
||||
return getUpdateTime() > time;
|
||||
}
|
||||
}
|
||||
-51
@@ -1,51 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.configuration.gui;
|
||||
|
||||
import cc.carm.plugin.ultradepository.util.gui.GUIItem;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class GUIActionConfiguration {
|
||||
|
||||
|
||||
@Nullable ClickType clickType;
|
||||
final @NotNull GUIActionType actionType;
|
||||
final @Nullable String actionContent;
|
||||
|
||||
public GUIActionConfiguration(@Nullable ClickType clickType, @NotNull GUIActionType actionType, @Nullable String actionContent) {
|
||||
this.clickType = clickType;
|
||||
this.actionType = actionType;
|
||||
this.actionContent = actionContent;
|
||||
}
|
||||
|
||||
public @Nullable ClickType getClickType() {
|
||||
return clickType;
|
||||
}
|
||||
|
||||
public @NotNull GUIActionType getActionType() {
|
||||
return actionType;
|
||||
}
|
||||
|
||||
public @Nullable String getActionContent() {
|
||||
return actionContent;
|
||||
}
|
||||
|
||||
public void checkAction(Player player, ClickType type) {
|
||||
if (getClickType() == null || getClickType() == type) executeAction(player);
|
||||
}
|
||||
|
||||
public void executeAction(Player targetPlayer) {
|
||||
getActionType().getExecutor().accept(targetPlayer, getActionContent());
|
||||
}
|
||||
|
||||
public GUIItem.GUIClickAction toClickAction() {
|
||||
return new GUIItem.GUIClickAction() {
|
||||
@Override
|
||||
public void run(ClickType type, Player player) {
|
||||
checkAction(player, type);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.configuration.gui;
|
||||
|
||||
import cc.carm.plugin.ultradepository.util.MessageUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public enum GUIActionType {
|
||||
|
||||
/**
|
||||
* 以玩家聊天的形式执行
|
||||
* 若内容以 “/" 开头,则会以玩家身份执行命令。
|
||||
*/
|
||||
CHAT((player, string) -> {
|
||||
if (string == null) return;
|
||||
MessageUtil.setPlaceholders(player, Collections.singletonList(string)).forEach(player::chat);
|
||||
}),
|
||||
|
||||
/**
|
||||
* 以后台的形式执行指令
|
||||
* 指令内容不需要以“/”开头。
|
||||
*/
|
||||
CONSOLE((player, string) -> {
|
||||
if (string == null) return;
|
||||
MessageUtil.setPlaceholders(player, Collections.singletonList(string))
|
||||
.forEach(message -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), message));
|
||||
}),
|
||||
|
||||
/**
|
||||
* 向玩家发送消息。
|
||||
*/
|
||||
MESSAGE(MessageUtil::send),
|
||||
|
||||
/**
|
||||
* 向玩家发送声音。
|
||||
* 允许配置音量与音调
|
||||
* <ul>
|
||||
* <li>SOUND_NAME</li>
|
||||
* <li>SOUND_NAME:VOLUME</li>
|
||||
* <li>SOUND_NAME:VOLUME:PITCH</li>
|
||||
* </ul>
|
||||
*/
|
||||
SOUND((player, string) -> {
|
||||
if (string == null) return;
|
||||
try {
|
||||
String[] args = string.contains(":") ? string.split(":") : new String[]{string};
|
||||
Sound sound = Arrays.stream(Sound.values())
|
||||
.filter(s -> s.name().equals(args[0]))
|
||||
.findFirst().orElse(null);
|
||||
|
||||
if (sound == null) return;
|
||||
float volume = args.length > 1 ? Float.parseFloat(args[1]) : 1F;
|
||||
float pitch = args.length > 2 ? Float.parseFloat(args[2]) : 1F;
|
||||
|
||||
player.playSound(player.getLocation(), sound, volume, pitch);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}),
|
||||
|
||||
/**
|
||||
* 为玩家关闭GUI。
|
||||
*/
|
||||
CLOSE((player, string) -> player.closeInventory());
|
||||
|
||||
BiConsumer<@NotNull Player, @Nullable String> executor;
|
||||
|
||||
|
||||
GUIActionType(BiConsumer<@NotNull Player, @Nullable String> executor) {
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
public BiConsumer<@NotNull Player, @Nullable String> getExecutor() {
|
||||
return executor;
|
||||
}
|
||||
|
||||
public static GUIActionType readActionType(String string) {
|
||||
return Arrays.stream(GUIActionType.values())
|
||||
.filter(action -> action.name().equalsIgnoreCase(string))
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.configuration.gui;
|
||||
|
||||
import cc.carm.plugin.ultradepository.util.ColorParser;
|
||||
import cc.carm.plugin.ultradepository.util.gui.GUI;
|
||||
import cc.carm.plugin.ultradepository.util.gui.GUIType;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GUIConfiguration {
|
||||
|
||||
String title;
|
||||
int lines;
|
||||
|
||||
List<GUIItemConfiguration> guiItems;
|
||||
|
||||
public GUIConfiguration(String title, int lines, List<GUIItemConfiguration> guiItems) {
|
||||
this.title = title;
|
||||
this.lines = lines;
|
||||
this.guiItems = guiItems;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return ColorParser.parse(title);
|
||||
}
|
||||
|
||||
public int getLines() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
public GUIType getGUIType() {
|
||||
switch (lines) {
|
||||
case 1:
|
||||
return GUIType.ONE_BY_NINE;
|
||||
case 2:
|
||||
return GUIType.TWO_BY_NINE;
|
||||
case 3:
|
||||
return GUIType.THREE_BY_NINE;
|
||||
case 4:
|
||||
return GUIType.FOUR_BY_NINE;
|
||||
case 5:
|
||||
return GUIType.FIVE_BY_NINE;
|
||||
default:
|
||||
return GUIType.SIX_BY_NINE;
|
||||
}
|
||||
}
|
||||
|
||||
public List<GUIItemConfiguration> getGuiItems() {
|
||||
return guiItems;
|
||||
}
|
||||
|
||||
public void setupItems(Player player, GUI gui) {
|
||||
getGuiItems().forEach(itemConfiguration -> itemConfiguration.setupItems(player, gui));
|
||||
}
|
||||
|
||||
|
||||
public static GUIConfiguration readConfiguration(@Nullable ConfigurationSection section) {
|
||||
if (section == null) return new GUIConfiguration("name", 6, new ArrayList<>());
|
||||
|
||||
String title = section.getString("title", "");
|
||||
int lines = section.getInt("lines", 6);
|
||||
ConfigurationSection itemsSection = section.getConfigurationSection("items");
|
||||
if (itemsSection == null) return new GUIConfiguration(title, lines, new ArrayList<>());
|
||||
|
||||
return new GUIConfiguration(
|
||||
title, lines, itemsSection.getKeys(false).stream()
|
||||
.map(key -> GUIItemConfiguration.readFrom(itemsSection.getConfigurationSection(key)))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
public static ClickType readClickType(String type) {
|
||||
return Arrays.stream(ClickType.values())
|
||||
.filter(click -> click.name().equalsIgnoreCase(type))
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
}
|
||||
-92
@@ -1,92 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.configuration.gui;
|
||||
|
||||
import cc.carm.plugin.ultradepository.util.ItemStackFactory;
|
||||
import cc.carm.plugin.ultradepository.util.MessageUtil;
|
||||
import cc.carm.plugin.ultradepository.util.gui.GUI;
|
||||
import cc.carm.plugin.ultradepository.util.gui.GUIItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class GUIItemConfiguration {
|
||||
|
||||
Material material;
|
||||
int data;
|
||||
String name;
|
||||
@NotNull List<String> lore;
|
||||
|
||||
@NotNull List<Integer> slots;
|
||||
@NotNull List<GUIActionConfiguration> actions;
|
||||
|
||||
public GUIItemConfiguration(Material material, int data,
|
||||
String name, @NotNull List<String> lore,
|
||||
@NotNull List<GUIActionConfiguration> actions,
|
||||
@NotNull List<Integer> slots) {
|
||||
this.material = material;
|
||||
this.data = data;
|
||||
this.name = name;
|
||||
this.lore = lore;
|
||||
this.slots = slots;
|
||||
this.actions = actions;
|
||||
}
|
||||
|
||||
public void setupItems(Player player, GUI gui) {
|
||||
ItemStackFactory icon = new ItemStackFactory(this.material);
|
||||
icon.setDurability(this.data);
|
||||
if (this.name != null) icon.setDisplayName(this.name);
|
||||
icon.setLore(MessageUtil.setPlaceholders(player, this.lore));
|
||||
|
||||
GUIItem item = new GUIItem(icon.toItemStack());
|
||||
this.actions.stream().map(GUIActionConfiguration::toClickAction).forEach(item::addClickAction);
|
||||
this.slots.forEach(slot -> gui.setItem(slot, item));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static GUIItemConfiguration readFrom(@Nullable ConfigurationSection itemSection) {
|
||||
if (itemSection == null) return null;
|
||||
Material material = Optional.ofNullable(Material.matchMaterial(itemSection.getString("material", "STONE"))).orElse(Material.STONE);
|
||||
int data = itemSection.getInt("data", 0);
|
||||
String name = itemSection.getString("name");
|
||||
List<String> lore = itemSection.getStringList("lore");
|
||||
|
||||
List<Integer> slots = itemSection.getIntegerList("slots");
|
||||
int slot = itemSection.getInt("slot", 0);
|
||||
|
||||
List<String> actionsString = itemSection.getStringList("actions");
|
||||
List<GUIActionConfiguration> actions = new ArrayList<>();
|
||||
for (String actionString : actionsString) {
|
||||
int prefixStart = actionString.indexOf("[");
|
||||
int prefixEnd = actionString.indexOf("]");
|
||||
if (prefixStart < 0 || prefixEnd < 0) continue;
|
||||
|
||||
String prefix = actionString.substring(prefixStart + 1, prefixEnd);
|
||||
ClickType clickType = null;
|
||||
GUIActionType actionType;
|
||||
if (prefix.contains(":")) {
|
||||
String[] args = prefix.split(":");
|
||||
clickType = GUIConfiguration.readClickType(args[0]);
|
||||
actionType = GUIActionType.readActionType(args[1]);
|
||||
} else {
|
||||
actionType = GUIActionType.readActionType(prefix);
|
||||
}
|
||||
|
||||
if (actionType == null) continue;
|
||||
actions.add(new GUIActionConfiguration(clickType, actionType, actionString.substring(prefixEnd + 1).trim()));
|
||||
}
|
||||
|
||||
return new GUIItemConfiguration(
|
||||
material, data, name, lore, actions,
|
||||
slots.size() > 0 ? slots : Collections.singletonList(slot)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.configuration.message;
|
||||
|
||||
|
||||
import cc.carm.plugin.ultradepository.configuration.file.FileConfig;
|
||||
import cc.carm.plugin.ultradepository.configuration.values.ConfigValue;
|
||||
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
||||
import cc.carm.plugin.ultradepository.util.MessageUtil;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigMessage extends ConfigValue<String> {
|
||||
|
||||
String[] messageParams;
|
||||
|
||||
public ConfigMessage(String configSection) {
|
||||
this(configSection, null);
|
||||
}
|
||||
|
||||
public ConfigMessage(String configSection, String defaultValue) {
|
||||
this(configSection, defaultValue, null);
|
||||
}
|
||||
|
||||
public ConfigMessage(String configSection, String defaultValue, String[] messageParams) {
|
||||
super(ConfigManager.getMessageConfig(), configSection, String.class, defaultValue);
|
||||
this.messageParams = messageParams;
|
||||
}
|
||||
|
||||
public ConfigMessage(FileConfig config, String configSection, String defaultValue, String[] messageParams) {
|
||||
super(config, configSection, String.class, defaultValue);
|
||||
this.messageParams = messageParams;
|
||||
}
|
||||
|
||||
public String get(CommandSender sender, Object[] values) {
|
||||
if (messageParams != null) {
|
||||
return get(sender, messageParams, values);
|
||||
} else {
|
||||
return get(sender, new String[0], new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public String get(CommandSender sender, String[] params, Object[] values) {
|
||||
List<String> messages = MessageUtil.setPlaceholders(sender, Collections.singletonList(get()), params, values);
|
||||
return messages != null && !messages.isEmpty() ? messages.get(0) : "";
|
||||
}
|
||||
|
||||
public void send(CommandSender sender) {
|
||||
MessageUtil.sendWithPlaceholders(sender, get());
|
||||
}
|
||||
|
||||
public void send(CommandSender sender, Object[] values) {
|
||||
if (messageParams != null) {
|
||||
send(sender, messageParams, values);
|
||||
} else {
|
||||
send(sender, new String[0], new Object[0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void send(CommandSender sender, String[] params, Object[] values) {
|
||||
MessageUtil.sendWithPlaceholders(sender, Collections.singletonList(get()), params, values);
|
||||
}
|
||||
|
||||
}
|
||||
-68
@@ -1,68 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.configuration.message;
|
||||
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import cc.carm.plugin.ultradepository.configuration.file.FileConfig;
|
||||
import cc.carm.plugin.ultradepository.configuration.values.ConfigValueList;
|
||||
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
||||
import cc.carm.plugin.ultradepository.util.MessageUtil;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigMessageList extends ConfigValueList<String> {
|
||||
|
||||
String[] messageParams;
|
||||
|
||||
public ConfigMessageList(String configSection) {
|
||||
super(ConfigManager.getMessageConfig(), configSection, String.class);
|
||||
}
|
||||
|
||||
public ConfigMessageList(String configSection, String[] defaultValue) {
|
||||
this(configSection, defaultValue, null);
|
||||
}
|
||||
|
||||
public ConfigMessageList(String configSection, String[] defaultValue, String[] messageParams) {
|
||||
super(ConfigManager.getMessageConfig(), configSection, String.class, defaultValue);
|
||||
this.messageParams = messageParams;
|
||||
}
|
||||
|
||||
public ConfigMessageList(FileConfig config, String configSection, String[] defaultValue, String[] messageParams) {
|
||||
super(config, configSection, String.class, defaultValue);
|
||||
this.messageParams = messageParams;
|
||||
}
|
||||
|
||||
public List<String> get(@Nullable CommandSender sender) {
|
||||
return MessageUtil.setPlaceholders(sender, get());
|
||||
}
|
||||
|
||||
public List<String> get(@Nullable CommandSender sender, Object[] values) {
|
||||
if (messageParams != null) {
|
||||
return get(sender, messageParams, values);
|
||||
} else {
|
||||
return get(sender);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> get(@Nullable CommandSender sender, String[] params, Object[] values) {
|
||||
return MessageUtil.setPlaceholders(sender, get(), params, values);
|
||||
}
|
||||
|
||||
public void send(@Nullable CommandSender sender) {
|
||||
MessageUtil.sendWithPlaceholders(sender, get());
|
||||
}
|
||||
|
||||
public void send(@Nullable CommandSender sender, Object[] values) {
|
||||
if (messageParams != null) {
|
||||
send(sender, messageParams, values);
|
||||
} else {
|
||||
send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
public void send(@Nullable CommandSender sender, String[] params, Object[] values) {
|
||||
MessageUtil.sendWithPlaceholders(sender, get(), params, values);
|
||||
}
|
||||
}
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.configuration.values;
|
||||
|
||||
import cc.carm.plugin.ultradepository.configuration.file.FileConfig;
|
||||
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ConfigSectionCast<V> {
|
||||
|
||||
FileConfig source;
|
||||
|
||||
String configSection;
|
||||
@NotNull Function<ConfigurationSection, V> valueCast;
|
||||
V defaultValue;
|
||||
|
||||
V valueCache;
|
||||
long updateTime;
|
||||
|
||||
public ConfigSectionCast(String configSection, @NotNull Function<ConfigurationSection, V> valueCast) {
|
||||
this(configSection, valueCast, null);
|
||||
}
|
||||
|
||||
public ConfigSectionCast(String configSection,
|
||||
@NotNull Function<ConfigurationSection, V> valueCast,
|
||||
V defaultValue) {
|
||||
this(ConfigManager.getPluginConfig(), configSection, valueCast, defaultValue);
|
||||
}
|
||||
|
||||
public ConfigSectionCast(FileConfig source, String configSection,
|
||||
@NotNull Function<ConfigurationSection, V> valueCast,
|
||||
V defaultValue) {
|
||||
this.source = source;
|
||||
this.configSection = configSection;
|
||||
this.valueCast = valueCast;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public FileConfiguration getConfiguration() {
|
||||
return this.source.getConfig();
|
||||
}
|
||||
|
||||
|
||||
public @Nullable V get() {
|
||||
if (valueCache != null && !this.source.isExpired(this.updateTime)) return valueCache;
|
||||
if (!getConfiguration().contains(this.configSection)) return defaultValue;
|
||||
try {
|
||||
V finalValue = this.valueCast.apply(getConfiguration().getConfigurationSection(this.configSection));
|
||||
if (finalValue != null) {
|
||||
this.valueCache = finalValue;
|
||||
this.updateTime = System.currentTimeMillis();
|
||||
return finalValue;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void set(ConfigurationSection section) {
|
||||
|
||||
}
|
||||
|
||||
public void save() {
|
||||
this.source.save();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.configuration.values;
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import cc.carm.plugin.ultradepository.configuration.file.FileConfig;
|
||||
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ConfigSound {
|
||||
|
||||
|
||||
FileConfig source;
|
||||
String configSection;
|
||||
|
||||
Sound defaultValue;
|
||||
|
||||
public ConfigSound(String configSection) {
|
||||
this(configSection, null);
|
||||
}
|
||||
|
||||
public ConfigSound(String configSection, Sound defaultValue) {
|
||||
this(ConfigManager.getPluginConfig(), configSection, defaultValue);
|
||||
}
|
||||
|
||||
public ConfigSound(FileConfig source, String configSection, Sound defaultValue) {
|
||||
this.source = source;
|
||||
this.configSection = configSection;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public FileConfiguration getConfiguration() {
|
||||
return this.source.getConfig();
|
||||
}
|
||||
|
||||
public void set(Sound value, float volume) {
|
||||
getConfiguration().set(this.configSection, value.name() + ":" + volume);
|
||||
this.save();
|
||||
}
|
||||
|
||||
public void set(Sound value, float volume, float pitch) {
|
||||
getConfiguration().set(this.configSection, value.name() + ":" + volume + ":" + pitch);
|
||||
this.save();
|
||||
}
|
||||
|
||||
public void play(Player player) {
|
||||
Sound finalSound = defaultValue;
|
||||
float pitch = 1;
|
||||
float volume = 1;
|
||||
String soundString = getConfiguration().getString(this.configSection);
|
||||
if (soundString != null) {
|
||||
String[] args = soundString.contains(":") ? soundString.split(":") : new String[]{soundString};
|
||||
try {
|
||||
if (args.length >= 1) finalSound = Sound.valueOf(args[0]);
|
||||
if (args.length >= 2) volume = Float.parseFloat(args[1]);
|
||||
if (args.length >= 3) volume = Float.parseFloat(args[2]);
|
||||
} catch (Exception exception) {
|
||||
Main.log("声音 " + this.configSection + " 配置错误,不存在 " + soundString + " ,请检查。");
|
||||
Main.log("In " + this.configSection + " (" + soundString + ") doesn't match any sound name.");
|
||||
}
|
||||
}
|
||||
if (finalSound != null) {
|
||||
player.playSound(player.getLocation(), finalSound, volume, pitch);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void save() {
|
||||
this.source.save();
|
||||
}
|
||||
|
||||
}
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.configuration.values;
|
||||
|
||||
import cc.carm.plugin.ultradepository.configuration.file.FileConfig;
|
||||
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ConfigStringCast<V> {
|
||||
|
||||
FileConfig source;
|
||||
|
||||
String configSection;
|
||||
@NotNull Function<String, V> valueCast;
|
||||
V defaultValue;
|
||||
|
||||
V valueCache;
|
||||
long updateTime;
|
||||
|
||||
public ConfigStringCast(String configSection, @NotNull Function<String, V> valueCast) {
|
||||
this(configSection, valueCast, null);
|
||||
}
|
||||
|
||||
public ConfigStringCast(String configSection, @NotNull Function<String, V> valueCast, V defaultValue) {
|
||||
this(ConfigManager.getPluginConfig(), configSection, valueCast, defaultValue);
|
||||
}
|
||||
|
||||
public ConfigStringCast(FileConfig source, String configSection, @NotNull Function<String, V> valueCast, V defaultValue) {
|
||||
this.source = source;
|
||||
this.configSection = configSection;
|
||||
this.valueCast = valueCast;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public FileConfiguration getConfiguration() {
|
||||
return this.source.getConfig();
|
||||
}
|
||||
|
||||
public @Nullable V get() {
|
||||
if (valueCache != null && !this.source.isExpired(this.updateTime)) return valueCache;
|
||||
if (!getConfiguration().contains(this.configSection)) return setDefault();
|
||||
try {
|
||||
V finalValue = this.valueCast.apply(getConfiguration().getString(this.configSection));
|
||||
if (finalValue != null) {
|
||||
this.valueCache = finalValue;
|
||||
this.updateTime = System.currentTimeMillis();
|
||||
return finalValue;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void set(V value) {
|
||||
getConfiguration().set(this.configSection, value);
|
||||
this.save();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
this.source.save();
|
||||
}
|
||||
|
||||
public V setDefault() {
|
||||
set(this.defaultValue);
|
||||
return this.defaultValue;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.configuration.values;
|
||||
|
||||
import cc.carm.plugin.ultradepository.configuration.file.FileConfig;
|
||||
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class ConfigValue<V> {
|
||||
|
||||
FileConfig source;
|
||||
|
||||
String configSection;
|
||||
Class<V> clazz;
|
||||
V defaultValue;
|
||||
|
||||
public ConfigValue(String configSection, Class<V> clazz) {
|
||||
this(configSection, clazz, null);
|
||||
}
|
||||
|
||||
public ConfigValue(String configSection, Class<V> clazz, V defaultValue) {
|
||||
this(ConfigManager.getPluginConfig(), configSection, clazz, defaultValue);
|
||||
}
|
||||
|
||||
public ConfigValue(FileConfig source, String configSection, Class<V> clazz, V defaultValue) {
|
||||
this.source = source;
|
||||
this.configSection = configSection;
|
||||
this.clazz = clazz;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public FileConfiguration getConfiguration() {
|
||||
return this.source.getConfig();
|
||||
}
|
||||
|
||||
public V get() {
|
||||
if (getConfiguration().contains(this.configSection)) {
|
||||
Object val = getConfiguration().get(this.configSection, this.defaultValue);
|
||||
return this.clazz.isInstance(val) ? this.clazz.cast(val) : this.defaultValue;
|
||||
} else {
|
||||
// 如果没有默认值,就把配置写进去,便于配置
|
||||
return setDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public void set(V value) {
|
||||
getConfiguration().set(this.configSection, value);
|
||||
this.save();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
this.source.save();
|
||||
}
|
||||
|
||||
public V setDefault() {
|
||||
set(this.defaultValue);
|
||||
return this.defaultValue;
|
||||
}
|
||||
|
||||
}
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.configuration.values;
|
||||
|
||||
|
||||
import cc.carm.plugin.ultradepository.configuration.file.FileConfig;
|
||||
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigValueList<V> {
|
||||
FileConfig source;
|
||||
String configSection;
|
||||
Class<V> clazz;
|
||||
|
||||
V[] defaultValue;
|
||||
|
||||
public ConfigValueList(String configSection, Class<V> clazz) {
|
||||
this(ConfigManager.getPluginConfig(), configSection, clazz);
|
||||
}
|
||||
|
||||
public ConfigValueList(String configSection, Class<V> clazz, V[] defaultValue) {
|
||||
this(ConfigManager.getPluginConfig(), configSection, clazz, defaultValue);
|
||||
}
|
||||
|
||||
public ConfigValueList(FileConfig configuration, String configSection, Class<V> clazz) {
|
||||
this(configuration, configSection, clazz, null);
|
||||
}
|
||||
|
||||
public ConfigValueList(FileConfig configuration, String configSection, Class<V> clazz, V[] defaultValue) {
|
||||
this.source = configuration;
|
||||
this.configSection = configSection;
|
||||
this.clazz = clazz;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public FileConfiguration getConfiguration() {
|
||||
return this.source.getConfig();
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<V> get() {
|
||||
List<?> list = getConfiguration().getList(this.configSection);
|
||||
if (list == null) {
|
||||
if (defaultValue != null) {
|
||||
return new ArrayList<>(Arrays.asList(defaultValue));
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
} else {
|
||||
ArrayList<V> result = new ArrayList<>();
|
||||
|
||||
for (Object object : list) {
|
||||
if (this.clazz.isInstance(object)) {
|
||||
result.add(this.clazz.cast(object));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public void set(ArrayList<V> value) {
|
||||
getConfiguration().set(this.configSection, value);
|
||||
this.save();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
this.source.save();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.configuration.values;
|
||||
|
||||
import cc.carm.plugin.ultradepository.configuration.file.FileConfig;
|
||||
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ConfigValueMap<K, V> {
|
||||
|
||||
@NotNull FileConfig source;
|
||||
@NotNull String configSection;
|
||||
|
||||
@NotNull Function<String, K> keyCast;
|
||||
@NotNull Class<V> valueClazz;
|
||||
|
||||
@Nullable LinkedHashMap<K, V> valueCache;
|
||||
|
||||
long updateTime;
|
||||
|
||||
public ConfigValueMap(@NotNull String configSection, @NotNull Function<String, K> keyCast,
|
||||
@NotNull Class<V> valueClazz) {
|
||||
this(ConfigManager.getPluginConfig(), configSection, keyCast, valueClazz);
|
||||
}
|
||||
|
||||
public ConfigValueMap(@NotNull FileConfig configuration, @NotNull String configSection,
|
||||
@NotNull Function<String, K> keyCast, @NotNull Class<V> valueClazz) {
|
||||
this.source = configuration;
|
||||
this.configSection = configSection;
|
||||
this.keyCast = keyCast;
|
||||
this.valueClazz = valueClazz;
|
||||
}
|
||||
|
||||
|
||||
public @NotNull FileConfiguration getConfiguration() {
|
||||
return this.source.getConfig();
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
this.valueCache = null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<K, V> get() {
|
||||
if (valueCache != null && !this.source.isExpired(this.updateTime)) return valueCache;
|
||||
ConfigurationSection section = getConfiguration().getConfigurationSection(this.configSection);
|
||||
if (section == null) return new LinkedHashMap<>();
|
||||
Set<String> keys = section.getKeys(false);
|
||||
if (keys.isEmpty()) return new LinkedHashMap<>();
|
||||
else {
|
||||
LinkedHashMap<K, V> result = new LinkedHashMap<>();
|
||||
for (String key : keys) {
|
||||
K finalKey = keyCast.apply(key);
|
||||
Object val = section.get(key);
|
||||
V finalValue = this.valueClazz.isInstance(val) ? this.valueClazz.cast(val) : null;
|
||||
if (finalKey != null && finalValue != null) {
|
||||
result.put(finalKey, finalValue);
|
||||
}
|
||||
}
|
||||
this.updateTime = System.currentTimeMillis();
|
||||
this.valueCache = result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public void set(HashMap<K, V> valuesMap) {
|
||||
getConfiguration().createSection(this.configSection, valuesMap);
|
||||
this.save();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
this.source.save();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,6 +42,12 @@ public class DepositoryItemData {
|
||||
this.sold = Math.max(0, sold);
|
||||
}
|
||||
|
||||
public int[] applyChanges(int amountChanges, int soldChanges) {
|
||||
setAmount(getAmount() + amountChanges);
|
||||
setSold(getSold() + soldChanges);
|
||||
return new int[]{getAmount(), getSold()};
|
||||
}
|
||||
|
||||
public void clearSold() {
|
||||
this.sold = 0;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package cc.carm.plugin.ultradepository.data;
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.Depository;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.DepositoryItem;
|
||||
import cc.carm.plugin.ultradepository.storage.DataStorage;
|
||||
import cc.carm.plugin.ultradepository.util.DateIntUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -18,15 +17,13 @@ public class UserData {
|
||||
|
||||
public final UUID userUUID;
|
||||
|
||||
DataStorage storage;
|
||||
Map<String, DepositoryData> depositories;
|
||||
|
||||
int date;
|
||||
|
||||
public UserData(UUID userUUID, DataStorage storage,
|
||||
public UserData(UUID userUUID,
|
||||
Map<String, DepositoryData> depositories, int date) {
|
||||
this.userUUID = userUUID;
|
||||
this.storage = storage;
|
||||
this.depositories = depositories;
|
||||
this.date = date;
|
||||
}
|
||||
@@ -45,7 +42,7 @@ public class UserData {
|
||||
}
|
||||
|
||||
public @Nullable DepositoryData getDepositoryData(String depositoryID) {
|
||||
Depository depository = Main.getDepositoryManager().getDepository(depositoryID);
|
||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(depositoryID);
|
||||
if (depository == null) return null;
|
||||
return getDepositoryData(depository);
|
||||
}
|
||||
@@ -120,7 +117,7 @@ public class UserData {
|
||||
|
||||
|
||||
public Date getDate() {
|
||||
return new Date(DateIntUtil.getDateMillis(getDateInt()));
|
||||
return DateIntUtil.getDate(getDateInt());
|
||||
}
|
||||
|
||||
public int getDateInt() {
|
||||
@@ -134,22 +131,14 @@ public class UserData {
|
||||
|
||||
|
||||
public void checkoutDate() {
|
||||
if (isCurrentDay()) {
|
||||
Main.debug("Date is not change, skip clear sold amount.");
|
||||
return;
|
||||
}
|
||||
if (isCurrentDay()) return;
|
||||
|
||||
this.date = DateIntUtil.getCurrentDate(); //更新日期
|
||||
Main.debug("Date changed, clear sold.");
|
||||
getDepositories().values().stream()
|
||||
.flatMap(value -> value.getContents().values().stream())
|
||||
.forEach(DepositoryItemData::clearSold);
|
||||
}
|
||||
|
||||
|
||||
public void save() throws Exception {
|
||||
this.storage.saveUserData(this);
|
||||
}
|
||||
|
||||
public Map<String, Map<String, Map<String, Integer>>> serializeToMap() {
|
||||
Map<String, Map<String, Map<String, Integer>>> values = new LinkedHashMap<>();
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package cc.carm.plugin.ultradepository.event;
|
||||
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.Depository;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.DepositoryItem;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DepositoryCollectItemEvent extends UltraDepositoryEvent implements Cancellable {
|
||||
|
||||
public static HandlerList handlers = new HandlerList();
|
||||
|
||||
boolean cancelled;
|
||||
|
||||
private final DepositoryItem depositoryItem;
|
||||
int itemAmount;
|
||||
|
||||
public DepositoryCollectItemEvent(@NotNull Player player, @NotNull Depository depository,
|
||||
@NotNull DepositoryItem depositoryItem, int itemAmount) {
|
||||
super(player, depository);
|
||||
this.depositoryItem = depositoryItem;
|
||||
this.itemAmount = itemAmount;
|
||||
}
|
||||
|
||||
|
||||
public void setItemAmount(int itemAmount) {
|
||||
this.itemAmount = itemAmount;
|
||||
}
|
||||
|
||||
public int getItemAmount() {
|
||||
return itemAmount;
|
||||
}
|
||||
|
||||
public DepositoryItem getDepositoryItem() {
|
||||
return depositoryItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package cc.carm.plugin.ultradepository.event;
|
||||
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.DepositoryItem;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DepositorySellItemEvent extends UltraDepositoryEvent {
|
||||
|
||||
public static HandlerList handlers = new HandlerList();
|
||||
|
||||
int beforeAmount;
|
||||
int afterAmount;
|
||||
double earnedMoney;
|
||||
|
||||
public DepositorySellItemEvent(@NotNull Player player, @NotNull DepositoryItem depositoryItem,
|
||||
int beforeAmount, int afterAmount, double earnedMoney) {
|
||||
super(player, depositoryItem.getDepository());
|
||||
this.beforeAmount = beforeAmount;
|
||||
this.afterAmount = afterAmount;
|
||||
this.earnedMoney = earnedMoney;
|
||||
}
|
||||
|
||||
public int getBeforeAmount() {
|
||||
return beforeAmount;
|
||||
}
|
||||
|
||||
public int getAfterAmount() {
|
||||
return afterAmount;
|
||||
}
|
||||
|
||||
public double getEarnedMoney() {
|
||||
return earnedMoney;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cc.carm.plugin.ultradepository.event;
|
||||
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.Depository;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class UltraDepositoryEvent extends Event {
|
||||
|
||||
|
||||
@NotNull Player player;
|
||||
@NotNull Depository depository;
|
||||
|
||||
public UltraDepositoryEvent(@NotNull Player player, @NotNull Depository depository) {
|
||||
this.player = player;
|
||||
this.depository = depository;
|
||||
}
|
||||
|
||||
public @NotNull UserData getUserData() {
|
||||
return UltraDepository.getUserManager().getData(getPlayer());
|
||||
}
|
||||
|
||||
public @NotNull Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public @NotNull Depository getDepository() {
|
||||
return depository;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
package cc.carm.plugin.ultradepository.hooker;
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.Depository;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.DepositoryItem;
|
||||
import cc.carm.plugin.ultradepository.data.DepositoryItemData;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -24,10 +25,10 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
||||
"%UltraDepository_usable_<BackpackID>%"
|
||||
);
|
||||
|
||||
Main main;
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
public PAPIExpansion(Main main) {
|
||||
this.main = main;
|
||||
public PAPIExpansion(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,17 +43,17 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return main.getDescription().getAuthors().toString();
|
||||
return plugin.getDescription().getAuthors().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return main.getDescription().getName();
|
||||
return plugin.getDescription().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return main.getDescription().getVersion();
|
||||
return plugin.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,7 +65,7 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
||||
return "Error Params";
|
||||
}
|
||||
|
||||
UserData data = Main.getUserManager().getData(player);
|
||||
UserData data = UltraDepository.getUserManager().getData(player);
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "amount": {
|
||||
@@ -81,7 +82,7 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
||||
}
|
||||
case "remain": {
|
||||
if (args.length < 2) return "Error Params";
|
||||
Depository depository = Main.getDepositoryManager().getDepository(args[1]);
|
||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
|
||||
if (depository == null) return "Depository not exists";
|
||||
DepositoryItem item = depository.getItems().get(args[2]);
|
||||
if (item == null) return "Depository Item not exists";
|
||||
@@ -91,34 +92,36 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
||||
}
|
||||
case "limit": {
|
||||
if (args.length < 3) return "Error Params";
|
||||
Integer limit = Main.getDepositoryManager().getItemSellLimit(args[1], args[2]);
|
||||
Integer limit = UltraDepository.getDepositoryManager().getItemSellLimit(args[1], args[2]);
|
||||
if (limit == null) return "Depository or Item not exists";
|
||||
else return limit.toString();
|
||||
}
|
||||
case "price": {
|
||||
if (args.length < 3) return "Error Params";
|
||||
Double price = Main.getDepositoryManager().getItemPrice(args[1], args[2]);
|
||||
Double price = UltraDepository.getDepositoryManager().getItemPrice(args[1], args[2]);
|
||||
if (price == null) return "Depository or Item not exists";
|
||||
else return price.toString();
|
||||
}
|
||||
case "capacity": {
|
||||
if (args.length < 2) return "Error Params";
|
||||
Depository depository = Main.getDepositoryManager().getDepository(args[1]);
|
||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
|
||||
if (depository == null) return "Depository not exists";
|
||||
return Integer.toString(depository.getCapacity().getPlayerCapacity(player));
|
||||
int capacity = depository.getCapacity().getPlayerCapacity(player);
|
||||
return capacity < 0 ? "∞" : Integer.toString(capacity);
|
||||
}
|
||||
case "used": {
|
||||
if (args.length < 2) return "Error Params";
|
||||
Depository depository = Main.getDepositoryManager().getDepository(args[1]);
|
||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
|
||||
if (depository == null) return "Depository not exists";
|
||||
return Integer.toString(data.getDepositoryData(depository).getUsedCapacity());
|
||||
}
|
||||
case "usable": {
|
||||
if (args.length < 2) return "Error Params";
|
||||
Depository depository = Main.getDepositoryManager().getDepository(args[1]);
|
||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
|
||||
if (depository == null) return "Depository not exists";
|
||||
int max = depository.getCapacity().getPlayerCapacity(player);
|
||||
int used = data.getDepositoryData(depository).getUsedCapacity();
|
||||
return Integer.toString(depository.getCapacity().getPlayerCapacity(player) - used);
|
||||
return max < 0 ? "∞" : Integer.toString(max - used);
|
||||
}
|
||||
case "version": {
|
||||
return getVersion();
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package cc.carm.plugin.ultradepository.listener;
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -25,19 +23,17 @@ public class CollectListener implements Listener {
|
||||
if (event.isCancelled() || !PluginConfig.Collect.BREAK.get()) return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if (!Main.getUserManager().isCollectEnabled(player)) return;
|
||||
if (event.getBlock().getType() == Material.CHEST || event.getBlock().getType() == Material.TRAPPED_CHEST) {
|
||||
return;
|
||||
}
|
||||
if (!UltraDepository.getUserManager().isCollectEnabled(player)) return;
|
||||
if (event.getBlock().getType().isOccluding()) return;
|
||||
|
||||
List<Item> droppedItems = event.getItems();
|
||||
if (droppedItems.isEmpty()) return;
|
||||
|
||||
for (Item drop : droppedItems) {
|
||||
Main.debug("Dropped " + drop.getType().name() + " " + drop.getItemStack().getAmount());
|
||||
UltraDepository.getInstance().debug("Dropped " + drop.getType().name() + " " + drop.getItemStack().getAmount());
|
||||
}
|
||||
|
||||
event.getItems().removeIf(item -> Main.getDepositoryManager().collectItem(player, item.getItemStack()));
|
||||
event.getItems().removeIf(item -> UltraDepository.getDepositoryManager().collectItem(player, item.getItemStack()));
|
||||
|
||||
}
|
||||
|
||||
@@ -47,9 +43,9 @@ public class CollectListener implements Listener {
|
||||
|
||||
Player player = event.getEntity().getKiller();
|
||||
if (player == null) return;
|
||||
if (!Main.getUserManager().isCollectEnabled(player)) return;
|
||||
if (!UltraDepository.getUserManager().isCollectEnabled(player)) return;
|
||||
|
||||
Collection<ItemStack> finalDrops = Main.getDepositoryManager().collectItem(player, event.getDrops());
|
||||
Collection<ItemStack> finalDrops = UltraDepository.getDepositoryManager().collectItem(player, event.getDrops());
|
||||
event.getDrops().clear();
|
||||
event.getDrops().addAll(finalDrops);
|
||||
}
|
||||
@@ -60,15 +56,15 @@ public class CollectListener implements Listener {
|
||||
if (!(event.getEntity() instanceof Player)) return;
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
if (!Main.getUserManager().isCollectEnabled(player)) return;
|
||||
if (!UltraDepository.getUserManager().isCollectEnabled(player)) return;
|
||||
|
||||
// 自己扔出去的东西不计入背包
|
||||
UUID thrower = event.getItem().getThrower();
|
||||
if (thrower != null && thrower.equals(player.getUniqueId())) return;
|
||||
|
||||
ItemStack item = event.getItem().getItemStack();
|
||||
Main.debug("Picked up " + item.getType().name() + " " + item.getAmount());
|
||||
if (Main.getDepositoryManager().collectItem(player, item)) {
|
||||
UltraDepository.getInstance().debug("Picked up " + item.getType().name() + " " + item.getAmount());
|
||||
if (UltraDepository.getDepositoryManager().collectItem(player, item)) {
|
||||
event.setCancelled(true);
|
||||
event.getItem().remove();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cc.carm.plugin.ultradepository.listener;
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
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,24 +20,22 @@ public class UserListener implements Listener {
|
||||
if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
||||
return;
|
||||
}
|
||||
UUID uuid = event.getUniqueId();
|
||||
Main.debug("尝试加载玩家 " + event.getName() + " 的数据...");
|
||||
Main.getUserManager().getDataCache().put(uuid, Main.getUserManager().loadData(uuid));
|
||||
UltraDepository.getUserManager().loadDataCache(event.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPreLoginMonitor(AsyncPlayerPreLoginEvent event) {
|
||||
if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
||||
Main.getUserManager().getDataCache().remove(event.getUniqueId());
|
||||
UltraDepository.getUserManager().removeDataCache(event.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerLogin(PlayerLoginEvent e) {
|
||||
UserData data = Main.getUserManager().getData(e.getPlayer().getUniqueId());
|
||||
UserData data = UltraDepository.getUserManager().getData(e.getPlayer().getUniqueId());
|
||||
if (data == null) {
|
||||
e.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
e.setKickMessage(Main.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();
|
||||
Main.getScheduler().runAsync(() -> Main.getUserManager().unloadData(playerUUID, true));
|
||||
UltraDepository.getInstance().getScheduler()
|
||||
.runAsync(() -> UltraDepository.getUserManager().unloadData(playerUUID, true));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,48 +1,76 @@
|
||||
package cc.carm.plugin.ultradepository.manager;
|
||||
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import cc.carm.plugin.ultradepository.configuration.file.FileConfig;
|
||||
import cc.carm.plugin.ultradepository.configuration.gui.GUIActionConfiguration;
|
||||
import cc.carm.plugin.ultradepository.configuration.gui.GUIActionType;
|
||||
import cc.carm.plugin.ultradepository.configuration.gui.GUIConfiguration;
|
||||
import cc.carm.plugin.ultradepository.util.gui.GUIItem;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||
import cc.carm.lib.easyplugin.configuration.language.MessagesConfig;
|
||||
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 java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
private static FileConfig config;
|
||||
private static FileConfig messageConfig;
|
||||
private static FileConfig pluginConfiguration;
|
||||
private static MessagesConfig messageConfiguration;
|
||||
|
||||
public static void initConfig() {
|
||||
ConfigManager.config = new FileConfig(Main.getInstance(), "config.yml");
|
||||
ConfigManager.messageConfig = new FileConfig(Main.getInstance(), "messages.yml");
|
||||
public static boolean initialize() {
|
||||
UltraDepository udPlugin = UltraDepository.getInstance();
|
||||
|
||||
|
||||
try {
|
||||
File configFile = new File(udPlugin.getDataFolder(), "config.yml");
|
||||
if (!configFile.exists()) {
|
||||
//没找到配置文件,可能是第一次加载此插件
|
||||
//把一些英文版的东西复制出来,方便英文用户使用。
|
||||
UltraDepository.getInstance().log(" 未找到配置文件,生成默认配置...");
|
||||
JarUtil.copyFolderFromJar(
|
||||
"i18n", udPlugin.getDataFolder(),
|
||||
JarUtil.CopyOption.COPY_IF_NOT_EXIST
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
pluginConfiguration = new FileConfig(udPlugin, "config.yml");
|
||||
messageConfiguration = new MessagesConfig(udPlugin, "messages.yml");
|
||||
|
||||
FileConfig.pluginConfiguration = () -> pluginConfiguration;
|
||||
FileConfig.messageConfiguration = () -> messageConfiguration;
|
||||
|
||||
MessagesInitializer.initialize(messageConfiguration, PluginMessages.class);
|
||||
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static FileConfig getPluginConfig() {
|
||||
return config;
|
||||
return pluginConfiguration;
|
||||
}
|
||||
|
||||
public static FileConfig getMessageConfig() {
|
||||
return messageConfig;
|
||||
public static MessagesConfig getMessageConfig() {
|
||||
return messageConfiguration;
|
||||
}
|
||||
|
||||
public static void reload() {
|
||||
try {
|
||||
getPluginConfig().reload();
|
||||
getMessageConfig().reload();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveConfig() {
|
||||
try {
|
||||
getPluginConfig().save();
|
||||
getMessageConfig().save();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package cc.carm.plugin.ultradepository.manager;
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
|
||||
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.data.UserData;
|
||||
import cc.carm.plugin.ultradepository.event.DepositoryCollectItemEvent;
|
||||
import cc.carm.plugin.ultradepository.util.JarUtil;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@@ -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;
|
||||
|
||||
@@ -41,10 +43,19 @@ public class DepositoryManager {
|
||||
|
||||
public void loadDepositories() {
|
||||
long start = System.currentTimeMillis();
|
||||
Main.log(" 开始加载仓库配置...");
|
||||
File folder = new File(Main.getInstance().getDataFolder(), "depositories");
|
||||
UltraDepository.getInstance().log(" 开始加载仓库配置...");
|
||||
File folder = new File(UltraDepository.getInstance().getDataFolder(), "depositories");
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
|
||||
try {
|
||||
JarUtil.copyFolderFromJar(
|
||||
"depositories", UltraDepository.getInstance().getDataFolder(),
|
||||
JarUtil.CopyOption.COPY_IF_NOT_EXIST
|
||||
);
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
|
||||
} else if (folder.isDirectory()) {
|
||||
folder.delete();
|
||||
folder.mkdir();
|
||||
@@ -56,7 +67,8 @@ public class DepositoryManager {
|
||||
HashMap<@NotNull String, @NotNull Depository> data = new HashMap<>();
|
||||
for (File file : files) {
|
||||
String fileName = file.getName();
|
||||
if (!file.isFile() || !fileName.toLowerCase().endsWith(".yml")) continue;
|
||||
if (!file.isFile() || fileName.startsWith(".")) continue;
|
||||
if (!fileName.toLowerCase().endsWith(".yml")) continue;
|
||||
String identifier = fileName.substring(0, fileName.lastIndexOf("."));
|
||||
FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);
|
||||
Depository depository = Depository.loadFrom(identifier, configuration);
|
||||
@@ -64,19 +76,19 @@ public class DepositoryManager {
|
||||
depository.getItems().values().forEach(value -> items.put(value.getTypeID(), depository.getIdentifier()));
|
||||
data.put(identifier, depository);
|
||||
} else {
|
||||
Main.error(" 仓库 " + depository.getName() + " 未配置任何物品,请检查相关配置!");
|
||||
UltraDepository.getInstance().error(" 仓库 " + depository.getName() + " 未配置任何物品,请检查相关配置!");
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, Collection<String>> entry : items.asMap().entrySet()) {
|
||||
Main.debug("# " + entry.getKey());
|
||||
UltraDepository.getInstance().debug("# " + entry.getKey());
|
||||
for (String depositoryID : entry.getValue()) {
|
||||
Main.debug("- " + depositoryID);
|
||||
UltraDepository.getInstance().debug("- " + depositoryID);
|
||||
}
|
||||
}
|
||||
|
||||
this.depositories = data;
|
||||
this.itemMap = items;
|
||||
Main.log(" 仓库配置加载完成,共加载 " + data.size() + " 个仓库,耗时 " + (System.currentTimeMillis() - start) + "ms 。");
|
||||
UltraDepository.getInstance().log(" 仓库配置加载完成,共加载 " + data.size() + " 个仓库,耗时 " + (System.currentTimeMillis() - start) + "ms 。");
|
||||
}
|
||||
|
||||
public @NotNull HashMap<@NotNull String, @NotNull Depository> getDepositories() {
|
||||
@@ -101,6 +113,7 @@ public class DepositoryManager {
|
||||
return getDepositories().get(depositoryID);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public Set<Depository> getItemDepositories(ItemStack itemStack) {
|
||||
return getItemDepositories(itemStack.getType(), itemStack.getDurability());
|
||||
}
|
||||
@@ -112,56 +125,74 @@ public class DepositoryManager {
|
||||
}
|
||||
|
||||
public Set<Depository> getPlayerUsableDepository(Player player, ItemStack itemStack) {
|
||||
String typeID = getItemTypeID(itemStack);
|
||||
return getItemDepositories(itemStack).stream().filter(configuration -> {
|
||||
int currentAmount = Optional.ofNullable(Main.getUserManager().getData(player)
|
||||
.getItemAmount(configuration.getIdentifier(), typeID)).orElse(0);
|
||||
int depositoryCapacity = configuration.getCapacity().getPlayerCapacity(player);
|
||||
return currentAmount + itemStack.getAmount() <= depositoryCapacity;
|
||||
int used = UltraDepository.getUserManager().getData(player).getDepositoryData(configuration).getUsedCapacity();
|
||||
int max = configuration.getCapacity().getPlayerCapacity(player);
|
||||
return max < 0 || used + itemStack.getAmount() <= max;
|
||||
}).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public @NotNull String getItemTypeID(Material material, int data) {
|
||||
return material.name() + ":" + data;
|
||||
if (data == 0) return material.name();
|
||||
else return material.name() + ":" + data;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public @NotNull String getItemTypeID(ItemStack itemStack) {
|
||||
return getItemTypeID(itemStack.getType(), itemStack.getDurability());
|
||||
}
|
||||
|
||||
public Collection<ItemStack> collectItem(Player player, Collection<ItemStack> items) {
|
||||
if (!Main.getUserManager().isCollectEnabled(player)) {
|
||||
Main.debug("player " + player.getName() + " disabled collect, skipped.");
|
||||
if (!UltraDepository.getUserManager().isCollectEnabled(player)) {
|
||||
UltraDepository.getInstance().debug("player " + player.getName() + " disabled collect, skipped.");
|
||||
return items;
|
||||
} else return items.stream().filter(item -> !collectItem(player, item)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public boolean collectItem(Player player, ItemStack item) {
|
||||
String typeID = getItemTypeID(item);
|
||||
Main.debug("Checking item " + typeID + " ...");
|
||||
if (!Main.getUserManager().isCollectEnabled(player)) {
|
||||
Main.debug("Player " + player.getName() + " disabled collect, skipped.");
|
||||
UltraDepository.getInstance().debug("Checking item " + typeID + " ...");
|
||||
if (!UltraDepository.getUserManager().isCollectEnabled(player)) {
|
||||
UltraDepository.getInstance().debug("Player " + player.getName() + " disabled collect, skipped.");
|
||||
return false;
|
||||
}
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta != null && (meta.hasLore() || meta.hasDisplayName() || meta.hasEnchants())) {
|
||||
// 不收集有特殊属性的物品
|
||||
Main.debug("Item has special meta, skipped.");
|
||||
UltraDepository.getInstance().debug("Item has special meta, skipped.");
|
||||
return false;
|
||||
}
|
||||
Set<Depository> usableDepositories = getPlayerUsableDepository(player, item);
|
||||
if (usableDepositories.size() < 1) {
|
||||
Main.debug("Item doesn't has any depository, skipped.");
|
||||
UltraDepository.getInstance().debug("Item doesn't has any depository, skipped.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Depository depository = usableDepositories.stream().findFirst().orElse(null);
|
||||
String itemName = depository.getItems().get(typeID).getName();
|
||||
UserData data = Main.getUserManager().getData(player);
|
||||
DepositoryItem depositoryItem = depository.getItems().get(typeID);
|
||||
int itemAmount = item.getAmount();
|
||||
data.addItemAmount(depository.getIdentifier(), typeID, itemAmount);
|
||||
PluginMessages.COLLECTED.send(player, new Object[]{itemName, itemAmount, depository.getName()});
|
||||
|
||||
DepositoryCollectItemEvent collectItemEvent = new DepositoryCollectItemEvent(player, depository, depositoryItem, itemAmount);
|
||||
Bukkit.getPluginManager().callEvent(collectItemEvent);
|
||||
|
||||
if (collectItemEvent.isCancelled()) return false;
|
||||
int finalAmount = collectItemEvent.getItemAmount();
|
||||
|
||||
collectItemEvent.getUserData().addItemAmount(depository.getIdentifier(), typeID, finalAmount);
|
||||
if (!player.hasPermission("UltraDepository.silent")) {
|
||||
PluginMessages.ITEM_COLLECT.send(player, new Object[]{
|
||||
depository.getItems().get(typeID).getName(),
|
||||
finalAmount, depository.getName()
|
||||
});
|
||||
PluginConfig.Sounds.COLLECT.play(player);
|
||||
Main.debug("Item collected successfully.");
|
||||
|
||||
PluginMessages.ITEM_COLLECT_ACTIONBAR.sendBar(player, new Object[]{
|
||||
depository.getItems().get(typeID).getName(),
|
||||
finalAmount, depository.getName()
|
||||
}); // Support action bar
|
||||
|
||||
}
|
||||
UltraDepository.getInstance().debug("Item collected successfully.");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,19 @@ package cc.carm.plugin.ultradepository.manager;
|
||||
|
||||
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
|
||||
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.data.DepositoryData;
|
||||
import cc.carm.plugin.ultradepository.data.DepositoryItemData;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import cc.carm.plugin.ultradepository.event.DepositorySellItemEvent;
|
||||
import cc.carm.plugin.ultradepository.hooker.VaultHooker;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
public class EconomyManager {
|
||||
|
||||
VaultHooker hooker;
|
||||
@@ -31,9 +38,9 @@ public class EconomyManager {
|
||||
|
||||
public double sell(Player player, double price, int amount) {
|
||||
if (!isInitialized()) return 0D;
|
||||
double money = price * amount;
|
||||
getHooker().addMoney(player, money);
|
||||
return money;
|
||||
BigDecimal money = BigDecimal.valueOf(price * amount).setScale(2, RoundingMode.DOWN);
|
||||
getHooker().addMoney(player, money.doubleValue());
|
||||
return money.doubleValue();
|
||||
}
|
||||
|
||||
public void sellAllItem(Player player, UserData userData) {
|
||||
@@ -41,43 +48,48 @@ public class EconomyManager {
|
||||
}
|
||||
|
||||
public void sellAllItem(Player player, UserData userData, boolean playSound) {
|
||||
userData.getDepositories().values().forEach(depositoryData -> sellAllItem(player, userData, depositoryData, false));
|
||||
userData.getDepositories().values().stream().map(DepositoryData::getSource)
|
||||
.forEach(depositoryData -> sellAllItem(player, userData, depositoryData, false));
|
||||
if (playSound) PluginConfig.Sounds.SELL_SUCCESS.play(player);
|
||||
}
|
||||
|
||||
|
||||
public void sellAllItem(Player player, UserData userData, DepositoryData depositoryData) {
|
||||
sellAllItem(player, userData, depositoryData, true);
|
||||
public void sellAllItem(Player player, UserData userData, Depository depository) {
|
||||
sellAllItem(player, userData, depository, true);
|
||||
}
|
||||
|
||||
public void sellAllItem(Player player, UserData userData, DepositoryData depositoryData, boolean playSound) {
|
||||
depositoryData.getContents().values().forEach(value -> sellAllItem(player, userData, value, false));
|
||||
public void sellAllItem(Player player, UserData userData, Depository depository, boolean playSound) {
|
||||
depository.getItems().values().forEach(value -> sellAllItem(player, userData, value, false));
|
||||
if (playSound) PluginConfig.Sounds.SELL_SUCCESS.play(player);
|
||||
}
|
||||
|
||||
|
||||
public void sellAllItem(Player player, UserData userData, DepositoryItemData itemData) {
|
||||
sellAllItem(player, userData, itemData, true);
|
||||
public void sellAllItem(Player player, UserData userData, DepositoryItem depositoryItem) {
|
||||
sellAllItem(player, userData, depositoryItem, true);
|
||||
}
|
||||
|
||||
public void sellAllItem(Player player, UserData userData, DepositoryItemData itemData, boolean playSound) {
|
||||
public void sellAllItem(Player player, UserData userData, DepositoryItem depositoryItem, boolean playSound) {
|
||||
DepositoryItemData itemData = userData.getItemData(depositoryItem);
|
||||
int amount = itemData.getAmount();
|
||||
int sold = itemData.getSold();
|
||||
int limit = itemData.getSource().getLimit();
|
||||
int limit = depositoryItem.getLimit();
|
||||
int finalAmount = Math.min(amount, (limit - sold));
|
||||
if (finalAmount > 0) sellItem(player, userData, itemData, finalAmount, false);
|
||||
if (finalAmount > 0) sellItem(player, userData, depositoryItem, finalAmount, false);
|
||||
if (playSound) PluginConfig.Sounds.SELL_SUCCESS.play(player);
|
||||
}
|
||||
|
||||
public void sellItem(Player player, UserData userData, DepositoryItemData itemData, int amount) {
|
||||
sellItem(player, userData, itemData, amount, true);
|
||||
public void sellItem(Player player, UserData userData, DepositoryItem depositoryItem, int amount) {
|
||||
sellItem(player, userData, depositoryItem, amount, true);
|
||||
}
|
||||
|
||||
public void sellItem(Player player, UserData userData, DepositoryItemData itemData, int amount, boolean playSound) {
|
||||
userData.addItemSold(itemData.getOwner().getSource().getIdentifier(), itemData.getSource().getTypeID(), amount);
|
||||
userData.removeItemAmount(itemData.getOwner().getSource().getIdentifier(), itemData.getSource().getTypeID(), amount);
|
||||
double money = sell(player, itemData.getSource().getPrice(), amount);
|
||||
PluginMessages.SOLD.send(player, new Object[]{itemData.getSource().getName(), amount, money});
|
||||
public void sellItem(Player player, UserData userData, DepositoryItem depositoryItem, int amount, boolean playSound) {
|
||||
int[] changes = userData.getItemData(depositoryItem).applyChanges(-amount, amount);
|
||||
double money = sell(player, depositoryItem.getPrice(), amount);
|
||||
Bukkit.getPluginManager().callEvent(new DepositorySellItemEvent(
|
||||
player, depositoryItem, changes[0] + amount, changes[0], money
|
||||
));
|
||||
|
||||
PluginMessages.ITEM_SOLD.send(player, new Object[]{depositoryItem.getName(), amount, money});
|
||||
if (playSound) PluginConfig.Sounds.SELL_SUCCESS.play(player);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package cc.carm.plugin.ultradepository.manager;
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
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;
|
||||
@@ -19,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);
|
||||
}
|
||||
@@ -29,11 +52,25 @@ public class UserManager {
|
||||
|
||||
public @NotNull UserData loadData(@NotNull UUID userUUID) {
|
||||
try {
|
||||
return Main.getStorage().loadData(userUUID);
|
||||
long start = System.currentTimeMillis();
|
||||
DataStorage storage = UltraDepository.getStorage();
|
||||
UltraDepository.getInstance().debug("正通过 " + storage.getClass().getSimpleName() + " 加载 " + userUUID + " 的用户数据...(" + System.currentTimeMillis() + ")");
|
||||
UserData data = UltraDepository.getStorage().loadData(userUUID);
|
||||
|
||||
if (data == null) {
|
||||
UltraDepository.getInstance().debug("当前还不存在玩家 " + userUUID + " 的数据,视作新档。");
|
||||
return new UserData(userUUID, new HashMap<>(), DateIntUtil.getCurrentDate());
|
||||
}
|
||||
|
||||
UltraDepository.getInstance().debug("通过 " + storage.getClass().getSimpleName() + "加载 " + userUUID + " 的用户数据完成,"
|
||||
+ "耗时 " + (System.currentTimeMillis() - start) + "ms。");
|
||||
|
||||
return data;
|
||||
} catch (Exception e) {
|
||||
Main.error("无法正常加载玩家数据,玩家操作将不会被保存,请检查数据配置!");
|
||||
Main.error("Could not load user's data, please check the data configuration!");
|
||||
return new UserData(userUUID, Main.getStorage(), new HashMap<>(), DateIntUtil.getCurrentDate());
|
||||
UltraDepository.getInstance().error("无法正常加载玩家数据,玩家操作将不会被保存,请检查数据配置!");
|
||||
UltraDepository.getInstance().error("Could not load user's data, please check the data configuration!");
|
||||
e.printStackTrace();
|
||||
return new UserData(userUUID, new HashMap<>(), DateIntUtil.getCurrentDate());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,16 +78,23 @@ 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) {
|
||||
try {
|
||||
data.save();
|
||||
Main.debug(" 玩家 " + data.getUserUUID() + " 数据已保存。");
|
||||
long start = System.currentTimeMillis();
|
||||
DataStorage storage = UltraDepository.getStorage();
|
||||
|
||||
UltraDepository.getInstance().debug("正通过 " + storage.getClass().getSimpleName() + " 保存 " + data.getUserUUID() + " 的用户数据...(" + System.currentTimeMillis() + ")");
|
||||
storage.saveUserData(data);
|
||||
|
||||
UltraDepository.getInstance().debug("通过 " + storage.getClass().getSimpleName() + " 保存 " + data.getUserUUID() + " 的用户数据完成," +
|
||||
"耗时 " + (System.currentTimeMillis() - start) + "ms。");
|
||||
|
||||
} catch (Exception e) {
|
||||
Main.error("无法正常保存玩家数据,请检查数据配置!");
|
||||
Main.error("Could not save user's data, please check the data configuration!");
|
||||
UltraDepository.getInstance().error("无法正常保存玩家数据,请检查数据配置!");
|
||||
UltraDepository.getInstance().error("Could not save user's data, please check the data configuration!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,70 @@
|
||||
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;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface DataStorage {
|
||||
|
||||
|
||||
/**
|
||||
* 在插件加载存储源时执行。
|
||||
*
|
||||
* @return 是否初始化成功
|
||||
*/
|
||||
boolean initialize();
|
||||
|
||||
/**
|
||||
* 在插件被卸载时执行。
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
@NotNull
|
||||
/**
|
||||
* 用于加载用户数据的方法。<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;
|
||||
|
||||
/**
|
||||
* Support old data which is forced to use data value.
|
||||
* 老数据强制给typeID加上了data值(包括0),然而1.13后每个物品都有对应的Material。
|
||||
* 自插件v1.1.6版本开始不再强制,但需要为此额外做出支持,避免玩家数据丢失。
|
||||
*
|
||||
* @param typeID ID源数据
|
||||
* @return 正确ID数据
|
||||
* @since v1.1.6
|
||||
*/
|
||||
static String getFixedTypeID(String typeID) {
|
||||
String trueID = typeID;
|
||||
if (typeID.contains(":")) {
|
||||
try {
|
||||
String[] args = trueID.split(":");
|
||||
if (Integer.parseInt(args[1]) == 0) {
|
||||
|
||||
trueID = args[0];
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
return trueID;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,218 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.storage;
|
||||
|
||||
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.lib.easysql.api.action.query.SQLQuery;
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.Depository;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.DepositoryItem;
|
||||
import cc.carm.plugin.ultradepository.configuration.values.ConfigValue;
|
||||
import cc.carm.plugin.ultradepository.data.DepositoryData;
|
||||
import cc.carm.plugin.ultradepository.data.DepositoryItemData;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import cc.carm.plugin.ultradepository.util.DateIntUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MySQLStorage implements DataStorage {
|
||||
|
||||
private static final ConfigValue<String> DRIVER_NAME = new ConfigValue<>(
|
||||
"storage.mysql.driver", String.class, "com.mysql.jdbc.Driver"
|
||||
);
|
||||
|
||||
private static final ConfigValue<String> URL = new ConfigValue<>(
|
||||
"storage.mysql.url", String.class, "jdbc:mysql://127.0.0.1:3306/minecraft"
|
||||
);
|
||||
|
||||
private static final ConfigValue<String> USERNAME = new ConfigValue<>(
|
||||
"storage.mysql.username", String.class, "username"
|
||||
);
|
||||
private static final ConfigValue<String> PASSWORD = new ConfigValue<>(
|
||||
"storage.mysql.password", String.class, "password"
|
||||
);
|
||||
|
||||
public enum SQLTables {
|
||||
|
||||
USER_DATA("ub_data", new String[]{
|
||||
"`uuid` VARCHAR(36) NOT NULL PRIMARY KEY", // 用户的UUID
|
||||
"`data` MEDIUMTEXT NOT NULL",// 背包内具体物品
|
||||
"`day` DATE NOT NULL", // 记录卖出数量的所在天
|
||||
});
|
||||
|
||||
String name;
|
||||
String[] columns;
|
||||
|
||||
SQLTables(String name, String[] columns) {
|
||||
this.name = name;
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
|
||||
public static void createTables(SQLManager sqlManager) throws SQLException {
|
||||
for (SQLTables value : values()) {
|
||||
sqlManager.createTable(value.getName())
|
||||
.setColumns(value.getColumns())
|
||||
.build().execute();
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String[] getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final Gson GSON = new Gson();
|
||||
public static final JsonParser PARSER = new JsonParser();
|
||||
|
||||
SQLManager sqlManager;
|
||||
|
||||
@Override
|
||||
public boolean initialize() {
|
||||
|
||||
try {
|
||||
Main.log(" 尝试连接到数据库...");
|
||||
this.sqlManager = EasySQL.createManager(DRIVER_NAME.get(), URL.get(), USERNAME.get(), PASSWORD.get());
|
||||
this.sqlManager.setDebugMode(PluginConfig.DEBUG.get());
|
||||
} catch (Exception exception) {
|
||||
Main.error("无法连接到数据库,请检查配置文件。");
|
||||
Main.error("Could not connect to the database, please check the configuration.");
|
||||
exception.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
Main.log(" 创建插件所需表...");
|
||||
SQLTables.createTables(sqlManager);
|
||||
} catch (SQLException exception) {
|
||||
Main.error("无法创建插件所需的表,请检查数据库权限。");
|
||||
Main.error("Could not create necessary tables, please check the database privileges.");
|
||||
exception.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
Main.log(" 关闭数据库连接...");
|
||||
EasySQL.shutdownManager(getSQLManager());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull UserData loadData(@NotNull UUID uuid) throws Exception {
|
||||
long start = System.currentTimeMillis();
|
||||
Main.debug("正通过 MySQLStorage 加载 " + uuid + " 的用户数据...");
|
||||
try (SQLQuery query = createAction(uuid).execute()) {
|
||||
ResultSet resultSet = query.getResultSet();
|
||||
if (resultSet != null && resultSet.next()) {
|
||||
String dataJSON = resultSet.getString("data");
|
||||
Date date = resultSet.getDate("day");
|
||||
UserData data = new UserData(uuid, this, new HashMap<>(), DateIntUtil.getDateInt(date));
|
||||
|
||||
JsonElement dataElement = PARSER.parse(dataJSON);
|
||||
if (dataElement.isJsonObject()) {
|
||||
for (Map.Entry<String, JsonElement> entry : dataElement.getAsJsonObject().entrySet()) {
|
||||
Depository depository = Main.getDepositoryManager().getDepository(entry.getKey());
|
||||
if (depository == null) continue;
|
||||
|
||||
DepositoryData contentsData = parseContentsData(depository, data, entry.getValue());
|
||||
if (contentsData != null) data.setDepository(contentsData);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Main.debug("通过 MySQLStorage 加载 " + uuid + " 的用户数据完成,"
|
||||
+ "耗时 " + (System.currentTimeMillis() - start) + "ms。");
|
||||
|
||||
return data;
|
||||
}
|
||||
Main.debug("当前库内不存在玩家 " + uuid + " 的数据,视作新档。");
|
||||
return new UserData(uuid, this, new HashMap<>(), DateIntUtil.getCurrentDate());
|
||||
} catch (Exception exception) {
|
||||
throw new Exception(exception);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUserData(@NotNull UserData data) throws Exception {
|
||||
long start = System.currentTimeMillis();
|
||||
Main.debug("正通过 MySQLStorage 保存 " + data.getUserUUID() + " 的用户数据...");
|
||||
|
||||
try {
|
||||
|
||||
getSQLManager().createReplace(SQLTables.USER_DATA.getName())
|
||||
.setColumnNames("uuid", "data", "day")
|
||||
.setParams(data.getUserUUID(), GSON.toJson(data.serializeToMap()), data.getDate())
|
||||
.execute();
|
||||
|
||||
} catch (SQLException exception) {
|
||||
Main.error("在保存玩家 #" + data.getUserUUID() + " 的数据时出现异常。");
|
||||
Main.error("Error occurred when saving #" + data.getUserUUID() + " data.");
|
||||
throw new Exception(exception);
|
||||
}
|
||||
|
||||
Main.debug("通过 MySQLStorage 保存 " + data.getUserUUID() + " 的用户数据完成," +
|
||||
"耗时 " + (System.currentTimeMillis() - start) + "ms。");
|
||||
|
||||
}
|
||||
|
||||
private SQLManager getSQLManager() {
|
||||
return sqlManager;
|
||||
}
|
||||
|
||||
private PreparedQueryAction createAction(UUID uuid) {
|
||||
return getSQLManager().createQuery()
|
||||
.inTable(SQLTables.USER_DATA.getName())
|
||||
.addCondition("uuid", uuid.toString())
|
||||
.setLimit(1).build();
|
||||
}
|
||||
|
||||
private DepositoryData parseContentsData(Depository source, UserData owner, JsonElement contentsElement) {
|
||||
return contentsElement.isJsonObject() ? parseContentsData(source, owner, contentsElement.getAsJsonObject()) : null;
|
||||
}
|
||||
|
||||
private DepositoryData parseContentsData(Depository source, UserData owner, JsonObject contentsObject) {
|
||||
DepositoryData data = DepositoryData.emptyContents(source, owner);
|
||||
for (Map.Entry<String, JsonElement> entry : contentsObject.entrySet()) {
|
||||
|
||||
DepositoryItem item = source.getItems().get(entry.getKey());
|
||||
if (item == null) continue;
|
||||
|
||||
DepositoryItemData itemData = parseItemData(item, data, entry.getValue());
|
||||
if (itemData != null) data.getContents().put(item.getTypeID(), itemData);
|
||||
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private DepositoryItemData parseItemData(DepositoryItem source, DepositoryData owner, JsonElement itemElement) {
|
||||
return itemElement.isJsonObject() ? parseItemData(source, owner, itemElement.getAsJsonObject()) : null;
|
||||
}
|
||||
|
||||
private DepositoryItemData parseItemData(DepositoryItem source, DepositoryData owner, JsonObject itemObject) {
|
||||
int amount = itemObject.has("amount") ? itemObject.get("amount").getAsInt() : 0;
|
||||
int sold = itemObject.has("sold") ? itemObject.get("sold").getAsInt() : 0;
|
||||
if (amount == 0 && sold == 0) return null;
|
||||
|
||||
return new DepositoryItemData(source, owner, amount, sold);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package cc.carm.plugin.ultradepository.storage;
|
||||
|
||||
import cc.carm.plugin.ultradepository.storage.impl.CustomStorage;
|
||||
import cc.carm.plugin.ultradepository.storage.impl.JSONStorage;
|
||||
import cc.carm.plugin.ultradepository.storage.impl.MySQLStorage;
|
||||
import cc.carm.plugin.ultradepository.storage.impl.YAMLStorage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public enum StorageMethod {
|
||||
|
||||
CUSTOM(0, CustomStorage::new),
|
||||
YAML(1, YAMLStorage::new),
|
||||
JSON(2, JSONStorage::new),
|
||||
MYSQL(3, MySQLStorage::new);
|
||||
|
||||
private final int id;
|
||||
private @NotNull Supplier<@NotNull DataStorage> storageSupplier;
|
||||
|
||||
StorageMethod(int id, @NotNull Supplier<@NotNull DataStorage> storageSupplier) {
|
||||
this.id = id;
|
||||
this.storageSupplier = storageSupplier;
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public @NotNull Supplier<@NotNull DataStorage> getStorageSupplier() {
|
||||
return storageSupplier;
|
||||
}
|
||||
|
||||
public void setStorageSupplier(@NotNull Supplier<@NotNull DataStorage> storageSupplier) {
|
||||
this.storageSupplier = storageSupplier;
|
||||
}
|
||||
|
||||
public @NotNull DataStorage createStorage() {
|
||||
return getStorageSupplier().get();
|
||||
}
|
||||
|
||||
public static @NotNull StorageMethod read(String s) {
|
||||
StorageMethod byName = readByName(s);
|
||||
if (byName != null) return byName;
|
||||
try {
|
||||
return Optional.ofNullable(readByID(Integer.parseInt(s))).orElse(YAML);
|
||||
} catch (Exception ex) {
|
||||
return YAML;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static @Nullable StorageMethod readByName(String name) {
|
||||
return Arrays.stream(values()).filter(value -> value.name().equalsIgnoreCase(name)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
|
||||
public static @Nullable StorageMethod readByID(int id) {
|
||||
return Arrays.stream(values()).filter(value -> value.getID() == id).findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package cc.carm.plugin.ultradepository.storage.impl;
|
||||
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import cc.carm.plugin.ultradepository.storage.DataStorage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class CustomStorage implements DataStorage {
|
||||
|
||||
@Override
|
||||
@TestOnly
|
||||
public boolean initialize() {
|
||||
UltraDepository.getInstance().error("您选择使用自定义存储,但并没有应用成功。");
|
||||
UltraDepository.getInstance().error("请访问 https://github.com/CarmJos/UltraDepository/blob/master/.documentation 获取相关帮助!");
|
||||
UltraDepository.getInstance().error("You are using CustomStorage, but not overwrite the methods.");
|
||||
UltraDepository.getInstance().error("Please view https://github.com/CarmJos/UltraDepository/blob/master/.documentation to get more information.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@TestOnly
|
||||
public void shutdown() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@TestOnly
|
||||
public @Nullable UserData loadData(@NotNull UUID uuid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@TestOnly
|
||||
public void saveUserData(@NotNull UserData data) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package cc.carm.plugin.ultradepository.storage.impl;
|
||||
|
||||
import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.Depository;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.DepositoryItem;
|
||||
import cc.carm.plugin.ultradepository.data.DepositoryData;
|
||||
import cc.carm.plugin.ultradepository.data.DepositoryItemData;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import cc.carm.plugin.ultradepository.storage.DataStorage;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class JSONStorage implements DataStorage {
|
||||
|
||||
private static final ConfigValue<String> FILE_PATH = new ConfigValue<>(
|
||||
"storage.file-path", String.class, "data"
|
||||
);
|
||||
|
||||
private File dataContainer;
|
||||
|
||||
protected static final Gson GSON = new Gson();
|
||||
protected static final JsonParser PARSER = new JsonParser();
|
||||
|
||||
@Override
|
||||
public boolean initialize() {
|
||||
dataContainer = new File(UltraDepository.getInstance().getDataFolder(), FILE_PATH.get());
|
||||
if (!dataContainer.exists()) {
|
||||
return dataContainer.mkdir();
|
||||
} else {
|
||||
return dataContainer.isDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
// 似乎没什么需要做的?
|
||||
dataContainer = null;
|
||||
}
|
||||
|
||||
public File getDataContainer() {
|
||||
return dataContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable UserData loadData(@NotNull UUID uuid) throws Exception {
|
||||
File userDataFile = new File(getDataContainer(), uuid + ".json");
|
||||
if (!userDataFile.exists()) {
|
||||
UltraDepository.getInstance().debug("当前文件夾内不存在玩家 " + uuid + " 的数据,视作新档。");
|
||||
return null;
|
||||
}
|
||||
|
||||
JsonElement dataElement = PARSER.parse(new FileReader(userDataFile));
|
||||
if (!dataElement.isJsonObject()) throw new NullPointerException(userDataFile.getName());
|
||||
JsonObject dataObject = dataElement.getAsJsonObject();
|
||||
|
||||
int dateInt = dataObject.get("date").getAsInt();
|
||||
UserData userData = new UserData(uuid, new HashMap<>(), dateInt);
|
||||
|
||||
loadDepositoriesInto(userData, dataObject.getAsJsonObject("depositories"));
|
||||
|
||||
return userData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUserData(@NotNull UserData data) throws Exception {
|
||||
JsonObject dataObject = new JsonObject();
|
||||
dataObject.addProperty("date", data.getDateInt());
|
||||
dataObject.add("depositories", saveDepositoriesToJson(data));
|
||||
|
||||
FileWriter writer = new FileWriter(new File(getDataContainer(), data.getUserUUID() + ".json"));
|
||||
writer.write(GSON.toJson(dataObject));
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
public static JsonElement saveDepositoriesToJson(UserData data) {
|
||||
return GSON.toJsonTree(data.serializeToMap());
|
||||
}
|
||||
|
||||
public static String serializeDepositories(UserData data) {
|
||||
return GSON.toJson(saveDepositoriesToJson(data));
|
||||
}
|
||||
|
||||
public static void loadDepositoriesInto(UserData data, JsonElement depositoriesElement) {
|
||||
if (depositoriesElement == null || !depositoriesElement.isJsonObject()) return;
|
||||
|
||||
for (Map.Entry<String, JsonElement> entry : depositoriesElement.getAsJsonObject().entrySet()) {
|
||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(entry.getKey());
|
||||
if (depository == null) continue;
|
||||
|
||||
DepositoryData contentsData = parseContentsData(depository, data, entry.getValue());
|
||||
if (contentsData != null) data.setDepository(contentsData);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static DepositoryData parseContentsData(@NotNull Depository source,
|
||||
@NotNull UserData owner,
|
||||
@NotNull JsonElement contentsElement) {
|
||||
if (!contentsElement.isJsonObject()) return null;
|
||||
JsonObject contentsObject = contentsElement.getAsJsonObject();
|
||||
|
||||
DepositoryData data = DepositoryData.emptyContents(source, owner);
|
||||
for (Map.Entry<String, JsonElement> entry : contentsObject.entrySet()) {
|
||||
DepositoryItem item = source.getItems().get(DataStorage.getFixedTypeID(entry.getKey()));
|
||||
if (item == null) continue;
|
||||
|
||||
DepositoryItemData itemData = parseItemData(item, data, entry.getValue());
|
||||
if (itemData != null) data.getContents().put(item.getTypeID(), itemData);
|
||||
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
public static DepositoryItemData parseItemData(@NotNull DepositoryItem source,
|
||||
@NotNull DepositoryData owner,
|
||||
@NotNull JsonElement itemElement) {
|
||||
if (!itemElement.isJsonObject()) return null;
|
||||
JsonObject itemObject = itemElement.getAsJsonObject();
|
||||
|
||||
int amount = itemObject.has("amount") ? itemObject.get("amount").getAsInt() : 0;
|
||||
int sold = itemObject.has("sold") ? itemObject.get("sold").getAsInt() : 0;
|
||||
if (amount == 0 && sold == 0) return null;
|
||||
|
||||
return new DepositoryItemData(source, owner, amount, sold);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
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.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import cc.carm.plugin.ultradepository.util.DateIntUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MySQLStorage extends JSONStorage {
|
||||
|
||||
private static final ConfigValue<String> DRIVER_NAME = new ConfigValue<>(
|
||||
"storage.mysql.driver", String.class,
|
||||
"com.mysql.jdbc.Driver"
|
||||
);
|
||||
|
||||
private static final ConfigValue<String> URL = new ConfigValue<>(
|
||||
"storage.mysql.url", String.class,
|
||||
"jdbc:mysql://127.0.0.1:3306/minecraft"
|
||||
);
|
||||
|
||||
private static final ConfigValue<String> USERNAME = new ConfigValue<>(
|
||||
"storage.mysql.username", String.class,
|
||||
"root"
|
||||
);
|
||||
|
||||
private static final ConfigValue<String> PASSWORD = new ConfigValue<>(
|
||||
"storage.mysql.password", String.class,
|
||||
"password"
|
||||
);
|
||||
|
||||
private static final ConfigValue<String> TABLE_NAME = new ConfigValue<>(
|
||||
"storage.mysql.table", String.class,
|
||||
"ud_data"
|
||||
);
|
||||
|
||||
SQLManager sqlManager;
|
||||
DatabaseTable userDataTable;
|
||||
|
||||
@Override
|
||||
public boolean initialize() {
|
||||
|
||||
try {
|
||||
UltraDepository.getInstance().log(" 尝试连接到数据库...");
|
||||
this.sqlManager = EasySQL.createManager(DRIVER_NAME.get(), URL.get(), USERNAME.get(), PASSWORD.get());
|
||||
this.sqlManager.setDebugMode(UltraDepository.getInstance().isDebugging());
|
||||
} catch (Exception exception) {
|
||||
UltraDepository.getInstance().error("无法连接到数据库,请检查配置文件。");
|
||||
UltraDepository.getInstance().error("Could not connect to the database, please check the configuration.");
|
||||
exception.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
UltraDepository.getInstance().log(" 创建插件所需表...");
|
||||
|
||||
this.userDataTable = new DatabaseTable(
|
||||
TABLE_NAME.getOptional().orElse("ud_data"),
|
||||
new String[]{
|
||||
"`uuid` VARCHAR(36) NOT NULL PRIMARY KEY", // 用户的UUID
|
||||
"`data` MEDIUMTEXT NOT NULL",// 背包内具体物品
|
||||
"`day` DATE NOT NULL", // 记录卖出数量的所在天
|
||||
});
|
||||
|
||||
getUserDataTable().createTable(sqlManager);
|
||||
|
||||
} catch (SQLException exception) {
|
||||
UltraDepository.getInstance().error("无法创建插件所需的表,请检查数据库权限。");
|
||||
UltraDepository.getInstance().error("Could not create necessary tables, please check the database privileges.");
|
||||
exception.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
UltraDepository.getInstance().log(" 关闭数据库连接...");
|
||||
EasySQL.shutdownManager(getSQLManager());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable UserData loadData(@NotNull UUID uuid) throws Exception {
|
||||
return createAction(uuid).executeFunction((query) -> {
|
||||
ResultSet resultSet = query.getResultSet();
|
||||
|
||||
if (resultSet == null || !resultSet.next()) return null;
|
||||
|
||||
Date date = resultSet.getDate("day");
|
||||
UserData data = new UserData(uuid, new HashMap<>(), DateIntUtil.getDateInt(date));
|
||||
|
||||
loadDepositoriesInto(data, PARSER.parse(resultSet.getString("data")));
|
||||
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUserData(@NotNull UserData data) throws Exception {
|
||||
getSQLManager().createReplace(getUserDataTable().getTableName())
|
||||
.setColumnNames("uuid", "data", "day")
|
||||
.setParams(data.getUserUUID(), serializeDepositories(data), data.getDate())
|
||||
.execute();
|
||||
}
|
||||
|
||||
private SQLManager getSQLManager() {
|
||||
return sqlManager;
|
||||
}
|
||||
|
||||
public DatabaseTable getUserDataTable() {
|
||||
return userDataTable;
|
||||
}
|
||||
|
||||
private PreparedQueryAction createAction(UUID uuid) {
|
||||
return getUserDataTable().createQuery(getSQLManager())
|
||||
.addCondition("uuid", uuid.toString())
|
||||
.setLimit(1).build();
|
||||
}
|
||||
|
||||
}
|
||||
+15
-31
@@ -1,23 +1,25 @@
|
||||
package cc.carm.plugin.ultradepository.storage;
|
||||
package cc.carm.plugin.ultradepository.storage.impl;
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.Depository;
|
||||
import cc.carm.plugin.ultradepository.configuration.depository.DepositoryItem;
|
||||
import cc.carm.plugin.ultradepository.configuration.values.ConfigValue;
|
||||
import cc.carm.plugin.ultradepository.data.DepositoryData;
|
||||
import cc.carm.plugin.ultradepository.data.DepositoryItemData;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import cc.carm.plugin.ultradepository.storage.DataStorage;
|
||||
import cc.carm.plugin.ultradepository.util.DateIntUtil;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FileStorage implements DataStorage {
|
||||
public class YAMLStorage implements DataStorage {
|
||||
|
||||
private static final ConfigValue<String> FILE_PATH = new ConfigValue<>(
|
||||
"storage.file-path", String.class, "data"
|
||||
@@ -27,7 +29,7 @@ public class FileStorage implements DataStorage {
|
||||
|
||||
@Override
|
||||
public boolean initialize() {
|
||||
dataContainer = new File(Main.getInstance().getDataFolder(), FILE_PATH.get());
|
||||
dataContainer = new File(UltraDepository.getInstance().getDataFolder(), FILE_PATH.get());
|
||||
if (!dataContainer.exists()) {
|
||||
return dataContainer.mkdir();
|
||||
} else {
|
||||
@@ -38,6 +40,7 @@ public class FileStorage implements DataStorage {
|
||||
@Override
|
||||
public void shutdown() {
|
||||
// 似乎没什么需要做的?
|
||||
dataContainer = null;
|
||||
}
|
||||
|
||||
public File getDataContainer() {
|
||||
@@ -45,24 +48,22 @@ public class FileStorage implements DataStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull UserData loadData(@NotNull UUID uuid) {
|
||||
long start = System.currentTimeMillis();
|
||||
Main.debug("正通过 FileStorage 加载 " + uuid + " 的用户数据...");
|
||||
public @Nullable UserData loadData(@NotNull UUID uuid) {
|
||||
File userDataFile = new File(getDataContainer(), uuid + ".yml");
|
||||
if (!userDataFile.exists()) {
|
||||
Main.debug("当前文件夾内不存在玩家 " + uuid + " 的数据,视作新档。");
|
||||
return new UserData(uuid, this, new HashMap<>(), DateIntUtil.getCurrentDate());
|
||||
UltraDepository.getInstance().debug("当前文件夾内不存在玩家 " + uuid + " 的数据,视作新档。");
|
||||
return null;
|
||||
}
|
||||
|
||||
YamlConfiguration userDataConfig = YamlConfiguration.loadConfiguration(userDataFile);
|
||||
int dateInt = userDataConfig.getInt("date", DateIntUtil.getCurrentDate());
|
||||
UserData userData = new UserData(uuid, this, new HashMap<>(), dateInt);
|
||||
UserData userData = new UserData(uuid, new HashMap<>(), dateInt);
|
||||
|
||||
ConfigurationSection depositoriesSection = userDataConfig.getConfigurationSection("depositories");
|
||||
if (depositoriesSection != null) {
|
||||
for (String depositoryID : depositoriesSection.getKeys(false)) {
|
||||
|
||||
Depository depository = Main.getDepositoryManager().getDepository(depositoryID);
|
||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(depositoryID);
|
||||
if (depository == null) continue;
|
||||
|
||||
ConfigurationSection depositorySection = depositoriesSection.getConfigurationSection(depositoryID);
|
||||
@@ -71,7 +72,8 @@ public class FileStorage implements DataStorage {
|
||||
DepositoryData depositoryData = DepositoryData.emptyContents(depository, userData);
|
||||
|
||||
for (String itemTypeID : depositorySection.getKeys(false)) {
|
||||
DepositoryItem item = depository.getItems().get(itemTypeID);
|
||||
|
||||
DepositoryItem item = depository.getItems().get(DataStorage.getFixedTypeID(itemTypeID));
|
||||
if (item == null) continue;
|
||||
|
||||
ConfigurationSection itemSection = depositorySection.getConfigurationSection(itemTypeID);
|
||||
@@ -88,33 +90,15 @@ public class FileStorage implements DataStorage {
|
||||
if (!depositoryData.getContents().isEmpty()) userData.setDepository(depositoryData);
|
||||
}
|
||||
}
|
||||
Main.debug("通过 FileStorage 加载 " + uuid + " 的用户数据完成,"
|
||||
+ "耗时 " + (System.currentTimeMillis() - start) + "ms。");
|
||||
|
||||
return userData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUserData(@NotNull UserData data) throws IOException {
|
||||
long start = System.currentTimeMillis();
|
||||
Main.debug("正通过 FileStorage 保存 " + data.getUserUUID() + " 的用户数据...");
|
||||
|
||||
YamlConfiguration userDataConfig = new YamlConfiguration();
|
||||
userDataConfig.set("date", data.getDateInt());
|
||||
|
||||
try {
|
||||
userDataConfig.createSection("depositories", data.serializeToMap());
|
||||
userDataConfig.save(new File(getDataContainer(), data.getUserUUID() + ".yml"));
|
||||
} catch (IOException ioException) {
|
||||
Main.error("在保存玩家 #" + data.getUserUUID() + " 的数据时出现异常。");
|
||||
Main.error("Error occurred when saving #" + data.getUserUUID() + " data.");
|
||||
throw ioException;
|
||||
}
|
||||
|
||||
Main.debug(
|
||||
"通过 FileStorage 保存 " + data.getUserUUID() + " 的用户数据完成," +
|
||||
"耗时 " + (System.currentTimeMillis() - start) + "ms。"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +1,22 @@
|
||||
package cc.carm.plugin.ultradepository.ui;
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import cc.carm.lib.easyplugin.gui.GUI;
|
||||
import cc.carm.lib.easyplugin.gui.GUIItem;
|
||||
import cc.carm.lib.easyplugin.utils.ItemStackFactory;
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
|
||||
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.data.DepositoryItemData;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import cc.carm.plugin.ultradepository.util.ItemStackFactory;
|
||||
import cc.carm.plugin.ultradepository.util.gui.GUI;
|
||||
import cc.carm.plugin.ultradepository.util.gui.GUIItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@@ -24,79 +26,121 @@ public class DepositoryGUI extends GUI {
|
||||
UserData userData;
|
||||
Depository depository;
|
||||
|
||||
public DepositoryGUI(Player player, Depository depository) {
|
||||
private DepositoryGUI(Player player, Depository depository) {
|
||||
super(depository.getGUIConfiguration().getGUIType(), depository.getGUIConfiguration().getTitle());
|
||||
|
||||
this.player = player;
|
||||
this.userData = Main.getUserManager().getData(player);
|
||||
this.userData = UltraDepository.getUserManager().getData(player);
|
||||
this.depository = depository;
|
||||
|
||||
setupItems();
|
||||
}
|
||||
|
||||
public void setupItems() {
|
||||
loadConfigItems();
|
||||
loadDepositoryItems();
|
||||
}
|
||||
|
||||
public void loadConfigItems() {
|
||||
depository.getGUIConfiguration().setupItems(player, this);
|
||||
}
|
||||
|
||||
public void loadDepositoryItems() {
|
||||
depository.getItems().values().forEach(depositoryItem -> setItem(depositoryItem.getSlot(), createGUIItem(depositoryItem)));
|
||||
}
|
||||
|
||||
|
||||
private GUIItem createGUIItem(DepositoryItem item) {
|
||||
DepositoryItemData itemData = userData.getItemData(item);
|
||||
int remain = item.getLimit() - itemData.getSold();
|
||||
|
||||
ItemStackFactory factory = new ItemStackFactory(item.getDisplayItem());
|
||||
List<String> additionalLore = PluginConfig.General.ADDITIONAL_LORE.get(player, new Object[]{
|
||||
item.getName(), itemData.getAmount(), item.getPrice(),
|
||||
itemData.getSold(), remain, item.getLimit()
|
||||
});
|
||||
|
||||
additionalLore.forEach(factory::addLore);
|
||||
List<String> clickLore = PluginConfig.General.CLICK_LORE.get(player, new Object[]{
|
||||
item.getName(), itemData.getAmount(), item.getPrice()
|
||||
});
|
||||
clickLore.forEach(factory::addLore);
|
||||
|
||||
return new GUIItem(factory.toItemStack()) {
|
||||
return new GUIItem(getItemIcon(player, userData, item)) {
|
||||
@Override
|
||||
public void onClick(ClickType type) {
|
||||
if (itemData.getAmount() < 1) return;
|
||||
if (type == ClickType.LEFT) {
|
||||
player.closeInventory();
|
||||
if (itemData.getAmount() >= 1) {
|
||||
if (remain >= 1) {
|
||||
DepositoryItemData itemData = userData.getItemData(item);
|
||||
if (itemData.getAmount() < 1) {
|
||||
PluginConfig.Sounds.SELL_FAIL.play(player);
|
||||
PluginMessages.NO_ENOUGH_ITEM.send(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (canSell(item) && type == ClickType.LEFT) {
|
||||
int sellableAmount = item.getLimit() - itemData.getSold();
|
||||
if (sellableAmount >= 1) {
|
||||
SellItemGUI.open(player, userData, itemData, depository, item);
|
||||
} else {
|
||||
PluginMessages.ITEM_SOLD_LIMIT.send(player, new Object[]{remain, item.getLimit()});
|
||||
}
|
||||
} else {
|
||||
PluginMessages.NO_ENOUGH_ITEM.send(player);
|
||||
}
|
||||
|
||||
} else if (type == ClickType.RIGHT) {
|
||||
PluginConfig.Sounds.SELL_FAIL.play(player);
|
||||
PluginMessages.ITEM_SOLD_LIMIT.send(player, new Object[]{sellableAmount, item.getLimit()});
|
||||
player.closeInventory();
|
||||
}
|
||||
} else if (type == ClickType.RIGHT) {
|
||||
|
||||
if (hasEmptySlot(player)) {
|
||||
int pickupAmount = Math.min(itemData.getAmount(), item.getMaterial().getMaxStackSize());
|
||||
userData.removeItemAmount(item.getDepository().getIdentifier(), item.getTypeID(), pickupAmount);
|
||||
player.getInventory().addItem(item.getRawItem(pickupAmount));
|
||||
PluginMessages.PICKUP.send(player, new Object[]{
|
||||
item.getName(), pickupAmount
|
||||
int takeoutAmount = Math.min(itemData.getAmount(), item.getMaterial().getMaxStackSize());
|
||||
userData.removeItemAmount(
|
||||
item.getDepository().getIdentifier(), item.getTypeID(), takeoutAmount
|
||||
);
|
||||
player.getInventory().addItem(item.getRawItem(takeoutAmount));
|
||||
PluginMessages.ITEM_TAKEOUT.send(player, new Object[]{
|
||||
item.getName(), takeoutAmount
|
||||
});
|
||||
PluginConfig.Sounds.TAKEOUT.play(player);
|
||||
|
||||
setDisplay(getItemIcon(player, userData, item)); // 刷新物品显示
|
||||
loadConfigItems(); // 更新配置中的其他物品
|
||||
updateView();
|
||||
} else {
|
||||
PluginMessages.NO_SPACE.send(player);
|
||||
player.closeInventory();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private boolean hasEmptySlot(Player player) {
|
||||
public static boolean hasEmptySlot(Player player) {
|
||||
return IntStream.range(0, 36)
|
||||
.mapToObj(i -> player.getInventory().getItem(i))
|
||||
.anyMatch(i -> i == null || i.getType() == Material.AIR);
|
||||
}
|
||||
|
||||
public static ItemStack getItemIcon(@NotNull Player player,
|
||||
@NotNull UserData userData,
|
||||
@NotNull DepositoryItem item) {
|
||||
DepositoryItemData itemData = userData.getItemData(item);
|
||||
ItemStackFactory factory = new ItemStackFactory(item.getDisplayItem());
|
||||
getExtraLore(player, itemData).forEach(factory::addLore);
|
||||
return factory.toItemStack();
|
||||
}
|
||||
|
||||
public static List<String> getExtraLore(@NotNull Player player,
|
||||
@NotNull DepositoryItemData itemData) {
|
||||
DepositoryItem item = itemData.getSource();
|
||||
int canSell = item.getLimit() - itemData.getSold();
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
if (canSell(item)) {
|
||||
lore.addAll(PluginConfig.General.AdditionalLore.AVAILABLE_FOR_SALE.get(player, new Object[]{
|
||||
item.getName(), itemData.getAmount(), item.getPrice(),
|
||||
itemData.getSold(), canSell, item.getLimit()
|
||||
}));
|
||||
lore.addAll(PluginConfig.General.ClickLore.AVAILABLE_FOR_SALE.get(player, new Object[]{
|
||||
item.getName(), itemData.getAmount(), item.getPrice()
|
||||
}));
|
||||
} else {
|
||||
lore.addAll(PluginConfig.General.AdditionalLore.NOT_FOR_SALE.get(player, new Object[]{
|
||||
item.getName(), itemData.getAmount()
|
||||
}));
|
||||
lore.addAll(PluginConfig.General.ClickLore.NOT_FOR_SALE.get(player, new Object[]{
|
||||
item.getName(), itemData.getAmount()
|
||||
}));
|
||||
}
|
||||
return lore;
|
||||
}
|
||||
|
||||
public static boolean canSell(DepositoryItem item) {
|
||||
return UltraDepository.getEconomyManager().isInitialized()
|
||||
&& item.getLimit() > 0 && item.getPrice() > 0;
|
||||
}
|
||||
|
||||
public static void open(@NotNull Player player, @NotNull Depository depository) {
|
||||
player.closeInventory();
|
||||
DepositoryGUI gui = new DepositoryGUI(player, depository);
|
||||
gui.openGUI(player);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
package cc.carm.plugin.ultradepository.ui;
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import cc.carm.lib.easyplugin.gui.GUI;
|
||||
import cc.carm.lib.easyplugin.gui.GUIItem;
|
||||
import cc.carm.lib.easyplugin.gui.GUIType;
|
||||
import cc.carm.lib.easyplugin.utils.ItemStackFactory;
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
|
||||
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.data.DepositoryItemData;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import cc.carm.plugin.ultradepository.util.ItemStackFactory;
|
||||
import cc.carm.plugin.ultradepository.util.gui.GUI;
|
||||
import cc.carm.plugin.ultradepository.util.gui.GUIItem;
|
||||
import cc.carm.plugin.ultradepository.util.gui.GUIType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
|
||||
import static cc.carm.plugin.ultradepository.configuration.PluginConfig.General.SellGUI.Items.*;
|
||||
@@ -50,8 +53,9 @@ public class SellItemGUI extends GUI {
|
||||
private void load(int amount) {
|
||||
this.currentAmount = Math.max(1, amount); // 不可小于1
|
||||
ItemStackFactory factory = new ItemStackFactory(this.itemDisplay);
|
||||
List<String> additionalLore = PluginConfig.General.ADDITIONAL_LORE.get(player, new Object[]{
|
||||
getItemName(), getRemainAmount(), getItemPrice(),
|
||||
List<String> additionalLore = PluginConfig.General.AdditionalLore.AVAILABLE_FOR_SALE
|
||||
.get(player, new Object[]{
|
||||
getItemName(), getDepositoryAmount(), getItemPrice(),
|
||||
getSoldAmount(), (getSellLimit() - getSoldAmount()), getSellLimit()
|
||||
});
|
||||
additionalLore.forEach(factory::addLore);
|
||||
@@ -66,22 +70,15 @@ public class SellItemGUI extends GUI {
|
||||
setItem(16, getAddableAmount() >= 100 ? getAddItem(100) : null);
|
||||
setItem(17, getAddableAmount() >= 1000 ? getAddItem(1000) : null);
|
||||
|
||||
if (getCurrentAmount() >= 1) setItem(getConfirmItem(), 27, 28, 29, 30);
|
||||
setItem(getCurrentAmount() >= 1 ? getConfirmItem() : null, 27, 28, 29, 30);
|
||||
setItem(getCancelItem(), 32, 33, 34, 35);
|
||||
|
||||
}
|
||||
|
||||
private GUIItem getAddItem(int amount) {
|
||||
ItemStackFactory factory = new ItemStackFactory(Add.TYPE.get());
|
||||
factory.setDurability(Add.DATA.get());
|
||||
factory.setDisplayName(Add.NAME.get(player, new Object[]{
|
||||
return new GUIItem(ADD.getItem(player, new Object[]{
|
||||
getItemName(), amount
|
||||
}));
|
||||
factory.setLore(Add.LORE.get(player, new Object[]{
|
||||
getItemName(), amount
|
||||
}));
|
||||
|
||||
return new GUIItem(factory.toItemStack()) {
|
||||
})) {
|
||||
@Override
|
||||
public void onClick(ClickType type) {
|
||||
PluginConfig.Sounds.GUI_CLICK.play(player);
|
||||
@@ -92,15 +89,9 @@ public class SellItemGUI extends GUI {
|
||||
}
|
||||
|
||||
private GUIItem getRemoveItem(int amount) {
|
||||
ItemStackFactory factory = new ItemStackFactory(Remove.TYPE.get());
|
||||
factory.setDurability(Remove.DATA.get());
|
||||
factory.setDisplayName(Remove.NAME.get(player, new Object[]{
|
||||
return new GUIItem(REMOVE.getItem(player, new Object[]{
|
||||
getItemName(), amount
|
||||
}));
|
||||
factory.setLore(Remove.LORE.get(player, new Object[]{
|
||||
getItemName(), amount
|
||||
}));
|
||||
return new GUIItem(factory.toItemStack()) {
|
||||
})) {
|
||||
@Override
|
||||
public void onClick(ClickType type) {
|
||||
PluginConfig.Sounds.GUI_CLICK.play(player);
|
||||
@@ -111,30 +102,20 @@ public class SellItemGUI extends GUI {
|
||||
}
|
||||
|
||||
private GUIItem getConfirmItem() {
|
||||
ItemStackFactory factory = new ItemStackFactory(Confirm.TYPE.get());
|
||||
factory.setDurability(Confirm.DATA.get());
|
||||
factory.setDisplayName(Confirm.NAME.get(player, new Object[]{
|
||||
return new GUIItem(CONFIRM.getItem(player, new Object[]{
|
||||
getItemName(), getCurrentAmount(), getTotalMoney()
|
||||
}));
|
||||
factory.setLore(Confirm.LORE.get(player, new Object[]{
|
||||
getItemName(), getCurrentAmount(), getTotalMoney()
|
||||
}));
|
||||
return new GUIItem(factory.toItemStack()) {
|
||||
})) {
|
||||
@Override
|
||||
public void onClick(ClickType type) {
|
||||
int amount = Math.min(getCurrentAmount(), Math.min(getRemainAmount(), getSellLimit() - getSoldAmount()));
|
||||
if (amount > 0) Main.getEconomyManager().sellItem(player, userData, itemData, amount);
|
||||
int amount = Math.min(getCurrentAmount(), Math.min(getDepositoryAmount(), getSellLimit() - getSoldAmount()));
|
||||
if (amount > 0) UltraDepository.getEconomyManager().sellItem(player, userData, item, amount);
|
||||
player.closeInventory();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private GUIItem getCancelItem() {
|
||||
ItemStackFactory factory = new ItemStackFactory(Cancel.TYPE.get());
|
||||
factory.setDurability(Cancel.DATA.get());
|
||||
factory.setDisplayName(Cancel.NAME.get());
|
||||
factory.setLore(Cancel.LORE.get());
|
||||
return new GUIItem(factory.toItemStack()) {
|
||||
return new GUIItem(CANCEL.getItem(player)) {
|
||||
@Override
|
||||
public void onClick(ClickType type) {
|
||||
PluginConfig.Sounds.SELL_FAIL.play(player);
|
||||
@@ -160,10 +141,11 @@ public class SellItemGUI extends GUI {
|
||||
}
|
||||
|
||||
private double getTotalMoney() {
|
||||
return getCurrentAmount() * getItemPrice();
|
||||
BigDecimal money = BigDecimal.valueOf(getCurrentAmount() * getItemPrice()).setScale(2, RoundingMode.DOWN);
|
||||
return money.doubleValue();
|
||||
}
|
||||
|
||||
private int getRemainAmount() {
|
||||
private int getDepositoryAmount() {
|
||||
return userData.getItemData(this.item).getAmount();
|
||||
}
|
||||
|
||||
@@ -172,12 +154,17 @@ public class SellItemGUI extends GUI {
|
||||
}
|
||||
|
||||
private int getAddableAmount() {
|
||||
return Math.min(getRemainAmount(), getSellLimit() - getSoldAmount()) - getCurrentAmount();
|
||||
return Math.min(getDepositoryAmount(), getSellLimit() - getSoldAmount()) - getCurrentAmount();
|
||||
}
|
||||
|
||||
public static void open(Player player, UserData userData, DepositoryItemData itemData,
|
||||
Depository configuration, DepositoryItem item) {
|
||||
if (!Main.getEconomyManager().isInitialized()) return;
|
||||
player.closeInventory();
|
||||
if (!UltraDepository.getEconomyManager().isInitialized()) {
|
||||
PluginMessages.NO_ECONOMY.send(player);
|
||||
return;
|
||||
}
|
||||
|
||||
SellItemGUI gui = new SellItemGUI(player, userData, itemData, configuration, item);
|
||||
gui.openGUI(player);
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
|
||||
package cc.carm.plugin.ultradepository.util;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ColorParser {
|
||||
|
||||
public static String parse(String text) {
|
||||
text = parseHexColor(text);
|
||||
return parseColor(text);
|
||||
}
|
||||
|
||||
public static String parseColor(final String text) {
|
||||
return text.replaceAll("&", "§").replace("§§", "&");
|
||||
}
|
||||
|
||||
public static String parseHexColor(String text) {
|
||||
Pattern pattern = Pattern.compile("&\\((&?#[0-9a-fA-F]{6})\\)");
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
while (matcher.find()) {
|
||||
String hexColor = text.substring(matcher.start() + 2, matcher.end() - 1);
|
||||
hexColor = hexColor.replace("&", "");
|
||||
StringBuilder bukkitColorCode = new StringBuilder('§' + "x");
|
||||
for (int i = 1; i < hexColor.length(); i++) {
|
||||
bukkitColorCode.append('§').append(hexColor.charAt(i));
|
||||
}
|
||||
text = text.replaceAll("&\\(" + hexColor + "\\)", bukkitColorCode.toString().toLowerCase());
|
||||
matcher.reset(text);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,15 @@ public class DateIntUtil {
|
||||
}
|
||||
|
||||
public static long getDateMillis(int dateInt) {
|
||||
return getDate(dateInt).getTime();
|
||||
}
|
||||
|
||||
public static Date getDate(int dateInt) {
|
||||
try {
|
||||
return getFormat().parse(Integer.toString(dateInt)).getTime();
|
||||
} catch (ParseException e) {
|
||||
return System.currentTimeMillis();
|
||||
long millis = getFormat().parse(Integer.toString(dateInt)).getTime();
|
||||
return new java.sql.Date(millis);
|
||||
} catch (ParseException | NumberFormatException e) {
|
||||
return new Date(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.util;
|
||||
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ItemStackFactory {
|
||||
ItemStack item;
|
||||
|
||||
private ItemStackFactory() {
|
||||
}
|
||||
|
||||
public ItemStackFactory(ItemStack is) {
|
||||
this.item = is.clone();
|
||||
}
|
||||
|
||||
public ItemStackFactory(Material type) {
|
||||
this(type, 1);
|
||||
}
|
||||
|
||||
public ItemStackFactory(Material type, int amount) {
|
||||
this(type, amount, (short) 0);
|
||||
}
|
||||
|
||||
public ItemStackFactory(Material type, int amount, short data) {
|
||||
this.item = new ItemStack(type, amount, data);
|
||||
}
|
||||
|
||||
public ItemStackFactory(Material type, int amount, int data) {
|
||||
this(type, amount, (short) data);
|
||||
}
|
||||
|
||||
public ItemStack toItemStack() {
|
||||
return this.item;
|
||||
}
|
||||
|
||||
public ItemStackFactory setType(Material type) {
|
||||
this.item.setType(type);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStackFactory setDurability(int i) {
|
||||
this.item.setDurability((short) i);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStackFactory setAmount(int a) {
|
||||
this.item.setAmount(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStackFactory setDisplayName(@NotNull String name) {
|
||||
ItemMeta im = this.item.getItemMeta();
|
||||
if (im != null) {
|
||||
im.setDisplayName(ColorParser.parse(name));
|
||||
this.item.setItemMeta(im);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStackFactory setLore(@NotNull List<String> loreList) {
|
||||
ItemMeta im = this.item.getItemMeta();
|
||||
if (im != null) {
|
||||
im.setLore(
|
||||
loreList.stream()
|
||||
.map(ColorParser::parse)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
this.item.setItemMeta(im);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStackFactory addLore(@NotNull String s) {
|
||||
ItemMeta im = this.item.getItemMeta();
|
||||
if (im != null) {
|
||||
List<String> lore = im.getLore() != null ? im.getLore() : new ArrayList<>();
|
||||
lore.add(ColorParser.parse(s));
|
||||
im.setLore(lore);
|
||||
this.item.setItemMeta(im);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStackFactory addEnchant(@NotNull Enchantment enchant, int level, boolean ignoreLevelRestriction) {
|
||||
ItemMeta im = this.item.getItemMeta();
|
||||
if (im != null) {
|
||||
im.addEnchant(enchant, level, ignoreLevelRestriction);
|
||||
this.item.setItemMeta(im);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStackFactory removeEnchant(@NotNull Enchantment enchant) {
|
||||
ItemMeta im = this.item.getItemMeta();
|
||||
if (im != null) {
|
||||
im.removeEnchant(enchant);
|
||||
this.item.setItemMeta(im);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStackFactory addFlag(@NotNull ItemFlag flag) {
|
||||
ItemMeta im = this.item.getItemMeta();
|
||||
if (im != null) {
|
||||
im.addItemFlags(flag);
|
||||
this.item.setItemMeta(im);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStackFactory removeFlag(@NotNull ItemFlag flag) {
|
||||
ItemMeta im = this.item.getItemMeta();
|
||||
if (im != null) {
|
||||
im.removeItemFlags(flag);
|
||||
this.item.setItemMeta(im);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStackFactory setUnbreakable(boolean unbreakable) {
|
||||
ItemMeta im = this.item.getItemMeta();
|
||||
if (im != null) {
|
||||
im.setUnbreakable(unbreakable);
|
||||
this.item.setItemMeta(im);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package cc.carm.plugin.ultradepository.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public class JarUtil {
|
||||
public static final char JAR_SEPARATOR = '/';
|
||||
|
||||
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 = JarUtil.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);
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.util;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class MessageUtil {
|
||||
|
||||
public static boolean hasPlaceholderAPI() {
|
||||
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||
}
|
||||
|
||||
public static void send(@Nullable CommandSender sender, List<String> messages) {
|
||||
if (messages == null || messages.isEmpty() || sender == null) return;
|
||||
for (String s : messages) {
|
||||
sender.sendMessage(ColorParser.parse(s));
|
||||
}
|
||||
}
|
||||
|
||||
public static void send(@Nullable CommandSender sender, String... messages) {
|
||||
send(sender, Arrays.asList(messages));
|
||||
}
|
||||
|
||||
public static void sendWithPlaceholders(CommandSender sender, String... messages) {
|
||||
sendWithPlaceholders(sender, Arrays.asList(messages));
|
||||
}
|
||||
|
||||
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages) {
|
||||
if (messages == null || messages.isEmpty() || sender == null) return;
|
||||
send(sender, setPlaceholders(sender, messages));
|
||||
}
|
||||
|
||||
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages, String param, Object value) {
|
||||
sendWithPlaceholders(sender, messages, new String[]{param}, new Object[]{value});
|
||||
}
|
||||
|
||||
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages, String[] params, Object[] values) {
|
||||
sendWithPlaceholders(sender, setCustomParams(messages, params, values));
|
||||
}
|
||||
|
||||
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages) {
|
||||
if (messages == null || messages.isEmpty() || sender == null) return messages;
|
||||
if (hasPlaceholderAPI() && sender instanceof Player) {
|
||||
return PlaceholderAPI.setPlaceholders((Player) sender, messages);
|
||||
} else {
|
||||
return messages;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages, String[] params, Object[] values) {
|
||||
return setPlaceholders(sender, setCustomParams(messages, params, values));
|
||||
}
|
||||
|
||||
public static List<String> setCustomParams(List<String> messages, String param, Object value) {
|
||||
return setCustomParams(messages, new String[]{param}, new Object[]{value});
|
||||
}
|
||||
|
||||
public static List<String> setCustomParams(List<String> messages, String[] params, Object[] values) {
|
||||
if (params.length != values.length) return messages;
|
||||
HashMap<String, Object> paramsMap = new HashMap<>();
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
paramsMap.put(params[i], values[i]);
|
||||
}
|
||||
return setCustomParams(messages, paramsMap);
|
||||
}
|
||||
|
||||
|
||||
public static List<String> setCustomParams(List<String> messages, HashMap<String, Object> params) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String message : messages) {
|
||||
String afterMessage = message;
|
||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||
afterMessage = afterMessage.replace(entry.getKey(), entry.getValue().toString());
|
||||
}
|
||||
list.add(afterMessage);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,351 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class SchedulerUtils {
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
public SchedulerUtils(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
private JavaPlugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在主线程延时执行一个任务。
|
||||
*
|
||||
* @param delay 延迟的ticks
|
||||
* @param runnable 需要执行的任务
|
||||
*/
|
||||
public void runLater(long delay, Runnable runnable) {
|
||||
Bukkit.getScheduler().runTaskLater(getPlugin(), runnable, delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步延时执行一个任务。
|
||||
*
|
||||
* @param delay 延迟的ticks
|
||||
* @param runnable 需要执行的任务
|
||||
*/
|
||||
public void runLaterAsync(long delay, Runnable runnable) {
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(getPlugin(), runnable, delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步执行一个任务。
|
||||
*
|
||||
* @param runnable 需要执行的任务
|
||||
*/
|
||||
public void runAsync(Runnable runnable) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在服务端主线程中执行一个任务
|
||||
*
|
||||
* @param runnable 需要执行的任务
|
||||
*/
|
||||
public void run(Runnable runnable) {
|
||||
Bukkit.getScheduler().runTask(getPlugin(), runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 间隔一段时间按顺序异步执行列表中的任务
|
||||
*
|
||||
* @param interval 间隔时间
|
||||
* @param tasks 任务列表
|
||||
*/
|
||||
public void runAtIntervalAsync(long interval, Runnable... tasks) {
|
||||
runAtIntervalAsync(0L, interval, tasks);
|
||||
}
|
||||
|
||||
/**
|
||||
* 间隔一段时间按顺序执行列表中的任务
|
||||
*
|
||||
* @param interval 间隔时间
|
||||
* @param tasks 任务列表
|
||||
*/
|
||||
public void runAtInterval(long interval, Runnable... tasks) {
|
||||
runAtInterval(0L, interval, tasks);
|
||||
}
|
||||
|
||||
/**
|
||||
* 间隔一段时间按顺序异步执行列表中的任务
|
||||
*
|
||||
* @param delay 延迟时间
|
||||
* @param interval 间隔时间
|
||||
* @param tasks 任务列表
|
||||
*/
|
||||
public void runAtIntervalAsync(long delay, long interval, Runnable... tasks) {
|
||||
new BukkitRunnable() {
|
||||
private int index;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (this.index >= tasks.length) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
tasks[index].run();
|
||||
index++;
|
||||
}
|
||||
}.runTaskTimerAsynchronously(getPlugin(), delay, interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* 间隔一段时间按顺序执行列表中的任务
|
||||
*
|
||||
* @param delay 延迟时间
|
||||
* @param interval 间隔时间
|
||||
* @param tasks 任务列表
|
||||
*/
|
||||
public void runAtInterval(long delay, long interval, Runnable... tasks) {
|
||||
new BukkitRunnable() {
|
||||
private int index;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (this.index >= tasks.length) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
tasks[index].run();
|
||||
index++;
|
||||
}
|
||||
}.runTaskTimer(getPlugin(), delay, interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重复执行一个任务。
|
||||
*
|
||||
* @param repetitions 重复次数
|
||||
* @param interval 间隔时间
|
||||
* @param task 任务
|
||||
* @param onComplete 结束时执行的任务
|
||||
*/
|
||||
public void repeat(int repetitions, long interval, Runnable task, Runnable onComplete) {
|
||||
new BukkitRunnable() {
|
||||
private int index;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
index++;
|
||||
if (this.index >= repetitions) {
|
||||
this.cancel();
|
||||
if (onComplete == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
onComplete.run();
|
||||
return;
|
||||
}
|
||||
|
||||
task.run();
|
||||
}
|
||||
}.runTaskTimer(getPlugin(), 0L, interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重复执行一个任务。
|
||||
*
|
||||
* @param repetitions 重复次数
|
||||
* @param interval 间隔时间
|
||||
* @param task 任务
|
||||
* @param onComplete 结束时执行的任务
|
||||
*/
|
||||
public void repeatAsync(int repetitions, long interval, Runnable task, Runnable onComplete) {
|
||||
new BukkitRunnable() {
|
||||
private int index;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
index++;
|
||||
if (this.index >= repetitions) {
|
||||
this.cancel();
|
||||
if (onComplete == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
onComplete.run();
|
||||
return;
|
||||
}
|
||||
|
||||
task.run();
|
||||
}
|
||||
}.runTaskTimerAsynchronously(getPlugin(), 0L, interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在满足某个条件时,重复执行一个任务。
|
||||
*
|
||||
* @param interval 重复间隔时间
|
||||
* @param predicate 条件
|
||||
* @param task 任务
|
||||
* @param onComplete 结束时执行的任务
|
||||
*/
|
||||
public void repeatWhile(long interval, Callable<Boolean> predicate, Runnable task, Runnable onComplete) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (!predicate.call()) {
|
||||
this.cancel();
|
||||
if (onComplete == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
onComplete.run();
|
||||
return;
|
||||
}
|
||||
|
||||
task.run();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(getPlugin(), 0L, interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在满足某个条件时,重复执行一个任务。
|
||||
*
|
||||
* @param interval 重复间隔时间
|
||||
* @param predicate 条件
|
||||
* @param task 任务
|
||||
* @param onComplete 结束时执行的任务
|
||||
*/
|
||||
public void repeatWhileAsync(long interval, Callable<Boolean> predicate, Runnable task, Runnable onComplete) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (!predicate.call()) {
|
||||
this.cancel();
|
||||
if (onComplete == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
onComplete.run();
|
||||
return;
|
||||
}
|
||||
|
||||
task.run();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(getPlugin(), 0L, interval);
|
||||
}
|
||||
|
||||
public interface Task {
|
||||
void start(Runnable onComplete);
|
||||
}
|
||||
|
||||
public class TaskBuilder {
|
||||
private Queue<Task> taskList;
|
||||
|
||||
public TaskBuilder() {
|
||||
this.taskList = new LinkedList<>();
|
||||
}
|
||||
|
||||
public TaskBuilder append(TaskBuilder builder) {
|
||||
this.taskList.addAll(builder.taskList);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskBuilder appendDelay(long delay) {
|
||||
this.taskList.add(onComplete -> SchedulerUtils.this.runLater(delay, onComplete));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskBuilder appendTask(Runnable task) {
|
||||
this.taskList.add(onComplete ->
|
||||
{
|
||||
task.run();
|
||||
onComplete.run();
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskBuilder appendTask(Task task) {
|
||||
this.taskList.add(task);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskBuilder appendDelayedTask(long delay, Runnable task) {
|
||||
this.taskList.add(onComplete -> SchedulerUtils.this.runLater(delay, () ->
|
||||
{
|
||||
task.run();
|
||||
onComplete.run();
|
||||
}));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskBuilder appendTasks(long delay, long interval, Runnable... tasks) {
|
||||
this.taskList.add(onComplete ->
|
||||
{
|
||||
Runnable[] runnables = Arrays.copyOf(tasks, tasks.length + 1);
|
||||
runnables[runnables.length - 1] = onComplete;
|
||||
SchedulerUtils.this.runAtInterval(delay, interval, runnables);
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskBuilder appendRepeatingTask(int repetitions, long interval, Runnable task) {
|
||||
this.taskList.add(onComplete -> SchedulerUtils.this.repeat(repetitions, interval, task, onComplete));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskBuilder appendConditionalRepeatingTask(long interval, Callable<Boolean> predicate, Runnable task) {
|
||||
this.taskList.add(onComplete -> SchedulerUtils.this.repeatWhile(interval, predicate, task, onComplete));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskBuilder waitFor(Callable<Boolean> predicate) {
|
||||
this.taskList.add(onComplete -> new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (!predicate.call()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.cancel();
|
||||
onComplete.run();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(getPlugin(), 0L, 1L));
|
||||
return this;
|
||||
}
|
||||
|
||||
public void runTasks() {
|
||||
this.startNext();
|
||||
}
|
||||
|
||||
private void startNext() {
|
||||
Task task = this.taskList.poll();
|
||||
if (task == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
task.start(this::startNext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,222 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.util.gui;
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import cc.carm.plugin.ultradepository.util.ColorParser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class GUI {
|
||||
|
||||
private static final HashMap<Player, GUI> openedGUIs = new HashMap<>();
|
||||
|
||||
GUIType type;
|
||||
String name;
|
||||
public GUIItem[] items;
|
||||
public Inventory inv;
|
||||
|
||||
boolean cancelOnTarget = true;
|
||||
boolean cancelOnSelf = true;
|
||||
boolean cancelOnOuter = true;
|
||||
|
||||
Map<String, Object> flags;
|
||||
|
||||
public GUIListener listener;
|
||||
|
||||
public GUI(GUIType type, String name) {
|
||||
this.type = type;
|
||||
this.name = ColorParser.parse(name);
|
||||
switch (type) {
|
||||
case ONE_BY_NINE:
|
||||
this.items = new GUIItem[9];
|
||||
break;
|
||||
case TWO_BY_NINE:
|
||||
this.items = new GUIItem[18];
|
||||
break;
|
||||
case THREE_BY_NINE:
|
||||
this.items = new GUIItem[27];
|
||||
break;
|
||||
case FOUR_BY_NINE:
|
||||
this.items = new GUIItem[36];
|
||||
break;
|
||||
case FIVE_BY_NINE:
|
||||
this.items = new GUIItem[45];
|
||||
break;
|
||||
case SIX_BY_NINE:
|
||||
this.items = new GUIItem[54];
|
||||
break;
|
||||
case CANCEL:
|
||||
default:
|
||||
this.items = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final void setItem(int index, GUIItem item) {
|
||||
if (item == null) {
|
||||
this.items[index] = new GUIItem(new ItemStack(Material.AIR));
|
||||
} else {
|
||||
this.items[index] = item;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量添加GUI Item
|
||||
*
|
||||
* @param item 物品
|
||||
* @param index 对应格
|
||||
*/
|
||||
public void setItem(GUIItem item, int... index) {
|
||||
Arrays.stream(index).forEach(i -> setItem(i, item));
|
||||
}
|
||||
|
||||
public void setItem(GUIItem item, int start, int end) {
|
||||
IntStream.rangeClosed(start, end).forEach(i -> setItem(i, item));
|
||||
}
|
||||
|
||||
public GUIItem getItem(int index) {
|
||||
return this.items[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新玩家箱子的视图
|
||||
*/
|
||||
public void updateView() {
|
||||
if (this.inv != null) {
|
||||
List<HumanEntity> viewers = this.inv.getViewers();
|
||||
IntStream.range(0, this.items.length).forEach(index -> {
|
||||
GUIItem item = items[index];
|
||||
if (item == null) {
|
||||
inv.setItem(index, new ItemStack(Material.AIR));
|
||||
} else {
|
||||
inv.setItem(index, items[index].display);
|
||||
}
|
||||
});
|
||||
|
||||
for (HumanEntity p : viewers) {
|
||||
((Player) p).updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否取消点击GUI内物品的事件
|
||||
* 如果不取消,玩家可以从GUI中拿取物品。
|
||||
*
|
||||
* @param b 是否取消
|
||||
*/
|
||||
public void setCancelledIfClickOnTarget(boolean b) {
|
||||
this.cancelOnTarget = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否取消点击自己背包内物品的事件
|
||||
* 如果不取消,玩家可以从自己的背包中拿取物品。
|
||||
*
|
||||
* @param b 是否取消
|
||||
*/
|
||||
public void setCancelledIfClickOnSelf(boolean b) {
|
||||
this.cancelOnSelf = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否取消点击GUI外的事件
|
||||
* 如果不取消,玩家可以把物品从GUI或背包中丢出去
|
||||
*
|
||||
* @param b 是否取消
|
||||
*/
|
||||
public void setCancelledIfClickOnOuter(boolean b) {
|
||||
this.cancelOnOuter = b;
|
||||
}
|
||||
|
||||
public void addFlag(String flag, Object obj) {
|
||||
if (this.flags == null) this.flags = new HashMap<>();
|
||||
this.flags.put(flag, obj);
|
||||
}
|
||||
|
||||
public Object getFlag(String flag) {
|
||||
if (this.flags == null) return null;
|
||||
else
|
||||
return this.flags.get(flag);
|
||||
}
|
||||
|
||||
public void setFlag(String flag, Object obj) {
|
||||
if (this.flags == null) this.flags = new HashMap<>();
|
||||
this.flags.replace(flag, obj);
|
||||
}
|
||||
|
||||
public void removeFlag(String flag) {
|
||||
if (this.flags == null) this.flags = new HashMap<>();
|
||||
this.flags.remove(flag);
|
||||
}
|
||||
|
||||
public void rawClickListener(InventoryClickEvent event) {
|
||||
}
|
||||
|
||||
public void openGUI(Player player) {
|
||||
Inventory inv;
|
||||
if (this.type == GUIType.CANCEL) {
|
||||
throw new NullPointerException("被取消或不存在的GUI");
|
||||
}
|
||||
inv = Bukkit.createInventory(null, this.items.length, this.name);
|
||||
|
||||
for (int index = 0; index < this.items.length; index++) {
|
||||
if (items[index] == null) {
|
||||
inv.setItem(index, new ItemStack(Material.AIR));
|
||||
} else {
|
||||
inv.setItem(index, items[index].display);
|
||||
}
|
||||
}
|
||||
setOpenedGUI(player, this);
|
||||
this.inv = inv;
|
||||
player.openInventory(inv);
|
||||
|
||||
if (listener == null) {
|
||||
Main.regListener(listener = new GUIListener(this, player));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 拖动GUI内物品时执行的代码
|
||||
*
|
||||
* @param event InventoryDragEvent
|
||||
*/
|
||||
public void onDrag(InventoryDragEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭GUI时执行的代码
|
||||
*/
|
||||
public void onClose() {
|
||||
}
|
||||
|
||||
|
||||
public static void setOpenedGUI(Player player, GUI gui) {
|
||||
openedGUIs.put(player, gui);
|
||||
}
|
||||
|
||||
public static boolean hasOpenedGUI(Player player) {
|
||||
return openedGUIs.containsKey(player);
|
||||
}
|
||||
|
||||
public static GUI getOpenedGUI(Player player) {
|
||||
return openedGUIs.get(player);
|
||||
}
|
||||
|
||||
public static void removeOpenedGUI(Player player) {
|
||||
openedGUIs.remove(player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.util.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class GUIItem {
|
||||
|
||||
ItemStack display;
|
||||
boolean actionActive = true;
|
||||
|
||||
public Set<GUIClickAction> actions = new HashSet<>();
|
||||
public Set<GUIClickAction> actionsIgnoreActive = new HashSet<>();
|
||||
|
||||
public GUIItem(ItemStack display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
public final ItemStack getDisplay() {
|
||||
return this.display;
|
||||
}
|
||||
|
||||
public final void setDisplay(ItemStack display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
public final boolean isActionActive() {
|
||||
return this.actionActive;
|
||||
}
|
||||
|
||||
public final void setActionActive(boolean b) {
|
||||
actionActive = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* 玩家点击GUI后执行的代码
|
||||
*
|
||||
* @param type 点击的类型
|
||||
*/
|
||||
public void onClick(ClickType type) {
|
||||
|
||||
}
|
||||
|
||||
public void addClickAction(GUIClickAction action) {
|
||||
actions.add(action);
|
||||
}
|
||||
|
||||
public void addActionIgnoreActive(GUIClickAction action) {
|
||||
actionsIgnoreActive.add(action);
|
||||
}
|
||||
|
||||
public void rawClickAction(InventoryClickEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void realRawClickAction(InventoryClickEvent event) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 玩家点击GUI后执行的代码
|
||||
*
|
||||
* @param player 点击GUI的玩家
|
||||
*/
|
||||
public void customAction(Player player) {
|
||||
|
||||
}
|
||||
|
||||
public abstract static class GUIClickAction {
|
||||
public abstract void run(ClickType type, Player player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.util.gui;
|
||||
|
||||
import cc.carm.plugin.ultradepository.Main;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
|
||||
public class GUIListener implements Listener {
|
||||
|
||||
final GUI currentGUI;
|
||||
final Player player;
|
||||
|
||||
public GUIListener(GUI gui, Player player) {
|
||||
this.currentGUI = gui;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public GUI getCurrentGUI() {
|
||||
return currentGUI;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClickEvent(InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player)) return;
|
||||
getCurrentGUI().rawClickListener(event);
|
||||
|
||||
Player p = (Player) event.getWhoClicked();
|
||||
if (event.getSlot() != -999) {
|
||||
try {
|
||||
if (GUI.getOpenedGUI(p) == getCurrentGUI()
|
||||
&& event.getClickedInventory() != null
|
||||
&& event.getClickedInventory().equals(getCurrentGUI().inv)
|
||||
&& getCurrentGUI().items[event.getSlot()] != null) {
|
||||
getCurrentGUI().items[event.getSlot()].realRawClickAction(event);
|
||||
}
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
Main.error("error cause by GUI(" + getCurrentGUI() + "), name=" + getCurrentGUI().name);
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
} else if (getCurrentGUI().cancelOnOuter) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (GUI.hasOpenedGUI(p)
|
||||
&& GUI.getOpenedGUI(p) == getCurrentGUI()
|
||||
&& event.getClickedInventory() != null) {
|
||||
|
||||
if (event.getClickedInventory().equals(getCurrentGUI().inv)) {
|
||||
if (getCurrentGUI().cancelOnTarget) event.setCancelled(true);
|
||||
|
||||
if (event.getSlot() != -999 && getCurrentGUI().items[event.getSlot()] != null) {
|
||||
|
||||
GUIItem item = getCurrentGUI().items[event.getSlot()];
|
||||
|
||||
if (item.isActionActive()) {
|
||||
item.onClick(event.getClick());
|
||||
item.rawClickAction(event);
|
||||
item.actions.forEach(action -> action.run(event.getClick(), player));
|
||||
}
|
||||
|
||||
item.actionsIgnoreActive.forEach(action -> action.run(event.getClick(), player));
|
||||
|
||||
}
|
||||
} else if (event.getClickedInventory().equals(p.getInventory()) && getCurrentGUI().cancelOnSelf) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDrag(InventoryDragEvent e) {
|
||||
if (!(e.getWhoClicked() instanceof Player)) return;
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
if (e.getInventory().equals(getCurrentGUI().inv) || e.getInventory().equals(p.getInventory())) {
|
||||
getCurrentGUI().onDrag(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryCloseEvent(InventoryCloseEvent event) {
|
||||
Player p = (Player) event.getPlayer();
|
||||
if (event.getInventory().equals(getCurrentGUI().inv)) {
|
||||
HandlerList.unregisterAll(this);
|
||||
getCurrentGUI().listener = null;
|
||||
getCurrentGUI().onClose();
|
||||
GUI.removeOpenedGUI(p);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onOpen(InventoryOpenEvent event) {
|
||||
Player p = (Player) event.getPlayer();
|
||||
//开启新界面后 结束旧界面
|
||||
if (!event.getInventory().equals(getCurrentGUI().inv)) {
|
||||
HandlerList.unregisterAll(this);
|
||||
getCurrentGUI().listener = null;
|
||||
getCurrentGUI().onClose();
|
||||
GUI.removeOpenedGUI(p);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package cc.carm.plugin.ultradepository.util.gui;
|
||||
|
||||
public enum GUIType {
|
||||
|
||||
ONE_BY_NINE,
|
||||
TWO_BY_NINE,
|
||||
THREE_BY_NINE,
|
||||
FOUR_BY_NINE,
|
||||
FIVE_BY_NINE,
|
||||
SIX_BY_NINE,
|
||||
CANCEL
|
||||
|
||||
}
|
||||
@@ -6,16 +6,21 @@ version: ${project.version}
|
||||
|
||||
debug: false
|
||||
|
||||
# 统计数据设定
|
||||
# 该选项用于帮助开发者统计插件版本与使用情况,且绝不会影响性能与使用体验。
|
||||
# 当然,您也可以选择在这里关闭,或在plugins/bStats下的配置文件中关闭。
|
||||
metrics: true
|
||||
|
||||
# 存储相关配置
|
||||
# 注意:存储配置不会通过重载指令生效,如有修改请重新启动服务器。
|
||||
storage:
|
||||
|
||||
# 存储方式,可选 [ file | mysql ]
|
||||
method: file
|
||||
# 存储方式,可选 [ yaml | json | mysql(推荐) ]
|
||||
method: yaml
|
||||
|
||||
# 选择 file 存储方式时的存储路径
|
||||
# 选择 yaml/json 存储方式时的存储路径
|
||||
# 默认为相对路径,相对于插件生成的配置文件夹下的路径
|
||||
# 支持绝对路径,如 “/var/data/ub/"(linux) 或 "D:\data\ub\"(windows)
|
||||
# 支持绝对路径,如 “/var/data/ud/"(linux) 或 "D:\data\ud\"(windows)
|
||||
# 使用绝对路径时请注意权限问题
|
||||
file-path: data
|
||||
|
||||
@@ -24,6 +29,7 @@ storage:
|
||||
# 数据库驱动路径
|
||||
driver: "com.mysql.jdbc.Driver"
|
||||
url: "jdbc:mysql://127.0.0.1:3306/<db-name>"
|
||||
table: "ud_data" # 插件表名,允许自定义
|
||||
username: "username"
|
||||
password: "password"
|
||||
|
||||
@@ -38,6 +44,7 @@ collect:
|
||||
|
||||
sounds:
|
||||
collect: "ENTITY_EXPERIENCE_ORB_PICKUP:0.5"
|
||||
takeout: "ENTITY_HORSE_ARMOR:0.5"
|
||||
sell-success: "ENTITY_VILLAGER_CELEBRATE"
|
||||
sell-fail: "ENTITY_VILLAGER_NO"
|
||||
gui-click: "UI_BUTTON_CLICK"
|
||||
@@ -45,20 +52,34 @@ sounds:
|
||||
# 通用配置
|
||||
general:
|
||||
|
||||
# 针对每一件物品的额外介绍
|
||||
# 针对可出售物品的额外介绍
|
||||
# 将添加到背包界面内的物品上,避免重复配置
|
||||
additional-lore:
|
||||
available-for-sale:
|
||||
# 可出售物品的介绍
|
||||
- " "
|
||||
- "&f仓库内数量 &a%(amount)"
|
||||
- "&f该物品单价 &a%(price)"
|
||||
- "&f今日可出售 &a%(remain)&8/%(limit)"
|
||||
not-for-sale:
|
||||
# 针对不可出售的物品的额外介绍
|
||||
# (当 未安装经济插件 或 每日可售出数量<=0 或 单价<=0 时判断为不可出售)
|
||||
- " "
|
||||
- "&f仓库内数量 &a%(amount)"
|
||||
|
||||
|
||||
# 提示玩家点击行为的介绍
|
||||
# 将添加到背包界面内的物品上,避免重复配置
|
||||
click-lore:
|
||||
available-for-sale:
|
||||
- " "
|
||||
- "&a&l左键点击 &8| &f按量售出该物品"
|
||||
- "&a&l右键点击 &8| &f取出一组该物品"
|
||||
not-for-sale:
|
||||
# 针对不可出售的物品的额外介绍
|
||||
# (当 未安装经济插件 或 每日可售出数量<=0 或 单价<=0 时判断为不可出售)
|
||||
- " "
|
||||
- "&a&l右键点击 &8| &f取出一组该物品"
|
||||
|
||||
# 售出界面的配置
|
||||
sell-gui:
|
||||
@@ -72,7 +93,6 @@ general:
|
||||
name: "&c减少 %(amount) 个"
|
||||
confirm:
|
||||
type: EMERALD
|
||||
data: 0
|
||||
name: "&a确认售出"
|
||||
lore:
|
||||
- " "
|
||||
@@ -82,7 +102,6 @@ general:
|
||||
- "&a&l点击确认售出"
|
||||
cancel:
|
||||
type: REDSTONE
|
||||
data: 0
|
||||
name: "&c取消售出"
|
||||
lore:
|
||||
- " "
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
name: "&b&lExample Depository" # 仓库名,用于消息显示
|
||||
|
||||
capacity: # 容量配置
|
||||
default: 500 # 若为0则默认不可以使用该仓库
|
||||
permissions: # 特殊权限对应的仓库容量,格式为 "权限:容量
|
||||
- "UltraDepository.vip:1000"
|
||||
- "UltraDepository.mvp:1500"
|
||||
|
||||
gui: # GUI额外配置
|
||||
title: "&b&l示例仓库 &7| 界面" #示例仓库的GUI标题
|
||||
lines: 4 # GUI的行数,支持 1-6行。
|
||||
items:
|
||||
"TEST":
|
||||
material: CHEST # 物品图标的类型
|
||||
data: 0 # 物品图标的数据值
|
||||
slot: 31 # 在GUI中显示的格子
|
||||
name: "&9&l测试图标"
|
||||
lore:
|
||||
# 支持使用变量
|
||||
- "你好 %player_name% !"
|
||||
actions: # 物品点击操作
|
||||
- "[CHAT] Hello!" #以玩家身份发送Hello,支持PlaceholderAPI变量
|
||||
- "[CHAT] /help" #若内容以"/"开头,则会以玩家身份执行指令,支持PlaceholderAPI变量
|
||||
- "[CONSOLE] say HELLO WORLD" #以后台身份执行指令,不需要加"/",支持PlaceholderAPI变量
|
||||
- "[MESSAGE] &(#FFBBBBB)Test %player_name%" # 向玩家发送消息,支持PlaceholderAPI变量和RGB颜色
|
||||
- "[SOUND] ENTITY_EXPERIENCE_ORB_PICKUP:0.5" # 向玩家发送声音,可以规定音量大小和音调,格式为 <声音>:[音量]:[音调]
|
||||
- "[CLOSE]" # 为玩家关闭界面
|
||||
|
||||
- "[LEFT:CLOSE]" #限制只有 鼠标左键 才触发CLOSE
|
||||
- "[SHIFT_LEFT:CLOSE]" #限制只有 按住Shift+鼠标左键 才触发CLOSE
|
||||
- "[RIGHT:CLOSE]" #限制只有 鼠标右键 才触发CLOSE
|
||||
- "[SHIFT_RIGHT:CLOSE]" #限制只有 按住Shift+鼠标右键 才触发CLOSE
|
||||
- "[MIDDLE:CLOSE]" #限制只有 鼠标中键 才触发CLOSE
|
||||
- "[DROP:CLOSE]" #限制只有 丢弃建 才触发CLOSE
|
||||
- "[CONTROL_DROP:CLOSE]" #限制只有 按住Ctrl+丢弃键 才触发CLOSE
|
||||
- "[DOUBLE_CLICK:CLOSE]" #限制只有 鼠标双击物品 才触发CLOSE
|
||||
- "[NUMBER_KEY:CLOSE]" #限制只有 数字键切换 才触发CLOSE
|
||||
|
||||
items:
|
||||
"INK_SAC": #物品ID,若需要限制数据ID则可以加“:”,如 "INK_SANK:4"
|
||||
slot: 11 # 物品在GUI中显示的槽位
|
||||
price: 0.1 # 物品单价
|
||||
limit: 500 # 物品每日售出限制
|
||||
name: "&8&l墨囊" # 物品显示的名字
|
||||
lore: # 物品的lore
|
||||
- " "
|
||||
- "&f抓住墨鱼!"
|
||||
@@ -0,0 +1,110 @@
|
||||
# ${project.name} - ${project.description}
|
||||
# Source url: ${project.url}
|
||||
# Download URL: ${project.distributionManagement.downloadUrl}
|
||||
|
||||
version: ${project.version}
|
||||
|
||||
debug: false
|
||||
|
||||
# bStats Metrics
|
||||
# This option is used to help developers analysis plugin stats,
|
||||
# and will never affect performance and user experience.
|
||||
# You can choose to turn it off here.
|
||||
metrics: true
|
||||
|
||||
# Storage Configuration
|
||||
storage:
|
||||
|
||||
# Storage method
|
||||
# You can choose [ yaml | json | mysql ]
|
||||
method: yaml
|
||||
|
||||
# The storage file path when choosing "yaml"/"json" method.
|
||||
# Support absolute paths, e.g. “/var/data/ud/"(linux) or "D:\data\ud\"(windows)
|
||||
# **Be aware of permission issues when using absolute paths!**
|
||||
file-path: data
|
||||
|
||||
# The Database configuration when choosing "mysql" method.
|
||||
mysql:
|
||||
driver: "com.mysql.jdbc.Driver"
|
||||
url: "jdbc:mysql://127.0.0.1:3306/<db-name>"
|
||||
table: "ud_data" # Plugin data table name, allowing customization
|
||||
username: "username"
|
||||
password: "password"
|
||||
|
||||
|
||||
# Player Collect Configuration
|
||||
# Used to determine when put the player's item into the backpack automatically
|
||||
collect:
|
||||
pickup: true # Pickup Items
|
||||
kill: true # Kill Entities (Animals/Monsters)
|
||||
break: true # Break Blocks
|
||||
|
||||
sounds:
|
||||
collect: "ENTITY_EXPERIENCE_ORB_PICKUP:0.5"
|
||||
sell-success: "ENTITY_VILLAGER_CELEBRATE"
|
||||
sell-fail: "ENTITY_VILLAGER_NO"
|
||||
gui-click: "UI_BUTTON_CLICK"
|
||||
|
||||
# General Configuration
|
||||
general:
|
||||
|
||||
# Hints lore for the item's information
|
||||
# Will add to items in BackpackGUI and SellGUI.
|
||||
additional-lore:
|
||||
available-for-sale:
|
||||
- " "
|
||||
- "&fAmount &a%(amount)"
|
||||
- "&fPrice &a%(price)"
|
||||
- "&fSold &a%(remain)&8/%(limit)"
|
||||
not-for-sale:
|
||||
# Display when :
|
||||
# 1. Vault not installed
|
||||
# 2. No economy plugins
|
||||
# 3. daily sell limit <= 0
|
||||
# 4. item price <=0
|
||||
- " "
|
||||
- "&fAmount &a%(amount)"
|
||||
|
||||
# Hints lore for the player's click
|
||||
# Will add to items in BackpackGUI.
|
||||
click-lore:
|
||||
available-for-sale:
|
||||
- " "
|
||||
- "&a&lLEFT-CLICK &8| &fSell items"
|
||||
- "&a&lRIGHT-CLICK &8| &fTake one Stack"
|
||||
not-for-sale:
|
||||
# Display when :
|
||||
# 1. Vault not installed
|
||||
# 2. No economy plugins
|
||||
# 3. daily sell limit <= 0
|
||||
# 4. item price <=0
|
||||
- " "
|
||||
- "&a&lRIGHT-CLICK &8| &fTake one Stack"
|
||||
|
||||
|
||||
# Configuration of the SellGUI
|
||||
sell-gui:
|
||||
title: "&8Selling %(item_name)"
|
||||
items:
|
||||
add:
|
||||
type: GREEN_STAINED_GLASS_PANE
|
||||
name: "&aAdd %(amount)"
|
||||
remove:
|
||||
type: RED_STAINED_GLASS_PANE
|
||||
name: "&cReduce %(amount)"
|
||||
confirm:
|
||||
type: EMERALD
|
||||
name: "&a&lConfirm"
|
||||
lore:
|
||||
- " "
|
||||
- "&7You will sell &r%(item_name) &8x &f%(amount)"
|
||||
- "&7and will get $&e%(money) &7."
|
||||
- " "
|
||||
- "&a&lClick to confirm"
|
||||
cancel:
|
||||
type: REDSTONE
|
||||
name: "&c&lCancel"
|
||||
lore:
|
||||
- " "
|
||||
- "&cClick to cancel"
|
||||
@@ -0,0 +1,48 @@
|
||||
help:
|
||||
console:
|
||||
- '&6&l超级仓库 &f后台指令帮助'
|
||||
- '&8#&f info &6<玩家> &e[仓库ID] &e[物品ID]'
|
||||
- '&8-&7 得到玩家的相关物品信息。'
|
||||
- '&8#&f add &6<玩家> &6<仓库ID> &6<物品ID> &6<数量>'
|
||||
- '&8-&7 为玩家添加对应仓库中对于物品的数量。'
|
||||
- '&8#&f remove &6<玩家> &6<仓库ID> &6<物品ID> &e[数量]'
|
||||
- '&8-&7 为玩家减少对应仓库中对于物品的数量。'
|
||||
- '&8-&7 若不填写数量,则清空对应仓库的对应物品。'
|
||||
- '&8#&f sell &6<玩家> &e[仓库ID] &e[物品ID] &e[数量]'
|
||||
- '&8-&7 为玩家售出相关物品。'
|
||||
- '&8-&7 若不填写数量,则售出所有对应仓库的对应物品。'
|
||||
- '&8-&7 若不填写物品,则售出对应仓库内所有物品。'
|
||||
- '&8-&7 若不填写仓库,则售出所有仓库内所有物品。'
|
||||
- '&8-&7 该指令受到玩家每日售出数量的限制。'
|
||||
player:
|
||||
- '&6&l超级仓库 &f玩家指令帮助'
|
||||
- '&8#&f open &e[仓库ID]'
|
||||
- '&8-&7 打开对应仓库的界面。'
|
||||
- '&8#&f sell &6<仓库ID> &6<物品ID> &6<数量>'
|
||||
- '&8-&7 售出对应数量的对应物品。'
|
||||
- '&8-&7 该指令受到玩家每日售出数量的限制。'
|
||||
- '&8#&f sellAll &e[仓库ID] &e[物品ID]'
|
||||
- '&8-&7 该指令受到玩家每日售出数量的限制。'
|
||||
item-sold:
|
||||
- '&f您出售了 &r%(item)&7x%(amount) &f,共赚取 &6%(money) &f元。'
|
||||
item-sold-limit:
|
||||
- '&f该物品今日剩余可出售额度为 &a%(amount)&8/%(limit) &f个。'
|
||||
item-pickup:
|
||||
- '&f您拾取了 &r%(item)&7x%(amount) &f,已自动放入到您的仓库中。'
|
||||
item-takeout:
|
||||
- '&f您从仓库中拿取了 &r%(item)&7x%(amount) &f放入到您的背包中。'
|
||||
item-collect:
|
||||
- '&f您收集了 &r%(item)&7x%(amount) &f,已自动放入到您的 &6%(depository) &f中。'
|
||||
item-collect-actionbar: '&r%(item)&7x%(amount) &f-> &6%(depository)'
|
||||
no-space:
|
||||
- '&f您背包内没有足够的空间取出物品!'
|
||||
no-economy:
|
||||
- '&f本服务器暂未启用出售功能。'
|
||||
no-depository:
|
||||
- '&f不存在该仓库,请检查仓库ID是否正确。'
|
||||
no-item:
|
||||
- '&f仓库中不存在该物品,请检查物品ID是否正确。'
|
||||
no-enough-item:
|
||||
- '&f仓库中不存在足够的物品。'
|
||||
wrong-number:
|
||||
- '&f数目输入错误,请输入正确的数字!'
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
name: "&b&l示例仓库" # 仓库名,用于消息显示
|
||||
|
||||
capacity: # 容量配置
|
||||
default: 500 # 若为0则默认不可以使用该仓库
|
||||
permissions: # 特殊权限对应的仓库容量,格式为 "权限:容量
|
||||
- "UltraDepository.vip:1000"
|
||||
- "UltraDepository.mvp:1500"
|
||||
|
||||
gui: # GUI额外配置
|
||||
title: "&b&l示例仓库 &7| 界面" #示例仓库的GUI标题
|
||||
lines: 4 # GUI的行数,支持 1-6行。
|
||||
items:
|
||||
"TEST":
|
||||
material: CHEST # 物品图标的类型
|
||||
data: 0 # 物品图标的数据值
|
||||
slot: 31 # 在GUI中显示的格子
|
||||
name: "&9&l测试图标"
|
||||
lore:
|
||||
# 支持使用变量
|
||||
- "你好 %player_name% !"
|
||||
actions: # 物品点击操作
|
||||
- "[CHAT] Hello!" #以玩家身份发送Hello,支持PlaceholderAPI变量
|
||||
- "[CHAT] /help" #若内容以"/"开头,则会以玩家身份执行指令,支持PlaceholderAPI变量
|
||||
- "[CONSOLE] say HELLO WORLD" #以后台身份执行指令,不需要加"/",支持PlaceholderAPI变量
|
||||
- "[MESSAGE] &(#FFBBBBB)Test %player_name%" # 向玩家发送消息,支持PlaceholderAPI变量和RGB颜色
|
||||
- "[SOUND] ENTITY_EXPERIENCE_ORB_PICKUP:0.5" # 向玩家发送声音,可以规定音量大小和音调,格式为 <声音>:[音量]:[音调]
|
||||
- "[CLOSE]" # 为玩家关闭界面
|
||||
|
||||
- "[LEFT:CLOSE]" #限制只有 鼠标左键 才触发CLOSE
|
||||
- "[SHIFT_LEFT:CLOSE]" #限制只有 按住Shift+鼠标左键 才触发CLOSE
|
||||
- "[RIGHT:CLOSE]" #限制只有 鼠标右键 才触发CLOSE
|
||||
- "[SHIFT_RIGHT:CLOSE]" #限制只有 按住Shift+鼠标右键 才触发CLOSE
|
||||
- "[MIDDLE:CLOSE]" #限制只有 鼠标中键 才触发CLOSE
|
||||
- "[DROP:CLOSE]" #限制只有 丢弃建 才触发CLOSE
|
||||
- "[CONTROL_DROP:CLOSE]" #限制只有 按住Ctrl+丢弃键 才触发CLOSE
|
||||
- "[DOUBLE_CLICK:CLOSE]" #限制只有 鼠标双击物品 才触发CLOSE
|
||||
- "[NUMBER_KEY:CLOSE]" #限制只有 数字键切换 才触发CLOSE
|
||||
|
||||
items:
|
||||
"INK_SAC": #物品ID,若需要限制数据ID则可以加“:”,如 "INK_SANK:4"
|
||||
slot: 11 # 物品在GUI中显示的槽位
|
||||
price: 0.1 # 物品单价
|
||||
limit: 500 # 物品每日售出限制
|
||||
name: "&8&l墨囊" # 物品显示的名字
|
||||
lore: # 物品的lore
|
||||
- " "
|
||||
- "&f抓住墨鱼!"
|
||||
@@ -0,0 +1,109 @@
|
||||
# ${project.name} - ${project.description}
|
||||
# Source url: ${project.url}
|
||||
# Download URL: ${project.distributionManagement.downloadUrl}
|
||||
|
||||
version: ${project.version}
|
||||
|
||||
debug: false
|
||||
|
||||
# bStats Metrics
|
||||
# This option is used to help developers analysis plugin stats,
|
||||
# and will never affect performance and user experience.
|
||||
# You can choose to turn it off here.
|
||||
metrics: true
|
||||
|
||||
# Storage Configuration
|
||||
storage:
|
||||
|
||||
# Storage method
|
||||
# You can choose [ yaml | json | mysql ]
|
||||
method: yaml
|
||||
|
||||
# The storage file path when choosing "yaml"/"json" method.
|
||||
# Support absolute paths, e.g. “/var/data/ud/"(linux) or "D:\data\ud\"(windows)
|
||||
# **Be aware of permission issues when using absolute paths!**
|
||||
file-path: data
|
||||
|
||||
# The Database configuration when choosing "mysql" method.
|
||||
mysql:
|
||||
driver: "com.mysql.jdbc.Driver"
|
||||
url: "jdbc:mysql://127.0.0.1:3306/<db-name>"
|
||||
table: "ud_data" # Plugin data table name, allowing customization
|
||||
username: "username"
|
||||
password: "password"
|
||||
|
||||
|
||||
# Player Collect Configuration
|
||||
# Used to determine when put the player's item into the backpack automatically
|
||||
collect:
|
||||
pickup: true # Pickup Items
|
||||
kill: true # Kill Entities (Animals/Monsters)
|
||||
break: true # Break Blocks
|
||||
|
||||
sounds:
|
||||
collect: "ENTITY_EXPERIENCE_ORB_PICKUP:0.5"
|
||||
sell-success: "ENTITY_VILLAGER_CELEBRATE"
|
||||
sell-fail: "ENTITY_VILLAGER_NO"
|
||||
gui-click: "UI_BUTTON_CLICK"
|
||||
|
||||
# General Configuration
|
||||
general:
|
||||
|
||||
# Hints lore for the item's information
|
||||
# Will add to items in BackpackGUI and SellGUI.
|
||||
additional-lore:
|
||||
available-for-sale:
|
||||
- " "
|
||||
- "&fAmount &a%(amount)"
|
||||
- "&fPrice &a%(price)"
|
||||
- "&fSold &a%(remain)&8/%(limit)"
|
||||
not-for-sale:
|
||||
# Display when :
|
||||
# 1. Vault not installed
|
||||
# 2. No economy plugins
|
||||
# 3. daily sell limit <= 0
|
||||
# 4. item price <=0
|
||||
- " "
|
||||
- "&fAmount &a%(amount)"
|
||||
|
||||
# Hints lore for the player's click
|
||||
# Will add to items in BackpackGUI.
|
||||
click-lore:
|
||||
available-for-sale:
|
||||
- " "
|
||||
- "&a&lLEFT-CLICK &8| &fSell items"
|
||||
- "&a&lRIGHT-CLICK &8| &fTake one Stack"
|
||||
not-for-sale:
|
||||
# Display when :
|
||||
# 1. Vault not installed
|
||||
# 2. No economy plugins
|
||||
# 3. daily sell limit <= 0
|
||||
# 4. item price <=0
|
||||
- " "
|
||||
- "&a&lRIGHT-CLICK &8| &fTake one Stack"
|
||||
|
||||
# Configuration of the SellGUI
|
||||
sell-gui:
|
||||
title: "&8Selling %(item_name)"
|
||||
items:
|
||||
add:
|
||||
type: GREEN_STAINED_GLASS_PANE
|
||||
name: "&aAdd %(amount)"
|
||||
remove:
|
||||
type: RED_STAINED_GLASS_PANE
|
||||
name: "&cReduce %(amount)"
|
||||
confirm:
|
||||
type: EMERALD
|
||||
name: "&a&lConfirm"
|
||||
lore:
|
||||
- " "
|
||||
- "&7You will sell &r%(item_name) &8x &f%(amount)"
|
||||
- "&7and will get $&e%(money) &7."
|
||||
- " "
|
||||
- "&a&lClick to confirm"
|
||||
cancel:
|
||||
type: REDSTONE
|
||||
name: "&c&lCancel"
|
||||
lore:
|
||||
- " "
|
||||
- "&cClick to cancel"
|
||||
@@ -0,0 +1,48 @@
|
||||
help:
|
||||
console:
|
||||
- '&6&l超级仓库 &f后台指令帮助'
|
||||
- '&8#&f info &6<玩家> &e[仓库ID] &e[物品ID]'
|
||||
- '&8-&7 得到玩家的相关物品信息。'
|
||||
- '&8#&f add &6<玩家> &6<仓库ID> &6<物品ID> &6<数量>'
|
||||
- '&8-&7 为玩家添加对应仓库中对于物品的数量。'
|
||||
- '&8#&f remove &6<玩家> &6<仓库ID> &6<物品ID> &e[数量]'
|
||||
- '&8-&7 为玩家减少对应仓库中对于物品的数量。'
|
||||
- '&8-&7 若不填写数量,则清空对应仓库的对应物品。'
|
||||
- '&8#&f sell &6<玩家> &e[仓库ID] &e[物品ID] &e[数量]'
|
||||
- '&8-&7 为玩家售出相关物品。'
|
||||
- '&8-&7 若不填写数量,则售出所有对应仓库的对应物品。'
|
||||
- '&8-&7 若不填写物品,则售出对应仓库内所有物品。'
|
||||
- '&8-&7 若不填写仓库,则售出所有仓库内所有物品。'
|
||||
- '&8-&7 该指令受到玩家每日售出数量的限制。'
|
||||
player:
|
||||
- '&6&l超级仓库 &f玩家指令帮助'
|
||||
- '&8#&f open &e[仓库ID]'
|
||||
- '&8-&7 打开对应仓库的界面。'
|
||||
- '&8#&f sell &6<仓库ID> &6<物品ID> &6<数量>'
|
||||
- '&8-&7 售出对应数量的对应物品。'
|
||||
- '&8-&7 该指令受到玩家每日售出数量的限制。'
|
||||
- '&8#&f sellAll &e[仓库ID] &e[物品ID]'
|
||||
- '&8-&7 该指令受到玩家每日售出数量的限制。'
|
||||
item-sold:
|
||||
- '&f您出售了 &r%(item)&7x%(amount) &f,共赚取 &6%(money) &f元。'
|
||||
item-sold-limit:
|
||||
- '&f该物品今日剩余可出售额度为 &a%(amount)&8/%(limit) &f个。'
|
||||
item-pickup:
|
||||
- '&f您拾取了 &r%(item)&7x%(amount) &f,已自动放入到您的仓库中。'
|
||||
item-takeout:
|
||||
- '&f您从仓库中拿取了 &r%(item)&7x%(amount) &f放入到您的背包中。'
|
||||
item-collect:
|
||||
- '&f您收集了 &r%(item)&7x%(amount) &f,已自动放入到您的 &6%(depository) &f中。'
|
||||
item-collect-actionbar: '&r%(item)&7x%(amount) &f-> &6%(depository)'
|
||||
no-space:
|
||||
- '&f您背包内没有足够的空间取出物品!'
|
||||
no-economy:
|
||||
- '&f本服务器暂未启用出售功能。'
|
||||
no-depository:
|
||||
- '&f不存在该仓库,请检查仓库ID是否正确。'
|
||||
no-item:
|
||||
- '&f仓库中不存在该物品,请检查物品ID是否正确。'
|
||||
no-enough-item:
|
||||
- '&f仓库中不存在足够的物品。'
|
||||
wrong-number:
|
||||
- '&f数目输入错误,请输入正确的数字!'
|
||||
@@ -1,58 +0,0 @@
|
||||
help:
|
||||
|
||||
player:
|
||||
- "&6&l超级仓库 &f玩家指令帮助"
|
||||
- "&8#&f open &e[仓库ID]"
|
||||
- "&8-&7 打开对应仓库的界面。"
|
||||
- "&8#&f sell &6<仓库ID> &6<物品ID> &6<数量>"
|
||||
- "&8-&7 售出对应数量的对应物品。"
|
||||
- "&8-&7 该指令受到玩家每日售出数量的限制。"
|
||||
- "&8#&f sellAll &e[仓库ID] &e[物品ID]"
|
||||
- "&8-&7 该指令受到玩家每日售出数量的限制。"
|
||||
console:
|
||||
- "&6&l超级仓库 &f后台指令帮助"
|
||||
- "&8#&f info &6<玩家> &e[仓库ID] &e[物品ID]"
|
||||
- "&8-&7 得到玩家的相关物品信息。"
|
||||
- "&8#&f add &6<玩家> &6<仓库ID> &6<物品ID> &6<数量>"
|
||||
- "&8-&7 为玩家添加对应仓库中对于物品的数量。"
|
||||
- "&8#&f remove &6<玩家> &6<仓库ID> &6<物品ID> &e[数量]"
|
||||
- "&8-&7 为玩家减少对应仓库中对于物品的数量。"
|
||||
- "&8-&7 若不填写数量,则清空对应仓库的对应物品。"
|
||||
- "&8#&f sell &6<玩家> &e[仓库ID] &e[物品ID] &e[数量]"
|
||||
- "&8-&7 为玩家售出相关物品。"
|
||||
- "&8-&7 若不填写数量,则售出所有对应仓库的对应物品。"
|
||||
- "&8-&7 若不填写物品,则售出对应仓库内所有物品。"
|
||||
- "&8-&7 若不填写仓库,则售出所有仓库内所有物品。"
|
||||
- "&8-&7 该指令受到玩家每日售出数量的限制。"
|
||||
|
||||
item-collected:
|
||||
- "&f您收集了 &r%(item)&7x%(amount) &f,已自动放入到您的 &6%(depository) &f中。"
|
||||
|
||||
item-pickup:
|
||||
- "&f您取出了 &r%(item)&7x%(amount) &f,已自动放入到您的仓库中。"
|
||||
|
||||
item-sold:
|
||||
- "&f您出售了 &r%(item)&7x%(amount) &f,共赚取 &6%(money) &f元。"
|
||||
|
||||
item-sold-limit:
|
||||
- "&f该物品今日剩余可出售额度为 &a%(amount)&8/%(limit) &f个。"
|
||||
|
||||
|
||||
no-economy:
|
||||
- "&f本服务器暂未启用出售功能。"
|
||||
|
||||
no-space:
|
||||
- "&f您仓库内没有足够的空间取出物品!"
|
||||
|
||||
no-depository:
|
||||
- "&f不存在该仓库,请检查仓库ID是否正确。"
|
||||
|
||||
no-item:
|
||||
- "&f仓库中不存在该物品,请检查物品ID是否正确。"
|
||||
|
||||
no-enough-item:
|
||||
- "&f仓库中不存在足够的物品。"
|
||||
|
||||
|
||||
wrong-number:
|
||||
- "&f数目输入错误,请输入正确的数字!"
|
||||
@@ -1,13 +1,15 @@
|
||||
main: cc.carm.plugin.ultradepository.Main
|
||||
main: cc.carm.plugin.ultradepository.UltraDepository
|
||||
name: UltraDepository
|
||||
|
||||
version: ${project.version}
|
||||
description: ${project.description}
|
||||
website: ${project.url}
|
||||
|
||||
author: CarmJos
|
||||
authors:
|
||||
- CarmJos
|
||||
- Zimrs
|
||||
|
||||
api-version: 1.13
|
||||
api-version: 1.16
|
||||
|
||||
softdepend:
|
||||
- PlaceholderAPI
|
||||
@@ -28,6 +30,10 @@ permissions:
|
||||
description: "超级仓库的基本使用权限"
|
||||
default: true
|
||||
|
||||
"UltraDepository.silent":
|
||||
description: "超级仓库的安静模式权限,拥有该权限将不再接收到放入背包的提示。"
|
||||
default: false
|
||||
|
||||
"UltraDepository.auto":
|
||||
description: "超级仓库的自动收集权限"
|
||||
default: op
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
import cc.carm.plugin.ultradepository.configuration.gui.GUIActionType;
|
||||
import cc.carm.plugin.ultradepository.configuration.gui.GUIConfiguration;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ActionReadTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
List<String> actions = Arrays.asList(
|
||||
"[CHAT] 123123",
|
||||
"[SHIFT_LEFT:CHAT] /test qwq",
|
||||
"[CONSOLE] say hello",
|
||||
"[CLOSE]"
|
||||
);
|
||||
|
||||
for (String actionString : actions) {
|
||||
int prefixStart = actionString.indexOf("[");
|
||||
int prefixEnd = actionString.indexOf("]");
|
||||
if (prefixStart < 0 || prefixEnd < 0) continue;
|
||||
|
||||
String prefix = actionString.substring(prefixStart + 1, prefixEnd);
|
||||
ClickType clickType = null;
|
||||
GUIActionType actionType;
|
||||
if (prefix.contains(":")) {
|
||||
String[] args = prefix.split(":");
|
||||
clickType = GUIConfiguration.readClickType(args[0]);
|
||||
actionType = GUIActionType.readActionType(args[1]);
|
||||
} else {
|
||||
actionType = GUIActionType.readActionType(prefix);
|
||||
}
|
||||
|
||||
if (actionType == null) {
|
||||
System.out.println("# " + actionString);
|
||||
System.out.println("- actionType is Null");
|
||||
continue;
|
||||
}
|
||||
|
||||
System.out.println("# " + actionType.name() + " " + (clickType == null ? "" : clickType.name()));
|
||||
System.out.println("- " + actionString.substring(prefixEnd + 1).trim());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,23 @@
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.Test;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
public class GsonMapTest {
|
||||
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
@Test
|
||||
@org.junit.Test
|
||||
public void test() {
|
||||
System.out.println(this.getClass().getSimpleName());
|
||||
|
||||
|
||||
List<Test> tests = new ArrayList<>();
|
||||
tests.add(new Test1());
|
||||
tests.add(new Test2());
|
||||
tests.add(new Test3());
|
||||
tests.stream().map(test -> test.getClass().getSimpleName() + " : " + test.isOverride("load")).forEach(System.out::println);
|
||||
|
||||
Map<String, Map<String, Map<String, Integer>>> values = new LinkedHashMap<>();
|
||||
|
||||
@@ -32,9 +41,53 @@ public class GsonMapTest {
|
||||
|
||||
System.out.println(values.size());
|
||||
|
||||
|
||||
String jsonValues = GSON.toJson(values);
|
||||
System.out.println(jsonValues);
|
||||
|
||||
JsonObject dataObject = new JsonObject();
|
||||
dataObject.addProperty("date", 20201011);
|
||||
dataObject.add("depositories", GSON.toJsonTree(values));
|
||||
|
||||
System.out.println(GSON.toJson(dataObject));
|
||||
}
|
||||
|
||||
public interface Test {
|
||||
|
||||
void load();
|
||||
|
||||
default boolean isOverride(String methodName) {
|
||||
Map<Method, Method> methodMap = new HashMap<>();
|
||||
Arrays.stream(Test.class.getDeclaredMethods())
|
||||
.filter(method -> method.getName().equals(methodName))
|
||||
.forEach(method -> Arrays.stream(getClass().getDeclaredMethods())
|
||||
.filter(extend -> extend.getName().equals(methodName))
|
||||
.filter(extend -> extend.getReturnType().equals(method.getReturnType()))
|
||||
.filter(extend -> extend.getParameterTypes().length == method.getParameterTypes().length)
|
||||
.findFirst().ifPresent(extendMethod -> methodMap.put(method, extendMethod))
|
||||
);
|
||||
return !methodMap.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Test1 implements Test {
|
||||
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
System.out.println("test1");
|
||||
}
|
||||
}
|
||||
|
||||
public static class Test2 extends Test1 {
|
||||
|
||||
}
|
||||
|
||||
public static class Test3 extends Test2 {
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
public class MoneyTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
System.out.println(get(1.2, 100));
|
||||
System.out.println(get(0.55, 10));
|
||||
System.out.println(get(0.21, 5));
|
||||
}
|
||||
|
||||
|
||||
public double get(double price, int amount) {
|
||||
BigDecimal money = BigDecimal.valueOf(price * amount).setScale(2, RoundingMode.DOWN);
|
||||
return money.doubleValue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user