Compare commits
31 Commits
Author | SHA1 | Date | |
---|---|---|---|
007142891b | |||
bda0f8dee7 | |||
0c3c0e0726 | |||
7fd8f8450c | |||
198c4dd426 | |||
e7cb4cfb80 | |||
3038fc6e3c | |||
17bb269f76 | |||
acae6d5ec7 | |||
d7362c2f0d | |||
4767d270f2 | |||
eb431c65cf | |||
f3fb232fa6 | |||
055953958a | |||
c5eb4e6035 | |||
f68b80a30a | |||
127a91c46f | |||
3ac5df6179 | |||
609a090235 | |||
a681fca1b9 | |||
76edc1d146 | |||
23848cc2f5 | |||
1dd8ce906c | |||
f8f71cb300 | |||
f41b75b9f3 | |||
24aff565fb | |||
d978fcab50 | |||
4780ede21f | |||
9f86548dd4 | |||
c384508ffa | |||
cead35b6a1 |
@ -9,34 +9,35 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Pull & Checkout"
|
||||
uses: https://ssl.lunadeer.cn:14446/actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: "Set up Maven"
|
||||
uses: https://ssl.lunadeer.cn:14446/actions/setup-maven@v4
|
||||
- name: "Set up JDK 17"
|
||||
uses: https://ssl.lunadeer.cn:14446/actions/setup-java@v3
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'zulu'
|
||||
cache: maven
|
||||
- name: "Build with Maven"
|
||||
run: mvn -B package --file pom.xml
|
||||
- name: "Copy jar to staging"
|
||||
run: mkdir staging && cp target/*.jar staging
|
||||
- name: "Build & test"
|
||||
run: |
|
||||
echo "done!"
|
||||
- name: "setup go for release script"
|
||||
run: |
|
||||
wget --no-check-certificate https://go.dev/dl/go1.21.6.linux-amd64.tar.gz
|
||||
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.6.linux-amd64.tar.gz
|
||||
ln -s /usr/local/go/bin/go /usr/bin/go
|
||||
go version
|
||||
- name: "Release"
|
||||
uses: https://ssl.lunadeer.cn:14446/actions/release-action@main
|
||||
with:
|
||||
files: |-
|
||||
staging/*.jar
|
||||
api_key: '${{secrets.RELEASE_TOKEN}}'
|
||||
- name: "Pull & Checkout"
|
||||
uses: https://ssl.lunadeer.cn:14446/actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: "Set up Maven"
|
||||
uses: https://ssl.lunadeer.cn:14446/actions/setup-maven@v4
|
||||
- name: "Set up JDK 17"
|
||||
uses: https://ssl.lunadeer.cn:14446/actions/setup-java@v3
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'zulu'
|
||||
cache: maven
|
||||
- name: "Build with Maven"
|
||||
run: mvn -B package --file pom.xml
|
||||
- name: "Copy jar to staging"
|
||||
run: mkdir staging && cp target/*.jar staging
|
||||
- name: "Build & test"
|
||||
run: |
|
||||
echo "done!"
|
||||
- name: "setup go for release script"
|
||||
run: |
|
||||
wget --no-check-certificate https://golang.google.cn/dl/go1.21.6.linux-amd64.tar.gz
|
||||
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.6.linux-amd64.tar.gz
|
||||
ln -s /usr/local/go/bin/go /usr/bin/go
|
||||
go version
|
||||
- name: "Release"
|
||||
uses: https://ssl.lunadeer.cn:14446/zhangyuheng/release-action@main
|
||||
with:
|
||||
note: "带 `original-` 前缀的文件无法用于运行,请下载不带此前缀的版本。"
|
||||
files: |-
|
||||
staging/*.jar
|
||||
api_key: '${{secrets.RELEASE_TOKEN}}'
|
109
README.md
109
README.md
@ -1,4 +1,13 @@
|
||||
# LiteWorldEdit
|
||||
|
||||
<div style="text-align: center;">
|
||||
|
||||
<img src="https://ssl.lunadeer.cn:14437/i/2024/03/28/6604dfebcffd8.png" alt="" width="70%">
|
||||
|
||||
### [开源地址](https://ssl.lunadeer.cn:14446/zhangyuheng/LiteWorldEdit) | [文档地址](https://ssl.lunadeer.cn:14448/doc/3/)
|
||||
### [下载页面](https://ssl.lunadeer.cn:14446/zhangyuheng/LiteWorldEdit/releases)
|
||||
### [统计页面](https://bstats.org/plugin/bukkit/LiteWorldEdit/21436) | [Hangar](https://hangar.papermc.io/zhangyuheng/LiteWorldEdit)
|
||||
|
||||
</div>
|
||||
|
||||
## 轻量创世神
|
||||
|
||||
@ -24,46 +33,80 @@
|
||||
2. 使用破坏操作需要拥有下届合金镐(作为一种使用门槛),并且消耗耐久度,同时支持耐久附魔效果;
|
||||
3. 当合金镐耐久度不足10时会自动终止任务(暂不支持恢复);
|
||||
4. 支持填充操作,填充操作需要消耗玩家物品栏中的物品;
|
||||
5. 禁止超视距操作(128以外),防止玩家利用创世神插件加载大量区块导致服务器卡顿;
|
||||
6. 支持自动从背包里的潜影盒补充材料;
|
||||
7. 支持设置是否产生掉落物;
|
||||
5. 支持自动从背包中的盒子里提取物品;
|
||||
6. 禁止超视距操作(128以外),防止玩家利用创世神插件加载大量区块导致服务器卡顿;
|
||||
7. 支持自动从背包里的潜影盒补充材料;
|
||||
8. 支持设置是否产生掉落物;
|
||||
9. 支持设置速度倍率(整数,默认1表示每tick操作一个方块,设置为2则每次操作两个方块)
|
||||
10. 选区可视
|
||||
|
||||
## 支持版本
|
||||
|
||||
- 1.20.1+ (Folia Paper)
|
||||
- 1.20.1+ (Folia、Paper)
|
||||
|
||||
## 使用方法
|
||||
## 安装方法
|
||||
|
||||
1. 将插件放入服务器的 `plugins` 目录下
|
||||
1. 将插件放入服务器# 标题的 `plugins` 目录下
|
||||
2. 重启服务器
|
||||
3. 在 `plugins/LiteWorldEdit/config.yml` 中配置
|
||||
4. 控制台或OP输入 `/lwe reload` 重载配置
|
||||
|
||||
## 玩家使用方法
|
||||
|
||||
### 1. 指令选区
|
||||
|
||||
所有的操作均以**选区**为基础进行,因此需要先确定选区。而选区又是由点构成,因此需要先选点。
|
||||
根据小学知识,可以通过立方体对角线两点确定立方体。因此我们在进行选区操作前需要至少准备两个点。通过`/lwe point [点序号(整数)] [x] [y] [z]`
|
||||
或者 `/lwe p [点序号(整数)] [x] [y] [z]` 来选择空间中的点,点序号可以是任意想要的整数。
|
||||
|
||||
### 2. 操作
|
||||
|
||||
准备好点后即可使用对应的指令对点组成的选区进行具体的操作。如果不指定选点则默认使用 1 号 2 号点构成的区域。
|
||||
|
||||
### 3. 快捷选区
|
||||
|
||||
使用指令 `/lwe select` 打开快速选区模式,然后使用下届合金镐左键选择第一个点、右键选择第二个点,即可快速创建 1 号 2 号选点。
|
||||
|
||||
![](https://ssl.lunadeer.cn:14437/i/2024/03/20/65fa94193f11a.gif)
|
||||
|
||||
## 管理员指南
|
||||
|
||||
### Multiplier
|
||||
|
||||
默认为 1,表示每个玩家每 tick 操作1个方块,设置为 2 则表示每 tick 操作两个方块。根据服务器实际配置与玩家数量调整此配置。
|
||||
|
||||
### DropItems
|
||||
|
||||
默认为 false,如果开启则 `empty` 等清理方块的操作会像普通挖掘那样生成掉落物。建议不开启,避免滥用此功能挖矿或短时间内产生大量掉落物品造成服务器卡顿。
|
||||
|
||||
## 指令
|
||||
|
||||
以下指令尖括号`<>`表示必填参数,方括号`[]`表示可选参数。
|
||||
|
||||
### 玩家指令
|
||||
|
||||
`/lwe help` 查看帮助
|
||||
| 指令 | 功能描述 |
|
||||
|------------------------------------|---------------------------|
|
||||
| `/lwe help` | 查看帮助 |
|
||||
| `/lwe point <点序号(整数)> <x> <y> <z>` | 创建点 |
|
||||
| `/lwe p <点序号(整数)> <x> <y> <z>` | 创建点 |
|
||||
| `lwe select` | 开启/关闭选点模式 使用下届合金镐选择点 |
|
||||
| `/lwe points` | 查看当前添加的所有点 |
|
||||
| `/lwe fill [点序号A] [点序号B]` | 在AB点对角线间放置方块 - 需要手持被放置的方块 |
|
||||
| `/lwe empty [点序号A] [点序号B]` | 破坏AB点对角线间方块 - 需要拥有下届合金镐 |
|
||||
| `/lwe overlay [点序号A] [点序号B]` | 在选区地面上铺一层方块 - 需要手持被放置的方块 |
|
||||
| `/lwe drain [点序号A] [点序号B]` | 排干AB点对角线间的流体 - 需要背包里有一个海绵 |
|
||||
| `/lwe cancel` | 取消(终止)所有任务 |
|
||||
| `/lwe pause` | 暂停所有任务 |
|
||||
| `/lwe resume` | 恢复所有任务 |
|
||||
|
||||
`/lwe point [点序号(整数)] [x] [y] [z]` 创建点
|
||||
> 选区操作不填写点序号则默认使用 1 号 2 号点构成的区域。
|
||||
|
||||
`/lwe p [点序号(整数)] [x] [y] [z]` 创建点
|
||||
### 管理员指令
|
||||
|
||||
`/lwe points` 查看当前添加的所有点
|
||||
|
||||
`/lwe fill [点序号A] [点序号B]` 在AB点对角线间放置方块 - 需要手持被放置的方块
|
||||
|
||||
`/lwe empty [点序号A] [点序号B]` 破坏AB点对角线间方块 - 需要拥有下届合金镐
|
||||
|
||||
`/lwe overlay [点序号A] [点序号B]` 在选区地面上铺一层方块 - 需要手持被放置的方块
|
||||
|
||||
`/lwe cancel` 取消(终止)所有任务
|
||||
|
||||
`/lwe pause` 暂停所有任务
|
||||
|
||||
`/lwe resume` 恢复所有任务
|
||||
|
||||
`/lwe reload` 重载配置(仅管理员)
|
||||
| 指令 | 功能描述 |
|
||||
|---------------|------|
|
||||
| `/lwe reload` | 重载配置 |
|
||||
|
||||
## 配置文件参考
|
||||
|
||||
@ -76,6 +119,10 @@ MaxZ: 64
|
||||
|
||||
DropItems: false
|
||||
|
||||
Multiplier: 1
|
||||
|
||||
CheckUpdate: true
|
||||
|
||||
Debug: false
|
||||
```
|
||||
|
||||
@ -83,8 +130,18 @@ Debug: false
|
||||
|
||||
- [X] 从潜影盒中自动补充材料
|
||||
|
||||
- [ ] 选区可视化
|
||||
- [X] 选区可视化
|
||||
|
||||
- [X] 可手动暂停、恢复任务
|
||||
|
||||
- [ ] 更多的任务类型支持(如画圆、弧线)
|
||||
|
||||
## 建议与反馈
|
||||
|
||||
Mail: [zhangyuheng@lunadeer.cn](mailto:zhangyuheng@lunadeer.cn)
|
||||
|
||||
QQ群:309428300
|
||||
|
||||
## 统计
|
||||
|
||||
![bstats](https://bstats.org/signatures/bukkit/LiteWorldEdit.svg)
|
6
pom.xml
6
pom.xml
@ -4,9 +4,9 @@
|
||||
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>
|
||||
|
||||
<groupId>site.deercloud</groupId>
|
||||
<groupId>cn.lunadeer</groupId>
|
||||
<artifactId>LiteWorldEdit</artifactId>
|
||||
<version>2.2.1.0</version>
|
||||
<version>2.5.0.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>LiteWorldEdit</name>
|
||||
@ -16,7 +16,7 @@
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<url>https://blog.deercloud.site</url>
|
||||
<url>https://ssl.lunadeer.cn:14448/project-2/</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
BIN
resources/logo.png
Normal file
BIN
resources/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.9 KiB |
3
resources/logo.svg
Normal file
3
resources/logo.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 14 KiB |
BIN
resources/logo2.png
Normal file
BIN
resources/logo2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
@ -1,5 +1,12 @@
|
||||
package site.deercloud.liteworldedit;
|
||||
package cn.lunadeer.liteworldedit;
|
||||
|
||||
import cn.lunadeer.liteworldedit.JobGenerator.Drain;
|
||||
import cn.lunadeer.liteworldedit.JobGenerator.Empty;
|
||||
import cn.lunadeer.liteworldedit.JobGenerator.Fill;
|
||||
import cn.lunadeer.liteworldedit.JobGenerator.OverLay;
|
||||
import cn.lunadeer.liteworldedit.Jobs.Job;
|
||||
import cn.lunadeer.liteworldedit.Managers.ConfigManager;
|
||||
import cn.lunadeer.liteworldedit.Managers.Point;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
@ -8,11 +15,6 @@ import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import site.deercloud.liteworldedit.JobGenerator.Empty;
|
||||
import site.deercloud.liteworldedit.JobGenerator.Fill;
|
||||
import site.deercloud.liteworldedit.JobGenerator.OverLay;
|
||||
import site.deercloud.liteworldedit.Jobs.Job;
|
||||
import site.deercloud.liteworldedit.Managers.Point;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -26,16 +28,26 @@ public class Commands implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
if (Objects.equals(args[0], "point") || Objects.equals(args[0], "p")) {
|
||||
return addPoint(sender, args);
|
||||
addPoint(sender, args);
|
||||
return true;
|
||||
} else if (Objects.equals(args[0], "select")) {
|
||||
selectModeToggle(sender, args);
|
||||
return true;
|
||||
} else if (Objects.equals(args[0], "points")) {
|
||||
listPoints(sender);
|
||||
return true;
|
||||
} else if (Objects.equals(args[0], "fill")) {
|
||||
return fillTask(sender, args);
|
||||
fillTask(sender, args);
|
||||
return true;
|
||||
} else if (Objects.equals(args[0], "empty")) {
|
||||
return emptyTask(sender, args);
|
||||
emptyTask(sender, args);
|
||||
return true;
|
||||
} else if (Objects.equals(args[0], "overlay")) {
|
||||
return overlayTask(sender, args);
|
||||
overlayTask(sender, args);
|
||||
return true;
|
||||
} else if (Objects.equals(args[0], "drain")) {
|
||||
drainTask(sender, args);
|
||||
return true;
|
||||
} else if (Objects.equals(args[0], "help")) {
|
||||
print_help(sender);
|
||||
return true;
|
||||
@ -91,11 +103,11 @@ public class Commands implements TabExecutor {
|
||||
if (!player.isOp()) {
|
||||
Notification.error(player, "你没有权限。");
|
||||
} else {
|
||||
LiteWorldEdit.instance.reloadConfig();
|
||||
LiteWorldEdit.config.reload();
|
||||
Notification.info(player, "已重载配置文件。");
|
||||
}
|
||||
} else {
|
||||
LiteWorldEdit.instance.reloadConfig();
|
||||
LiteWorldEdit.config.reload();
|
||||
LoggerX.info("已重载配置文件。");
|
||||
}
|
||||
}
|
||||
@ -114,87 +126,94 @@ public class Commands implements TabExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean emptyTask(CommandSender sender, String[] args) {
|
||||
private static void emptyTask(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
LoggerX.err("该命令只能由玩家执行。");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
if (args.length == 3) {
|
||||
try {
|
||||
Vector2 diagonalPoint = getVector2(sender, args, player);
|
||||
if (diagonalPoint == null) return true;
|
||||
Empty.empty(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB);
|
||||
Notification.info(player, "已添加任务。");
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
Notification.error(player, "参数错误。");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Vector2 diagonalPoint = getVector2(sender, args, player);
|
||||
if (diagonalPoint == null) return;
|
||||
Empty.empty(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB);
|
||||
Notification.info(player, "已添加任务。");
|
||||
} catch (NumberFormatException e) {
|
||||
Notification.error(player, "参数错误。");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean overlayTask(CommandSender sender, String[] args) {
|
||||
private static void drainTask(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
LoggerX.err("该命令只能由玩家执行。");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
if (args.length == 3) {
|
||||
try {
|
||||
Vector2 diagonalPoint = getVector2(sender, args, player);
|
||||
if (diagonalPoint == null) return true;
|
||||
ItemStack items_in_hand = player.getInventory().getItemInMainHand();
|
||||
if (!items_in_hand.getType().isBlock() || items_in_hand.getType() == Material.AIR) {
|
||||
Notification.error(player, "你手上没有方块。");
|
||||
return true;
|
||||
}
|
||||
Material material = Material.getMaterial(items_in_hand.getType().name());
|
||||
OverLay.overLay(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB, material);
|
||||
Notification.info(player, "已添加任务。");
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
Notification.error(player, "参数错误。");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Vector2 diagonalPoint = getVector2(sender, args, player);
|
||||
if (diagonalPoint == null) return;
|
||||
Drain.drain(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB);
|
||||
Notification.info(player, "已添加任务。");
|
||||
} catch (NumberFormatException e) {
|
||||
Notification.error(player, "参数错误。");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean fillTask(CommandSender sender, String[] args) {
|
||||
private static void overlayTask(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
LoggerX.err("该命令只能由玩家执行。");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
if (args.length == 3) {
|
||||
try {
|
||||
Vector2 diagonalPoint = getVector2(sender, args, player);
|
||||
if (diagonalPoint == null) return true;
|
||||
ItemStack items_in_hand = player.getInventory().getItemInMainHand();
|
||||
if (!items_in_hand.getType().isBlock() || items_in_hand.getType() == Material.AIR) {
|
||||
Notification.error(player, "你手上没有方块。");
|
||||
return true;
|
||||
}
|
||||
Material material = Material.getMaterial(items_in_hand.getType().name());
|
||||
Fill.fill(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB, material);
|
||||
Notification.info(player, "已添加任务。");
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
Notification.error(player, "参数错误。");
|
||||
try {
|
||||
Vector2 diagonalPoint = getVector2(sender, args, player);
|
||||
if (diagonalPoint == null) return;
|
||||
ItemStack items_in_hand = player.getInventory().getItemInMainHand();
|
||||
if (!items_in_hand.getType().isBlock() || items_in_hand.getType() == Material.AIR) {
|
||||
Notification.error(player, "你手上没有方块。");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Material material = Material.getMaterial(items_in_hand.getType().name());
|
||||
OverLay.overLay(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB, material);
|
||||
Notification.info(player, "已添加任务。");
|
||||
return;
|
||||
} catch (NumberFormatException e) {
|
||||
Notification.error(player, "参数错误。");
|
||||
}
|
||||
}
|
||||
|
||||
private static void fillTask(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
LoggerX.err("该命令只能由玩家执行。");
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
try {
|
||||
Vector2 diagonalPoint = getVector2(sender, args, player);
|
||||
if (diagonalPoint == null) return;
|
||||
ItemStack items_in_hand = player.getInventory().getItemInMainHand();
|
||||
if (!items_in_hand.getType().isBlock() || items_in_hand.getType() == Material.AIR) {
|
||||
Notification.error(player, "你手上没有方块。");
|
||||
return;
|
||||
}
|
||||
Material material = Material.getMaterial(items_in_hand.getType().name());
|
||||
Fill.fill(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB, material);
|
||||
Notification.info(player, "已添加任务。");
|
||||
return;
|
||||
} catch (NumberFormatException e) {
|
||||
Notification.error(player, "参数错误。");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Vector2 getVector2(CommandSender sender, String[] args, Player player) {
|
||||
Integer indexA = Integer.parseInt(args[1]);
|
||||
Integer indexB = Integer.parseInt(args[2]);
|
||||
int indexA;
|
||||
int indexB;
|
||||
if (args.length == 3) {
|
||||
indexA = Integer.parseInt(args[1]);
|
||||
indexB = Integer.parseInt(args[2]);
|
||||
} else {
|
||||
indexA = 1;
|
||||
indexB = 2;
|
||||
}
|
||||
Map<Integer, Point> points = LiteWorldEdit.instance.getCache().getPlayer(player).getPoints();
|
||||
if (points == null) {
|
||||
Notification.error(player, "你没有设置任何点。");
|
||||
@ -203,7 +222,7 @@ public class Commands implements TabExecutor {
|
||||
Point pointA = points.get(indexA);
|
||||
Point pointB = points.get(indexB);
|
||||
if (pointA == null || pointB == null) {
|
||||
Notification.error(player, "点不存在。");
|
||||
Notification.error(player, "点不存在,使用 /lwe points 查看所有已添加的点。");
|
||||
return null;
|
||||
}
|
||||
if (out_of_region(pointA, pointB)) {
|
||||
@ -241,10 +260,10 @@ public class Commands implements TabExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean addPoint(CommandSender sender, String[] args) {
|
||||
private static void addPoint(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
LoggerX.err("该命令只能由玩家执行。");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
if (args.length == 5) {
|
||||
@ -255,12 +274,12 @@ public class Commands implements TabExecutor {
|
||||
int z = Integer.parseInt(args[4]);
|
||||
// 选择的点不允许超过128格范围
|
||||
if (!Job.in_range(player, new Location(player.getWorld(), x, y, z))) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
Point point = new Point(x, y, z, player);
|
||||
if (!LiteWorldEdit.instance.getCache().getPlayer(player).addPoint(index, point)) {
|
||||
Notification.error(player, "点的数量不允许超过20,请使用已有点序号覆盖已有点。");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
Notification.info(player, "点 " + index + " 已设置为 " + x + ", " + y + ", " + z + "。");
|
||||
} catch (NumberFormatException e) {
|
||||
@ -269,18 +288,26 @@ public class Commands implements TabExecutor {
|
||||
} else {
|
||||
Notification.error(player, "参数错误。");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void selectModeToggle(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
LoggerX.err("该命令只能由玩家执行。");
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
LiteWorldEdit.instance.getCache().getPlayer(player).toggleSelectMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||
if (args.length == 1) {
|
||||
return Arrays.asList("point", "p", "points", "fill", "empty", "overlay", "cancel", "pause", "resume", "help", "reload");
|
||||
return Arrays.asList("point", "p", "select", "points", "fill", "empty", "overlay", "drain", "cancel", "pause", "resume", "help", "reload");
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equals("point") || args[0].equals("p")) {
|
||||
return Collections.singletonList("[点序号(整数)] [x] [y] [z] - 创建点");
|
||||
} else if (args[0].equals("fill") || args[0].equals("empty") || args[0].equals("overlay")) {
|
||||
return Collections.singletonList("[点序号A] [点序号B]");
|
||||
return Collections.singletonList("<点序号(整数)> <x> <y> <z> - 创建点");
|
||||
} else if (args[0].equals("fill") || args[0].equals("empty") || args[0].equals("overlay") || args[0].equals("drain")) {
|
||||
return Collections.singletonList("[点序号A] [点序号B] - 不填写默认为 1 2");
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
@ -293,11 +320,13 @@ public class Commands implements TabExecutor {
|
||||
}
|
||||
Notification.info((Player) sender, "LiteWorldEdit 帮助");
|
||||
Notification.info((Player) sender, "/lwe help - 查看帮助");
|
||||
Notification.info((Player) sender, "/lwe point|p [点序号(整数)] [x] [y] [z] - 创建点");
|
||||
Notification.info((Player) sender, "/lwe point|p <点序号(整数)> <x> <y> <z> - 创建点");
|
||||
Notification.info((Player) sender, "/lwe select - 开启/关闭选点模式 使用下届合金镐选择点");
|
||||
Notification.info((Player) sender, "/lwe points - 查看所有点");
|
||||
Notification.info((Player) sender, "/lwe fill [点序号A] [点序号B] - (在AB点对角线间放置方块 - 需要手持被放置的方块)");
|
||||
Notification.info((Player) sender, "/lwe empty [点序号A] [点序号B] - (破坏AB点对角线间方块 - 需要拥有下届合金镐)");
|
||||
Notification.info((Player) sender, "/lwe overlay [点序号A] [点序号B] - (在AB点对角线间放置方块 - 不需要手持被放置的方块)");
|
||||
Notification.info((Player) sender, "/lwe drain [点序号A] [点序号B] - (排干AB点对角线间的流体 - 需要背包里有一个海绵)");
|
||||
Notification.info((Player) sender, "/lwe cancel - 取消当前任务");
|
||||
Notification.info((Player) sender, "/lwe pause - 暂停当前任务");
|
||||
Notification.info((Player) sender, "/lwe resume - 恢复当前任务");
|
71
src/main/java/cn/lunadeer/liteworldedit/Events.java
Normal file
71
src/main/java/cn/lunadeer/liteworldedit/Events.java
Normal file
@ -0,0 +1,71 @@
|
||||
package cn.lunadeer.liteworldedit;
|
||||
|
||||
import cn.lunadeer.liteworldedit.Managers.Point;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Events implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
LiteWorldEdit.instance.getCache().playerQuit(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
LiteWorldEdit.instance.getCache().playerJoin(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void selectPoint(PlayerInteractEvent event) {
|
||||
XPlayer xplayer = LiteWorldEdit.instance.getCache().getPlayer(event.getPlayer());
|
||||
if (!xplayer.isSelectMode()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
if (item.getType() != Material.NETHERITE_PICKAXE) {
|
||||
return;
|
||||
}
|
||||
Block block = event.getClickedBlock();
|
||||
Action action = event.getAction();
|
||||
if (block == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
Point point = new Point(x, y, z, player);
|
||||
|
||||
if (action == Action.LEFT_CLICK_BLOCK) {
|
||||
event.setCancelled(true);
|
||||
Notification.info(player, "已选择第一个点: " + x + " " + y + " " + z);
|
||||
xplayer.addPoint(1, point);
|
||||
} else if (action == Action.RIGHT_CLICK_BLOCK) {
|
||||
event.setCancelled(true);
|
||||
Notification.info(player, "已选择第二个点: " + x + " " + y + " " + z);
|
||||
xplayer.addPoint(2, point);
|
||||
}
|
||||
|
||||
if (xplayer.getPoints().get(1) != null && xplayer.getPoints().get(2) != null) {
|
||||
Point p1 = xplayer.getPoints().get(1);
|
||||
Point p2 = xplayer.getPoints().get(2);
|
||||
int deltaX = Math.abs(p1.x - p2.x);
|
||||
int deltaY = Math.abs(p1.y - p2.y);
|
||||
int deltaZ = Math.abs(p1.z - p2.z);
|
||||
if (deltaX > LiteWorldEdit.config.getXMax() || deltaY > LiteWorldEdit.config.getYMax() || deltaZ > LiteWorldEdit.config.getZMax()) {
|
||||
return;
|
||||
}
|
||||
ParticleRender.showBoxBorder(LiteWorldEdit.instance, player.getWorld().getName(), p1.x, p1.y, p1.z, p2.x, p2.y, p2.z);
|
||||
}
|
||||
}
|
||||
}
|
199
src/main/java/cn/lunadeer/liteworldedit/GiteaReleaseCheck.java
Normal file
199
src/main/java/cn/lunadeer/liteworldedit/GiteaReleaseCheck.java
Normal file
@ -0,0 +1,199 @@
|
||||
package cn.lunadeer.liteworldedit;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class GiteaReleaseCheck {
|
||||
private static class GiteaRelease {
|
||||
public String tag_name;
|
||||
public String message;
|
||||
public String html_url;
|
||||
public String download_url;
|
||||
}
|
||||
|
||||
public GiteaReleaseCheck(JavaPlugin plugin, String giteaServer, String owner, String repo) {
|
||||
this.gitea_server = giteaServer;
|
||||
this.owner = owner;
|
||||
this.repo = repo;
|
||||
this.plugin = plugin;
|
||||
this.current_version = plugin.getPluginMeta().getVersion();
|
||||
// 异步每12小时检查一次更新
|
||||
plugin.getServer().getAsyncScheduler().runAtFixedRate(plugin, (instance) -> {
|
||||
getLatestRelease();
|
||||
if (auto_update) {
|
||||
downloadUpdate();
|
||||
}
|
||||
}, 10, 60 * 60 * 12, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public void enableAutoUpdate() {
|
||||
auto_update = true;
|
||||
}
|
||||
|
||||
private String repoReleases() {
|
||||
return gitea_server + "/api/v1/repos/" + owner + "/" + repo + "/releases";
|
||||
}
|
||||
|
||||
private String tag(String tagName) {
|
||||
return gitea_server + "/api/v1/repos/" + owner + "/" + repo + "/tags/" + tagName;
|
||||
}
|
||||
|
||||
private void getLatestRelease() {
|
||||
LoggerX.info("================================");
|
||||
LoggerX.info("正在检查更新...");
|
||||
// send get request to repoReleases()
|
||||
try {
|
||||
// 发送 GET 请求
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(repoReleases()).openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.setReadTimeout(5000);
|
||||
connection.connect();
|
||||
// 获取响应
|
||||
StringBuilder builder = new StringBuilder();
|
||||
try (BufferedReader bufferedReader =
|
||||
new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
}
|
||||
JSONArray releaseList = (JSONArray) new JSONParser().parse(builder.toString());
|
||||
JSONObject latestRelease = (JSONObject) releaseList.get(0);
|
||||
GiteaRelease release = new GiteaRelease();
|
||||
release.tag_name = (String) latestRelease.get("tag_name");
|
||||
release.message = (String) latestRelease.get("body");
|
||||
release.html_url = (String) latestRelease.get("html_url");
|
||||
JSONArray assets = (JSONArray) latestRelease.get("assets");
|
||||
if (assets.size() > 0) {
|
||||
JSONObject asset = (JSONObject) assets.get(0);
|
||||
release.download_url = (String) asset.get("browser_download_url");
|
||||
}
|
||||
latest_release = release;
|
||||
LoggerX.debug("Latest release: " + latest_release.tag_name);
|
||||
LoggerX.debug("Message: " + latest_release.message);
|
||||
LoggerX.debug("Download URL: " + latest_release.download_url);
|
||||
LoggerX.debug("HTML URL: " + latest_release.html_url);
|
||||
if (isNewVersion(current_version, latest_release.tag_name)) {
|
||||
LoggerX.info("发现新版本:" + latest_release.tag_name);
|
||||
LoggerX.info("版本信息:");
|
||||
String[] message = latest_release.message.split("\n");
|
||||
for (String line : message) {
|
||||
LoggerX.info("\t" + line);
|
||||
}
|
||||
LoggerX.info("下载页面:" + latest_release.html_url);
|
||||
} else {
|
||||
LoggerX.info("当前已是最新版本:" + current_version);
|
||||
}
|
||||
LoggerX.info("================================");
|
||||
} catch (Exception e) {
|
||||
LoggerX.err("Failed to get latest release: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String getTagMessage(String tagName) {
|
||||
try {
|
||||
// 发送 GET 请求
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(tag(tagName)).openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.setReadTimeout(5000);
|
||||
connection.connect();
|
||||
// 获取响应
|
||||
StringBuilder builder = new StringBuilder();
|
||||
try (BufferedReader bufferedReader =
|
||||
new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
}
|
||||
JSONObject tag = (JSONObject) new JSONParser().parse(builder.toString());
|
||||
return (String) tag.get("message");
|
||||
} catch (Exception e) {
|
||||
LoggerX.debug("Failed to get tag message: " + e.getMessage());
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
|
||||
private void downloadUpdate() {
|
||||
if (latest_release == null) {
|
||||
getLatestRelease();
|
||||
if (latest_release == null)
|
||||
return;
|
||||
}
|
||||
if (!isNewVersion(current_version, latest_release.tag_name)) {
|
||||
LoggerX.info("当前已是最新版本");
|
||||
return;
|
||||
}
|
||||
if (latest_release.download_url == null) {
|
||||
LoggerX.err("下载地址不可用");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
LoggerX.info("================================");
|
||||
LoggerX.info("正在下载更新...");
|
||||
File pluginsFolder = plugin.getDataFolder().getParentFile();
|
||||
File newJarFile = new File(pluginsFolder, latest_release.download_url.substring(latest_release.download_url.lastIndexOf("/") + 1));
|
||||
// send get request to download_url
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(latest_release.download_url).openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.setReadTimeout(5000);
|
||||
connection.connect();
|
||||
// 获取响应写入文件到 newJarFile
|
||||
try (DataOutputStream outputStream = new DataOutputStream(Files.newOutputStream(newJarFile.toPath()))) {
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = connection.getInputStream().read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, length);
|
||||
}
|
||||
}
|
||||
LoggerX.info("更新下载完成");
|
||||
LoggerX.info("新版本:" + latest_release.tag_name);
|
||||
LoggerX.info("请删除旧版本插件,然后重启服务器。");
|
||||
LoggerX.info("================================");
|
||||
} catch (Exception e) {
|
||||
LoggerX.err("Failed to auto update: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String gitea_server;
|
||||
private String owner;
|
||||
private String repo;
|
||||
private JavaPlugin plugin;
|
||||
private String current_version;
|
||||
private GiteaRelease latest_release = null;
|
||||
private boolean auto_update = false;
|
||||
|
||||
private boolean isNewVersion(String current, String in_coming) {
|
||||
// 只保留数字和点号
|
||||
current = current.replaceAll("[^0-9.]", "");
|
||||
in_coming = in_coming.replaceAll("[^0-9.]", "");
|
||||
LoggerX.debug("Current version: " + current);
|
||||
LoggerX.debug("In-coming version: " + in_coming);
|
||||
String[] current_version = current.split("\\.");
|
||||
String[] in_coming_version = in_coming.split("\\.");
|
||||
for (int i = 0; i < Math.min(current_version.length, in_coming_version.length); i++) {
|
||||
int current_v = Integer.parseInt(current_version[i]);
|
||||
int in_coming_v = Integer.parseInt(in_coming_version[i]);
|
||||
if (current_v < in_coming_v) {
|
||||
return true;
|
||||
} else if (current_v > in_coming_v) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return current_version.length < in_coming_version.length;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package cn.lunadeer.liteworldedit.JobGenerator;
|
||||
|
||||
import cn.lunadeer.liteworldedit.Jobs.Absorb;
|
||||
import cn.lunadeer.liteworldedit.LiteWorldEdit;
|
||||
import cn.lunadeer.liteworldedit.Managers.Point;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Drain {
|
||||
public static void drain(Player player, World world, Point p1, Point p2) {
|
||||
for (int y = Math.max(p1.y, p2.y); y >= Math.min(p1.y, p2.y); y--) {
|
||||
for (int x = Math.min(p1.x, p2.x); x <= Math.max(p1.x, p2.x); x++) {
|
||||
for (int z = Math.min(p1.z, p2.z); z <= Math.max(p1.z, p2.z); z++) {
|
||||
Location location = new Location(world, (double) x, (double) y, (double) z);
|
||||
Absorb absorb_job = new Absorb(location, player);
|
||||
LiteWorldEdit.instance.getCache().getPlayer(player).addJob(absorb_job);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
package site.deercloud.liteworldedit.JobGenerator;
|
||||
package cn.lunadeer.liteworldedit.JobGenerator;
|
||||
|
||||
import cn.lunadeer.liteworldedit.Jobs.Remove;
|
||||
import cn.lunadeer.liteworldedit.LiteWorldEdit;
|
||||
import cn.lunadeer.liteworldedit.Managers.Point;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import site.deercloud.liteworldedit.Jobs.Remove;
|
||||
import site.deercloud.liteworldedit.LiteWorldEdit;
|
||||
import site.deercloud.liteworldedit.Managers.Point;
|
||||
|
||||
public class Empty {
|
||||
public static void empty(Player player, World world, Point p1, Point p2) {
|
@ -1,13 +1,12 @@
|
||||
package site.deercloud.liteworldedit.JobGenerator;
|
||||
package cn.lunadeer.liteworldedit.JobGenerator;
|
||||
|
||||
import cn.lunadeer.liteworldedit.Jobs.Place;
|
||||
import cn.lunadeer.liteworldedit.LiteWorldEdit;
|
||||
import cn.lunadeer.liteworldedit.Managers.Point;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import site.deercloud.liteworldedit.Jobs.Place;
|
||||
import site.deercloud.liteworldedit.LiteWorldEdit;
|
||||
import site.deercloud.liteworldedit.Managers.Point;
|
||||
|
||||
public class Fill {
|
||||
|
@ -1,13 +1,13 @@
|
||||
package site.deercloud.liteworldedit.JobGenerator;
|
||||
package cn.lunadeer.liteworldedit.JobGenerator;
|
||||
|
||||
import cn.lunadeer.liteworldedit.Jobs.Place;
|
||||
import cn.lunadeer.liteworldedit.LiteWorldEdit;
|
||||
import cn.lunadeer.liteworldedit.Managers.Point;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import site.deercloud.liteworldedit.Jobs.Place;
|
||||
import site.deercloud.liteworldedit.LiteWorldEdit;
|
||||
import site.deercloud.liteworldedit.Managers.Point;
|
||||
|
||||
public class OverLay {
|
||||
|
62
src/main/java/cn/lunadeer/liteworldedit/Jobs/Absorb.java
Normal file
62
src/main/java/cn/lunadeer/liteworldedit/Jobs/Absorb.java
Normal file
@ -0,0 +1,62 @@
|
||||
package cn.lunadeer.liteworldedit.Jobs;
|
||||
|
||||
import cn.lunadeer.liteworldedit.LoggerX;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Absorb extends Job {
|
||||
public Absorb(Location location, Player player) {
|
||||
super(player.getWorld(), location, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobErrCode Do() {
|
||||
Player _creator = this.get_creator();
|
||||
Location _location = this.get_location();
|
||||
World _world = this.get_world();
|
||||
// 超出距离
|
||||
if (!in_range(_creator, _location)) {
|
||||
LoggerX.debug("超出距离!");
|
||||
return JobErrCode.OUT_OF_RANGE;
|
||||
}
|
||||
Block raw_block = _world.getBlockAt(_location);
|
||||
// 跳过非流体
|
||||
if (!raw_block.isLiquid()) {
|
||||
LoggerX.debug("目标方块不是流体!");
|
||||
return JobErrCode.NOT_LIQUID;
|
||||
}
|
||||
HashMap<Integer, ?> sponge = _creator.getInventory().all(Material.SPONGE);
|
||||
if (sponge.size() == 0) {
|
||||
return JobErrCode.NO_SPONGE;
|
||||
}
|
||||
// 模拟海绵吸水事件
|
||||
BlockPlaceEvent event = new BlockPlaceEvent(raw_block, raw_block.getState(), raw_block, new ItemStack(Material.SPONGE), _creator, true, null);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
// 获取玩家背包中的下届合金镐
|
||||
HashMap<Integer, ?> pickaxes = getNetherPickaxes(_creator);
|
||||
if (pickaxes.size() == 0) {
|
||||
return JobErrCode.NO_PICKAXE;
|
||||
}
|
||||
ItemStack pickaxe = getUsableNetherPickaxe(pickaxes, _creator);
|
||||
// 没有合适的镐
|
||||
if (pickaxe == null) {
|
||||
return JobErrCode.NOT_ENOUGH_DURATION;
|
||||
}
|
||||
if (!event.isCancelled()) {
|
||||
raw_block.setType(Material.SPONGE);
|
||||
raw_block.setType(Material.AIR);
|
||||
// 损坏镐
|
||||
if (!_creator.isOp() && _creator.getGameMode() != GameMode.CREATIVE) {
|
||||
useNetherPickaxe(pickaxe);
|
||||
}
|
||||
return JobErrCode.OK;
|
||||
} else {
|
||||
return JobErrCode.NO_PERMISSION;
|
||||
}
|
||||
}
|
||||
}
|
121
src/main/java/cn/lunadeer/liteworldedit/Jobs/Job.java
Normal file
121
src/main/java/cn/lunadeer/liteworldedit/Jobs/Job.java
Normal file
@ -0,0 +1,121 @@
|
||||
package cn.lunadeer.liteworldedit.Jobs;
|
||||
|
||||
import cn.lunadeer.liteworldedit.LoggerX;
|
||||
import cn.lunadeer.liteworldedit.Notification;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Job {
|
||||
private final World _world;
|
||||
private final Location _location;
|
||||
private final Long _time;
|
||||
private final Player _creator;
|
||||
private final Inventory _inventory;
|
||||
|
||||
public Long get_time() {
|
||||
return _time;
|
||||
}
|
||||
|
||||
public Player get_creator() {
|
||||
return _creator;
|
||||
}
|
||||
|
||||
public Inventory get_inventory() {
|
||||
return _inventory;
|
||||
}
|
||||
|
||||
public Location get_location() {
|
||||
return _location;
|
||||
}
|
||||
|
||||
public World get_world() {
|
||||
return _world;
|
||||
}
|
||||
|
||||
public Job(World world, Location location, Player player) {
|
||||
_world = world;
|
||||
_location = location;
|
||||
_creator = player;
|
||||
_time = System.currentTimeMillis();
|
||||
_inventory = player.getInventory();
|
||||
}
|
||||
|
||||
public JobErrCode Do() {
|
||||
// nothing
|
||||
return JobErrCode.OK;
|
||||
}
|
||||
|
||||
static public Boolean in_range(Player player, Location location) {
|
||||
if (!player.getWorld().getName().equals(location.getWorld().getName())) {
|
||||
return false;
|
||||
}
|
||||
if (player.getLocation().distance(location) > 128) {
|
||||
Notification.error(player, "不允许超过128格操作!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, ?> getNetherPickaxes(Player player) {
|
||||
Inventory _inventory = player.getInventory();
|
||||
return _inventory.all(Material.NETHERITE_PICKAXE);
|
||||
}
|
||||
|
||||
public static ItemStack getUsableNetherPickaxe(HashMap<Integer, ?> pickaxes, Player player) {
|
||||
Inventory _inventory = player.getInventory();
|
||||
ItemStack pickaxe = null;
|
||||
Damageable pickaxe_damage = null;
|
||||
for (Integer index : pickaxes.keySet()) {
|
||||
ItemStack p = _inventory.getItem(index);
|
||||
if (p == null) {
|
||||
LoggerX.debug(index + " 获取到的下界合金镐为空!");
|
||||
continue;
|
||||
}
|
||||
ItemMeta pickaxe_meta = p.getItemMeta();
|
||||
if (pickaxe_meta == null) {
|
||||
LoggerX.debug(index + " 获取到的下界合金镐元数据为空!");
|
||||
continue;
|
||||
}
|
||||
if (!(pickaxe_meta instanceof Damageable)) {
|
||||
LoggerX.debug(index + " 无法转换为Damageable!");
|
||||
continue;
|
||||
}
|
||||
// 如果耐久小于10,提示玩家
|
||||
pickaxe_damage = (Damageable) pickaxe_meta;
|
||||
if (!pickaxe_meta.isUnbreakable()) {
|
||||
if (pickaxe_damage.getDamage() >= 2031 - 10) {
|
||||
LoggerX.debug(index + " 下界合金镐耐久太低!");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
pickaxe = p;
|
||||
break;
|
||||
}
|
||||
return pickaxe;
|
||||
}
|
||||
|
||||
public static ItemStack useNetherPickaxe(ItemStack pickaxe) {
|
||||
int durability = pickaxe.getEnchantmentLevel(Enchantment.DURABILITY);
|
||||
double random = Math.random();
|
||||
Damageable pickaxe_damage = (Damageable) pickaxe.getItemMeta();
|
||||
if (pickaxe_damage.isUnbreakable()) {
|
||||
// 无限耐久则不损坏
|
||||
return pickaxe;
|
||||
}
|
||||
if (random < 1.0 / (durability + 1)) {
|
||||
// 扣除耐久
|
||||
pickaxe_damage.setDamage(pickaxe_damage.getDamage() + 1);
|
||||
pickaxe.setItemMeta(pickaxe_damage);
|
||||
}
|
||||
return pickaxe;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package site.deercloud.liteworldedit.Jobs;
|
||||
package cn.lunadeer.liteworldedit.Jobs;
|
||||
|
||||
public enum JobErrCode {
|
||||
OK(0, ""), // 无错误
|
||||
@ -8,11 +8,13 @@ public enum JobErrCode {
|
||||
NOT_ENOUGH_DURATION(102, "所有下界合金镐耐久均不足10"),
|
||||
NOT_ENOUGH_ITEMS(103, "物品不足"),
|
||||
OUT_OF_RANGE(104, "超出操作距离"),
|
||||
NO_SPONGE(105, "没有海绵,无法排水"),
|
||||
|
||||
// ------------ 以下结果应当跳过任务 ------------
|
||||
NO_PERMISSION(201, "跳过没有权限操作的方块"),
|
||||
NOT_AIR_BLOCK(202, "跳过非空气方块"),
|
||||
NO_BREAKABLE(203, "跳过不可破坏方块"),
|
||||
NOT_LIQUID(204, "跳过非液体方块"),
|
||||
;
|
||||
|
||||
private final int value;
|
@ -1,5 +1,6 @@
|
||||
package site.deercloud.liteworldedit.Jobs;
|
||||
package cn.lunadeer.liteworldedit.Jobs;
|
||||
|
||||
import cn.lunadeer.liteworldedit.LoggerX;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.ShulkerBox;
|
||||
@ -9,7 +10,6 @@ import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||
import site.deercloud.liteworldedit.LoggerX;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -18,16 +18,16 @@ public class Place extends Job {
|
||||
|
||||
|
||||
public Place(Location location, Player player, Material material) {
|
||||
_world = player.getWorld();
|
||||
_location = location;
|
||||
_creator = player;
|
||||
_time = System.currentTimeMillis();
|
||||
super(player.getWorld(), location, player);
|
||||
_block = material;
|
||||
_inventory = player.getInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobErrCode Do() {
|
||||
Player _creator = this.get_creator();
|
||||
Location _location = this.get_location();
|
||||
World _world = this.get_world();
|
||||
Inventory _inventory = this.get_inventory();
|
||||
// 超出距离
|
||||
if (!in_range(_creator, _location)) {
|
||||
LoggerX.debug("超出距离!");
|
||||
@ -72,7 +72,9 @@ public class Place extends Job {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
raw_block.setType(_block);
|
||||
stack.setAmount(stack.getAmount() - 1);
|
||||
if (!_creator.isOp() && _creator.getGameMode() != GameMode.CREATIVE) {
|
||||
stack.setAmount(stack.getAmount() - 1);
|
||||
}
|
||||
return JobErrCode.OK;
|
||||
} else {
|
||||
return JobErrCode.NO_PERMISSION;
|
||||
@ -80,7 +82,44 @@ public class Place extends Job {
|
||||
}
|
||||
|
||||
private boolean moveBlockFromShulkerBoxToInv() {
|
||||
HashMap<Integer, ?> shulkerBoxes = _inventory.all(Material.SHULKER_BOX);
|
||||
Inventory _inventory = this.get_inventory();
|
||||
HashMap<Integer, ItemStack> shulkerBoxes = new HashMap<>();
|
||||
HashMap<Integer, ? extends ItemStack> plainShulkerBoxes = _inventory.all(Material.SHULKER_BOX);
|
||||
HashMap<Integer, ? extends ItemStack> whiteShulkerBoxes = _inventory.all(Material.WHITE_SHULKER_BOX);
|
||||
HashMap<Integer, ? extends ItemStack> orangeShulkerBoxes = _inventory.all(Material.ORANGE_SHULKER_BOX);
|
||||
HashMap<Integer, ? extends ItemStack> magentaShulkerBoxes = _inventory.all(Material.MAGENTA_SHULKER_BOX);
|
||||
HashMap<Integer, ? extends ItemStack> lightBlueShulkerBoxes = _inventory.all(Material.LIGHT_BLUE_SHULKER_BOX);
|
||||
HashMap<Integer, ? extends ItemStack> yellowShulkerBoxes = _inventory.all(Material.YELLOW_SHULKER_BOX);
|
||||
HashMap<Integer, ? extends ItemStack> limeShulkerBoxes = _inventory.all(Material.LIME_SHULKER_BOX);
|
||||
HashMap<Integer, ? extends ItemStack> pinkShulkerBoxes = _inventory.all(Material.PINK_SHULKER_BOX);
|
||||
HashMap<Integer, ? extends ItemStack> grayShulkerBoxes = _inventory.all(Material.GRAY_SHULKER_BOX);
|
||||
HashMap<Integer, ? extends ItemStack> lightGrayShulkerBoxes = _inventory.all(Material.LIGHT_GRAY_SHULKER_BOX);
|
||||
HashMap<Integer, ? extends ItemStack> cyanShulkerBoxes = _inventory.all(Material.CYAN_SHULKER_BOX);
|
||||
HashMap<Integer, ? extends ItemStack> purpleShulkerBoxes = _inventory.all(Material.PURPLE_SHULKER_BOX);
|
||||
HashMap<Integer, ? extends ItemStack> blueShulkerBoxes = _inventory.all(Material.BLUE_SHULKER_BOX);
|
||||
HashMap<Integer, ? extends ItemStack> brownShulkerBoxes = _inventory.all(Material.BROWN_SHULKER_BOX);
|
||||
HashMap<Integer, ? extends ItemStack> greenShulkerBoxes = _inventory.all(Material.GREEN_SHULKER_BOX);
|
||||
HashMap<Integer, ? extends ItemStack> redShulkerBoxes = _inventory.all(Material.RED_SHULKER_BOX);
|
||||
HashMap<Integer, ? extends ItemStack> blackShulkerBoxes = _inventory.all(Material.BLACK_SHULKER_BOX);
|
||||
|
||||
shulkerBoxes.putAll(plainShulkerBoxes);
|
||||
shulkerBoxes.putAll(whiteShulkerBoxes);
|
||||
shulkerBoxes.putAll(orangeShulkerBoxes);
|
||||
shulkerBoxes.putAll(magentaShulkerBoxes);
|
||||
shulkerBoxes.putAll(lightBlueShulkerBoxes);
|
||||
shulkerBoxes.putAll(yellowShulkerBoxes);
|
||||
shulkerBoxes.putAll(limeShulkerBoxes);
|
||||
shulkerBoxes.putAll(pinkShulkerBoxes);
|
||||
shulkerBoxes.putAll(grayShulkerBoxes);
|
||||
shulkerBoxes.putAll(lightGrayShulkerBoxes);
|
||||
shulkerBoxes.putAll(cyanShulkerBoxes);
|
||||
shulkerBoxes.putAll(purpleShulkerBoxes);
|
||||
shulkerBoxes.putAll(blueShulkerBoxes);
|
||||
shulkerBoxes.putAll(brownShulkerBoxes);
|
||||
shulkerBoxes.putAll(greenShulkerBoxes);
|
||||
shulkerBoxes.putAll(redShulkerBoxes);
|
||||
shulkerBoxes.putAll(blackShulkerBoxes);
|
||||
|
||||
for (Integer index : shulkerBoxes.keySet()) {
|
||||
LoggerX.debug("找到潜影盒:" + index);
|
||||
ItemStack itemStack = _inventory.getItem(index);
|
||||
@ -102,8 +141,12 @@ public class Place extends Job {
|
||||
if (item_idx == -1) {
|
||||
continue;
|
||||
}
|
||||
ItemStack i = boxInv.getItem(item_idx);
|
||||
if (i == null) {
|
||||
continue;
|
||||
}
|
||||
// 把物品放到玩家物品栏
|
||||
_inventory.addItem(boxInv.getItem(item_idx));
|
||||
_inventory.addItem(i);
|
||||
// 把潜影盒中的物品移除
|
||||
shulkerBox.getInventory().setItem(item_idx, null);
|
||||
// 更新潜影盒
|
65
src/main/java/cn/lunadeer/liteworldedit/Jobs/Remove.java
Normal file
65
src/main/java/cn/lunadeer/liteworldedit/Jobs/Remove.java
Normal file
@ -0,0 +1,65 @@
|
||||
package cn.lunadeer.liteworldedit.Jobs;
|
||||
|
||||
import cn.lunadeer.liteworldedit.LiteWorldEdit;
|
||||
import cn.lunadeer.liteworldedit.LoggerX;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Remove extends Job {
|
||||
|
||||
public Remove(Location location, Player player) {
|
||||
super(player.getWorld(), location, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobErrCode Do() {
|
||||
Player _creator = this.get_creator();
|
||||
Location _location = this.get_location();
|
||||
World _world = this.get_world();
|
||||
// 超出距离
|
||||
if (!in_range(_creator, _location)) {
|
||||
LoggerX.debug("超出距离!");
|
||||
return JobErrCode.OUT_OF_RANGE;
|
||||
}
|
||||
Block raw_block = _world.getBlockAt(_location);
|
||||
// 跳过不破坏的对象
|
||||
if (raw_block.isLiquid() || raw_block.isEmpty() || raw_block.getType().getHardness() == -1) {
|
||||
LoggerX.debug("目标方块是液体或空气或不可破坏!");
|
||||
return JobErrCode.NO_BREAKABLE;
|
||||
}
|
||||
// 获取玩家背包中的下届合金镐
|
||||
HashMap<Integer, ?> pickaxes = getNetherPickaxes(_creator);
|
||||
if (pickaxes.isEmpty()) {
|
||||
return JobErrCode.NO_PICKAXE;
|
||||
}
|
||||
ItemStack pickaxe = getUsableNetherPickaxe(pickaxes, _creator);
|
||||
// 没有合适的镐
|
||||
if (pickaxe == null) {
|
||||
return JobErrCode.NOT_ENOUGH_DURATION;
|
||||
}
|
||||
BlockBreakEvent event = new BlockBreakEvent(raw_block, _creator);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
Collection<ItemStack> drops = raw_block.getDrops(pickaxe, _creator);
|
||||
raw_block.setType(Material.AIR);
|
||||
if (LiteWorldEdit.instance.getConfigMgr().isDropItems()) {
|
||||
for (ItemStack drop : drops) {
|
||||
raw_block.getWorld().dropItemNaturally(raw_block.getLocation(), drop);
|
||||
}
|
||||
}
|
||||
// 损坏镐
|
||||
if (!_creator.isOp() && _creator.getGameMode() != GameMode.CREATIVE) {
|
||||
useNetherPickaxe(pickaxe);
|
||||
}
|
||||
return JobErrCode.OK;
|
||||
} else {
|
||||
return JobErrCode.NO_PERMISSION;
|
||||
}
|
||||
}
|
||||
}
|
62
src/main/java/cn/lunadeer/liteworldedit/LiteWorldEdit.java
Normal file
62
src/main/java/cn/lunadeer/liteworldedit/LiteWorldEdit.java
Normal file
@ -0,0 +1,62 @@
|
||||
package cn.lunadeer.liteworldedit;
|
||||
|
||||
import cn.lunadeer.liteworldedit.Managers.Cache;
|
||||
import cn.lunadeer.liteworldedit.Managers.ConfigManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class LiteWorldEdit extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
config = new ConfigManager();
|
||||
_cache = new Cache();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new Events(), this);
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("LiteWorldEdit")).setExecutor(new Commands());
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("LiteWorldEdit")).setTabCompleter(new Commands());
|
||||
|
||||
Metrics metrics = new Metrics(this, 21436);
|
||||
if (config.isCheckUpdate()) {
|
||||
giteaReleaseCheck = new GiteaReleaseCheck(this,
|
||||
"https://ssl.lunadeer.cn:14446",
|
||||
"zhangyuheng",
|
||||
"LiteWorldEdit");
|
||||
}
|
||||
|
||||
LoggerX.info("LiteWorldEdit 已加载");
|
||||
LoggerX.info("版本: " + getPluginMeta().getVersion());
|
||||
LoggerX.info("");
|
||||
// https://patorjk.com/software/taag/#p=display&f=Big&t=LiteWorldEdit
|
||||
LoggerX.info(" _ _ _ __ __ _ _ ______ _ _ _ ");
|
||||
LoggerX.info("| | (_) | \\ \\ / / | | | | ____| | (_) | ");
|
||||
LoggerX.info("| | _| |_ __\\ \\ /\\ / /__ _ __| | __| | |__ __| |_| |_ ");
|
||||
LoggerX.info("| | | | __/ _ \\\\/ \\/ / _ \\| '__| |/ _` | __| / _` | | __|");
|
||||
LoggerX.info("| |____| | || __/\\ /\\ / (_) | | | | (_| | |___| (_| | | |_ ");
|
||||
LoggerX.info("|______|_|\\__\\___| \\/ \\/ \\___/|_| |_|\\__,_|______\\__,_|_|\\__|");
|
||||
LoggerX.info("");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
|
||||
public ConfigManager getConfigMgr() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public Cache getCache() {
|
||||
return _cache;
|
||||
}
|
||||
|
||||
public static LiteWorldEdit instance;
|
||||
public static ConfigManager config;
|
||||
private Cache _cache;
|
||||
private GiteaReleaseCheck giteaReleaseCheck;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package site.deercloud.liteworldedit;
|
||||
package cn.lunadeer.liteworldedit;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -1,8 +1,7 @@
|
||||
package site.deercloud.liteworldedit.Managers;
|
||||
package cn.lunadeer.liteworldedit.Managers;
|
||||
|
||||
import cn.lunadeer.liteworldedit.XPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import site.deercloud.liteworldedit.Jobs.Job;
|
||||
import site.deercloud.liteworldedit.XPlayer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
@ -1,7 +1,7 @@
|
||||
package site.deercloud.liteworldedit.Managers;
|
||||
package cn.lunadeer.liteworldedit.Managers;
|
||||
|
||||
import cn.lunadeer.liteworldedit.LiteWorldEdit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import site.deercloud.liteworldedit.LiteWorldEdit;
|
||||
|
||||
public class ConfigManager {
|
||||
public ConfigManager() {
|
||||
@ -16,7 +16,10 @@ public class ConfigManager {
|
||||
_x_max = _file.getInt("MaxX", 64);
|
||||
_y_max = _file.getInt("MaxY", 64);
|
||||
_z_max = _file.getInt("MaxZ", 64);
|
||||
_multiplier = _file.getInt("Multiplier", 1);
|
||||
_drop_items = _file.getBoolean("DropItems", false);
|
||||
_check_update = _file.getBoolean("CheckUpdate", true);
|
||||
_plugin.saveConfig();
|
||||
}
|
||||
|
||||
public Boolean isDebug() {
|
||||
@ -45,6 +48,10 @@ public class ConfigManager {
|
||||
return _drop_items;
|
||||
}
|
||||
|
||||
public Integer getMultiplier() {
|
||||
return _multiplier;
|
||||
}
|
||||
|
||||
public void setDropItems(Boolean drop_items) {
|
||||
_drop_items = drop_items;
|
||||
_file.set("DropItems", drop_items);
|
||||
@ -62,6 +69,10 @@ public class ConfigManager {
|
||||
_plugin.saveConfig();
|
||||
}
|
||||
|
||||
public Boolean isCheckUpdate() {
|
||||
return _check_update;
|
||||
}
|
||||
|
||||
|
||||
private final LiteWorldEdit _plugin = LiteWorldEdit.instance;
|
||||
private FileConfiguration _file;
|
||||
@ -73,4 +84,8 @@ public class ConfigManager {
|
||||
private Integer _z_max;
|
||||
|
||||
private Boolean _drop_items;
|
||||
|
||||
private Integer _multiplier;
|
||||
|
||||
private Boolean _check_update;
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
package site.deercloud.liteworldedit.Managers;
|
||||
package cn.lunadeer.liteworldedit.Managers;
|
||||
|
||||
import cn.lunadeer.liteworldedit.Jobs.Job;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.entity.Player;
|
||||
import site.deercloud.liteworldedit.Jobs.Job;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
@ -20,6 +20,10 @@ public class JobQueue {
|
||||
int total = 0;
|
||||
|
||||
int ms_last_pop;
|
||||
int time_remain_count = 0;
|
||||
|
||||
int time_s_remaining = 0;
|
||||
int time_m_remaining = 0;
|
||||
|
||||
Player player;
|
||||
|
||||
@ -44,7 +48,6 @@ public class JobQueue {
|
||||
}
|
||||
Job job = queue.pop();
|
||||
updateBarProgressBar();
|
||||
ms_last_pop = (int) System.currentTimeMillis();
|
||||
return job;
|
||||
}
|
||||
|
||||
@ -76,11 +79,16 @@ public class JobQueue {
|
||||
|
||||
private void updateBarProgressBar() {
|
||||
bar.setProgress((total - queue.size()) * 1.0 / total);
|
||||
int delta_time_ms = (int) System.currentTimeMillis() - ms_last_pop;
|
||||
int time_s_remaining = queue.size() * delta_time_ms / 1000;
|
||||
int time_m_remaining = time_s_remaining / 60;
|
||||
int time_s_remaining_mod = time_s_remaining % 60;
|
||||
bar.setTitle("§a§lLiteWorldEdit [正在运行] 剩余任务: " + queue.size() + " 预计剩余时间: " + time_m_remaining + "分" + time_s_remaining_mod + "秒");
|
||||
time_remain_count++;
|
||||
if (time_remain_count >= 100) {
|
||||
time_remain_count = 0;
|
||||
int delta_time_ms = (int) System.currentTimeMillis() - ms_last_pop;
|
||||
time_s_remaining = queue.size() * delta_time_ms / 100 / 1000;
|
||||
time_m_remaining = time_s_remaining / 60;
|
||||
time_s_remaining = time_s_remaining % 60;
|
||||
ms_last_pop = (int) System.currentTimeMillis();
|
||||
}
|
||||
bar.setTitle("§a§lLiteWorldEdit [正在运行] 剩余任务: " + queue.size() + " 预计剩余时间: " + time_m_remaining + "分" + time_s_remaining + "秒");
|
||||
bar.setVisible(queue.size() != 0);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package site.deercloud.liteworldedit.Managers;
|
||||
package cn.lunadeer.liteworldedit.Managers;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
863
src/main/java/cn/lunadeer/liteworldedit/Metrics.java
Normal file
863
src/main/java/cn/lunadeer/liteworldedit/Metrics.java
Normal file
@ -0,0 +1,863 @@
|
||||
package cn.lunadeer.liteworldedit;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public class Metrics {
|
||||
private final Plugin plugin;
|
||||
|
||||
private final MetricsBase metricsBase;
|
||||
|
||||
/**
|
||||
* Creates a new Metrics instance.
|
||||
*
|
||||
* @param plugin Your plugin instance.
|
||||
* @param serviceId The id of the service. It can be found at <a
|
||||
* href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
|
||||
*/
|
||||
public Metrics(JavaPlugin plugin, int serviceId) {
|
||||
this.plugin = plugin;
|
||||
// Get the config file
|
||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||
File configFile = new File(bStatsFolder, "config.yml");
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||
if (!config.isSet("serverUuid")) {
|
||||
config.addDefault("enabled", true);
|
||||
config.addDefault("serverUuid", UUID.randomUUID().toString());
|
||||
config.addDefault("logFailedRequests", false);
|
||||
config.addDefault("logSentData", false);
|
||||
config.addDefault("logResponseStatusText", false);
|
||||
// Inform the server owners about bStats
|
||||
config
|
||||
.options()
|
||||
.header(
|
||||
"bStats (https://bStats.org) collects some basic information for plugin authors, like how\n"
|
||||
+ "many people use their plugin and their total player count. It's recommended to keep bStats\n"
|
||||
+ "enabled, but if you're not comfortable with this, you can turn this setting off. There is no\n"
|
||||
+ "performance penalty associated with having metrics enabled, and data sent to bStats is fully\n"
|
||||
+ "anonymous.")
|
||||
.copyDefaults(true);
|
||||
try {
|
||||
config.save(configFile);
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
// Load the data
|
||||
boolean enabled = config.getBoolean("enabled", true);
|
||||
String serverUUID = config.getString("serverUuid");
|
||||
boolean logErrors = config.getBoolean("logFailedRequests", false);
|
||||
boolean logSentData = config.getBoolean("logSentData", false);
|
||||
boolean logResponseStatusText = config.getBoolean("logResponseStatusText", false);
|
||||
metricsBase =
|
||||
new MetricsBase(
|
||||
"bukkit",
|
||||
serverUUID,
|
||||
serviceId,
|
||||
enabled,
|
||||
this::appendPlatformData,
|
||||
this::appendServiceData,
|
||||
null,
|
||||
//submitDataTask -> Bukkit.getScheduler().runTask(plugin, submitDataTask),
|
||||
plugin::isEnabled,
|
||||
(message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error),
|
||||
(message) -> this.plugin.getLogger().log(Level.INFO, message),
|
||||
logErrors,
|
||||
logSentData,
|
||||
logResponseStatusText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuts down the underlying scheduler service.
|
||||
*/
|
||||
public void shutdown() {
|
||||
metricsBase.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom chart.
|
||||
*
|
||||
* @param chart The chart to add.
|
||||
*/
|
||||
public void addCustomChart(CustomChart chart) {
|
||||
metricsBase.addCustomChart(chart);
|
||||
}
|
||||
|
||||
private void appendPlatformData(JsonObjectBuilder builder) {
|
||||
builder.appendField("playerAmount", getPlayerAmount());
|
||||
builder.appendField("onlineMode", Bukkit.getOnlineMode() ? 1 : 0);
|
||||
builder.appendField("bukkitVersion", Bukkit.getVersion());
|
||||
builder.appendField("bukkitName", Bukkit.getName());
|
||||
builder.appendField("javaVersion", System.getProperty("java.version"));
|
||||
builder.appendField("osName", System.getProperty("os.name"));
|
||||
builder.appendField("osArch", System.getProperty("os.arch"));
|
||||
builder.appendField("osVersion", System.getProperty("os.version"));
|
||||
builder.appendField("coreCount", Runtime.getRuntime().availableProcessors());
|
||||
}
|
||||
|
||||
private void appendServiceData(JsonObjectBuilder builder) {
|
||||
builder.appendField("pluginVersion", plugin.getDescription().getVersion());
|
||||
}
|
||||
|
||||
private int getPlayerAmount() {
|
||||
try {
|
||||
// Around MC 1.8 the return type was changed from an array to a collection,
|
||||
// This fixes java.lang.NoSuchMethodError:
|
||||
// org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
||||
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
||||
return onlinePlayersMethod.getReturnType().equals(Collection.class)
|
||||
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
||||
} catch (Exception e) {
|
||||
// Just use the new method if the reflection failed
|
||||
return Bukkit.getOnlinePlayers().size();
|
||||
}
|
||||
}
|
||||
|
||||
public static class MetricsBase {
|
||||
|
||||
/**
|
||||
* The version of the Metrics class.
|
||||
*/
|
||||
public static final String METRICS_VERSION = "3.0.2";
|
||||
|
||||
private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s";
|
||||
|
||||
private final ScheduledExecutorService scheduler;
|
||||
|
||||
private final String platform;
|
||||
|
||||
private final String serverUuid;
|
||||
|
||||
private final int serviceId;
|
||||
|
||||
private final Consumer<JsonObjectBuilder> appendPlatformDataConsumer;
|
||||
|
||||
private final Consumer<JsonObjectBuilder> appendServiceDataConsumer;
|
||||
|
||||
private final Consumer<Runnable> submitTaskConsumer;
|
||||
|
||||
private final Supplier<Boolean> checkServiceEnabledSupplier;
|
||||
|
||||
private final BiConsumer<String, Throwable> errorLogger;
|
||||
|
||||
private final Consumer<String> infoLogger;
|
||||
|
||||
private final boolean logErrors;
|
||||
|
||||
private final boolean logSentData;
|
||||
|
||||
private final boolean logResponseStatusText;
|
||||
|
||||
private final Set<CustomChart> customCharts = new HashSet<>();
|
||||
|
||||
private final boolean enabled;
|
||||
|
||||
/**
|
||||
* Creates a new MetricsBase class instance.
|
||||
*
|
||||
* @param platform The platform of the service.
|
||||
* @param serviceId The id of the service.
|
||||
* @param serverUuid The server uuid.
|
||||
* @param enabled Whether or not data sending is enabled.
|
||||
* @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and
|
||||
* appends all platform-specific data.
|
||||
* @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and
|
||||
* appends all service-specific data.
|
||||
* @param submitTaskConsumer A consumer that takes a runnable with the submit task. This can be
|
||||
* used to delegate the data collection to a another thread to prevent errors caused by
|
||||
* concurrency. Can be {@code null}.
|
||||
* @param checkServiceEnabledSupplier A supplier to check if the service is still enabled.
|
||||
* @param errorLogger A consumer that accepts log message and an error.
|
||||
* @param infoLogger A consumer that accepts info log messages.
|
||||
* @param logErrors Whether or not errors should be logged.
|
||||
* @param logSentData Whether or not the sent data should be logged.
|
||||
* @param logResponseStatusText Whether or not the response status text should be logged.
|
||||
*/
|
||||
public MetricsBase(
|
||||
String platform,
|
||||
String serverUuid,
|
||||
int serviceId,
|
||||
boolean enabled,
|
||||
Consumer<JsonObjectBuilder> appendPlatformDataConsumer,
|
||||
Consumer<JsonObjectBuilder> appendServiceDataConsumer,
|
||||
Consumer<Runnable> submitTaskConsumer,
|
||||
Supplier<Boolean> checkServiceEnabledSupplier,
|
||||
BiConsumer<String, Throwable> errorLogger,
|
||||
Consumer<String> infoLogger,
|
||||
boolean logErrors,
|
||||
boolean logSentData,
|
||||
boolean logResponseStatusText) {
|
||||
ScheduledThreadPoolExecutor scheduler =
|
||||
new ScheduledThreadPoolExecutor(1, task -> new Thread(task, "bStats-Metrics"));
|
||||
// We want delayed tasks (non-periodic) that will execute in the future to be
|
||||
// cancelled when the scheduler is shutdown.
|
||||
// Otherwise, we risk preventing the server from shutting down even when
|
||||
// MetricsBase#shutdown() is called
|
||||
scheduler.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
|
||||
this.scheduler = scheduler;
|
||||
this.platform = platform;
|
||||
this.serverUuid = serverUuid;
|
||||
this.serviceId = serviceId;
|
||||
this.enabled = enabled;
|
||||
this.appendPlatformDataConsumer = appendPlatformDataConsumer;
|
||||
this.appendServiceDataConsumer = appendServiceDataConsumer;
|
||||
this.submitTaskConsumer = submitTaskConsumer;
|
||||
this.checkServiceEnabledSupplier = checkServiceEnabledSupplier;
|
||||
this.errorLogger = errorLogger;
|
||||
this.infoLogger = infoLogger;
|
||||
this.logErrors = logErrors;
|
||||
this.logSentData = logSentData;
|
||||
this.logResponseStatusText = logResponseStatusText;
|
||||
checkRelocation();
|
||||
if (enabled) {
|
||||
// WARNING: Removing the option to opt-out will get your plugin banned from
|
||||
// bStats
|
||||
startSubmitting();
|
||||
}
|
||||
}
|
||||
|
||||
public void addCustomChart(CustomChart chart) {
|
||||
this.customCharts.add(chart);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
scheduler.shutdown();
|
||||
}
|
||||
|
||||
private void startSubmitting() {
|
||||
final Runnable submitTask =
|
||||
() -> {
|
||||
if (!enabled || !checkServiceEnabledSupplier.get()) {
|
||||
// Submitting data or service is disabled
|
||||
scheduler.shutdown();
|
||||
return;
|
||||
}
|
||||
if (submitTaskConsumer != null) {
|
||||
submitTaskConsumer.accept(this::submitData);
|
||||
} else {
|
||||
this.submitData();
|
||||
}
|
||||
};
|
||||
// Many servers tend to restart at a fixed time at xx:00 which causes an uneven
|
||||
// distribution of requests on the
|
||||
// bStats backend. To circumvent this problem, we introduce some randomness into
|
||||
// the initial and second delay.
|
||||
// WARNING: You must not modify and part of this Metrics class, including the
|
||||
// submit delay or frequency!
|
||||
// WARNING: Modifying this code will get your plugin banned on bStats. Just
|
||||
// don't do it!
|
||||
long initialDelay = (long) (1000 * 60 * (3 + Math.random() * 3));
|
||||
long secondDelay = (long) (1000 * 60 * (Math.random() * 30));
|
||||
scheduler.schedule(submitTask, initialDelay, TimeUnit.MILLISECONDS);
|
||||
scheduler.scheduleAtFixedRate(
|
||||
submitTask, initialDelay + secondDelay, 1000 * 60 * 30, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
private void submitData() {
|
||||
final JsonObjectBuilder baseJsonBuilder = new JsonObjectBuilder();
|
||||
appendPlatformDataConsumer.accept(baseJsonBuilder);
|
||||
final JsonObjectBuilder serviceJsonBuilder = new JsonObjectBuilder();
|
||||
appendServiceDataConsumer.accept(serviceJsonBuilder);
|
||||
JsonObjectBuilder.JsonObject[] chartData =
|
||||
customCharts.stream()
|
||||
.map(customChart -> customChart.getRequestJsonObject(errorLogger, logErrors))
|
||||
.filter(Objects::nonNull)
|
||||
.toArray(JsonObjectBuilder.JsonObject[]::new);
|
||||
serviceJsonBuilder.appendField("id", serviceId);
|
||||
serviceJsonBuilder.appendField("customCharts", chartData);
|
||||
baseJsonBuilder.appendField("service", serviceJsonBuilder.build());
|
||||
baseJsonBuilder.appendField("serverUUID", serverUuid);
|
||||
baseJsonBuilder.appendField("metricsVersion", METRICS_VERSION);
|
||||
JsonObjectBuilder.JsonObject data = baseJsonBuilder.build();
|
||||
scheduler.execute(
|
||||
() -> {
|
||||
try {
|
||||
// Send the data
|
||||
sendData(data);
|
||||
} catch (Exception e) {
|
||||
// Something went wrong! :(
|
||||
if (logErrors) {
|
||||
errorLogger.accept("Could not submit bStats metrics data", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void sendData(JsonObjectBuilder.JsonObject data) throws Exception {
|
||||
if (logSentData) {
|
||||
infoLogger.accept("Sent bStats metrics data: " + data.toString());
|
||||
}
|
||||
String url = String.format(REPORT_URL, platform);
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||
// Compress the data to save bandwidth
|
||||
byte[] compressedData = compress(data.toString());
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip");
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setRequestProperty("User-Agent", "Metrics-Service/1");
|
||||
connection.setDoOutput(true);
|
||||
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
||||
outputStream.write(compressedData);
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
try (BufferedReader bufferedReader =
|
||||
new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
}
|
||||
if (logResponseStatusText) {
|
||||
infoLogger.accept("Sent data to bStats and received response: " + builder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the class was properly relocated.
|
||||
*/
|
||||
private void checkRelocation() {
|
||||
// You can use the property to disable the check in your test environment
|
||||
if (System.getProperty("bstats.relocatecheck") == null
|
||||
|| !System.getProperty("bstats.relocatecheck").equals("false")) {
|
||||
// Maven's Relocate is clever and changes strings, too. So we have to use this
|
||||
// little "trick" ... :D
|
||||
final String defaultPackage =
|
||||
new String(new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'});
|
||||
final String examplePackage =
|
||||
new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
||||
// We want to make sure no one just copy & pastes the example and uses the wrong
|
||||
// package names
|
||||
if (MetricsBase.class.getPackage().getName().startsWith(defaultPackage)
|
||||
|| MetricsBase.class.getPackage().getName().startsWith(examplePackage)) {
|
||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given string.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped string.
|
||||
*/
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SimplePie extends CustomChart {
|
||||
|
||||
private final Callable<String> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimplePie(String chartId, Callable<String> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
String value = callable.call();
|
||||
if (value == null || value.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
return new JsonObjectBuilder().appendField("value", value).build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class MultiLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
// Skip this invalid
|
||||
continue;
|
||||
}
|
||||
allSkipped = false;
|
||||
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class AdvancedPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
// Skip this invalid
|
||||
continue;
|
||||
}
|
||||
allSkipped = false;
|
||||
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SimpleBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
valuesBuilder.appendField(entry.getKey(), new int[]{entry.getValue()});
|
||||
}
|
||||
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class AdvancedBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, int[]>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||
Map<String, int[]> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, int[]> entry : map.entrySet()) {
|
||||
if (entry.getValue().length == 0) {
|
||||
// Skip this invalid
|
||||
continue;
|
||||
}
|
||||
allSkipped = false;
|
||||
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class DrilldownPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Map<String, Integer>>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||
Map<String, Map<String, Integer>> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean reallyAllSkipped = true;
|
||||
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
|
||||
JsonObjectBuilder valueBuilder = new JsonObjectBuilder();
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
||||
valueBuilder.appendField(valueEntry.getKey(), valueEntry.getValue());
|
||||
allSkipped = false;
|
||||
}
|
||||
if (!allSkipped) {
|
||||
reallyAllSkipped = false;
|
||||
valuesBuilder.appendField(entryValues.getKey(), valueBuilder.build());
|
||||
}
|
||||
}
|
||||
if (reallyAllSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class CustomChart {
|
||||
|
||||
private final String chartId;
|
||||
|
||||
protected CustomChart(String chartId) {
|
||||
if (chartId == null) {
|
||||
throw new IllegalArgumentException("chartId must not be null");
|
||||
}
|
||||
this.chartId = chartId;
|
||||
}
|
||||
|
||||
public JsonObjectBuilder.JsonObject getRequestJsonObject(
|
||||
BiConsumer<String, Throwable> errorLogger, boolean logErrors) {
|
||||
JsonObjectBuilder builder = new JsonObjectBuilder();
|
||||
builder.appendField("chartId", chartId);
|
||||
try {
|
||||
JsonObjectBuilder.JsonObject data = getChartData();
|
||||
if (data == null) {
|
||||
// If the data is null we don't send the chart.
|
||||
return null;
|
||||
}
|
||||
builder.appendField("data", data);
|
||||
} catch (Throwable t) {
|
||||
if (logErrors) {
|
||||
errorLogger.accept("Failed to get data for custom chart with id " + chartId, t);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
protected abstract JsonObjectBuilder.JsonObject getChartData() throws Exception;
|
||||
}
|
||||
|
||||
public static class SingleLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Integer> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SingleLineChart(String chartId, Callable<Integer> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||
int value = callable.call();
|
||||
if (value == 0) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
return new JsonObjectBuilder().appendField("value", value).build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An extremely simple JSON builder.
|
||||
*
|
||||
* <p>While this class is neither feature-rich nor the most performant one, it's sufficient enough
|
||||
* for its use-case.
|
||||
*/
|
||||
public static class JsonObjectBuilder {
|
||||
|
||||
private StringBuilder builder = new StringBuilder();
|
||||
|
||||
private boolean hasAtLeastOneField = false;
|
||||
|
||||
public JsonObjectBuilder() {
|
||||
builder.append("{");
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a null field to the JSON.
|
||||
*
|
||||
* @param key The key of the field.
|
||||
* @return A reference to this object.
|
||||
*/
|
||||
public JsonObjectBuilder appendNull(String key) {
|
||||
appendFieldUnescaped(key, "null");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a string field to the JSON.
|
||||
*
|
||||
* @param key The key of the field.
|
||||
* @param value The value of the field.
|
||||
* @return A reference to this object.
|
||||
*/
|
||||
public JsonObjectBuilder appendField(String key, String value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException("JSON value must not be null");
|
||||
}
|
||||
appendFieldUnescaped(key, "\"" + escape(value) + "\"");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an integer field to the JSON.
|
||||
*
|
||||
* @param key The key of the field.
|
||||
* @param value The value of the field.
|
||||
* @return A reference to this object.
|
||||
*/
|
||||
public JsonObjectBuilder appendField(String key, int value) {
|
||||
appendFieldUnescaped(key, String.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an object to the JSON.
|
||||
*
|
||||
* @param key The key of the field.
|
||||
* @param object The object.
|
||||
* @return A reference to this object.
|
||||
*/
|
||||
public JsonObjectBuilder appendField(String key, JsonObject object) {
|
||||
if (object == null) {
|
||||
throw new IllegalArgumentException("JSON object must not be null");
|
||||
}
|
||||
appendFieldUnescaped(key, object.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a string array to the JSON.
|
||||
*
|
||||
* @param key The key of the field.
|
||||
* @param values The string array.
|
||||
* @return A reference to this object.
|
||||
*/
|
||||
public JsonObjectBuilder appendField(String key, String[] values) {
|
||||
if (values == null) {
|
||||
throw new IllegalArgumentException("JSON values must not be null");
|
||||
}
|
||||
String escapedValues =
|
||||
Arrays.stream(values)
|
||||
.map(value -> "\"" + escape(value) + "\"")
|
||||
.collect(Collectors.joining(","));
|
||||
appendFieldUnescaped(key, "[" + escapedValues + "]");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an integer array to the JSON.
|
||||
*
|
||||
* @param key The key of the field.
|
||||
* @param values The integer array.
|
||||
* @return A reference to this object.
|
||||
*/
|
||||
public JsonObjectBuilder appendField(String key, int[] values) {
|
||||
if (values == null) {
|
||||
throw new IllegalArgumentException("JSON values must not be null");
|
||||
}
|
||||
String escapedValues =
|
||||
Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining(","));
|
||||
appendFieldUnescaped(key, "[" + escapedValues + "]");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an object array to the JSON.
|
||||
*
|
||||
* @param key The key of the field.
|
||||
* @param values The integer array.
|
||||
* @return A reference to this object.
|
||||
*/
|
||||
public JsonObjectBuilder appendField(String key, JsonObject[] values) {
|
||||
if (values == null) {
|
||||
throw new IllegalArgumentException("JSON values must not be null");
|
||||
}
|
||||
String escapedValues =
|
||||
Arrays.stream(values).map(JsonObject::toString).collect(Collectors.joining(","));
|
||||
appendFieldUnescaped(key, "[" + escapedValues + "]");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a field to the object.
|
||||
*
|
||||
* @param key The key of the field.
|
||||
* @param escapedValue The escaped value of the field.
|
||||
*/
|
||||
private void appendFieldUnescaped(String key, String escapedValue) {
|
||||
if (builder == null) {
|
||||
throw new IllegalStateException("JSON has already been built");
|
||||
}
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("JSON key must not be null");
|
||||
}
|
||||
if (hasAtLeastOneField) {
|
||||
builder.append(",");
|
||||
}
|
||||
builder.append("\"").append(escape(key)).append("\":").append(escapedValue);
|
||||
hasAtLeastOneField = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the JSON string and invalidates this builder.
|
||||
*
|
||||
* @return The built JSON string.
|
||||
*/
|
||||
public JsonObject build() {
|
||||
if (builder == null) {
|
||||
throw new IllegalStateException("JSON has already been built");
|
||||
}
|
||||
JsonObject object = new JsonObject(builder.append("}").toString());
|
||||
builder = null;
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt.
|
||||
*
|
||||
* <p>This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'.
|
||||
* Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n").
|
||||
*
|
||||
* @param value The value to escape.
|
||||
* @return The escaped value.
|
||||
*/
|
||||
private static String escape(String value) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < value.length(); i++) {
|
||||
char c = value.charAt(i);
|
||||
if (c == '"') {
|
||||
builder.append("\\\"");
|
||||
} else if (c == '\\') {
|
||||
builder.append("\\\\");
|
||||
} else if (c <= '\u000F') {
|
||||
builder.append("\\u000").append(Integer.toHexString(c));
|
||||
} else if (c <= '\u001F') {
|
||||
builder.append("\\u00").append(Integer.toHexString(c));
|
||||
} else {
|
||||
builder.append(c);
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* A super simple representation of a JSON object.
|
||||
*
|
||||
* <p>This class only exists to make methods of the {@link JsonObjectBuilder} type-safe and not
|
||||
* allow a raw string inputs for methods like {@link JsonObjectBuilder#appendField(String,
|
||||
* JsonObject)}.
|
||||
*/
|
||||
public static class JsonObject {
|
||||
|
||||
private final String value;
|
||||
|
||||
private JsonObject(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
93
src/main/java/cn/lunadeer/liteworldedit/Notification.java
Normal file
93
src/main/java/cn/lunadeer/liteworldedit/Notification.java
Normal file
@ -0,0 +1,93 @@
|
||||
package cn.lunadeer.liteworldedit;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Notification {
|
||||
private static final Style i_style = Style.style(TextColor.color(139, 255, 123));
|
||||
private static final Style w_style = Style.style(TextColor.color(255, 185, 69));
|
||||
private static final Style e_style = Style.style(TextColor.color(255, 96, 72));
|
||||
|
||||
private static final String prefix = "[LWE] ";
|
||||
|
||||
public static void info(Player player, String msg) {
|
||||
player.sendMessage(Component.text(prefix + msg, i_style));
|
||||
}
|
||||
|
||||
public static void warn(Player player, String msg) {
|
||||
player.sendMessage(Component.text(prefix + msg, w_style));
|
||||
}
|
||||
|
||||
public static void error(Player player, String msg) {
|
||||
player.sendMessage(Component.text(prefix + msg, e_style));
|
||||
}
|
||||
|
||||
public static void info(CommandSender sender, String msg) {
|
||||
sender.sendMessage(Component.text(prefix + msg, i_style));
|
||||
}
|
||||
|
||||
public static void warn(CommandSender sender, String msg) {
|
||||
sender.sendMessage(Component.text(prefix + msg, w_style));
|
||||
}
|
||||
|
||||
public static void error(CommandSender sender, String msg) {
|
||||
sender.sendMessage(Component.text(prefix + msg, e_style));
|
||||
}
|
||||
|
||||
public static void info(Player player, Component msg) {
|
||||
player.sendMessage(Component.text(prefix, i_style).append(msg));
|
||||
if (LiteWorldEdit.config.isDebug())
|
||||
LoggerX.debug("来自玩家[ " + player.getName() + " ] 的提示 | " + msg);
|
||||
}
|
||||
|
||||
public static void warn(Player player, Component msg) {
|
||||
player.sendMessage(Component.text(prefix, w_style).append(msg));
|
||||
if (LiteWorldEdit.config.isDebug())
|
||||
LoggerX.debug("来自玩家[ " + player.getName() + " ] 的警告 | " + msg);
|
||||
}
|
||||
|
||||
public static void error(Player player, Component msg) {
|
||||
player.sendMessage(Component.text(prefix, e_style).append(msg));
|
||||
if (LiteWorldEdit.config.isDebug())
|
||||
LoggerX.debug("来自玩家[ " + player.getName() + " ] 的报错 | " + msg);
|
||||
}
|
||||
|
||||
public static void info(CommandSender player, Component msg) {
|
||||
player.sendMessage(Component.text(prefix, i_style).append(msg));
|
||||
}
|
||||
|
||||
public static void warn(CommandSender player, Component msg) {
|
||||
player.sendMessage(Component.text(prefix, w_style).append(msg));
|
||||
}
|
||||
|
||||
public static void error(CommandSender player, Component msg) {
|
||||
player.sendMessage(Component.text(prefix, e_style).append(msg));
|
||||
}
|
||||
|
||||
private static void sendTitle(Player player, Component title, Component subtitle) {
|
||||
Title title_t = Title.title(title, subtitle);
|
||||
player.showTitle(title_t);
|
||||
}
|
||||
|
||||
public static void titleInfo(Player player, String title, String subtitle) {
|
||||
Component title_c = Component.text(title, i_style);
|
||||
Component subtitle_c = Component.text(subtitle, i_style);
|
||||
sendTitle(player, title_c, subtitle_c);
|
||||
}
|
||||
|
||||
public static void titleWarn(Player player, String title, String subtitle) {
|
||||
Component title_c = Component.text(title, w_style);
|
||||
Component subtitle_c = Component.text(subtitle, w_style);
|
||||
sendTitle(player, title_c, subtitle_c);
|
||||
}
|
||||
|
||||
public static void titleError(Player player, String title, String subtitle) {
|
||||
Component title_c = Component.text(title, e_style);
|
||||
Component subtitle_c = Component.text(subtitle, e_style);
|
||||
sendTitle(player, title_c, subtitle_c);
|
||||
}
|
||||
}
|
51
src/main/java/cn/lunadeer/liteworldedit/ParticleRender.java
Normal file
51
src/main/java/cn/lunadeer/liteworldedit/ParticleRender.java
Normal file
@ -0,0 +1,51 @@
|
||||
package cn.lunadeer.liteworldedit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class ParticleRender {
|
||||
|
||||
public static void showBoxBorder(JavaPlugin plugin, String world, int x1, int y1, int z1, int x2, int y2, int z2) {
|
||||
showBoxBorder(plugin, new Location(plugin.getServer().getWorld(world), x1, y1, z1),
|
||||
new Location(plugin.getServer().getWorld(world), x2, y2, z2));
|
||||
}
|
||||
|
||||
public static void showBoxBorder(JavaPlugin plugin, Location loc1, Location loc2) {
|
||||
plugin.getServer().getGlobalRegionScheduler().run(LiteWorldEdit.instance, (instance) -> {
|
||||
if (!loc1.getWorld().equals(loc2.getWorld())) {
|
||||
return;
|
||||
}
|
||||
int minX = Math.min(loc1.getBlockX(), loc2.getBlockX());
|
||||
int minY = Math.min(loc1.getBlockY(), loc2.getBlockY());
|
||||
int minZ = Math.min(loc1.getBlockZ(), loc2.getBlockZ());
|
||||
int maxX = Math.max(loc1.getBlockX(), loc2.getBlockX()) + 1;
|
||||
int maxY = Math.max(loc1.getBlockY(), loc2.getBlockY()) + 1;
|
||||
int maxZ = Math.max(loc1.getBlockZ(), loc2.getBlockZ()) + 1;
|
||||
World world = loc1.getWorld();
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
spawnParticle(world, x, minY, minZ);
|
||||
spawnParticle(world, x, minY, maxZ);
|
||||
spawnParticle(world, x, maxY, minZ);
|
||||
spawnParticle(world, x, maxY, maxZ);
|
||||
}
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
spawnParticle(world, minX, y, minZ);
|
||||
spawnParticle(world, minX, y, maxZ);
|
||||
spawnParticle(world, maxX, y, minZ);
|
||||
spawnParticle(world, maxX, y, maxZ);
|
||||
}
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
spawnParticle(world, minX, minY, z);
|
||||
spawnParticle(world, minX, maxY, z);
|
||||
spawnParticle(world, maxX, minY, z);
|
||||
spawnParticle(world, maxX, maxY, z);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void spawnParticle(World world, double x, double y, double z) {
|
||||
world.spawnParticle(Particle.FLAME, x, y, z, 10, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
package site.deercloud.liteworldedit;
|
||||
package cn.lunadeer.liteworldedit;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class SchedulerUtil {
|
||||
|
63
src/main/java/cn/lunadeer/liteworldedit/Task.java
Normal file
63
src/main/java/cn/lunadeer/liteworldedit/Task.java
Normal file
@ -0,0 +1,63 @@
|
||||
package cn.lunadeer.liteworldedit;
|
||||
|
||||
import cn.lunadeer.liteworldedit.Jobs.Job;
|
||||
import cn.lunadeer.liteworldedit.Jobs.JobErrCode;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Task implements Runnable {
|
||||
/**
|
||||
* When an object implementing interface {@code Runnable} is used
|
||||
* to create a thread, starting the thread causes the object's
|
||||
* {@code run} method to be called in that separately executing
|
||||
* thread.
|
||||
* <p>
|
||||
* The general contract of the method {@code run} is that it may
|
||||
* take any action whatsoever.
|
||||
*
|
||||
* @see Thread#run()
|
||||
*/
|
||||
|
||||
private final XPlayer xPlayer;
|
||||
|
||||
Task(XPlayer player) {
|
||||
this.xPlayer = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < LiteWorldEdit.config.getMultiplier(); i++) {
|
||||
Job job = this.xPlayer.popJob();
|
||||
if (job == null) {
|
||||
return;
|
||||
}
|
||||
// 如果任务不可执行 允许在一个tick内多次执行直到任务可执行
|
||||
int max_retries = 100;
|
||||
JobErrCode re;
|
||||
while ((re = job.Do()) != JobErrCode.OK) {
|
||||
max_retries--;
|
||||
if (max_retries <= 0) {
|
||||
break;
|
||||
}
|
||||
Player player = job.get_creator();
|
||||
if (re.canContinue()) {
|
||||
TextComponent warn = Component.text("警告:" + re.getMessage(), Style.style(TextColor.color(TextColor.color(255, 185, 69)), TextDecoration.BOLD));
|
||||
player.sendActionBar(warn);
|
||||
job = this.xPlayer.popJob();
|
||||
if (job == null) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Notification.titleError(player, "错误 任务已自动暂停", re.getMessage());
|
||||
this.xPlayer.addJob(job); // 任务暂停 将没有执行的任务重新加入队列
|
||||
this.xPlayer.pauseJob();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +1,25 @@
|
||||
package site.deercloud.liteworldedit;
|
||||
package cn.lunadeer.liteworldedit;
|
||||
|
||||
import cn.lunadeer.liteworldedit.Jobs.Job;
|
||||
import cn.lunadeer.liteworldedit.Managers.JobQueue;
|
||||
import cn.lunadeer.liteworldedit.Managers.Point;
|
||||
import org.bukkit.entity.Player;
|
||||
import site.deercloud.liteworldedit.Jobs.Job;
|
||||
import site.deercloud.liteworldedit.Managers.JobQueue;
|
||||
import site.deercloud.liteworldedit.Managers.Point;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static site.deercloud.liteworldedit.SchedulerUtil.runAtFixedRateEntity;
|
||||
import static cn.lunadeer.liteworldedit.SchedulerUtil.runAtFixedRateEntity;
|
||||
|
||||
public class XPlayer {
|
||||
|
||||
private boolean select_mode = false;
|
||||
private final Map<Integer, Point> points;
|
||||
private final Player player;
|
||||
private final JobQueue queue;
|
||||
private final Task task;
|
||||
|
||||
public XPlayer(Player player) {
|
||||
Notification.info(player, "当前选点模式: 关闭");
|
||||
this.player = player;
|
||||
this.points = new HashMap<>();
|
||||
this.queue = new JobQueue(player);
|
||||
@ -25,6 +27,20 @@ public class XPlayer {
|
||||
runAtFixedRateEntity(player, LiteWorldEdit.instance, task, 1);
|
||||
}
|
||||
|
||||
public boolean isSelectMode() {
|
||||
return select_mode;
|
||||
}
|
||||
|
||||
public void toggleSelectMode() {
|
||||
select_mode = !select_mode;
|
||||
if (select_mode) {
|
||||
Notification.info(player, "当前选点模式: 开启");
|
||||
Notification.info(player, "左键选择第一个点, 右键选择第二个点");
|
||||
} else {
|
||||
Notification.info(player, "当前选点模式: 关闭");
|
||||
}
|
||||
}
|
||||
|
||||
public void addJob(Job job) {
|
||||
queue.add(job);
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package site.deercloud.liteworldedit;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class Events implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
LiteWorldEdit.instance.getCache().playerQuit(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
LiteWorldEdit.instance.getCache().playerJoin(event.getPlayer());
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package site.deercloud.liteworldedit.Jobs;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import site.deercloud.liteworldedit.Notification;
|
||||
|
||||
public class Job {
|
||||
protected World _world;
|
||||
protected Location _location;
|
||||
protected Long _time;
|
||||
protected Player _creator;
|
||||
protected Inventory _inventory;
|
||||
|
||||
public Long get_time() {
|
||||
return _time;
|
||||
}
|
||||
|
||||
public Player get_creator() {
|
||||
return _creator;
|
||||
}
|
||||
|
||||
public JobErrCode Do() {
|
||||
// nothing
|
||||
return JobErrCode.OK;
|
||||
}
|
||||
|
||||
static public Boolean in_range(Player player, Location location) {
|
||||
if (!player.getWorld().getName().equals(location.getWorld().getName())) {
|
||||
return false;
|
||||
}
|
||||
if (player.getLocation().distance(location) > 128) {
|
||||
Notification.error(player, "不允许超过128格操作!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
package site.deercloud.liteworldedit.Jobs;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import site.deercloud.liteworldedit.LiteWorldEdit;
|
||||
import site.deercloud.liteworldedit.LoggerX;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Remove extends Job {
|
||||
|
||||
public Remove(Location location, Player player) {
|
||||
_world = player.getWorld();
|
||||
_location = location;
|
||||
_creator = player;
|
||||
_time = System.currentTimeMillis();
|
||||
_inventory = player.getInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobErrCode Do() {
|
||||
// 超出距离
|
||||
if (!in_range(_creator, _location)) {
|
||||
LoggerX.debug("超出距离!");
|
||||
return JobErrCode.OUT_OF_RANGE;
|
||||
}
|
||||
Block raw_block = _world.getBlockAt(_location);
|
||||
// 跳过不破坏的对象
|
||||
if (raw_block.isLiquid() || raw_block.isEmpty() || raw_block.getType().getHardness() == -1) {
|
||||
LoggerX.debug("目标方块是液体或空气或不可破坏!");
|
||||
return JobErrCode.NO_BREAKABLE;
|
||||
}
|
||||
// 获取玩家背包中的下届合金镐
|
||||
HashMap<Integer, ?> pickaxes = _inventory.all(Material.NETHERITE_PICKAXE);
|
||||
if (pickaxes.size() == 0) {
|
||||
return JobErrCode.NO_PICKAXE;
|
||||
}
|
||||
ItemStack pickaxe = null;
|
||||
Damageable pickaxe_damage = null;
|
||||
for (Integer index : pickaxes.keySet()) {
|
||||
ItemStack p = _inventory.getItem(index);
|
||||
if (p == null) {
|
||||
LoggerX.debug(index + " 获取到的下界合金镐为空!");
|
||||
continue;
|
||||
}
|
||||
ItemMeta pickaxe_meta = p.getItemMeta();
|
||||
if (pickaxe_meta == null) {
|
||||
LoggerX.debug(index + " 获取到的下界合金镐元数据为空!");
|
||||
continue;
|
||||
}
|
||||
if (!(pickaxe_meta instanceof Damageable)) {
|
||||
LoggerX.debug(index + " 无法转换为Damageable!");
|
||||
continue;
|
||||
}
|
||||
// 如果耐久小于10,提示玩家
|
||||
pickaxe_damage = (Damageable) pickaxe_meta;
|
||||
if (pickaxe_damage.getDamage() >= 2031 - 10) {
|
||||
LoggerX.debug(index + " 下界合金镐耐久太低!");
|
||||
continue;
|
||||
}
|
||||
pickaxe = p;
|
||||
break;
|
||||
}
|
||||
// 没有合适的镐
|
||||
if (pickaxe == null) {
|
||||
return JobErrCode.NOT_ENOUGH_DURATION;
|
||||
}
|
||||
BlockBreakEvent event = new BlockBreakEvent(raw_block, _creator);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
raw_block.setType(Material.AIR);
|
||||
if (LiteWorldEdit.instance.getConfigMgr().isDropItems()) {
|
||||
raw_block.getWorld().dropItemNaturally(raw_block.getLocation(), new ItemStack(raw_block.getType()));
|
||||
}
|
||||
// 获取耐久附魔
|
||||
int durability = pickaxe.getEnchantmentLevel(Enchantment.DURABILITY);
|
||||
double random = Math.random();
|
||||
if (random < 1.0 / (durability + 1)) {
|
||||
// 扣除耐久
|
||||
pickaxe_damage.setDamage(pickaxe_damage.getDamage() + 1);
|
||||
pickaxe.setItemMeta((ItemMeta) pickaxe_damage);
|
||||
}
|
||||
return JobErrCode.OK;
|
||||
} else {
|
||||
return JobErrCode.NO_PERMISSION;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package site.deercloud.liteworldedit;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import site.deercloud.liteworldedit.Managers.Cache;
|
||||
import site.deercloud.liteworldedit.Managers.ConfigManager;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class LiteWorldEdit extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
_config = new ConfigManager();
|
||||
_cache = new Cache();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new Events(), this);
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("LiteWorldEdit")).setExecutor(new Commands());
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("LiteWorldEdit")).setTabCompleter(new Commands());
|
||||
|
||||
String logo = "LiteWorldEdit 已加载 版本: " + getPluginMeta().getVersion() + "\n";
|
||||
// https://patorjk.com/software/taag/#p=display&f=Big&t=LiteWorldEdit
|
||||
logo += " _ _ _ __ __ _ _ ______ _ _ _ \n";
|
||||
logo += "| | (_) | \\ \\ / / | | | | ____| | (_) | \n";
|
||||
logo += "| | _| |_ __\\ \\ /\\ / /__ _ __| | __| | |__ __| |_| |_ \n";
|
||||
logo += "| | | | __/ _ \\\\/ \\/ / _ \\| '__| |/ _` | __| / _` | | __|\n";
|
||||
logo += "| |____| | || __/\\ /\\ / (_) | | | | (_| | |___| (_| | | |_ \n";
|
||||
logo += "|______|_|\\__\\___| \\/ \\/ \\___/|_| |_|\\__,_|______\\__,_|_|\\__|\n";
|
||||
logo += "\n";
|
||||
LoggerX.info(logo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
|
||||
public ConfigManager getConfigMgr() {
|
||||
return _config;
|
||||
}
|
||||
|
||||
public Cache getCache() {
|
||||
return _cache;
|
||||
}
|
||||
|
||||
public static LiteWorldEdit instance;
|
||||
private ConfigManager _config;
|
||||
private Cache _cache;
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package site.deercloud.liteworldedit;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Notification {
|
||||
private static final Style i_style = Style.style(TextColor.color(139, 255, 123));
|
||||
private static final Style w_style = Style.style(TextColor.color(255, 185, 69));
|
||||
private static final Style e_style = Style.style(TextColor.color(255, 96, 72));
|
||||
|
||||
public static void info(Player player, String msg) {
|
||||
player.sendMessage(Component.text("[LWE] " + msg, i_style));
|
||||
}
|
||||
|
||||
|
||||
public static void warn(Player player, String msg) {
|
||||
player.sendMessage(Component.text("[LWE] " + msg, w_style));
|
||||
}
|
||||
|
||||
public static void error(Player player, String msg) {
|
||||
player.sendMessage(Component.text("[LWE] " + msg, e_style));
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
package site.deercloud.liteworldedit;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import site.deercloud.liteworldedit.Jobs.Job;
|
||||
import site.deercloud.liteworldedit.Jobs.JobErrCode;
|
||||
|
||||
public class Task implements Runnable{
|
||||
/**
|
||||
* When an object implementing interface {@code Runnable} is used
|
||||
* to create a thread, starting the thread causes the object's
|
||||
* {@code run} method to be called in that separately executing
|
||||
* thread.
|
||||
* <p>
|
||||
* The general contract of the method {@code run} is that it may
|
||||
* take any action whatsoever.
|
||||
*
|
||||
* @see Thread#run()
|
||||
*/
|
||||
|
||||
private final XPlayer xPlayer;
|
||||
|
||||
Task(XPlayer player) {
|
||||
this.xPlayer = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Job job = this.xPlayer.popJob();
|
||||
if (job == null) {
|
||||
return;
|
||||
}
|
||||
// 如果任务不可执行 允许在一个tick内多次执行直到任务可执行
|
||||
int max_retries = 100;
|
||||
JobErrCode re;
|
||||
while ((re = job.Do()) != JobErrCode.OK) {
|
||||
max_retries--;
|
||||
if (max_retries <= 0) {
|
||||
break;
|
||||
}
|
||||
if (re.canContinue()) {
|
||||
job.get_creator().sendTitle("§e警告", "§e" + re.getMessage(), 10, 70, 20);
|
||||
job = this.xPlayer.popJob();
|
||||
if (job == null) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Player player = job.get_creator();
|
||||
player.sendTitle("§c错误 任务已自动暂停", "§c" + re.getMessage(), 10, 70, 20);
|
||||
this.xPlayer.pauseJob();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,10 @@ MaxY: 64
|
||||
|
||||
MaxZ: 64
|
||||
|
||||
Multiplier: 1
|
||||
|
||||
DropItems: false
|
||||
|
||||
CheckUpdate: true
|
||||
|
||||
Debug: false
|
@ -1,15 +1,21 @@
|
||||
name: LiteWorldEdit
|
||||
version: '${project.version}'
|
||||
main: site.deercloud.liteworldedit.LiteWorldEdit
|
||||
main: cn.lunadeer.liteworldedit.LiteWorldEdit
|
||||
api-version: 1.14
|
||||
prefix: LWE
|
||||
load: STARTUP
|
||||
authors: [ Luming ]
|
||||
description: 生存用简易创世神。
|
||||
website: https://blog.deercloud.site
|
||||
website: https://ssl.lunadeer.cn:14448/project-2/
|
||||
folia-supported: true
|
||||
commands:
|
||||
LiteWorldEdit:
|
||||
description: 简易创世神命令
|
||||
usage: /lwe <cmd>
|
||||
aliases: [lwe]
|
||||
aliases: [ lwe ]
|
||||
permission: lwe.command
|
||||
permission-message: 你没有权限使用这个命令。
|
||||
permissions:
|
||||
lwe.command:
|
||||
description: 是否允许使用 LiteWorldEdit
|
||||
default: true
|
Loading…
Reference in New Issue
Block a user