From c5eb4e60359d38387d46a14e9a2f3a8f69e0f5b4 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Fri, 26 Apr 2024 13:10:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=80=89=E5=8F=96=E5=8F=AF?= =?UTF-8?q?=E8=A7=86=E5=8C=96=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- pom.xml | 2 +- .../cn/lunadeer/liteworldedit/Events.java | 6 +++ .../liteworldedit/ParticleRender.java | 51 +++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 src/main/java/cn/lunadeer/liteworldedit/ParticleRender.java diff --git a/README.md b/README.md index 07692d1..375b8e8 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ Debug: false - [X] 从潜影盒中自动补充材料 -- [ ] 选区可视化 +- [X] 选区可视化 - [X] 可手动暂停、恢复任务 diff --git a/pom.xml b/pom.xml index 73fb29b..210e4a9 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cn.lunadeer LiteWorldEdit - 2.4.2.0 + 2.4.3.0 jar LiteWorldEdit diff --git a/src/main/java/cn/lunadeer/liteworldedit/Events.java b/src/main/java/cn/lunadeer/liteworldedit/Events.java index 9f58fd9..1832afb 100644 --- a/src/main/java/cn/lunadeer/liteworldedit/Events.java +++ b/src/main/java/cn/lunadeer/liteworldedit/Events.java @@ -55,5 +55,11 @@ public class Events implements Listener { 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); + ParticleRender.showBoxBorder(LiteWorldEdit.instance, player.getWorld().getName(), p1.x, p1.y, p1.z, p2.x, p2.y, p2.z); + } } } diff --git a/src/main/java/cn/lunadeer/liteworldedit/ParticleRender.java b/src/main/java/cn/lunadeer/liteworldedit/ParticleRender.java new file mode 100644 index 0000000..b86cb52 --- /dev/null +++ b/src/main/java/cn/lunadeer/liteworldedit/ParticleRender.java @@ -0,0 +1,51 @@ +package cn.lunadeer.liteworldedit; + +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.World; +import org.bukkit.plugin.java.JavaPlugin; + +public class ParticleRender { + + public static void showBoxBorder(JavaPlugin plugin, String world, int x1, int y1, int z1, int x2, int y2, int z2) { + showBoxBorder(plugin, new Location(plugin.getServer().getWorld(world), x1, y1, z1), + new Location(plugin.getServer().getWorld(world), x2, y2, z2)); + } + + public static void showBoxBorder(JavaPlugin plugin, Location loc1, Location loc2) { + plugin.getServer().getGlobalRegionScheduler().run(LiteWorldEdit.instance, (instance) -> { + if (!loc1.getWorld().equals(loc2.getWorld())) { + return; + } + int minX = Math.min(loc1.getBlockX(), loc2.getBlockX()); + int minY = Math.min(loc1.getBlockY(), loc2.getBlockY()); + int minZ = Math.min(loc1.getBlockZ(), loc2.getBlockZ()); + int maxX = Math.max(loc1.getBlockX(), loc2.getBlockX()) + 1; + int maxY = Math.max(loc1.getBlockY(), loc2.getBlockY()) + 1; + int maxZ = Math.max(loc1.getBlockZ(), loc2.getBlockZ()) + 1; + World world = loc1.getWorld(); + for (int x = minX; x <= maxX; x++) { + spawnParticle(world, x, minY, minZ); + spawnParticle(world, x, minY, maxZ); + spawnParticle(world, x, maxY, minZ); + spawnParticle(world, x, maxY, maxZ); + } + for (int y = minY; y <= maxY; y++) { + spawnParticle(world, minX, y, minZ); + spawnParticle(world, minX, y, maxZ); + spawnParticle(world, maxX, y, minZ); + spawnParticle(world, maxX, y, maxZ); + } + for (int z = minZ; z <= maxZ; z++) { + spawnParticle(world, minX, minY, z); + spawnParticle(world, minX, maxY, z); + spawnParticle(world, maxX, minY, z); + spawnParticle(world, maxX, maxY, z); + } + }); + } + + private static void spawnParticle(World world, double x, double y, double z) { + world.spawnParticle(Particle.FLAME, x, y, z, 10, 0, 0, 0, 0); + } +}