Compare commits
No commits in common. "master" and "v2.3.5.6" have entirely different histories.
@ -9,35 +9,34 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: "Pull & Checkout"
|
- name: "Pull & Checkout"
|
||||||
uses: https://ssl.lunadeer.cn:14446/actions/checkout@v3
|
uses: https://ssl.lunadeer.cn:14446/actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: "Set up Maven"
|
- name: "Set up Maven"
|
||||||
uses: https://ssl.lunadeer.cn:14446/actions/setup-maven@v4
|
uses: https://ssl.lunadeer.cn:14446/actions/setup-maven@v4
|
||||||
- name: "Set up JDK 17"
|
- name: "Set up JDK 17"
|
||||||
uses: https://ssl.lunadeer.cn:14446/actions/setup-java@v3
|
uses: https://ssl.lunadeer.cn:14446/actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
java-version: '17'
|
java-version: '17'
|
||||||
distribution: 'zulu'
|
distribution: 'zulu'
|
||||||
cache: maven
|
cache: maven
|
||||||
- name: "Build with Maven"
|
- name: "Build with Maven"
|
||||||
run: mvn -B package --file pom.xml
|
run: mvn -B package --file pom.xml
|
||||||
- name: "Copy jar to staging"
|
- name: "Copy jar to staging"
|
||||||
run: mkdir staging && cp target/*.jar staging
|
run: mkdir staging && cp target/*.jar staging
|
||||||
- name: "Build & test"
|
- name: "Build & test"
|
||||||
run: |
|
run: |
|
||||||
echo "done!"
|
echo "done!"
|
||||||
- name: "setup go for release script"
|
- name: "setup go for release script"
|
||||||
run: |
|
run: |
|
||||||
wget --no-check-certificate https://golang.google.cn/dl/go1.21.6.linux-amd64.tar.gz
|
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
|
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
|
ln -s /usr/local/go/bin/go /usr/bin/go
|
||||||
go version
|
go version
|
||||||
- name: "Release"
|
- name: "Release"
|
||||||
uses: https://ssl.lunadeer.cn:14446/zhangyuheng/release-action@main
|
uses: https://ssl.lunadeer.cn:14446/actions/release-action@main
|
||||||
with:
|
with:
|
||||||
note: "带 `original-` 前缀的文件无法用于运行,请下载不带此前缀的版本。"
|
files: |-
|
||||||
files: |-
|
staging/*.jar
|
||||||
staging/*.jar
|
api_key: '${{secrets.RELEASE_TOKEN}}'
|
||||||
api_key: '${{secrets.RELEASE_TOKEN}}'
|
|
108
README.md
108
README.md
@ -1,13 +1,8 @@
|
|||||||
|
# LiteWorldEdit
|
||||||
|
|
||||||
<div style="text-align: center;">
|
开源地址:[Gitea](https://ssl.lunadeer.cn:14446/zhangyuheng/LiteWorldEdit)
|
||||||
|
|
||||||
<img src="https://ssl.lunadeer.cn:14437/i/2024/03/28/6604dfebcffd8.png" alt="" width="70%">
|
文档地址:[Doc](https://ssl.lunadeer.cn:14448/doc/3/)
|
||||||
|
|
||||||
### [开源地址](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>
|
|
||||||
|
|
||||||
## 轻量创世神
|
## 轻量创世神
|
||||||
|
|
||||||
@ -33,80 +28,47 @@
|
|||||||
2. 使用破坏操作需要拥有下届合金镐(作为一种使用门槛),并且消耗耐久度,同时支持耐久附魔效果;
|
2. 使用破坏操作需要拥有下届合金镐(作为一种使用门槛),并且消耗耐久度,同时支持耐久附魔效果;
|
||||||
3. 当合金镐耐久度不足10时会自动终止任务(暂不支持恢复);
|
3. 当合金镐耐久度不足10时会自动终止任务(暂不支持恢复);
|
||||||
4. 支持填充操作,填充操作需要消耗玩家物品栏中的物品;
|
4. 支持填充操作,填充操作需要消耗玩家物品栏中的物品;
|
||||||
5. 支持自动从背包中的盒子里提取物品;
|
5. 禁止超视距操作(128以外),防止玩家利用创世神插件加载大量区块导致服务器卡顿;
|
||||||
6. 禁止超视距操作(128以外),防止玩家利用创世神插件加载大量区块导致服务器卡顿;
|
6. 支持自动从背包里的潜影盒补充材料;
|
||||||
7. 支持自动从背包里的潜影盒补充材料;
|
7. 支持设置是否产生掉落物;
|
||||||
8. 支持设置是否产生掉落物;
|
8. 支持设置速度倍率(整数,默认1表示每tick操作一个方块,设置为2则每次操作两个方块)
|
||||||
9. 支持设置速度倍率(整数,默认1表示每tick操作一个方块,设置为2则每次操作两个方块)
|
|
||||||
10. 选区可视
|
|
||||||
|
|
||||||
## 支持版本
|
## 支持版本
|
||||||
|
|
||||||
- 1.20.1+ (Folia、Paper)
|
- 1.20.1+ (Folia Paper)
|
||||||
|
|
||||||
## 安装方法
|
## 使用方法
|
||||||
|
|
||||||
1. 将插件放入服务器# 标题的 `plugins` 目录下
|
1. 将插件放入服务器的 `plugins` 目录下
|
||||||
2. 重启服务器
|
2. 重启服务器
|
||||||
3. 在 `plugins/LiteWorldEdit/config.yml` 中配置
|
3. 在 `plugins/LiteWorldEdit/config.yml` 中配置
|
||||||
4. 控制台或OP输入 `/lwe reload` 重载配置
|
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` | 恢复所有任务 |
|
|
||||||
|
|
||||||
> 选区操作不填写点序号则默认使用 1 号 2 号点构成的区域。
|
`/lwe point [点序号(整数)] [x] [y] [z]` 创建点
|
||||||
|
|
||||||
### 管理员指令
|
`/lwe p [点序号(整数)] [x] [y] [z]` 创建点
|
||||||
|
|
||||||
| 指令 | 功能描述 |
|
`/lwe points` 查看当前添加的所有点
|
||||||
|---------------|------|
|
|
||||||
| `/lwe reload` | 重载配置 |
|
`/lwe fill [点序号A] [点序号B]` 在AB点对角线间放置方块 - 需要手持被放置的方块
|
||||||
|
|
||||||
|
`/lwe empty [点序号A] [点序号B]` 破坏AB点对角线间方块 - 需要拥有下届合金镐
|
||||||
|
|
||||||
|
`/lwe overlay [点序号A] [点序号B]` 在选区地面上铺一层方块 - 需要手持被放置的方块
|
||||||
|
|
||||||
|
`/lwe cancel` 取消(终止)所有任务
|
||||||
|
|
||||||
|
`/lwe pause` 暂停所有任务
|
||||||
|
|
||||||
|
`/lwe resume` 恢复所有任务
|
||||||
|
|
||||||
|
`/lwe reload` 重载配置(仅管理员)
|
||||||
|
|
||||||
## 配置文件参考
|
## 配置文件参考
|
||||||
|
|
||||||
@ -121,8 +83,6 @@ DropItems: false
|
|||||||
|
|
||||||
Multiplier: 1
|
Multiplier: 1
|
||||||
|
|
||||||
CheckUpdate: true
|
|
||||||
|
|
||||||
Debug: false
|
Debug: false
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -130,18 +90,8 @@ Debug: false
|
|||||||
|
|
||||||
- [X] 从潜影盒中自动补充材料
|
- [X] 从潜影盒中自动补充材料
|
||||||
|
|
||||||
- [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">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>cn.lunadeer</groupId>
|
<groupId>site.deercloud</groupId>
|
||||||
<artifactId>LiteWorldEdit</artifactId>
|
<artifactId>LiteWorldEdit</artifactId>
|
||||||
<version>2.5.0.1</version>
|
<version>2.3.5.6</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>LiteWorldEdit</name>
|
<name>LiteWorldEdit</name>
|
||||||
@ -16,7 +16,7 @@
|
|||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
<url>https://ssl.lunadeer.cn:14448/project-2/</url>
|
<url>https://blog.deercloud.site</url>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 9.9 KiB |
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 14 KiB |
Binary file not shown.
Before Width: | Height: | Size: 48 KiB |
@ -1,71 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,199 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
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,62 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,863 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
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,12 +1,5 @@
|
|||||||
package cn.lunadeer.liteworldedit;
|
package site.deercloud.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.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -15,6 +8,11 @@ import org.bukkit.command.TabExecutor;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
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.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -28,26 +26,16 @@ public class Commands implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (Objects.equals(args[0], "point") || Objects.equals(args[0], "p")) {
|
if (Objects.equals(args[0], "point") || Objects.equals(args[0], "p")) {
|
||||||
addPoint(sender, args);
|
return addPoint(sender, args);
|
||||||
return true;
|
|
||||||
} else if (Objects.equals(args[0], "select")) {
|
|
||||||
selectModeToggle(sender, args);
|
|
||||||
return true;
|
|
||||||
} else if (Objects.equals(args[0], "points")) {
|
} else if (Objects.equals(args[0], "points")) {
|
||||||
listPoints(sender);
|
listPoints(sender);
|
||||||
return true;
|
return true;
|
||||||
} else if (Objects.equals(args[0], "fill")) {
|
} else if (Objects.equals(args[0], "fill")) {
|
||||||
fillTask(sender, args);
|
return fillTask(sender, args);
|
||||||
return true;
|
|
||||||
} else if (Objects.equals(args[0], "empty")) {
|
} else if (Objects.equals(args[0], "empty")) {
|
||||||
emptyTask(sender, args);
|
return emptyTask(sender, args);
|
||||||
return true;
|
|
||||||
} else if (Objects.equals(args[0], "overlay")) {
|
} else if (Objects.equals(args[0], "overlay")) {
|
||||||
overlayTask(sender, args);
|
return overlayTask(sender, args);
|
||||||
return true;
|
|
||||||
} else if (Objects.equals(args[0], "drain")) {
|
|
||||||
drainTask(sender, args);
|
|
||||||
return true;
|
|
||||||
} else if (Objects.equals(args[0], "help")) {
|
} else if (Objects.equals(args[0], "help")) {
|
||||||
print_help(sender);
|
print_help(sender);
|
||||||
return true;
|
return true;
|
||||||
@ -103,11 +91,11 @@ public class Commands implements TabExecutor {
|
|||||||
if (!player.isOp()) {
|
if (!player.isOp()) {
|
||||||
Notification.error(player, "你没有权限。");
|
Notification.error(player, "你没有权限。");
|
||||||
} else {
|
} else {
|
||||||
LiteWorldEdit.config.reload();
|
LiteWorldEdit.instance.reloadConfig();
|
||||||
Notification.info(player, "已重载配置文件。");
|
Notification.info(player, "已重载配置文件。");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LiteWorldEdit.config.reload();
|
LiteWorldEdit.instance.reloadConfig();
|
||||||
LoggerX.info("已重载配置文件。");
|
LoggerX.info("已重载配置文件。");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,94 +114,87 @@ public class Commands implements TabExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void emptyTask(CommandSender sender, String[] args) {
|
private static boolean emptyTask(CommandSender sender, String[] args) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
LoggerX.err("该命令只能由玩家执行。");
|
LoggerX.err("该命令只能由玩家执行。");
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
try {
|
if (args.length == 3) {
|
||||||
Vector2 diagonalPoint = getVector2(sender, args, player);
|
try {
|
||||||
if (diagonalPoint == null) return;
|
Vector2 diagonalPoint = getVector2(sender, args, player);
|
||||||
Empty.empty(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB);
|
if (diagonalPoint == null) return true;
|
||||||
Notification.info(player, "已添加任务。");
|
Empty.empty(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB);
|
||||||
} catch (NumberFormatException e) {
|
Notification.info(player, "已添加任务。");
|
||||||
Notification.error(player, "参数错误。");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void drainTask(CommandSender sender, String[] args) {
|
} catch (NumberFormatException e) {
|
||||||
if (!(sender instanceof Player)) {
|
Notification.error(player, "参数错误。");
|
||||||
LoggerX.err("该命令只能由玩家执行。");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Player player = (Player) sender;
|
|
||||||
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, "参数错误。");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void overlayTask(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());
|
} else {
|
||||||
OverLay.overLay(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB, material);
|
|
||||||
Notification.info(player, "已添加任务。");
|
|
||||||
return;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
Notification.error(player, "参数错误。");
|
Notification.error(player, "参数错误。");
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void fillTask(CommandSender sender, String[] args) {
|
private static boolean overlayTask(CommandSender sender, String[] args) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
LoggerX.err("该命令只能由玩家执行。");
|
LoggerX.err("该命令只能由玩家执行。");
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
try {
|
if (args.length == 3) {
|
||||||
Vector2 diagonalPoint = getVector2(sender, args, player);
|
try {
|
||||||
if (diagonalPoint == null) return;
|
Vector2 diagonalPoint = getVector2(sender, args, player);
|
||||||
ItemStack items_in_hand = player.getInventory().getItemInMainHand();
|
if (diagonalPoint == null) return true;
|
||||||
if (!items_in_hand.getType().isBlock() || items_in_hand.getType() == Material.AIR) {
|
ItemStack items_in_hand = player.getInventory().getItemInMainHand();
|
||||||
Notification.error(player, "你手上没有方块。");
|
if (!items_in_hand.getType().isBlock() || items_in_hand.getType() == Material.AIR) {
|
||||||
return;
|
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, "参数错误。");
|
||||||
}
|
}
|
||||||
Material material = Material.getMaterial(items_in_hand.getType().name());
|
} else {
|
||||||
Fill.fill(player, player.getWorld(), diagonalPoint.pointA, diagonalPoint.pointB, material);
|
|
||||||
Notification.info(player, "已添加任务。");
|
|
||||||
return;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
Notification.error(player, "参数错误。");
|
Notification.error(player, "参数错误。");
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean fillTask(CommandSender sender, String[] args) {
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
LoggerX.err("该命令只能由玩家执行。");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
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, "参数错误。");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Notification.error(player, "参数错误。");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Vector2 getVector2(CommandSender sender, String[] args, Player player) {
|
private static Vector2 getVector2(CommandSender sender, String[] args, Player player) {
|
||||||
int indexA;
|
Integer indexA = Integer.parseInt(args[1]);
|
||||||
int indexB;
|
Integer indexB = Integer.parseInt(args[2]);
|
||||||
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();
|
Map<Integer, Point> points = LiteWorldEdit.instance.getCache().getPlayer(player).getPoints();
|
||||||
if (points == null) {
|
if (points == null) {
|
||||||
Notification.error(player, "你没有设置任何点。");
|
Notification.error(player, "你没有设置任何点。");
|
||||||
@ -222,7 +203,7 @@ public class Commands implements TabExecutor {
|
|||||||
Point pointA = points.get(indexA);
|
Point pointA = points.get(indexA);
|
||||||
Point pointB = points.get(indexB);
|
Point pointB = points.get(indexB);
|
||||||
if (pointA == null || pointB == null) {
|
if (pointA == null || pointB == null) {
|
||||||
Notification.error(player, "点不存在,使用 /lwe points 查看所有已添加的点。");
|
Notification.error(player, "点不存在。");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (out_of_region(pointA, pointB)) {
|
if (out_of_region(pointA, pointB)) {
|
||||||
@ -260,10 +241,10 @@ public class Commands implements TabExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addPoint(CommandSender sender, String[] args) {
|
private static boolean addPoint(CommandSender sender, String[] args) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
LoggerX.err("该命令只能由玩家执行。");
|
LoggerX.err("该命令只能由玩家执行。");
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
if (args.length == 5) {
|
if (args.length == 5) {
|
||||||
@ -274,12 +255,12 @@ public class Commands implements TabExecutor {
|
|||||||
int z = Integer.parseInt(args[4]);
|
int z = Integer.parseInt(args[4]);
|
||||||
// 选择的点不允许超过128格范围
|
// 选择的点不允许超过128格范围
|
||||||
if (!Job.in_range(player, new Location(player.getWorld(), x, y, z))) {
|
if (!Job.in_range(player, new Location(player.getWorld(), x, y, z))) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
Point point = new Point(x, y, z, player);
|
Point point = new Point(x, y, z, player);
|
||||||
if (!LiteWorldEdit.instance.getCache().getPlayer(player).addPoint(index, point)) {
|
if (!LiteWorldEdit.instance.getCache().getPlayer(player).addPoint(index, point)) {
|
||||||
Notification.error(player, "点的数量不允许超过20,请使用已有点序号覆盖已有点。");
|
Notification.error(player, "点的数量不允许超过20,请使用已有点序号覆盖已有点。");
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
Notification.info(player, "点 " + index + " 已设置为 " + x + ", " + y + ", " + z + "。");
|
Notification.info(player, "点 " + index + " 已设置为 " + x + ", " + y + ", " + z + "。");
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
@ -288,26 +269,18 @@ public class Commands implements TabExecutor {
|
|||||||
} else {
|
} else {
|
||||||
Notification.error(player, "参数错误。");
|
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
|
@Override
|
||||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
return Arrays.asList("point", "p", "select", "points", "fill", "empty", "overlay", "drain", "cancel", "pause", "resume", "help", "reload");
|
return Arrays.asList("point", "p", "points", "fill", "empty", "overlay", "cancel", "pause", "resume", "help", "reload");
|
||||||
} else if (args.length == 2) {
|
} else if (args.length == 2) {
|
||||||
if (args[0].equals("point") || args[0].equals("p")) {
|
if (args[0].equals("point") || args[0].equals("p")) {
|
||||||
return Collections.singletonList("<点序号(整数)> <x> <y> <z> - 创建点");
|
return Collections.singletonList("[点序号(整数)] [x] [y] [z] - 创建点");
|
||||||
} else if (args[0].equals("fill") || args[0].equals("empty") || args[0].equals("overlay") || args[0].equals("drain")) {
|
} else if (args[0].equals("fill") || args[0].equals("empty") || args[0].equals("overlay")) {
|
||||||
return Collections.singletonList("[点序号A] [点序号B] - 不填写默认为 1 2");
|
return Collections.singletonList("[点序号A] [点序号B]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
@ -320,13 +293,11 @@ public class Commands implements TabExecutor {
|
|||||||
}
|
}
|
||||||
Notification.info((Player) sender, "LiteWorldEdit 帮助");
|
Notification.info((Player) sender, "LiteWorldEdit 帮助");
|
||||||
Notification.info((Player) sender, "/lwe help - 查看帮助");
|
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 points - 查看所有点");
|
||||||
Notification.info((Player) sender, "/lwe fill [点序号A] [点序号B] - (在AB点对角线间放置方块 - 需要手持被放置的方块)");
|
Notification.info((Player) sender, "/lwe fill [点序号A] [点序号B] - (在AB点对角线间放置方块 - 需要手持被放置的方块)");
|
||||||
Notification.info((Player) sender, "/lwe empty [点序号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 overlay [点序号A] [点序号B] - (在AB点对角线间放置方块 - 不需要手持被放置的方块)");
|
||||||
Notification.info((Player) sender, "/lwe drain [点序号A] [点序号B] - (排干AB点对角线间的流体 - 需要背包里有一个海绵)");
|
|
||||||
Notification.info((Player) sender, "/lwe cancel - 取消当前任务");
|
Notification.info((Player) sender, "/lwe cancel - 取消当前任务");
|
||||||
Notification.info((Player) sender, "/lwe pause - 暂停当前任务");
|
Notification.info((Player) sender, "/lwe pause - 暂停当前任务");
|
||||||
Notification.info((Player) sender, "/lwe resume - 恢复当前任务");
|
Notification.info((Player) sender, "/lwe resume - 恢复当前任务");
|
18
src/main/java/site/deercloud/liteworldedit/Events.java
Normal file
18
src/main/java/site/deercloud/liteworldedit/Events.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
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,11 +1,11 @@
|
|||||||
package cn.lunadeer.liteworldedit.JobGenerator;
|
package site.deercloud.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.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
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 class Empty {
|
||||||
public static void empty(Player player, World world, Point p1, Point p2) {
|
public static void empty(Player player, World world, Point p1, Point p2) {
|
@ -1,12 +1,13 @@
|
|||||||
package cn.lunadeer.liteworldedit.JobGenerator;
|
package site.deercloud.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.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
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 {
|
public class Fill {
|
||||||
|
|
@ -1,13 +1,13 @@
|
|||||||
package cn.lunadeer.liteworldedit.JobGenerator;
|
package site.deercloud.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.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
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 {
|
public class OverLay {
|
||||||
|
|
@ -1,7 +1,5 @@
|
|||||||
package cn.lunadeer.liteworldedit.Jobs;
|
package site.deercloud.liteworldedit.Jobs;
|
||||||
|
|
||||||
import cn.lunadeer.liteworldedit.LoggerX;
|
|
||||||
import cn.lunadeer.liteworldedit.Notification;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -11,6 +9,8 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.Damageable;
|
import org.bukkit.inventory.meta.Damageable;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import site.deercloud.liteworldedit.LoggerX;
|
||||||
|
import site.deercloud.liteworldedit.Notification;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@ -91,11 +91,9 @@ public class Job {
|
|||||||
}
|
}
|
||||||
// 如果耐久小于10,提示玩家
|
// 如果耐久小于10,提示玩家
|
||||||
pickaxe_damage = (Damageable) pickaxe_meta;
|
pickaxe_damage = (Damageable) pickaxe_meta;
|
||||||
if (!pickaxe_meta.isUnbreakable()) {
|
if (pickaxe_damage.getDamage() >= 2031 - 10) {
|
||||||
if (pickaxe_damage.getDamage() >= 2031 - 10) {
|
LoggerX.debug(index + " 下界合金镐耐久太低!");
|
||||||
LoggerX.debug(index + " 下界合金镐耐久太低!");
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pickaxe = p;
|
pickaxe = p;
|
||||||
break;
|
break;
|
||||||
@ -106,13 +104,9 @@ public class Job {
|
|||||||
public static ItemStack useNetherPickaxe(ItemStack pickaxe) {
|
public static ItemStack useNetherPickaxe(ItemStack pickaxe) {
|
||||||
int durability = pickaxe.getEnchantmentLevel(Enchantment.DURABILITY);
|
int durability = pickaxe.getEnchantmentLevel(Enchantment.DURABILITY);
|
||||||
double random = Math.random();
|
double random = Math.random();
|
||||||
Damageable pickaxe_damage = (Damageable) pickaxe.getItemMeta();
|
|
||||||
if (pickaxe_damage.isUnbreakable()) {
|
|
||||||
// 无限耐久则不损坏
|
|
||||||
return pickaxe;
|
|
||||||
}
|
|
||||||
if (random < 1.0 / (durability + 1)) {
|
if (random < 1.0 / (durability + 1)) {
|
||||||
// 扣除耐久
|
// 扣除耐久
|
||||||
|
Damageable pickaxe_damage = (Damageable) pickaxe.getItemMeta();
|
||||||
pickaxe_damage.setDamage(pickaxe_damage.getDamage() + 1);
|
pickaxe_damage.setDamage(pickaxe_damage.getDamage() + 1);
|
||||||
pickaxe.setItemMeta(pickaxe_damage);
|
pickaxe.setItemMeta(pickaxe_damage);
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package cn.lunadeer.liteworldedit.Jobs;
|
package site.deercloud.liteworldedit.Jobs;
|
||||||
|
|
||||||
public enum JobErrCode {
|
public enum JobErrCode {
|
||||||
OK(0, ""), // 无错误
|
OK(0, ""), // 无错误
|
||||||
@ -8,13 +8,11 @@ public enum JobErrCode {
|
|||||||
NOT_ENOUGH_DURATION(102, "所有下界合金镐耐久均不足10"),
|
NOT_ENOUGH_DURATION(102, "所有下界合金镐耐久均不足10"),
|
||||||
NOT_ENOUGH_ITEMS(103, "物品不足"),
|
NOT_ENOUGH_ITEMS(103, "物品不足"),
|
||||||
OUT_OF_RANGE(104, "超出操作距离"),
|
OUT_OF_RANGE(104, "超出操作距离"),
|
||||||
NO_SPONGE(105, "没有海绵,无法排水"),
|
|
||||||
|
|
||||||
// ------------ 以下结果应当跳过任务 ------------
|
// ------------ 以下结果应当跳过任务 ------------
|
||||||
NO_PERMISSION(201, "跳过没有权限操作的方块"),
|
NO_PERMISSION(201, "跳过没有权限操作的方块"),
|
||||||
NOT_AIR_BLOCK(202, "跳过非空气方块"),
|
NOT_AIR_BLOCK(202, "跳过非空气方块"),
|
||||||
NO_BREAKABLE(203, "跳过不可破坏方块"),
|
NO_BREAKABLE(203, "跳过不可破坏方块"),
|
||||||
NOT_LIQUID(204, "跳过非液体方块"),
|
|
||||||
;
|
;
|
||||||
|
|
||||||
private final int value;
|
private final int value;
|
@ -1,6 +1,5 @@
|
|||||||
package cn.lunadeer.liteworldedit.Jobs;
|
package site.deercloud.liteworldedit.Jobs;
|
||||||
|
|
||||||
import cn.lunadeer.liteworldedit.LoggerX;
|
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.ShulkerBox;
|
import org.bukkit.block.ShulkerBox;
|
||||||
@ -10,6 +9,7 @@ import org.bukkit.inventory.EquipmentSlot;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||||
|
import site.deercloud.liteworldedit.LoggerX;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@ -35,8 +35,8 @@ public class Place extends Job {
|
|||||||
}
|
}
|
||||||
// 跳过非空气方块
|
// 跳过非空气方块
|
||||||
Block raw_block = _world.getBlockAt(_location);
|
Block raw_block = _world.getBlockAt(_location);
|
||||||
if (!raw_block.isEmpty()) {
|
if (!raw_block.isEmpty() && !raw_block.isLiquid()) {
|
||||||
LoggerX.debug("目标方块不是空气!");
|
LoggerX.debug("目标方块不是空气或流体!");
|
||||||
return JobErrCode.NOT_AIR_BLOCK;
|
return JobErrCode.NOT_AIR_BLOCK;
|
||||||
}
|
}
|
||||||
// 获取到玩家物品中材料的第一个堆叠
|
// 获取到玩家物品中材料的第一个堆叠
|
||||||
@ -72,9 +72,7 @@ public class Place extends Job {
|
|||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled()) {
|
||||||
raw_block.setType(_block);
|
raw_block.setType(_block);
|
||||||
if (!_creator.isOp() && _creator.getGameMode() != GameMode.CREATIVE) {
|
stack.setAmount(stack.getAmount() - 1);
|
||||||
stack.setAmount(stack.getAmount() - 1);
|
|
||||||
}
|
|
||||||
return JobErrCode.OK;
|
return JobErrCode.OK;
|
||||||
} else {
|
} else {
|
||||||
return JobErrCode.NO_PERMISSION;
|
return JobErrCode.NO_PERMISSION;
|
||||||
@ -83,43 +81,7 @@ public class Place extends Job {
|
|||||||
|
|
||||||
private boolean moveBlockFromShulkerBoxToInv() {
|
private boolean moveBlockFromShulkerBoxToInv() {
|
||||||
Inventory _inventory = this.get_inventory();
|
Inventory _inventory = this.get_inventory();
|
||||||
HashMap<Integer, ItemStack> shulkerBoxes = new HashMap<>();
|
HashMap<Integer, ?> shulkerBoxes = _inventory.all(Material.SHULKER_BOX);
|
||||||
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()) {
|
for (Integer index : shulkerBoxes.keySet()) {
|
||||||
LoggerX.debug("找到潜影盒:" + index);
|
LoggerX.debug("找到潜影盒:" + index);
|
||||||
ItemStack itemStack = _inventory.getItem(index);
|
ItemStack itemStack = _inventory.getItem(index);
|
@ -1,14 +1,20 @@
|
|||||||
package cn.lunadeer.liteworldedit.Jobs;
|
package site.deercloud.liteworldedit.Jobs;
|
||||||
|
|
||||||
import cn.lunadeer.liteworldedit.LiteWorldEdit;
|
import org.bukkit.Bukkit;
|
||||||
import cn.lunadeer.liteworldedit.LoggerX;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.*;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.Damageable;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import site.deercloud.liteworldedit.LiteWorldEdit;
|
||||||
|
import site.deercloud.liteworldedit.LoggerX;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Remove extends Job {
|
public class Remove extends Job {
|
||||||
@ -35,7 +41,7 @@ public class Remove extends Job {
|
|||||||
}
|
}
|
||||||
// 获取玩家背包中的下届合金镐
|
// 获取玩家背包中的下届合金镐
|
||||||
HashMap<Integer, ?> pickaxes = getNetherPickaxes(_creator);
|
HashMap<Integer, ?> pickaxes = getNetherPickaxes(_creator);
|
||||||
if (pickaxes.isEmpty()) {
|
if (pickaxes.size() == 0) {
|
||||||
return JobErrCode.NO_PICKAXE;
|
return JobErrCode.NO_PICKAXE;
|
||||||
}
|
}
|
||||||
ItemStack pickaxe = getUsableNetherPickaxe(pickaxes, _creator);
|
ItemStack pickaxe = getUsableNetherPickaxe(pickaxes, _creator);
|
||||||
@ -46,17 +52,12 @@ public class Remove extends Job {
|
|||||||
BlockBreakEvent event = new BlockBreakEvent(raw_block, _creator);
|
BlockBreakEvent event = new BlockBreakEvent(raw_block, _creator);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled()) {
|
||||||
Collection<ItemStack> drops = raw_block.getDrops(pickaxe, _creator);
|
|
||||||
raw_block.setType(Material.AIR);
|
raw_block.setType(Material.AIR);
|
||||||
if (LiteWorldEdit.instance.getConfigMgr().isDropItems()) {
|
if (LiteWorldEdit.instance.getConfigMgr().isDropItems()) {
|
||||||
for (ItemStack drop : drops) {
|
raw_block.getWorld().dropItemNaturally(raw_block.getLocation(), new ItemStack(raw_block.getType()));
|
||||||
raw_block.getWorld().dropItemNaturally(raw_block.getLocation(), drop);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// 损坏镐
|
// 损坏镐
|
||||||
if (!_creator.isOp() && _creator.getGameMode() != GameMode.CREATIVE) {
|
useNetherPickaxe(pickaxe);
|
||||||
useNetherPickaxe(pickaxe);
|
|
||||||
}
|
|
||||||
return JobErrCode.OK;
|
return JobErrCode.OK;
|
||||||
} else {
|
} else {
|
||||||
return JobErrCode.NO_PERMISSION;
|
return JobErrCode.NO_PERMISSION;
|
@ -1,9 +1,9 @@
|
|||||||
package cn.lunadeer.liteworldedit;
|
package site.deercloud.liteworldedit;
|
||||||
|
|
||||||
import cn.lunadeer.liteworldedit.Managers.Cache;
|
|
||||||
import cn.lunadeer.liteworldedit.Managers.ConfigManager;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import site.deercloud.liteworldedit.Managers.Cache;
|
||||||
|
import site.deercloud.liteworldedit.Managers.ConfigManager;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -20,14 +20,6 @@ public final class LiteWorldEdit extends JavaPlugin {
|
|||||||
Objects.requireNonNull(Bukkit.getPluginCommand("LiteWorldEdit")).setExecutor(new Commands());
|
Objects.requireNonNull(Bukkit.getPluginCommand("LiteWorldEdit")).setExecutor(new Commands());
|
||||||
Objects.requireNonNull(Bukkit.getPluginCommand("LiteWorldEdit")).setTabCompleter(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("LiteWorldEdit 已加载");
|
||||||
LoggerX.info("版本: " + getPluginMeta().getVersion());
|
LoggerX.info("版本: " + getPluginMeta().getVersion());
|
||||||
LoggerX.info("");
|
LoggerX.info("");
|
||||||
@ -58,5 +50,4 @@ public final class LiteWorldEdit extends JavaPlugin {
|
|||||||
public static LiteWorldEdit instance;
|
public static LiteWorldEdit instance;
|
||||||
public static ConfigManager config;
|
public static ConfigManager config;
|
||||||
private Cache _cache;
|
private Cache _cache;
|
||||||
private GiteaReleaseCheck giteaReleaseCheck;
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package cn.lunadeer.liteworldedit;
|
package site.deercloud.liteworldedit;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
@ -1,7 +1,8 @@
|
|||||||
package cn.lunadeer.liteworldedit.Managers;
|
package site.deercloud.liteworldedit.Managers;
|
||||||
|
|
||||||
import cn.lunadeer.liteworldedit.XPlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import site.deercloud.liteworldedit.Jobs.Job;
|
||||||
|
import site.deercloud.liteworldedit.XPlayer;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
@ -1,7 +1,7 @@
|
|||||||
package cn.lunadeer.liteworldedit.Managers;
|
package site.deercloud.liteworldedit.Managers;
|
||||||
|
|
||||||
import cn.lunadeer.liteworldedit.LiteWorldEdit;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import site.deercloud.liteworldedit.LiteWorldEdit;
|
||||||
|
|
||||||
public class ConfigManager {
|
public class ConfigManager {
|
||||||
public ConfigManager() {
|
public ConfigManager() {
|
||||||
@ -18,7 +18,6 @@ public class ConfigManager {
|
|||||||
_z_max = _file.getInt("MaxZ", 64);
|
_z_max = _file.getInt("MaxZ", 64);
|
||||||
_multiplier = _file.getInt("Multiplier", 1);
|
_multiplier = _file.getInt("Multiplier", 1);
|
||||||
_drop_items = _file.getBoolean("DropItems", false);
|
_drop_items = _file.getBoolean("DropItems", false);
|
||||||
_check_update = _file.getBoolean("CheckUpdate", true);
|
|
||||||
_plugin.saveConfig();
|
_plugin.saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,10 +68,6 @@ public class ConfigManager {
|
|||||||
_plugin.saveConfig();
|
_plugin.saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean isCheckUpdate() {
|
|
||||||
return _check_update;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private final LiteWorldEdit _plugin = LiteWorldEdit.instance;
|
private final LiteWorldEdit _plugin = LiteWorldEdit.instance;
|
||||||
private FileConfiguration _file;
|
private FileConfiguration _file;
|
||||||
@ -86,6 +81,4 @@ public class ConfigManager {
|
|||||||
private Boolean _drop_items;
|
private Boolean _drop_items;
|
||||||
|
|
||||||
private Integer _multiplier;
|
private Integer _multiplier;
|
||||||
|
|
||||||
private Boolean _check_update;
|
|
||||||
}
|
}
|
@ -1,11 +1,11 @@
|
|||||||
package cn.lunadeer.liteworldedit.Managers;
|
package site.deercloud.liteworldedit.Managers;
|
||||||
|
|
||||||
import cn.lunadeer.liteworldedit.Jobs.Job;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.boss.BarColor;
|
import org.bukkit.boss.BarColor;
|
||||||
import org.bukkit.boss.BarStyle;
|
import org.bukkit.boss.BarStyle;
|
||||||
import org.bukkit.boss.BossBar;
|
import org.bukkit.boss.BossBar;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import site.deercloud.liteworldedit.Jobs.Job;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package cn.lunadeer.liteworldedit.Managers;
|
package site.deercloud.liteworldedit.Managers;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package cn.lunadeer.liteworldedit;
|
package site.deercloud.liteworldedit;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.Style;
|
import net.kyori.adventure.text.format.Style;
|
||||||
@ -7,6 +7,8 @@ import net.kyori.adventure.title.Title;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import static site.deercloud.liteworldedit.LoggerX.*;
|
||||||
|
|
||||||
public class Notification {
|
public class Notification {
|
||||||
private static final Style i_style = Style.style(TextColor.color(139, 255, 123));
|
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 w_style = Style.style(TextColor.color(255, 185, 69));
|
||||||
@ -41,19 +43,19 @@ public class Notification {
|
|||||||
public static void info(Player player, Component msg) {
|
public static void info(Player player, Component msg) {
|
||||||
player.sendMessage(Component.text(prefix, i_style).append(msg));
|
player.sendMessage(Component.text(prefix, i_style).append(msg));
|
||||||
if (LiteWorldEdit.config.isDebug())
|
if (LiteWorldEdit.config.isDebug())
|
||||||
LoggerX.debug("来自玩家[ " + player.getName() + " ] 的提示 | " + msg);
|
debug("来自玩家[ " + player.getName() + " ] 的提示 | " + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warn(Player player, Component msg) {
|
public static void warn(Player player, Component msg) {
|
||||||
player.sendMessage(Component.text(prefix, w_style).append(msg));
|
player.sendMessage(Component.text(prefix, w_style).append(msg));
|
||||||
if (LiteWorldEdit.config.isDebug())
|
if (LiteWorldEdit.config.isDebug())
|
||||||
LoggerX.debug("来自玩家[ " + player.getName() + " ] 的警告 | " + msg);
|
debug("来自玩家[ " + player.getName() + " ] 的警告 | " + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void error(Player player, Component msg) {
|
public static void error(Player player, Component msg) {
|
||||||
player.sendMessage(Component.text(prefix, e_style).append(msg));
|
player.sendMessage(Component.text(prefix, e_style).append(msg));
|
||||||
if (LiteWorldEdit.config.isDebug())
|
if (LiteWorldEdit.config.isDebug())
|
||||||
LoggerX.debug("来自玩家[ " + player.getName() + " ] 的报错 | " + msg);
|
debug("来自玩家[ " + player.getName() + " ] 的报错 | " + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void info(CommandSender player, Component msg) {
|
public static void info(CommandSender player, Component msg) {
|
@ -1,8 +1,9 @@
|
|||||||
package cn.lunadeer.liteworldedit;
|
package site.deercloud.liteworldedit;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
public class SchedulerUtil {
|
public class SchedulerUtil {
|
||||||
|
|
@ -1,13 +1,9 @@
|
|||||||
package cn.lunadeer.liteworldedit;
|
package site.deercloud.liteworldedit;
|
||||||
|
|
||||||
import cn.lunadeer.liteworldedit.Jobs.Job;
|
|
||||||
import cn.lunadeer.liteworldedit.Jobs.JobErrCode;
|
|
||||||
import net.kyori.adventure.text.Component;
|
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;
|
import org.bukkit.entity.Player;
|
||||||
|
import site.deercloud.liteworldedit.Jobs.Job;
|
||||||
|
import site.deercloud.liteworldedit.Jobs.JobErrCode;
|
||||||
|
|
||||||
public class Task implements Runnable {
|
public class Task implements Runnable {
|
||||||
/**
|
/**
|
||||||
@ -45,8 +41,7 @@ public class Task implements Runnable {
|
|||||||
}
|
}
|
||||||
Player player = job.get_creator();
|
Player player = job.get_creator();
|
||||||
if (re.canContinue()) {
|
if (re.canContinue()) {
|
||||||
TextComponent warn = Component.text("警告:" + re.getMessage(), Style.style(TextColor.color(TextColor.color(255, 185, 69)), TextDecoration.BOLD));
|
Notification.titleWarn(player, "警告", re.getMessage());
|
||||||
player.sendActionBar(warn);
|
|
||||||
job = this.xPlayer.popJob();
|
job = this.xPlayer.popJob();
|
||||||
if (job == null) {
|
if (job == null) {
|
||||||
return;
|
return;
|
@ -1,25 +1,23 @@
|
|||||||
package cn.lunadeer.liteworldedit;
|
package site.deercloud.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 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.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.lunadeer.liteworldedit.SchedulerUtil.runAtFixedRateEntity;
|
import static site.deercloud.liteworldedit.SchedulerUtil.runAtFixedRateEntity;
|
||||||
|
|
||||||
public class XPlayer {
|
public class XPlayer {
|
||||||
|
|
||||||
private boolean select_mode = false;
|
|
||||||
private final Map<Integer, Point> points;
|
private final Map<Integer, Point> points;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final JobQueue queue;
|
private final JobQueue queue;
|
||||||
private final Task task;
|
private final Task task;
|
||||||
|
|
||||||
public XPlayer(Player player) {
|
public XPlayer(Player player) {
|
||||||
Notification.info(player, "当前选点模式: 关闭");
|
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.points = new HashMap<>();
|
this.points = new HashMap<>();
|
||||||
this.queue = new JobQueue(player);
|
this.queue = new JobQueue(player);
|
||||||
@ -27,20 +25,6 @@ public class XPlayer {
|
|||||||
runAtFixedRateEntity(player, LiteWorldEdit.instance, task, 1);
|
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) {
|
public void addJob(Job job) {
|
||||||
queue.add(job);
|
queue.add(job);
|
||||||
}
|
}
|
@ -8,6 +8,4 @@ Multiplier: 1
|
|||||||
|
|
||||||
DropItems: false
|
DropItems: false
|
||||||
|
|
||||||
CheckUpdate: true
|
|
||||||
|
|
||||||
Debug: false
|
Debug: false
|
@ -1,21 +1,15 @@
|
|||||||
name: LiteWorldEdit
|
name: LiteWorldEdit
|
||||||
version: '${project.version}'
|
version: '${project.version}'
|
||||||
main: cn.lunadeer.liteworldedit.LiteWorldEdit
|
main: site.deercloud.liteworldedit.LiteWorldEdit
|
||||||
api-version: 1.14
|
api-version: 1.14
|
||||||
prefix: LWE
|
prefix: LWE
|
||||||
load: STARTUP
|
load: STARTUP
|
||||||
authors: [ Luming ]
|
authors: [ Luming ]
|
||||||
description: 生存用简易创世神。
|
description: 生存用简易创世神。
|
||||||
website: https://ssl.lunadeer.cn:14448/project-2/
|
website: https://blog.deercloud.site
|
||||||
folia-supported: true
|
folia-supported: true
|
||||||
commands:
|
commands:
|
||||||
LiteWorldEdit:
|
LiteWorldEdit:
|
||||||
description: 简易创世神命令
|
description: 简易创世神命令
|
||||||
usage: /lwe <cmd>
|
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