mirror of
https://github.com/CarmJos/UltraDepository.git
synced 2026-06-05 00:58:22 +08:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 123ae0b039 | |||
| dd5793427a | |||
| 6bf8e261d0 | |||
| fcdda893f1 | |||
| 27ad14c7ab | |||
| b6a6502713 | |||
| d8d589ba76 | |||
| 52a0d28249 | |||
| 2f0a3d283b | |||
| 725ea4b4ee | |||
| e256278453 | |||
| 66dafb39b5 | |||
| 4640a8098d | |||
| 62c8350b8b | |||
| d0361c260d | |||
| fe256dc916 |
@@ -11,6 +11,72 @@
|
|||||||
|
|
||||||
# UltraDepository 帮助介绍文档
|
# 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)
|
## [开发文档](JAVADOC-README.md)
|
||||||
|
|
||||||
基于 [Github Pages](https://pages.github.com/) 搭建,请访问 [JavaDoc](https://carmjos.github.io/UltraDepository) 。
|
基于 [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** 从而完成自定义存储源。
|
||||||
@@ -1,30 +1,30 @@
|
|||||||
---
|
---
|
||||||
name: 问题提交
|
name: 问题提交
|
||||||
about: 提交并描述问题,帮助我们对其进行检查与修复。
|
about: 描述问题并提交,帮助我们对其进行检查与修复。
|
||||||
title: ''
|
title: ''
|
||||||
labels: bug
|
labels: bug
|
||||||
assignees: ''
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**问题简述**
|
### **问题简述**
|
||||||
用简短的话语描述一下大概问题。
|
用简短的话语描述一下大概问题。
|
||||||
|
|
||||||
**问题来源**
|
### **问题来源**
|
||||||
描述一下通过哪些操作才发现的问题,如:
|
描述一下通过哪些操作才发现的问题,如:
|
||||||
1. 打开 '...'
|
1. 打开 '...'
|
||||||
2. 点击了 '....'
|
2. 点击了 '....'
|
||||||
3. 出现了报错 '....'
|
3. 出现了报错 '....'
|
||||||
|
|
||||||
**预期结果**(可选)
|
### **预期结果**(可选)
|
||||||
如果问题不发生,应该是什么情况
|
如果问题不发生,应该是什么情况
|
||||||
|
|
||||||
**问题截图/问题报错**
|
### **问题截图/问题报错**
|
||||||
如果有报错或输出,请提供截图。
|
如果有报错或输出,请提供截图。
|
||||||
|
|
||||||
**操作环境**
|
### *操作环境**
|
||||||
请在后台输入 `version` 并复制相关输出。
|
请在后台输入 `version` 并复制相关输出。
|
||||||
|
|
||||||
|
|
||||||
**其他补充**
|
### **其他补充**
|
||||||
如有其他补充,可以在这里描述。
|
如有其他补充,可以在这里描述。
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ assignees: ''
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**功能简述**
|
### **功能简述**
|
||||||
简单的描述一下你想要的功能
|
简单的描述一下你想要的功能
|
||||||
|
|
||||||
**需求来源**
|
### **需求来源**
|
||||||
简单的描述一下为什么需要这个功能。
|
简单的描述一下为什么需要这个功能。
|
||||||
|
|
||||||
**功能参考**(可选)
|
### **功能参考**(可选)
|
||||||
如果有相关功能的参考,如文本、截图,请提供给我们。
|
如果有相关功能的参考,如文本、截图,请提供给我们。
|
||||||
|
|
||||||
**附加内容**
|
### **附加内容**
|
||||||
如果有什么小细节需要重点注意,请在这里告诉我们。
|
如果有什么小细节需要重点注意,请在这里告诉我们。
|
||||||
|
|||||||
@@ -60,7 +60,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) 实现。
|
- **[自带]** 数据部分基于 [EasySQL](https://github.com/CarmJos/EasySQL) 实现。
|
||||||
- 本插件连接池使用 [BeeCP](https://github.com/Chris2018998/BeeCP) ,更轻量、快速。
|
- 本插件连接池使用 [BeeCP](https://github.com/Chris2018998/BeeCP) ,更轻量、快速。
|
||||||
- **[推荐]** 变量部分基于 [PlaceholderAPI](https://www.spigotmc.org/resources/6245/) 实现。
|
- **[推荐]** 变量部分基于 [PlaceholderAPI](https://www.spigotmc.org/resources/6245/) 实现。
|
||||||
@@ -175,6 +176,9 @@
|
|||||||
# UltraDepository.use
|
# UltraDepository.use
|
||||||
- 超级仓库的基本使用权限 (默认所有人都有)
|
- 超级仓库的基本使用权限 (默认所有人都有)
|
||||||
|
|
||||||
|
# UltraDepository.silent
|
||||||
|
- 拥有该权限将不再接收到放入背包的提示。
|
||||||
|
|
||||||
# UltraDepository.Command.Sell
|
# UltraDepository.Command.Sell
|
||||||
- 玩家使用Sell指令的权限
|
- 玩家使用Sell指令的权限
|
||||||
|
|
||||||
@@ -213,10 +217,14 @@
|
|||||||
|
|
||||||
文件名即仓库的ID,**强烈推荐使用纯英文**,部分符号可能会影响正常读取,请避免使用。
|
文件名即仓库的ID,**强烈推荐使用纯英文**,部分符号可能会影响正常读取,请避免使用。
|
||||||
|
|
||||||
随本项目预设了几个常用的仓库类型,可以 [在这里](.examples/depositories) 找到您需要的直接使用或加以修改后使用。
|
随本项目预设了几个常用的仓库类型,可以 [在这里](.examples/depositories) 找到您需要的仓库配置加以修改后使用。
|
||||||
|
|
||||||
您也可以 [点击这里](.examples/depositories/full-example.yml) 查看一份*详细的仓库配置示例*,以制作您自己的仓库。
|
您也可以 [点击这里](.examples/depositories/full-example.yml) 查看一份*详细的仓库配置示例*,以制作您自己的仓库。
|
||||||
|
|
||||||
|
## 开发
|
||||||
|
|
||||||
|
详细开发介绍请 [点击这里](.documentation/README.md) , JavaDoc(最新Release) 请 [点击这里](https://carmjos.github.io/UltraDepository) 。
|
||||||
|
|
||||||
## 使用统计
|
## 使用统计
|
||||||
|
|
||||||
[](https://bstats.org/plugin/bukkit/UltraDepository/13777)
|
[](https://bstats.org/plugin/bukkit/UltraDepository/13777)
|
||||||
|
|||||||
@@ -9,13 +9,13 @@
|
|||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
<easyplugin.version>1.1.0</easyplugin.version>
|
<easyplugin.version>1.1.2</easyplugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<groupId>cc.carm.plugin</groupId>
|
<groupId>cc.carm.plugin</groupId>
|
||||||
<artifactId>ultradepository</artifactId>
|
<artifactId>ultradepository</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>1.1.6</version>
|
<version>1.2.0</version>
|
||||||
|
|
||||||
<name>UltraDepository</name>
|
<name>UltraDepository</name>
|
||||||
<description>超级仓库插件,支持设定不同物品的存储仓库。</description>
|
<description>超级仓库插件,支持设定不同物品的存储仓库。</description>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cc.carm.plugin.ultradepository;
|
|||||||
|
|
||||||
import cc.carm.lib.easyplugin.EasyPlugin;
|
import cc.carm.lib.easyplugin.EasyPlugin;
|
||||||
import cc.carm.lib.easyplugin.gui.GUI;
|
import cc.carm.lib.easyplugin.gui.GUI;
|
||||||
|
import cc.carm.lib.easyplugin.i18n.EasyPluginMessageProvider;
|
||||||
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||||
import cc.carm.plugin.ultradepository.command.DepositoryCommand;
|
import cc.carm.plugin.ultradepository.command.DepositoryCommand;
|
||||||
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
|
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
|
||||||
@@ -30,9 +31,12 @@ public class UltraDepository extends EasyPlugin {
|
|||||||
private static EconomyManager economyManager;
|
private static EconomyManager economyManager;
|
||||||
private static DepositoryManager depositoryManager;
|
private static DepositoryManager depositoryManager;
|
||||||
|
|
||||||
|
public UltraDepository() {
|
||||||
|
super(new EasyPluginMessageProvider.zh_CN());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load() {
|
protected void load() {
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
log("加载配置文件...");
|
log("加载配置文件...");
|
||||||
@@ -42,7 +46,7 @@ public class UltraDepository extends EasyPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean initialize() {
|
protected boolean initialize() {
|
||||||
|
|
||||||
log("初始化存储方式...");
|
log("初始化存储方式...");
|
||||||
StorageMethod storageMethod = PluginConfig.STORAGE_METHOD.get();
|
StorageMethod storageMethod = PluginConfig.STORAGE_METHOD.get();
|
||||||
@@ -97,7 +101,7 @@ public class UltraDepository extends EasyPlugin {
|
|||||||
"active_depositories",
|
"active_depositories",
|
||||||
() -> getDepositoryManager().getDepositories().size())
|
() -> getDepositoryManager().getDepositories().size())
|
||||||
);
|
);
|
||||||
metrics.addCustomChart(new SimplePie("storage_method", () -> getStorage().getClass().getSimpleName()));
|
metrics.addCustomChart(new SimplePie("storage_method", storageMethod::name));
|
||||||
metrics.addCustomChart(new SimplePie("economy_enabled", () -> economyManager.isInitialized() ? "YES" : "NO"));
|
metrics.addCustomChart(new SimplePie("economy_enabled", () -> economyManager.isInitialized() ? "YES" : "NO"));
|
||||||
metrics.addCustomChart(new SimplePie("papi_version", () -> {
|
metrics.addCustomChart(new SimplePie("papi_version", () -> {
|
||||||
Plugin plugin = Bukkit.getPluginManager().getPlugin("PlaceholderAPI");
|
Plugin plugin = Bukkit.getPluginManager().getPlugin("PlaceholderAPI");
|
||||||
@@ -109,7 +113,7 @@ public class UltraDepository extends EasyPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shutdown() {
|
protected void shutdown() {
|
||||||
if (!isInitialized()) return;
|
if (!isInitialized()) return;
|
||||||
|
|
||||||
log("保存现有用户数据...");
|
log("保存现有用户数据...");
|
||||||
@@ -143,16 +147,25 @@ public class UltraDepository extends EasyPlugin {
|
|||||||
return depositoryManager;
|
return depositoryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDebugging() {
|
||||||
|
return PluginConfig.DEBUG.get();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void outputInfo() {
|
public void outputInfo() {
|
||||||
log("&6 _ _ _ _ &e _____ _ _ ");
|
log(" ",
|
||||||
log("&6| | | | | | &e| __ \\ (_) | ");
|
"&6 _ _ _ _ &e _____ _ _ ",
|
||||||
log("&6| | | | | |_ _ __ __ _ &e| | | | ___ _ __ ___ ___ _| |_ ___ _ __ _ _ ");
|
"&6| | | | | | &e| __ \\ (_) | ",
|
||||||
log("&6| | | | | __| '__/ _` |&e| | | |/ _ \\ '_ \\ / _ \\/ __| | __/ _ \\| '__| | | |");
|
"&6| | | | | |_ _ __ __ _ &e| | | | ___ _ __ ___ ___ _| |_ ___ _ __ _ _ ",
|
||||||
log("&6| |__| | | |_| | | (_| |&e| |__| | __/ |_) | (_) \\__ \\ | || (_) | | | |_| |");
|
"&6| | | | | __| '__/ _` |&e| | | |/ _ \\ '_ \\ / _ \\/ __| | __/ _ \\| '__| | | |",
|
||||||
log("&6 \\____/|_|\\__|_| \\__,_|&e|_____/ \\___| .__/ \\___/|___/_|\\__\\___/|_| \\__, |");
|
"&6| |__| | | |_| | | (_| |&e| |__| | __/ |_) | (_) \\__ \\ | || (_) | | | |_| |",
|
||||||
log("&6 &e| | __/ |");
|
"&6 \\____/|_|\\__|_| \\__,_|&e|_____/ \\___| .__/ \\___/|___/_|\\__\\___/|_| \\__, |",
|
||||||
log("&6 &e|_| |___/ ");
|
"&6 &e| | __/ |",
|
||||||
log(" &fView more information at&6 https://github.com/CarmJos/UltraDepository");
|
"&6 &e|_| |___/ ",
|
||||||
|
"&f请访问项目主页查看详细插件介绍 &8/ &fView GitHub to get more information",
|
||||||
|
"&8-> &6https://github.com/CarmJos/UltraDepository",
|
||||||
|
" "
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
package cc.carm.plugin.ultradepository.configuration;
|
package cc.carm.plugin.ultradepository.configuration;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.configuration.cast.ConfigStringCast;
|
||||||
import cc.carm.lib.easyplugin.configuration.impl.ConfigSound;
|
import cc.carm.lib.easyplugin.configuration.impl.ConfigSound;
|
||||||
import cc.carm.lib.easyplugin.configuration.impl.ConfigStringCast;
|
|
||||||
import cc.carm.lib.easyplugin.configuration.message.ConfigMessage;
|
import cc.carm.lib.easyplugin.configuration.message.ConfigMessage;
|
||||||
import cc.carm.lib.easyplugin.configuration.message.ConfigMessageList;
|
import cc.carm.lib.easyplugin.configuration.message.ConfigMessageList;
|
||||||
import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
|
import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
|
||||||
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
||||||
import cc.carm.plugin.ultradepository.storage.StorageMethod;
|
import cc.carm.plugin.ultradepository.storage.StorageMethod;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
|
||||||
public class PluginConfig {
|
public class PluginConfig {
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ public class PluginConfig {
|
|||||||
|
|
||||||
public static class Sounds {
|
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 SELL_SUCCESS = new ConfigSound("sounds.sell-success");
|
public static final ConfigSound SELL_SUCCESS = new ConfigSound("sounds.sell-success");
|
||||||
public static final ConfigSound SELL_FAIL = new ConfigSound("sounds.sell-fail");
|
public static final ConfigSound SELL_FAIL = new ConfigSound("sounds.sell-fail");
|
||||||
public static final ConfigSound GUI_CLICK = new ConfigSound("sounds.gui-click");
|
public static final ConfigSound GUI_CLICK = new ConfigSound("sounds.gui-click");
|
||||||
|
|||||||
+15
-4
@@ -42,10 +42,21 @@ public class DepositoryCapacity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getPlayerCapacity(Player player) {
|
public int getPlayerCapacity(Player player) {
|
||||||
return getPermissions().entrySet().stream()
|
if (defaultCapacity == -1) return -1;
|
||||||
.filter(entry -> player.hasPermission(entry.getKey()))
|
|
||||||
.mapToInt(Map.Entry::getValue)
|
int capacity = defaultCapacity;
|
||||||
.max().orElse(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
|||||||
"%UltraDepository_amount_<BackpackID>_<ItemTypeID>%",
|
"%UltraDepository_amount_<BackpackID>_<ItemTypeID>%",
|
||||||
"%UltraDepository_sold_<BackpackID>_<ItemTypeID>%",
|
"%UltraDepository_sold_<BackpackID>_<ItemTypeID>%",
|
||||||
"%UltraDepository_price_<BackpackID>_<ItemTypeID>%",
|
"%UltraDepository_price_<BackpackID>_<ItemTypeID>%",
|
||||||
"%UltraDepository_reUltraDepository_<BackpackID>_<ItemTypeID>%",
|
"%UltraDepository_remain_<BackpackID>_<ItemTypeID>%",
|
||||||
"%UltraDepository_capacity_<BackpackID>%",
|
"%UltraDepository_capacity_<BackpackID>%",
|
||||||
"%UltraDepository_used_<BackpackID>%",
|
"%UltraDepository_used_<BackpackID>%",
|
||||||
"%UltraDepository_usable_<BackpackID>%"
|
"%UltraDepository_usable_<BackpackID>%"
|
||||||
@@ -80,7 +80,7 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
|||||||
if (sold == null) return "Depository or Item not exists";
|
if (sold == null) return "Depository or Item not exists";
|
||||||
else return sold.toString();
|
else return sold.toString();
|
||||||
}
|
}
|
||||||
case "reUltraDepository": {
|
case "remain": {
|
||||||
if (args.length < 2) return "Error Params";
|
if (args.length < 2) return "Error Params";
|
||||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
|
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
|
||||||
if (depository == null) return "Depository not exists";
|
if (depository == null) return "Depository not exists";
|
||||||
@@ -106,7 +106,8 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
|||||||
if (args.length < 2) return "Error Params";
|
if (args.length < 2) return "Error Params";
|
||||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
|
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
|
||||||
if (depository == null) return "Depository not exists";
|
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": {
|
case "used": {
|
||||||
if (args.length < 2) return "Error Params";
|
if (args.length < 2) return "Error Params";
|
||||||
@@ -118,8 +119,9 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
|||||||
if (args.length < 2) return "Error Params";
|
if (args.length < 2) return "Error Params";
|
||||||
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
|
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
|
||||||
if (depository == null) return "Depository not exists";
|
if (depository == null) return "Depository not exists";
|
||||||
|
int max = depository.getCapacity().getPlayerCapacity(player);
|
||||||
int used = data.getDepositoryData(depository).getUsedCapacity();
|
int used = data.getDepositoryData(depository).getUsedCapacity();
|
||||||
return Integer.toString(depository.getCapacity().getPlayerCapacity(player) - used);
|
return max < 0 ? "∞" : Integer.toString(max - used);
|
||||||
}
|
}
|
||||||
case "version": {
|
case "version": {
|
||||||
return getVersion();
|
return getVersion();
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ public class DepositoryManager {
|
|||||||
return getItemDepositories(itemStack).stream().filter(configuration -> {
|
return getItemDepositories(itemStack).stream().filter(configuration -> {
|
||||||
int used = UltraDepository.getUserManager().getData(player).getDepositoryData(configuration).getUsedCapacity();
|
int used = UltraDepository.getUserManager().getData(player).getDepositoryData(configuration).getUsedCapacity();
|
||||||
int max = configuration.getCapacity().getPlayerCapacity(player);
|
int max = configuration.getCapacity().getPlayerCapacity(player);
|
||||||
return used + itemStack.getAmount() <= max;
|
return max < 0 || used + itemStack.getAmount() <= max;
|
||||||
}).collect(Collectors.toSet());
|
}).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,11 +165,13 @@ public class DepositoryManager {
|
|||||||
int finalAmount = collectItemEvent.getItemAmount();
|
int finalAmount = collectItemEvent.getItemAmount();
|
||||||
|
|
||||||
collectItemEvent.getUserData().addItemAmount(depository.getIdentifier(), typeID, finalAmount);
|
collectItemEvent.getUserData().addItemAmount(depository.getIdentifier(), typeID, finalAmount);
|
||||||
|
if (!player.hasPermission("UltraDepository.silent")) {
|
||||||
PluginMessages.COLLECTED.send(player, new Object[]{
|
PluginMessages.COLLECTED.send(player, new Object[]{
|
||||||
depository.getItems().get(typeID).getName(),
|
depository.getItems().get(typeID).getName(),
|
||||||
finalAmount, depository.getName()
|
finalAmount, depository.getName()
|
||||||
});
|
});
|
||||||
PluginConfig.Sounds.COLLECT.play(player);
|
PluginConfig.Sounds.COLLECT.play(player);
|
||||||
|
}
|
||||||
UltraDepository.getInstance().debug("Item collected successfully.");
|
UltraDepository.getInstance().debug("Item collected successfully.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ import cc.carm.plugin.ultradepository.hooker.VaultHooker;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
|
||||||
public class EconomyManager {
|
public class EconomyManager {
|
||||||
|
|
||||||
VaultHooker hooker;
|
VaultHooker hooker;
|
||||||
@@ -35,9 +38,9 @@ public class EconomyManager {
|
|||||||
|
|
||||||
public double sell(Player player, double price, int amount) {
|
public double sell(Player player, double price, int amount) {
|
||||||
if (!isInitialized()) return 0D;
|
if (!isInitialized()) return 0D;
|
||||||
double money = price * amount;
|
BigDecimal money = BigDecimal.valueOf(price * amount).setScale(2, RoundingMode.DOWN);
|
||||||
getHooker().addMoney(player, money);
|
getHooker().addMoney(player, money.doubleValue());
|
||||||
return money;
|
return money.doubleValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sellAllItem(Player player, UserData userData) {
|
public void sellAllItem(Player player, UserData userData) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package cc.carm.plugin.ultradepository.storage.impl;
|
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.data.UserData;
|
||||||
import cc.carm.plugin.ultradepository.storage.DataStorage;
|
import cc.carm.plugin.ultradepository.storage.DataStorage;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -13,6 +14,10 @@ public class CustomStorage implements DataStorage {
|
|||||||
@Override
|
@Override
|
||||||
@TestOnly
|
@TestOnly
|
||||||
public boolean initialize() {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import cc.carm.lib.easyplugin.database.api.SQLManager;
|
|||||||
import cc.carm.lib.easyplugin.database.api.action.query.PreparedQueryAction;
|
import cc.carm.lib.easyplugin.database.api.action.query.PreparedQueryAction;
|
||||||
import cc.carm.lib.easyplugin.database.api.action.query.SQLQuery;
|
import cc.carm.lib.easyplugin.database.api.action.query.SQLQuery;
|
||||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||||
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
|
|
||||||
import cc.carm.plugin.ultradepository.configuration.depository.Depository;
|
import cc.carm.plugin.ultradepository.configuration.depository.Depository;
|
||||||
import cc.carm.plugin.ultradepository.data.DepositoryData;
|
import cc.carm.plugin.ultradepository.data.DepositoryData;
|
||||||
import cc.carm.plugin.ultradepository.data.UserData;
|
import cc.carm.plugin.ultradepository.data.UserData;
|
||||||
@@ -62,7 +61,7 @@ public class MySQLStorage extends JSONStorage {
|
|||||||
try {
|
try {
|
||||||
UltraDepository.getInstance().log(" 尝试连接到数据库...");
|
UltraDepository.getInstance().log(" 尝试连接到数据库...");
|
||||||
this.sqlManager = EasySQL.createManager(DRIVER_NAME.get(), URL.get(), USERNAME.get(), PASSWORD.get());
|
this.sqlManager = EasySQL.createManager(DRIVER_NAME.get(), URL.get(), USERNAME.get(), PASSWORD.get());
|
||||||
this.sqlManager.setDebugMode(PluginConfig.DEBUG.get());
|
this.sqlManager.setDebugMode(UltraDepository.getInstance().isDebugging());
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
UltraDepository.getInstance().error("无法连接到数据库,请检查配置文件。");
|
UltraDepository.getInstance().error("无法连接到数据库,请检查配置文件。");
|
||||||
UltraDepository.getInstance().error("Could not connect to the database, please check the configuration.");
|
UltraDepository.getInstance().error("Could not connect to the database, please check the configuration.");
|
||||||
|
|||||||
@@ -42,12 +42,12 @@ public class DepositoryGUI extends GUI {
|
|||||||
|
|
||||||
private GUIItem createGUIItem(DepositoryItem item) {
|
private GUIItem createGUIItem(DepositoryItem item) {
|
||||||
DepositoryItemData itemData = userData.getItemData(item);
|
DepositoryItemData itemData = userData.getItemData(item);
|
||||||
int remain = item.getLimit() - itemData.getSold();
|
int canSell = item.getLimit() - itemData.getSold();
|
||||||
|
|
||||||
ItemStackFactory factory = new ItemStackFactory(item.getDisplayItem());
|
ItemStackFactory factory = new ItemStackFactory(item.getDisplayItem());
|
||||||
List<String> additionalLore = PluginConfig.General.ADDITIONAL_LORE.get(player, new Object[]{
|
List<String> additionalLore = PluginConfig.General.ADDITIONAL_LORE.get(player, new Object[]{
|
||||||
item.getName(), itemData.getAmount(), item.getPrice(),
|
item.getName(), itemData.getAmount(), item.getPrice(),
|
||||||
itemData.getSold(), remain, item.getLimit()
|
itemData.getSold(), canSell, item.getLimit()
|
||||||
});
|
});
|
||||||
|
|
||||||
additionalLore.forEach(factory::addLore);
|
additionalLore.forEach(factory::addLore);
|
||||||
@@ -65,10 +65,12 @@ public class DepositoryGUI extends GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type == ClickType.LEFT) {
|
if (type == ClickType.LEFT) {
|
||||||
if (remain >= 1) {
|
if (canSell >= 1) {
|
||||||
SellItemGUI.open(player, userData, itemData, depository, item);
|
SellItemGUI.open(player, userData, itemData, depository, item);
|
||||||
} else {
|
} else {
|
||||||
PluginMessages.ITEM_SOLD_LIMIT.send(player, new Object[]{remain, item.getLimit()});
|
PluginConfig.Sounds.SELL_FAIL.play(player);
|
||||||
|
PluginMessages.ITEM_SOLD_LIMIT.send(player, new Object[]{canSell, item.getLimit()});
|
||||||
|
player.closeInventory();
|
||||||
}
|
}
|
||||||
} else if (type == ClickType.RIGHT) {
|
} else if (type == ClickType.RIGHT) {
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import cc.carm.plugin.ultradepository.configuration.depository.Depository;
|
|||||||
import cc.carm.plugin.ultradepository.configuration.depository.DepositoryItem;
|
import cc.carm.plugin.ultradepository.configuration.depository.DepositoryItem;
|
||||||
import cc.carm.plugin.ultradepository.data.DepositoryItemData;
|
import cc.carm.plugin.ultradepository.data.DepositoryItemData;
|
||||||
import cc.carm.plugin.ultradepository.data.UserData;
|
import cc.carm.plugin.ultradepository.data.UserData;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@@ -73,7 +74,7 @@ public class SellItemGUI extends GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private GUIItem getAddItem(int amount) {
|
private GUIItem getAddItem(int amount) {
|
||||||
ItemStackFactory factory = new ItemStackFactory(Add.TYPE.get());
|
ItemStackFactory factory = new ItemStackFactory(Add.TYPE.getOptional().orElse(Material.STONE));
|
||||||
factory.setDurability(Add.DATA.get());
|
factory.setDurability(Add.DATA.get());
|
||||||
factory.setDisplayName(Add.NAME.get(player, new Object[]{
|
factory.setDisplayName(Add.NAME.get(player, new Object[]{
|
||||||
getItemName(), amount
|
getItemName(), amount
|
||||||
@@ -93,7 +94,7 @@ public class SellItemGUI extends GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private GUIItem getRemoveItem(int amount) {
|
private GUIItem getRemoveItem(int amount) {
|
||||||
ItemStackFactory factory = new ItemStackFactory(Remove.TYPE.get());
|
ItemStackFactory factory = new ItemStackFactory(Remove.TYPE.getOptional().orElse(Material.STONE));
|
||||||
factory.setDurability(Remove.DATA.get());
|
factory.setDurability(Remove.DATA.get());
|
||||||
factory.setDisplayName(Remove.NAME.get(player, new Object[]{
|
factory.setDisplayName(Remove.NAME.get(player, new Object[]{
|
||||||
getItemName(), amount
|
getItemName(), amount
|
||||||
@@ -112,7 +113,7 @@ public class SellItemGUI extends GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private GUIItem getConfirmItem() {
|
private GUIItem getConfirmItem() {
|
||||||
ItemStackFactory factory = new ItemStackFactory(Confirm.TYPE.get());
|
ItemStackFactory factory = new ItemStackFactory(Confirm.TYPE.getOptional().orElse(Material.STONE));
|
||||||
factory.setDurability(Confirm.DATA.get());
|
factory.setDurability(Confirm.DATA.get());
|
||||||
factory.setDisplayName(Confirm.NAME.get(player, new Object[]{
|
factory.setDisplayName(Confirm.NAME.get(player, new Object[]{
|
||||||
getItemName(), getCurrentAmount(), getTotalMoney()
|
getItemName(), getCurrentAmount(), getTotalMoney()
|
||||||
@@ -131,7 +132,7 @@ public class SellItemGUI extends GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private GUIItem getCancelItem() {
|
private GUIItem getCancelItem() {
|
||||||
ItemStackFactory factory = new ItemStackFactory(Cancel.TYPE.get());
|
ItemStackFactory factory = new ItemStackFactory(Cancel.TYPE.getOptional().orElse(Material.STONE));
|
||||||
factory.setDurability(Cancel.DATA.get());
|
factory.setDurability(Cancel.DATA.get());
|
||||||
factory.setDisplayName(Cancel.NAME.get());
|
factory.setDisplayName(Cancel.NAME.get());
|
||||||
factory.setLore(Cancel.LORE.get());
|
factory.setLore(Cancel.LORE.get());
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ permissions:
|
|||||||
description: "超级仓库的基本使用权限"
|
description: "超级仓库的基本使用权限"
|
||||||
default: true
|
default: true
|
||||||
|
|
||||||
|
"UltraDepository.silent":
|
||||||
|
description: "超级仓库的安静模式权限,拥有该权限将不再接收到放入背包的提示。"
|
||||||
|
default: false
|
||||||
|
|
||||||
"UltraDepository.auto":
|
"UltraDepository.auto":
|
||||||
description: "超级仓库的自动收集权限"
|
description: "超级仓库的自动收集权限"
|
||||||
default: op
|
default: op
|
||||||
|
|||||||
@@ -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