From 7ebd2c5ea9b0dea00f68d5595e002a15d4a730dd Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Sat, 11 May 2024 18:51:50 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E4=BC=A0=E9=80=81=E6=9C=BA=E5=88=B6=EF=BC=8C=E7=8E=B0=E5=9C=A8?= =?UTF-8?q?=E5=8D=B3=E4=BD=BF=E6=B2=A1=E6=9C=89=E6=89=8B=E5=8A=A8=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=85=B7=E4=BD=93=E4=BC=A0=E9=80=81=E7=82=B9=E4=B9=9F?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E8=BF=9B=E8=A1=8C=E4=BC=A0=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../dominion/commands/DominionOperate.java | 27 ++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 699075c1..a9048b8f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cn.lunadeer Dominion - 1.23.8-beta + 1.23.9-beta jar Dominion diff --git a/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java b/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java index ffa8ab11..2a0069bc 100644 --- a/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java +++ b/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java @@ -6,9 +6,13 @@ import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.PlayerPrivilegeDTO; import cn.lunadeer.dominion.utils.Notification; +import cn.lunadeer.dominion.utils.XLogger; import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.entity.Wolf; +import org.bukkit.event.player.PlayerTeleportEvent; import java.time.LocalDateTime; import java.util.Map; @@ -376,12 +380,6 @@ public static void teleportToDominion(CommandSender sender, String[] args) { } } - Location location = dominionDTO.getTpLocation(); - if (location == null) { - Notification.error(sender, "此领地没有设置传送点"); - return; - } - LocalDateTime now = LocalDateTime.now(); LocalDateTime next_time = Cache.instance.NextTimeAllowTeleport.get(player.getUniqueId()); if (next_time != null) { @@ -396,10 +394,25 @@ public static void teleportToDominion(CommandSender sender, String[] args) { } Cache.instance.NextTimeAllowTeleport.put(player.getUniqueId(), now.plusSeconds(Dominion.config.getTpCoolDown())); Dominion.scheduler.region.runDelayed(Dominion.instance, (instance) -> { + Location location = dominionDTO.getTpLocation(); + if (location == null) { + int x = (dominionDTO.getX1() + dominionDTO.getX2()) / 2; + int z = (dominionDTO.getZ1() + dominionDTO.getZ2()) / 2; + World world = Dominion.instance.getServer().getWorld(dominionDTO.getWorld()); + location = new Location(world, x, player.getY(), z); + XLogger.warn("领地 " + dominionDTO.getName() + " 没有设置传送点,将传送到中心点"); + } if (player.isOnline()) { - player.teleportAsync(location); + doTeleportSafely(player, location); Notification.info(player, "已将你传送到 " + dominionDTO.getName()); } }, Dominion.config.getTpDelay() == 0 ? 1 : 20L * Dominion.config.getTpDelay()); } + + private static void doTeleportSafely(Player player, Location location) { + location.getWorld().getChunkAtAsyncUrgently(location).thenAccept((chunk) -> { + location.setY(chunk.getWorld().getHighestBlockYAt(location) + 1); + player.teleportAsync(location, PlayerTeleportEvent.TeleportCause.PLUGIN); + }); + } } From d434c2dd913bd9d3218fb5201083953ae7f668ef Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Sun, 12 May 2024 01:07:32 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86=E4=BC=A0?= =?UTF-8?q?=E9=80=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../dominion/commands/DominionOperate.java | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a9048b8f..c073428a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cn.lunadeer Dominion - 1.23.9-beta + 1.23.10-beta jar Dominion diff --git a/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java b/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java index 2a0069bc..d311bd28 100644 --- a/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java +++ b/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java @@ -8,7 +8,10 @@ import cn.lunadeer.dominion.utils.Notification; import cn.lunadeer.dominion.utils.XLogger; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.entity.Wolf; @@ -411,7 +414,33 @@ public static void teleportToDominion(CommandSender sender, String[] args) { private static void doTeleportSafely(Player player, Location location) { location.getWorld().getChunkAtAsyncUrgently(location).thenAccept((chunk) -> { - location.setY(chunk.getWorld().getHighestBlockYAt(location) + 1); + int max_attempts = 512; + while (location.getBlock().isPassable()) { + location.setY(location.getY() - 1); + max_attempts--; + if (max_attempts <= 0) { + Notification.error(player, "传送目的地不安全,已取消传送"); + return; + } + } + Block up1 = location.getBlock().getRelative(BlockFace.UP); + Block up2 = up1.getRelative(BlockFace.UP); + max_attempts = 512; + while (!(up1.isPassable() && !up1.isLiquid()) || !(up2.isPassable() && !up2.isLiquid())) { + location.setY(location.getY() + 1); + up1 = location.getBlock().getRelative(BlockFace.UP); + up2 = up1.getRelative(BlockFace.UP); + max_attempts--; + if (max_attempts <= 0) { + Notification.error(player, "传送目的地不安全,已取消传送"); + return; + } + } + location.setY(location.getY() + 1); + if (location.getBlock().getRelative(BlockFace.DOWN).getType() == Material.LAVA) { + Notification.error(player, "传送目的地不安全,已取消传送"); + return; + } player.teleportAsync(location, PlayerTeleportEvent.TeleportCause.PLUGIN); }); } From 10fd19b67a810ee63a40dc8f92df5f736cf4cd04 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Sun, 12 May 2024 18:44:42 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E4=BE=9D=E8=B5=96=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?sql=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index c073428a..527163bb 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cn.lunadeer Dominion - 1.23.10-beta + 1.23.11-beta jar Dominion @@ -78,12 +78,12 @@ org.xerial sqlite-jdbc - 3.34.0 + 3.41.2.2 org.postgresql postgresql - 42.6.0 + 42.7.2 com.github.BlueMap-Minecraft From 4f752d19084e0428b5d06b5c592f076765f8dea1 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Mon, 13 May 2024 00:51:37 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=BB=93=E6=9E=84=EF=BC=8C=E6=8F=90=E9=AB=98=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/cn/lunadeer/dominion/Dominion.java | 10 +++++++--- .../java/cn/lunadeer/dominion/dtos/DominionDTO.java | 4 ++-- src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java | 4 ++-- .../cn/lunadeer/dominion/dtos/PlayerPrivilegeDTO.java | 4 ++-- .../dominion/{utils => managers}/ConfigManager.java | 3 ++- .../Database.java => managers/DatabaseManager.java} | 5 +++-- 6 files changed, 18 insertions(+), 12 deletions(-) rename src/main/java/cn/lunadeer/dominion/{utils => managers}/ConfigManager.java (99%) rename src/main/java/cn/lunadeer/dominion/{utils/Database.java => managers/DatabaseManager.java} (99%) diff --git a/src/main/java/cn/lunadeer/dominion/Dominion.java b/src/main/java/cn/lunadeer/dominion/Dominion.java index ebc1fe1e..07412741 100644 --- a/src/main/java/cn/lunadeer/dominion/Dominion.java +++ b/src/main/java/cn/lunadeer/dominion/Dominion.java @@ -3,7 +3,11 @@ import cn.lunadeer.dominion.events.EnvironmentEvents; import cn.lunadeer.dominion.events.PlayerEvents; import cn.lunadeer.dominion.events.SelectPointEvents; -import cn.lunadeer.dominion.utils.*; +import cn.lunadeer.dominion.managers.ConfigManager; +import cn.lunadeer.dominion.managers.DatabaseManager; +import cn.lunadeer.dominion.utils.GiteaReleaseCheck; +import cn.lunadeer.dominion.utils.Scheduler; +import cn.lunadeer.dominion.utils.XLogger; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.plugin.java.JavaPlugin; @@ -22,8 +26,8 @@ public void onEnable() { // Plugin startup logic instance = this; config = new ConfigManager(this); - dbConnection = Database.createConnection(); - Database.migrate(); + dbConnection = DatabaseManager.createConnection(); + DatabaseManager.migrate(); scheduler = new Scheduler(this); AutoClean.run(); Cache.instance = new Cache(); diff --git a/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java b/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java index 8991aff7..407351f8 100644 --- a/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java +++ b/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java @@ -2,7 +2,7 @@ import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Dominion; -import cn.lunadeer.dominion.utils.Database; +import cn.lunadeer.dominion.managers.DatabaseManager; import cn.lunadeer.dominion.utils.XLogger; import org.bukkit.Location; import org.bukkit.World; @@ -18,7 +18,7 @@ public class DominionDTO { private static List query(String sql) { List dominions = new ArrayList<>(); - try (ResultSet rs = Database.query(sql)) { + try (ResultSet rs = DatabaseManager.query(sql)) { if (sql.contains("UPDATE") || sql.contains("DELETE") || sql.contains("INSERT")) { // 如果是更新操作,重新加载缓存 Cache.instance.loadDominions(); diff --git a/src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java b/src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java index 39d1205e..b84dbac2 100644 --- a/src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java +++ b/src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.dtos; -import cn.lunadeer.dominion.utils.Database; +import cn.lunadeer.dominion.managers.DatabaseManager; import cn.lunadeer.dominion.utils.XLogger; import org.bukkit.entity.Player; @@ -31,7 +31,7 @@ public PlayerDTO onJoin() { private static List query(String sql) { List players = new ArrayList<>(); - try (ResultSet rs = Database.query(sql)) { + try (ResultSet rs = DatabaseManager.query(sql)) { if (rs == null) return players; while (rs.next()) { Integer id = rs.getInt("id"); diff --git a/src/main/java/cn/lunadeer/dominion/dtos/PlayerPrivilegeDTO.java b/src/main/java/cn/lunadeer/dominion/dtos/PlayerPrivilegeDTO.java index a09dd216..8a3a21a8 100644 --- a/src/main/java/cn/lunadeer/dominion/dtos/PlayerPrivilegeDTO.java +++ b/src/main/java/cn/lunadeer/dominion/dtos/PlayerPrivilegeDTO.java @@ -1,7 +1,7 @@ package cn.lunadeer.dominion.dtos; import cn.lunadeer.dominion.Cache; -import cn.lunadeer.dominion.utils.Database; +import cn.lunadeer.dominion.managers.DatabaseManager; import cn.lunadeer.dominion.utils.XLogger; import java.sql.ResultSet; @@ -582,7 +582,7 @@ public PlayerPrivilegeDTO(UUID playerUUID, Integer domID, private static List query(String sql) { List players = new ArrayList<>(); - try (ResultSet rs = Database.query(sql)) { + try (ResultSet rs = DatabaseManager.query(sql)) { if (sql.contains("UPDATE") || sql.contains("DELETE") || sql.contains("INSERT")) { // 如果是更新操作,重新加载缓存 Cache.instance.loadPlayerPrivileges(); diff --git a/src/main/java/cn/lunadeer/dominion/utils/ConfigManager.java b/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java similarity index 99% rename from src/main/java/cn/lunadeer/dominion/utils/ConfigManager.java rename to src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java index 25517da8..12106ee7 100644 --- a/src/main/java/cn/lunadeer/dominion/utils/ConfigManager.java +++ b/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java @@ -1,6 +1,7 @@ -package cn.lunadeer.dominion.utils; +package cn.lunadeer.dominion.managers; import cn.lunadeer.dominion.Dominion; +import cn.lunadeer.dominion.utils.XLogger; import org.bukkit.Material; import org.bukkit.configuration.file.FileConfiguration; diff --git a/src/main/java/cn/lunadeer/dominion/utils/Database.java b/src/main/java/cn/lunadeer/dominion/managers/DatabaseManager.java similarity index 99% rename from src/main/java/cn/lunadeer/dominion/utils/Database.java rename to src/main/java/cn/lunadeer/dominion/managers/DatabaseManager.java index 2d06c576..2791865a 100644 --- a/src/main/java/cn/lunadeer/dominion/utils/Database.java +++ b/src/main/java/cn/lunadeer/dominion/managers/DatabaseManager.java @@ -1,10 +1,11 @@ -package cn.lunadeer.dominion.utils; +package cn.lunadeer.dominion.managers; import cn.lunadeer.dominion.Dominion; +import cn.lunadeer.dominion.utils.XLogger; import java.sql.*; -public class Database { +public class DatabaseManager { public static Connection createConnection() { try {