From 3dd1843adbf3dc2375295e61d98578a8b3916ea2 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Fri, 26 Apr 2024 12:58:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A2=86=E5=9C=B0=E8=BE=B9?= =?UTF-8?q?=E7=95=8C=E6=98=BE=E7=A4=BA=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E5=AF=B9=E5=BA=94=E6=9D=83=E9=99=90=E6=8E=A7?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- src/main/java/cn/lunadeer/dominion/Cache.java | 12 +++- .../dominion/commands/DominionOperate.java | 10 ---- .../controllers/DominionController.java | 4 ++ .../dominion/controllers/FlagsController.java | 1 + .../lunadeer/dominion/dtos/DominionDTO.java | 15 ++++- .../dominion/events/SelectPointEvents.java | 9 ++- .../dominion/tuis/DominionFlagInfo.java | 9 +++ .../dominion/tuis/DominionSizeInfo.java | 2 + .../cn/lunadeer/dominion/utils/Database.java | 3 + .../dominion/utils/ParticleRender.java | 55 +++++++++++++++++++ 11 files changed, 108 insertions(+), 14 deletions(-) create mode 100644 src/main/java/cn/lunadeer/dominion/utils/ParticleRender.java diff --git a/pom.xml b/pom.xml index 251cf7c..d63d66a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cn.lunadeer Dominion - 1.20.3-beta + 1.21.4-beta jar Dominion diff --git a/src/main/java/cn/lunadeer/dominion/Cache.java b/src/main/java/cn/lunadeer/dominion/Cache.java index 389e78e..f4e5405 100644 --- a/src/main/java/cn/lunadeer/dominion/Cache.java +++ b/src/main/java/cn/lunadeer/dominion/Cache.java @@ -3,6 +3,7 @@ package cn.lunadeer.dominion; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.PlayerPrivilegeDTO; import cn.lunadeer.dominion.utils.Notification; +import cn.lunadeer.dominion.utils.ParticleRender; import cn.lunadeer.dominion.utils.XLogger; import net.kyori.adventure.text.Component; import org.bukkit.Location; @@ -127,7 +128,7 @@ public class Cache { if (dominion.getParentDomId() == -1) { Notification.info(player, "您已离开领地:" + dominion.getName()); player.sendMessage(Component.text(dominion.getLeaveMessage())); - player_current_dominion_id.put(player.getUniqueId(), null); + update_player_current_dominion(player, null); dominion = null; } else { Notification.info(player, "您已离开子领地:" + dominion.getName()); @@ -172,7 +173,16 @@ public class Cache { } private void update_player_current_dominion(Player player, DominionDTO dominion) { + if (dominion == null) { + player.setGlowing(false); + player_current_dominion_id.put(player.getUniqueId(), null); + return; + } player_current_dominion_id.put(player.getUniqueId(), dominion.getId()); + // show border + if (dominion.getShowBorder()) { + ParticleRender.showBoxBorder(dominion); + } // glow PlayerPrivilegeDTO privilege = getPlayerPrivilege(player, dominion); if (privilege != null) { diff --git a/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java b/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java index 900f98a..d47838f 100644 --- a/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java +++ b/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java @@ -380,16 +380,6 @@ public class DominionOperate { if (location == null) { Notification.error(sender, "此领地没有设置传送点"); return; -// int center_x = (dominionDTO.getX1() + dominionDTO.getX2()) / 2; -// int center_z = (dominionDTO.getZ1() + dominionDTO.getZ2()) / 2; -// // find safe location -// World world = Dominion.instance.getServer().getWorld(dominionDTO.getWorld()); -// if (world == null) { -// Notification.error(sender, "此领地所在世界不存在"); -// XLogger.warn("领地 " + dominionDTO.getName() + " 所在世界不存在"); -// return; -// } -// location = world.getHighestBlockAt(center_x, center_z).getLocation(); } LocalDateTime now = LocalDateTime.now(); diff --git a/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java b/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java index 272eacd..fd15422 100644 --- a/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java +++ b/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Objects; import static cn.lunadeer.dominion.controllers.Apis.*; +import static cn.lunadeer.dominion.utils.ParticleRender.showBoxBorder; public class DominionController { @@ -157,6 +158,7 @@ public class DominionController { Notification.error(owner, "创建失败,详细错误请联系管理员查询日志(当前时间:" + Time.nowStr() + ")"); return null; } + showBoxBorder(dominion.getWorld(), dominion.getX1(), dominion.getY1(), dominion.getZ1(), dominion.getX2(), dominion.getY2(), dominion.getZ2()); return dominion.setParentDomId(parent_dominion.getId()); } @@ -268,6 +270,7 @@ public class DominionController { Notification.info(operator, "已扣除 " + price + " " + Dominion.vault.getEconomy().currencyNamePlural()); Dominion.vault.getEconomy().withdrawPlayer(operator, price); } + showBoxBorder(dominion.getWorld(), x1, y1, z1, x2, y2, z2); return dominion.setXYZ(x1, y1, z1, x2, y2, z2); } @@ -368,6 +371,7 @@ public class DominionController { Dominion.vault.getEconomy().depositPlayer(operator, refund); Notification.info(operator, "已经退还 " + refund + " " + Dominion.vault.getEconomy().currencyNamePlural()); } + showBoxBorder(dominion.getWorld(), x1, y1, z1, x2, y2, z2); return dominion.setXYZ(x1, y1, z1, x2, y2, z2); } diff --git a/src/main/java/cn/lunadeer/dominion/controllers/FlagsController.java b/src/main/java/cn/lunadeer/dominion/controllers/FlagsController.java index 56b2ca6..6e752fb 100644 --- a/src/main/java/cn/lunadeer/dominion/controllers/FlagsController.java +++ b/src/main/java/cn/lunadeer/dominion/controllers/FlagsController.java @@ -75,6 +75,7 @@ public class FlagsController { case "repeater": return dominion.setRepeater(value); case "shear": return dominion.setShear(value); case "shoot": return dominion.setShoot(value); + case "show_border": return dominion.setShowBorder(value); case "teleport": return dominion.setTeleport(value); case "tnt_explode": return dominion.setTntExplode(value); case "trade": return dominion.setTrade(value); diff --git a/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java b/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java index e6780b7..8991aff 100644 --- a/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java +++ b/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java @@ -78,6 +78,7 @@ public class DominionDTO { rs.getBoolean("repeater"), rs.getBoolean("shear"), rs.getBoolean("shoot"), + rs.getBoolean("show_border"), rs.getBoolean("teleport"), rs.getBoolean("tnt_explode"), rs.getBoolean("trade"), @@ -233,6 +234,7 @@ public class DominionDTO { "repeater = " + dominion.getRepeater() + ", " + "shear = " + dominion.getShear() + ", " + "shoot = " + dominion.getShoot() + ", " + + "show_border = " + dominion.getShowBorder() + ", " + // dom only "teleport = " + dominion.getTeleport() + ", " + "tnt_explode = " + dominion.getTntExplode() + ", " + // dom only "trade = " + dominion.getTrade() + ", " + @@ -265,7 +267,7 @@ public class DominionDTO { Boolean mobDropItem, Boolean monsterKilling, Boolean move, Boolean place, Boolean pressure, Boolean riding, Boolean repeater, - Boolean shear, Boolean shoot, + Boolean shear, Boolean shoot, Boolean showBorder, Boolean teleport, Boolean tntExplode, Boolean trade, Boolean trample, Boolean vehicleDestroy, Boolean vehicleSpawn, @@ -322,6 +324,7 @@ public class DominionDTO { this.repeater = repeater; this.shear = shear; this.shoot = shoot; + this.showBorder = showBorder; this.teleport = teleport; this.tntExplode = tntExplode; this.trade = trade; @@ -416,6 +419,7 @@ public class DominionDTO { private Boolean repeater = false; private Boolean shear = false; private Boolean shoot = false; + private Boolean showBorder = true; private Boolean teleport = false; private Boolean tntExplode = false; private Boolean trade = false; @@ -880,6 +884,15 @@ public class DominionDTO { return update(this); } + public Boolean getShowBorder() { + return showBorder; + } + + public DominionDTO setShowBorder(Boolean showBorder) { + this.showBorder = showBorder; + return update(this); + } + public Boolean getTeleport() { return teleport; } diff --git a/src/main/java/cn/lunadeer/dominion/events/SelectPointEvents.java b/src/main/java/cn/lunadeer/dominion/events/SelectPointEvents.java index 28d1b33..43001aa 100644 --- a/src/main/java/cn/lunadeer/dominion/events/SelectPointEvents.java +++ b/src/main/java/cn/lunadeer/dominion/events/SelectPointEvents.java @@ -3,6 +3,7 @@ package cn.lunadeer.dominion.events; import cn.lunadeer.dominion.Dominion; import cn.lunadeer.dominion.utils.Notification; import org.bukkit.Location; +import org.bukkit.Particle; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -16,6 +17,8 @@ import org.bukkit.inventory.ItemStack; import java.util.HashMap; import java.util.Map; +import static cn.lunadeer.dominion.utils.ParticleRender.showBoxBorder; + public class SelectPointEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) @@ -54,6 +57,10 @@ public class SelectPointEvents implements Listener { if (world == null) { return; } + if (!points.get(0).getWorld().equals(points.get(1).getWorld())) { + Notification.error(player, "两个点不在同一个世界"); + return; + } Location loc1 = points.get(0); Location loc2 = points.get(1); @@ -73,7 +80,7 @@ public class SelectPointEvents implements Listener { double price = count * Dominion.config.getEconomyPrice(); Notification.info(player, "预计领地创建价格为 " + price + " " + Dominion.vault.getEconomy().currencyNamePlural()); } - // todo 用粒子效果显示边界 + showBoxBorder(loc1, loc2); Notification.info(player, "已选择两个点,可以使用 /dominion create <领地名称> 创建领地"); Notification.info(player, "尺寸为 " + diff --git a/src/main/java/cn/lunadeer/dominion/tuis/DominionFlagInfo.java b/src/main/java/cn/lunadeer/dominion/tuis/DominionFlagInfo.java index 9d58239..e770fc2 100644 --- a/src/main/java/cn/lunadeer/dominion/tuis/DominionFlagInfo.java +++ b/src/main/java/cn/lunadeer/dominion/tuis/DominionFlagInfo.java @@ -380,6 +380,15 @@ public class DominionFlagInfo { .append(Button.createRed("☐", "/dominion set shoot true " + dominion.getName() + " " + page)) .append("射箭/雪球/三叉戟")); } + if (dominion.getShowBorder()) { + view.add(Line.create() + .append(Button.createGreen("☑", "/dominion set show_border false " + dominion.getName() + " " + page)) + .append("玩家进入时是否显示领地边界")); + } else { + view.add(Line.create() + .append(Button.createRed("☐", "/dominion set show_border true " + dominion.getName() + " " + page)) + .append("玩家进入时是否显示领地边界")); + } if (dominion.getTeleport()) { view.add(Line.create() .append(Button.createGreen("☑", "/dominion set teleport false " + dominion.getName() + " " + page)) diff --git a/src/main/java/cn/lunadeer/dominion/tuis/DominionSizeInfo.java b/src/main/java/cn/lunadeer/dominion/tuis/DominionSizeInfo.java index a9a0992..1d805ae 100644 --- a/src/main/java/cn/lunadeer/dominion/tuis/DominionSizeInfo.java +++ b/src/main/java/cn/lunadeer/dominion/tuis/DominionSizeInfo.java @@ -12,6 +12,7 @@ import org.bukkit.entity.Player; import static cn.lunadeer.dominion.commands.Apis.playerOnly; import static cn.lunadeer.dominion.tuis.Apis.getDominionNameArg_1; +import static cn.lunadeer.dominion.utils.ParticleRender.showBoxBorder; public class DominionSizeInfo { public static void show(CommandSender sender, String[] args) { @@ -47,5 +48,6 @@ public class DominionSizeInfo { .append(Button.create("管理界面", "/dominion manage " + dominion.getName())) .append(Button.create("权限列表", "/dominion flag_info " + dominion.getName()))) .showOn(player); + showBoxBorder(dominion.getWorld(), x1, y1, z1, x2, y2, z2); } } diff --git a/src/main/java/cn/lunadeer/dominion/utils/Database.java b/src/main/java/cn/lunadeer/dominion/utils/Database.java index b236877..2d06c57 100644 --- a/src/main/java/cn/lunadeer/dominion/utils/Database.java +++ b/src/main/java/cn/lunadeer/dominion/utils/Database.java @@ -245,5 +245,8 @@ public class Database { addColumnIfNotExists("dominion", "tp_location", "TEXT NOT NULL DEFAULT 'default'"); addColumnIfNotExists("dominion", "teleport", "BOOLEAN NOT NULL DEFAULT FALSE"); addColumnIfNotExists("player_privilege", "teleport", "BOOLEAN NOT NULL DEFAULT FALSE"); + + // 1.21 + addColumnIfNotExists("dominion", "show_border", "BOOLEAN NOT NULL DEFAULT TRUE"); } } diff --git a/src/main/java/cn/lunadeer/dominion/utils/ParticleRender.java b/src/main/java/cn/lunadeer/dominion/utils/ParticleRender.java new file mode 100644 index 0000000..3f38b16 --- /dev/null +++ b/src/main/java/cn/lunadeer/dominion/utils/ParticleRender.java @@ -0,0 +1,55 @@ +package cn.lunadeer.dominion.utils; + +import cn.lunadeer.dominion.Dominion; +import cn.lunadeer.dominion.dtos.DominionDTO; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.World; + +public class ParticleRender { + + public static void showBoxBorder(DominionDTO dominion) { + showBoxBorder(dominion.getWorld(), dominion.getX1(), dominion.getY1(), dominion.getZ1(), dominion.getX2(), dominion.getY2(), dominion.getZ2()); + } + + public static void showBoxBorder(String world, int x1, int y1, int z1, int x2, int y2, int z2) { + showBoxBorder(new Location(Dominion.instance.getServer().getWorld(world), x1, y1, z1), new Location(Dominion.instance.getServer().getWorld(world), x2, y2, z2)); + } + + public static void showBoxBorder(Location loc1, Location loc2) { + Dominion.scheduler.region.run(Dominion.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); + } +}