From f4bf972efce435242fd9864855a38a13f5c81c89 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Sun, 26 May 2024 14:04:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BD=93=E7=8E=A9=E5=AE=B6?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E7=A7=BB=E5=8A=A8=E6=9D=83=E9=99=90=E6=98=AF?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E8=A2=AB=E2=80=9C=E4=B8=8D=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E9=A3=9E=E8=A1=8C=E2=80=9D=E8=A2=AB=E8=B8=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../dominion/events/PlayerEvents.java | 24 +++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 919faf3..b3378a9 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cn.lunadeer Dominion - 1.26.6-beta + 1.26.7-beta jar Dominion diff --git a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java index 1244e55..97cacd4 100644 --- a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java +++ b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java @@ -1,9 +1,11 @@ package cn.lunadeer.dominion.events; import cn.lunadeer.dominion.Cache; +import cn.lunadeer.dominion.Dominion; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.Flag; import cn.lunadeer.dominion.dtos.PlayerDTO; +import cn.lunadeer.minecraftpluginutils.Teleport; import io.papermc.paper.event.entity.EntityDyeEvent; import org.bukkit.GameMode; import org.bukkit.Location; @@ -38,7 +40,7 @@ public class PlayerEvents implements Listener { PlayerDTO player = PlayerDTO.get(bukkitPlayer); player.onJoin(); // update name if (!Flag.FLY.getEnable()) { - if (bukkitPlayer.isOp() || bukkitPlayer.getGameMode()== GameMode.CREATIVE || bukkitPlayer.getGameMode() == GameMode.SPECTATOR) { + if (bukkitPlayer.isOp() || bukkitPlayer.getGameMode() == GameMode.CREATIVE || bukkitPlayer.getGameMode() == GameMode.SPECTATOR) { // do nothing } else { bukkitPlayer.setAllowFlight(false); @@ -511,7 +513,25 @@ public class PlayerEvents implements Listener { public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player); - checkFlag(dom, Flag.MOVE, player, event); + if (!checkFlag(dom, Flag.MOVE, player, null)) { + Location to = player.getLocation(); + int x1 = Math.abs(to.getBlockX() - dom.getX1()); + int x2 = Math.abs(to.getBlockX() - dom.getX2()); + int z1 = Math.abs(to.getBlockZ() - dom.getZ1()); + int z2 = Math.abs(to.getBlockZ() - dom.getZ2()); + // find min distance + int min = Math.min(Math.min(x1, x2), Math.min(z1, z2)); + if (min == x1) { + to.setX(dom.getX1() - 1); + } else if (min == x2) { + to.setX(dom.getX2() + 1); + } else if (min == z1) { + to.setZ(dom.getZ1() - 1); + } else { + to.setZ(dom.getZ2() + 1); + } + Teleport.doTeleportSafely(Dominion.instance, player, to); + } } @EventHandler(priority = EventPriority.HIGHEST) // place