mirror of
https://github.com/CarmJos/UltraDepository.git
synced 2026-06-04 16:48:21 +08:00
完善部分基础内容
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
# EasySQL Javadoc
|
# UltraBackpack Javadoc
|
||||||
|
|
||||||
基于 [Github Pages](https://pages.github.com/) 搭建,请访问 [JavaDoc](https://carmjos.github.io/UltraBackpack) 。
|
基于 [Github Pages](https://pages.github.com/) 搭建,请访问 [JavaDoc](https://carmjos.github.io/UltraBackpack) 。
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
```text
|
||||||
|
_ _ _ _ ____ _ _
|
||||||
|
| | | | | | | _ \ | | | |
|
||||||
|
| | | | | |_ _ __ __ _| |_) | __ _ ___| | ___ __ __ _ ___| | __
|
||||||
|
| | | | | __| '__/ _` | _ < / _` |/ __| |/ / '_ \ / _` |/ __| |/ /
|
||||||
|
| |__| | | |_| | | (_| | |_) | (_| | (__| <| |_) | (_| | (__| <
|
||||||
|
\____/|_|\__|_| \__,_|____/ \__,_|\___|_|\_\ .__/ \__,_|\___|_|\_\
|
||||||
|
| |
|
||||||
|
|_|
|
||||||
|
```
|
||||||
|
# UltraBackpack 帮助介绍文档
|
||||||
|
|
||||||
|
## [开发文档](JAVADOC-README.md)
|
||||||
|
|
||||||
|
基于 [Github Pages](https://pages.github.com/) 搭建,请访问 [JavaDoc](https://carmjos.github.io/UltraBackpack) 。
|
||||||
|
|
||||||
|
## 文档目录
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
title: "&e&l农业仓库"
|
||||||
|
|
||||||
|
capacity:
|
||||||
|
default: 1000
|
||||||
|
permissions:
|
||||||
|
5000: "ub.farmer.vip"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
items:
|
||||||
|
"POTATO":
|
||||||
|
slot: 5
|
||||||
|
limit: 500
|
||||||
|
price: 10
|
||||||
|
name: "土豆"
|
||||||
|
lore:
|
||||||
|
- "香甜的土豆。"
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
name: "&c&l矿业仓库"
|
||||||
|
|
||||||
|
capacity:
|
||||||
|
default: 1000
|
||||||
|
permissions:
|
||||||
|
5000: "ub.miner.vip"
|
||||||
|
|
||||||
|
gui:
|
||||||
|
title: "&c&l矿业仓库"
|
||||||
|
lines: 6
|
||||||
|
items:
|
||||||
|
"CLOSE":
|
||||||
|
slot: 0
|
||||||
|
type: BARRIER
|
||||||
|
data: 0
|
||||||
|
name: "关闭界面"
|
||||||
|
lore:
|
||||||
|
- "点击关闭界面"
|
||||||
|
actions:
|
||||||
|
- "[CLOSE]"
|
||||||
|
|
||||||
|
items:
|
||||||
|
"DIAMOND":
|
||||||
|
slot: 5
|
||||||
|
limit: 500
|
||||||
|
price: 10
|
||||||
|
name: "&b&l钻石"
|
||||||
@@ -36,8 +36,50 @@
|
|||||||
|
|
||||||
## 特殊优势
|
## 特殊优势
|
||||||
|
|
||||||
|
## 插件指令
|
||||||
|
|
||||||
|
## 插件变量 ([PlaceholderAPI](https://www.spigotmc.org/resources/6245/))
|
||||||
|
|
||||||
|
变量部分基于 [PlaceholderAPI](https://www.spigotmc.org/resources/6245/) 实现,如需使用变量请安装其插件。
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>展开查看所有变量</summary>
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
## 插件权限
|
||||||
|
|
||||||
|
|
||||||
## 配置文件
|
## 配置文件
|
||||||
|
|
||||||
|
### [插件配置文件](ultrabackpack-plugin/src/main/resources/config.yml) (config.yml)
|
||||||
|
|
||||||
|
详见源文件。
|
||||||
|
|
||||||
|
### [消息配置文件](ultrabackpack-plugin/src/main/resources/messages.yml) (messages.yml)
|
||||||
|
|
||||||
|
详见源文件。
|
||||||
|
|
||||||
|
### 背包类型配置文件 (backpacks/<ID>.yml)
|
||||||
|
|
||||||
|
所有 背包类均为单独的配置文件,存放于 `插件配置目录/backpacks` 下,便于管理。
|
||||||
|
|
||||||
|
文件名即背包的ID,理论上可以随便取,但强烈推荐使用纯英文,部分符号可能会影响正常读取,请避免使用。
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>展开查看示例背包配置</summary>
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
|
||||||
## 支持与捐赠
|
## 支持与捐赠
|
||||||
|
|
||||||
若您觉得本插件做的不错,您可以捐赠支持我!
|
若您觉得本插件做的不错,您可以捐赠支持我!
|
||||||
@@ -47,7 +89,10 @@
|
|||||||
## 开源协议
|
## 开源协议
|
||||||
|
|
||||||
本项目源码采用 [GNU General Public License v3.0](https://opensource.org/licenses/GPL-3.0) 开源协议。
|
本项目源码采用 [GNU General Public License v3.0](https://opensource.org/licenses/GPL-3.0) 开源协议。
|
||||||
> ### 关于 GPL 协议
|
|
||||||
|
<details>
|
||||||
|
<summary>关于 GPL 协议</summary>
|
||||||
|
|
||||||
> GNU General Public Licence (GPL) 有可能是开源界最常用的许可模式。GPL 保证了所有开发者的权利,同时为使用者提供了足够的复制,分发,修改的权利:
|
> GNU General Public Licence (GPL) 有可能是开源界最常用的许可模式。GPL 保证了所有开发者的权利,同时为使用者提供了足够的复制,分发,修改的权利:
|
||||||
>
|
>
|
||||||
> #### 可自由复制
|
> #### 可自由复制
|
||||||
@@ -62,4 +107,4 @@
|
|||||||
> 需要注意的是,分发的时候,需要明确提供源代码和二进制文件,另外,用于某些程序的某些协议有一些问题和限制,你可以看一下 @PierreJoye 写的 Practical Guide to GPL Compliance 一文。使用 GPL 协议,你必须在源代码代码中包含相应信息,以及协议本身。
|
> 需要注意的是,分发的时候,需要明确提供源代码和二进制文件,另外,用于某些程序的某些协议有一些问题和限制,你可以看一下 @PierreJoye 写的 Practical Guide to GPL Compliance 一文。使用 GPL 协议,你必须在源代码代码中包含相应信息,以及协议本身。
|
||||||
>
|
>
|
||||||
> *以上文字来自 [五种开源协议GPL,LGPL,BSD,MIT,Apache](https://www.oschina.net/question/54100_9455) 。*
|
> *以上文字来自 [五种开源协议GPL,LGPL,BSD,MIT,Apache](https://www.oschina.net/question/54100_9455) 。*
|
||||||
|
</details>
|
||||||
|
|||||||
@@ -4,6 +4,13 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<groupId>cc.carm.plugin</groupId>
|
<groupId>cc.carm.plugin</groupId>
|
||||||
<artifactId>ultrabackpack-parent</artifactId>
|
<artifactId>ultrabackpack-parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
@@ -46,13 +53,6 @@
|
|||||||
<url>https://github.com/CarmJos/UltraBackpack/actions/workflows/maven.yml</url>
|
<url>https://github.com/CarmJos/UltraBackpack/actions/workflows/maven.yml</url>
|
||||||
</ciManagement>
|
</ciManagement>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<downloadUrl>https://github.com/CarmJos/UltraBackpack/releases</downloadUrl>
|
<downloadUrl>https://github.com/CarmJos/UltraBackpack/releases</downloadUrl>
|
||||||
<repository>
|
<repository>
|
||||||
@@ -130,6 +130,10 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.1</version>
|
||||||
|
<configuration>
|
||||||
|
<useSystemClassLoader>false</useSystemClassLoader>
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
@@ -214,14 +218,6 @@
|
|||||||
</filters>
|
</filters>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<version>2.22.1</version>
|
|
||||||
<configuration>
|
|
||||||
<useSystemClassLoader>false</useSystemClassLoader>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
<resources>
|
<resources>
|
||||||
|
|||||||
@@ -2,12 +2,20 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>ultrabackpack-parent</artifactId>
|
<artifactId>ultrabackpack-parent</artifactId>
|
||||||
<groupId>cc.carm.plugin</groupId>
|
<groupId>cc.carm.plugin</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>ultrabackpack-api</artifactId>
|
<artifactId>ultrabackpack-api</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
@@ -45,12 +53,16 @@
|
|||||||
<url>https://github.com/CarmJos/UltraBackpack/actions/workflows/maven.yml</url>
|
<url>https://github.com/CarmJos/UltraBackpack/actions/workflows/maven.yml</url>
|
||||||
</ciManagement>
|
</ciManagement>
|
||||||
|
|
||||||
<properties>
|
<dependencies>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<dependency>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<artifactId>easysql-api</artifactId>
|
||||||
</properties>
|
<version>0.2.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.api.data;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public enum DatabaseTables {
|
||||||
|
|
||||||
|
USER_DATA("ub_data", new String[]{
|
||||||
|
"`uuid` VARCHAR(36) NOT NULL PRIMARY KEY", // 用户的UUID
|
||||||
|
"`backpack` VARCHAR(32) NOT NULL",// 背包组名
|
||||||
|
"`type` VARCHAR(32) NOT NULL",// 背包内具体物品类型
|
||||||
|
"`amount` INT(11) NOT NULL DEFAULT 0", // 该物品的数量
|
||||||
|
"`sold` INT(11) NOT NULL DEFAULT 0", // 一周卖出次数
|
||||||
|
"`day` DATE NOT NULL", // 记录卖出数量的所在天
|
||||||
|
"PRIMARY KEY `data`(`uuid`,`backpack`,`type`)" // 联合主键索引
|
||||||
|
}),
|
||||||
|
;
|
||||||
|
|
||||||
|
String name;
|
||||||
|
String[] columns;
|
||||||
|
|
||||||
|
DatabaseTables(String name, String[] columns) {
|
||||||
|
this.name = name;
|
||||||
|
this.columns = columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void createTables(SQLManager sqlManager) throws SQLException {
|
||||||
|
for (DatabaseTables value : DatabaseTables.values()) {
|
||||||
|
sqlManager.createTable(value.getName())
|
||||||
|
.setColumns(value.getColumns())
|
||||||
|
.build().execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getColumns() {
|
||||||
|
return columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.api.manager;
|
||||||
|
|
||||||
|
public interface UBUserManager {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.api.user;
|
||||||
|
|
||||||
|
public interface UBUserData {
|
||||||
|
}
|
||||||
@@ -2,12 +2,22 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
<maven.javadoc.skip>true</maven.javadoc.skip>
|
||||||
|
<maven.deploy.skip>true</maven.deploy.skip>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>ultrabackpack-parent</artifactId>
|
<artifactId>ultrabackpack-parent</artifactId>
|
||||||
<groupId>cc.carm.plugin</groupId>
|
<groupId>cc.carm.plugin</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>ultrabackpack-plugin</artifactId>
|
<artifactId>ultrabackpack-plugin</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
@@ -22,9 +32,6 @@
|
|||||||
<name>Carm Jos</name>
|
<name>Carm Jos</name>
|
||||||
<email>carm@carm.cc</email>
|
<email>carm@carm.cc</email>
|
||||||
<url>https://www.carm.cc</url>
|
<url>https://www.carm.cc</url>
|
||||||
<roles>
|
|
||||||
<role>Main Developer</role>
|
|
||||||
</roles>
|
|
||||||
</developer>
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
|
|
||||||
@@ -45,15 +52,6 @@
|
|||||||
<url>https://github.com/CarmJos/UltraBackpack/actions/workflows/maven.yml</url>
|
<url>https://github.com/CarmJos/UltraBackpack/actions/workflows/maven.yml</url>
|
||||||
</ciManagement>
|
</ciManagement>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
|
||||||
<maven.javadoc.skip>true</maven.javadoc.skip>
|
|
||||||
<maven.deploy.skip>true</maven.deploy.skip>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<downloadUrl>https://github.com/CarmJos/UltraBackpack/releases</downloadUrl>
|
<downloadUrl>https://github.com/CarmJos/UltraBackpack/releases</downloadUrl>
|
||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
@@ -75,15 +73,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easysql-beecp</artifactId>
|
<artifactId>easysql-beecp</artifactId>
|
||||||
<version>0.2.1</version>
|
<version>0.2.2</version>
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
|
||||||
<version>8.0.16</version>
|
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.configuration;
|
||||||
|
|
||||||
|
import cc.carm.plugin.ultrabackpack.configuration.values.ConfigValue;
|
||||||
|
|
||||||
|
public class PluginConfig {
|
||||||
|
|
||||||
|
public static final ConfigValue<Boolean> DEBUG = new ConfigValue<>(
|
||||||
|
"debug", Boolean.class
|
||||||
|
);
|
||||||
|
|
||||||
|
public static class Database {
|
||||||
|
public static final ConfigValue<String> DRIVER_NAME = new ConfigValue<>(
|
||||||
|
"database.driver", String.class, "com.mysql.jdbc.Driver"
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final ConfigValue<String> URL = new ConfigValue<>(
|
||||||
|
"database.url", String.class, "jdbc:mysql://127.0.0.1:3306/minecraft"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
public static final ConfigValue<String> USERNAME = new ConfigValue<>(
|
||||||
|
"database.username", String.class, "username"
|
||||||
|
);
|
||||||
|
public static final ConfigValue<String> PASSWORD = new ConfigValue<>(
|
||||||
|
"database.password", String.class, "password"
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.configuration;
|
||||||
|
|
||||||
|
|
||||||
|
import cc.carm.plugin.ultrabackpack.configuration.message.ConfigMessageList;
|
||||||
|
|
||||||
|
public class PluginMessages {
|
||||||
|
|
||||||
|
public static final ConfigMessageList NO_SPACE = new ConfigMessageList("no-space");
|
||||||
|
}
|
||||||
+64
@@ -0,0 +1,64 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.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 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.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() {
|
||||||
|
if (getFile().exists()) {
|
||||||
|
this.config = YamlConfiguration.loadConfiguration(getFile());
|
||||||
|
} else {
|
||||||
|
initFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.configuration.message;
|
||||||
|
|
||||||
|
|
||||||
|
import cc.carm.plugin.ultrabackpack.configuration.values.ConfigValue;
|
||||||
|
import cc.carm.plugin.ultrabackpack.manager.ConfigManager;
|
||||||
|
import cc.carm.plugin.ultrabackpack.util.MessageUtil;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
public class ConfigMessage extends ConfigValue<String> {
|
||||||
|
|
||||||
|
public ConfigMessage(String configSection) {
|
||||||
|
this(configSection, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigMessage(String configSection, String defaultValue) {
|
||||||
|
super(ConfigManager.getMessageConfig(), configSection, String.class, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(CommandSender sender) {
|
||||||
|
MessageUtil.send(sender, get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendWithPlaceholders(CommandSender sender) {
|
||||||
|
MessageUtil.sendWithPlaceholders(sender, get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendWithPlaceholders(CommandSender sender, String[] params, Object[] values) {
|
||||||
|
MessageUtil.sendWithPlaceholders(sender, Collections.singletonList(get()), params, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.configuration.message;
|
||||||
|
|
||||||
|
|
||||||
|
import cc.carm.plugin.ultrabackpack.configuration.values.ConfigValueList;
|
||||||
|
import cc.carm.plugin.ultrabackpack.manager.ConfigManager;
|
||||||
|
import cc.carm.plugin.ultrabackpack.util.MessageUtil;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class ConfigMessageList extends ConfigValueList<String> {
|
||||||
|
|
||||||
|
public ConfigMessageList(String configSection) {
|
||||||
|
super(ConfigManager.getMessageConfig(), configSection, String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigMessageList(String configSection, String[] defaultValue) {
|
||||||
|
super(ConfigManager.getMessageConfig(), configSection, String.class, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable CommandSender sender) {
|
||||||
|
MessageUtil.send(sender, get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendWithPlaceholders(@Nullable CommandSender sender) {
|
||||||
|
MessageUtil.sendWithPlaceholders(sender, get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendWithPlaceholders(@Nullable CommandSender sender, String[] params, Object[] values) {
|
||||||
|
MessageUtil.sendWithPlaceholders(sender, get(), params, values);
|
||||||
|
}
|
||||||
|
}
|
||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.configuration.values;
|
||||||
|
|
||||||
|
import cc.carm.plugin.ultrabackpack.configuration.file.FileConfig;
|
||||||
|
import cc.carm.plugin.ultrabackpack.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
@@ -0,0 +1,72 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.configuration.values;
|
||||||
|
|
||||||
|
|
||||||
|
import cc.carm.plugin.ultrabackpack.configuration.file.FileConfig;
|
||||||
|
import cc.carm.plugin.ultrabackpack.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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+79
@@ -0,0 +1,79 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.configuration.values;
|
||||||
|
|
||||||
|
import cc.carm.plugin.ultrabackpack.configuration.file.FileConfig;
|
||||||
|
import cc.carm.plugin.ultrabackpack.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;
|
||||||
|
|
||||||
|
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) 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.valueCache = result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(HashMap<K, V> valuesMap) {
|
||||||
|
getConfiguration().createSection(this.configSection, valuesMap);
|
||||||
|
this.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
this.source.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.manager;
|
||||||
|
|
||||||
|
|
||||||
|
import cc.carm.plugin.ultrabackpack.Main;
|
||||||
|
import cc.carm.plugin.ultrabackpack.configuration.file.FileConfig;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
public class ConfigManager {
|
||||||
|
|
||||||
|
private static FileConfig config;
|
||||||
|
private static FileConfig messageConfig;
|
||||||
|
|
||||||
|
public static void initConfig() {
|
||||||
|
ConfigManager.config = new FileConfig(Main.getInstance(), "config.yml");
|
||||||
|
ConfigManager.messageConfig = new FileConfig(Main.getInstance(), "messages.yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FileConfig getPluginConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FileConfig getMessageConfig() {
|
||||||
|
return messageConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reload() {
|
||||||
|
getPluginConfig().reload();
|
||||||
|
getMessageConfig().reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveConfig() {
|
||||||
|
getPluginConfig().save();
|
||||||
|
getMessageConfig().save();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+139
@@ -0,0 +1,139 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.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,76 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.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;
|
||||||
|
if (hasPlaceholderAPI() && sender instanceof Player) {
|
||||||
|
send(sender, PlaceholderAPI.setPlaceholders((Player) sender, messages));
|
||||||
|
} else {
|
||||||
|
send(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> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+351
@@ -0,0 +1,351 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,297 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.util.gui;
|
||||||
|
|
||||||
|
import cc.carm.plugin.ultrabackpack.Main;
|
||||||
|
import cc.carm.plugin.ultrabackpack.util.ColorParser;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
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.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 Listener 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)
|
||||||
|
Bukkit.getPluginManager().registerEvents(listener = new Listener() {
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryClickEvent(InventoryClickEvent event) {
|
||||||
|
if (!(event.getWhoClicked() instanceof Player)) return;
|
||||||
|
Player p = (Player) event.getWhoClicked();
|
||||||
|
rawClickListener(event);
|
||||||
|
if (event.getSlot() != -999) {
|
||||||
|
try {
|
||||||
|
if (getOpenedGUI(p) == GUI.this
|
||||||
|
&& event.getClickedInventory() != null
|
||||||
|
&& event.getClickedInventory().equals(GUI.this.inv)
|
||||||
|
&& GUI.this.items[event.getSlot()] != null) {
|
||||||
|
GUI.this.items[event.getSlot()].realRawClickAction(event);
|
||||||
|
}
|
||||||
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
|
System.err.print("err cause by GUI(" + GUI.this + "), name=" + name);
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (cancelOnOuter) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
if (hasOpenedGUI(p)
|
||||||
|
&& getOpenedGUI(p) == GUI.this
|
||||||
|
&& event.getClickedInventory() != null) {
|
||||||
|
if (event.getClickedInventory().equals(GUI.this.inv)) {
|
||||||
|
if (cancelOnTarget) event.setCancelled(true);
|
||||||
|
|
||||||
|
if (event.getSlot() != -999 && GUI.this.items[event.getSlot()] != null) {
|
||||||
|
if (GUI.this.items[event.getSlot()].isActionActive()) {
|
||||||
|
GUI.this.items[event.getSlot()].onClick(event.getClick());
|
||||||
|
GUI.this.items[event.getSlot()].rawClickAction(event);
|
||||||
|
if (!GUI.this.items[event.getSlot()].actions.isEmpty()) {
|
||||||
|
for (GUIItem.GUIClickAction action : GUI.this.items[event.getSlot()].actions) {
|
||||||
|
action.run(event.getClick(), player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!GUI.this.items[event.getSlot()].actionsIgnoreActive.isEmpty()) {
|
||||||
|
for (GUIItem.GUIClickAction action : GUI.this.items[event.getSlot()].actionsIgnoreActive) {
|
||||||
|
action.run(event.getClick(), player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (event.getClickedInventory().equals(p.getInventory()) && cancelOnSelf) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onDrag(InventoryDragEvent e) {
|
||||||
|
if (e.getWhoClicked() instanceof Player) {
|
||||||
|
Player p = (Player) e.getWhoClicked();
|
||||||
|
if (e.getInventory().equals(inv) || e.getInventory().equals(p.getInventory())) {
|
||||||
|
GUI.this.onDrag(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryCloseEvent(InventoryCloseEvent event) {
|
||||||
|
if (event.getPlayer() instanceof Player && event.getInventory().equals(inv)) {
|
||||||
|
Player p = (Player) event.getPlayer();
|
||||||
|
if (event.getInventory().equals(inv)) {
|
||||||
|
HandlerList.unregisterAll(this);
|
||||||
|
listener = null;
|
||||||
|
onClose();
|
||||||
|
removeOpenedGUI(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, Main.getInstance());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拖动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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.util.gui;
|
||||||
|
|
||||||
|
public enum GUIType {
|
||||||
|
|
||||||
|
ONE_BY_NINE,
|
||||||
|
TWO_BY_NINE,
|
||||||
|
THREE_BY_NINE,
|
||||||
|
FOUR_BY_NINE,
|
||||||
|
FIVE_BY_NINE,
|
||||||
|
SIX_BY_NINE,
|
||||||
|
CANCEL
|
||||||
|
|
||||||
|
}
|
||||||
+75
@@ -0,0 +1,75 @@
|
|||||||
|
package cc.carm.plugin.ultrabackpack.util.gui;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class PagedGUI extends GUI {
|
||||||
|
|
||||||
|
protected List<GUIItem> container = new ArrayList<>();
|
||||||
|
public int page = 1;
|
||||||
|
|
||||||
|
public PagedGUI(GUIType type, String name) {
|
||||||
|
super(type, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int addItem(GUIItem i) {
|
||||||
|
container.add(i);
|
||||||
|
return container.size() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从GUI中移除一个物品
|
||||||
|
*
|
||||||
|
* @param item 物品
|
||||||
|
*/
|
||||||
|
public void removeItem(GUIItem item) {
|
||||||
|
container.remove(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从GUI中移除一个物品
|
||||||
|
*
|
||||||
|
* @param slot 物品格子数
|
||||||
|
*/
|
||||||
|
public void removeItem(int slot) {
|
||||||
|
container.remove(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GUIItem> getItemsContainer() {
|
||||||
|
return new ArrayList<>(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前往上一页
|
||||||
|
*/
|
||||||
|
public void goPreviousPage() {
|
||||||
|
if (hasPreviousPage())
|
||||||
|
page--;
|
||||||
|
else
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前往下一页
|
||||||
|
*/
|
||||||
|
public void goNextPage() {
|
||||||
|
if (hasNextPage())
|
||||||
|
page++;
|
||||||
|
else
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 是否有上一页
|
||||||
|
*/
|
||||||
|
public abstract boolean hasPreviousPage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 是否有下一页
|
||||||
|
*/
|
||||||
|
public abstract boolean hasNextPage();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,19 +1,70 @@
|
|||||||
# UltraBackpack
|
# ${project.parent.name} - ${project.parent.description}
|
||||||
# -> ${project.url}
|
# 项目地址: ${project.parent.url}
|
||||||
|
# 下载地址: ${project.parent.distributionManagement.downloadUrl}
|
||||||
|
|
||||||
version: ${project.version}
|
version: ${project.parent.version}
|
||||||
|
|
||||||
stroage:
|
stroage:
|
||||||
|
|
||||||
# 存储方式,可选 [ yaml | mysql ]
|
# 存储方式,可选 [ yaml | mysql ]
|
||||||
method: database
|
method: database
|
||||||
|
|
||||||
# 选择 file 存储方式时的存储路径
|
# 选择 file 存储方式时的存储路径
|
||||||
|
# 默认为相对路径,相对于插件生成的配置文件夹下的路径
|
||||||
# 支持绝对路径,如 “/var/data/ub/"(linux) 或 "D:\data\ub\"(windows)
|
# 支持绝对路径,如 “/var/data/ub/"(linux) 或 "D:\data\ub\"(windows)
|
||||||
# 使用绝对路径时请注意权限问题
|
# 使用绝对路径时请注意权限问题
|
||||||
file-path: data
|
file-path: data
|
||||||
|
|
||||||
# 选择 database 存储方式时的数据库配置
|
# 选择 database 存储方式时的数据库配置
|
||||||
mysql:
|
mysql:
|
||||||
# 数据库驱动路径
|
# 数据库驱动路径
|
||||||
driver: "com.mysql.cj.jdbc.Driver"
|
driver: "com.mysql.jdbc.Driver"
|
||||||
url: ""
|
url: "jdbc:mysql://127.0.0.1:3306/db-name"
|
||||||
username: ""
|
username: "username"
|
||||||
passwd: ""
|
password: "password"
|
||||||
|
|
||||||
|
# 通用配置
|
||||||
|
general:
|
||||||
|
|
||||||
|
# 针对每一件物品的额外介绍
|
||||||
|
# 将添加到背包界面内的物品上,避免重复配置
|
||||||
|
addtional-lore:
|
||||||
|
- " "
|
||||||
|
- "&f仓库内数量 &a%(amount)"
|
||||||
|
- "&f该物品单价 &a%(price)"
|
||||||
|
- "&f今日可出售 &a%(sold)&8/%(limit)"
|
||||||
|
|
||||||
|
# 提示玩家点击行为的介绍
|
||||||
|
# 将添加到背包界面内的物品上,避免重复配置
|
||||||
|
click-lore:
|
||||||
|
- " "
|
||||||
|
- "&a&l左键点击 &8| &f按量售出该物品"
|
||||||
|
- "&a&l右键点击 &8| &f取出一组该物品"
|
||||||
|
|
||||||
|
# 售出界面的配置
|
||||||
|
sell-gui:
|
||||||
|
title: "&8出售 %(item_name)"
|
||||||
|
items:
|
||||||
|
add:
|
||||||
|
type: GREEN_STAINED_GLASS_PANE
|
||||||
|
name: "&a增加 %(amount) 个"
|
||||||
|
remove:
|
||||||
|
type: RED_STAINED_GLASS_PANE
|
||||||
|
name: "&c减少 %(amount) 个"
|
||||||
|
confirm:
|
||||||
|
type: EMERALD
|
||||||
|
data: 0
|
||||||
|
name: "&a确认售出"
|
||||||
|
lore:
|
||||||
|
- " "
|
||||||
|
- "&7您将售出 &r%(item_name) &8x &f%(amount)"
|
||||||
|
- "&7共计获得 &e%(money) &7元作为回报。"
|
||||||
|
- " "
|
||||||
|
- "&a&l点击确认售出"
|
||||||
|
cancel: "&c取消售出"
|
||||||
|
type: REDSTONE
|
||||||
|
data: 0
|
||||||
|
name: "&a确认售出"
|
||||||
|
lore:
|
||||||
|
- " "
|
||||||
|
- "&c&l点击取消售出"
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
main: ${project.groupId}.${project.artifactId}.Main
|
main: cc.carm.plugin.ultrabackpack.Main
|
||||||
version: ${project.version}
|
name: UltraBackpack
|
||||||
|
|
||||||
name: ${project.name}
|
version: ${project.version}
|
||||||
description: ${project.description}
|
description: ${project.parent.description}
|
||||||
website: ${project.url}
|
website: ${project.parent.url}
|
||||||
|
|
||||||
author: CarmJos
|
author: CarmJos
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user