From b5b435d398ad197c8624e80776fa6436910fdfe5 Mon Sep 17 00:00:00 2001 From: HaHaWTH Date: Fri, 13 Oct 2023 20:13:02 +0800 Subject: [PATCH] Improve check logic --- .../listener/LoginLocationFixListener.java | 90 +++++++++---------- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java b/src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java index fbf05b32..49f38958 100644 --- a/src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java +++ b/src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java @@ -23,57 +23,55 @@ public class LoginLocationFixListener implements Listener{ @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - if (!authmeApi.isRegistered(player.getName()) || !authmeApi.isAuthenticated(player)) { - Material material = Material.matchMaterial("PORTAL"); - if(material == null){ - material = Material.matchMaterial("PORTAL_BLOCK"); - } else { - material = Material.matchMaterial("NETHER_PORTAL"); + Material material = Material.matchMaterial("PORTAL"); + if(material == null){ + material = Material.matchMaterial("PORTAL_BLOCK"); + } else { + material = Material.matchMaterial("NETHER_PORTAL"); + } + Location JoinLocation = player.getLocation().getBlock().getLocation().add(0.5, 0.1, 0.5); + if (AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_PORTAL)) { + if (!JoinLocation.getBlock().getType().equals(material) && !JoinLocation.getBlock().getRelative(BlockFace.UP).getType().equals(material)) { + return; } - Location JoinLocation = player.getLocation().getBlock().getLocation().add(0.5, 0.1, 0.5); - if (AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_PORTAL)) { - if (!JoinLocation.getBlock().getType().equals(material) && !JoinLocation.getBlock().getRelative(BlockFace.UP).getType().equals(material)) { - return; + Block JoinBlock = JoinLocation.getBlock(); + boolean solved = false; + for (BlockFace face : faces) { + if (JoinBlock.getRelative(face).getType().equals(Material.AIR) && JoinBlock.getRelative(face).getRelative(BlockFace.UP).getType().equals(Material.AIR)) { + player.teleport(JoinBlock.getRelative(face).getLocation().add(0.5, 0.1, 0.5)); + solved = true; + break; } + } + if (!solved) { + JoinBlock.getRelative(BlockFace.UP).breakNaturally(); + JoinBlock.breakNaturally(); + } + player.sendMessage("§a你在登录时卡在了地狱门, 现已修正"); + } else if (AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_UNDERGROUND)) { + Material UpType = JoinLocation.getBlock().getRelative(BlockFace.UP).getType(); + World world = player.getWorld(); + int MaxHeight = world.getMaxHeight(); + int MinHeight = world.getMinHeight(); + if (!UpType.isOccluding() && !UpType.equals(Material.LAVA)) { + return; + } + for (int i = MinHeight; i <= MaxHeight; i++) { + JoinLocation.setY(i); Block JoinBlock = JoinLocation.getBlock(); - boolean solved = false; - for (BlockFace face : faces) { - if (JoinBlock.getRelative(face).getType().equals(Material.AIR) && JoinBlock.getRelative(face).getRelative(BlockFace.UP).getType().equals(Material.AIR)) { - player.teleport(JoinBlock.getRelative(face).getLocation().add(0.5, 0.1, 0.5)); - solved = true; - break; + if ((JoinBlock.getRelative(BlockFace.DOWN).getType().isBlock()) + && JoinBlock.getType().equals(Material.AIR) + && JoinBlock.getRelative(BlockFace.UP).getType().equals(Material.AIR)) { + if (JoinBlock.getRelative(BlockFace.DOWN).getType().equals(Material.LAVA)) { + JoinBlock.getRelative(BlockFace.DOWN).setType(Material.DIRT); } + player.teleport(JoinBlock.getLocation().add(0.5, 0.1, 0.5)); + player.sendMessage("§a你被埋住了, 坐标已修正, 下次下线之前请小心!"); + break; } - if (!solved) { - JoinBlock.getRelative(BlockFace.UP).breakNaturally(); - JoinBlock.breakNaturally(); - } - player.sendMessage("§a你在登录时卡在了地狱门, 现已修正"); - } else if (AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_UNDERGROUND)) { - Material UpType = JoinLocation.getBlock().getRelative(BlockFace.UP).getType(); - World world = player.getWorld(); - int MaxHeight = world.getMaxHeight(); - int MinHeight = world.getMinHeight(); - if (!UpType.isOccluding() && !UpType.equals(Material.LAVA)) { - return; - } - for (int i = MinHeight; i <= MaxHeight; i++) { - JoinLocation.setY(i); - Block JoinBlock = JoinLocation.getBlock(); - if ((JoinBlock.getRelative(BlockFace.DOWN).getType().isBlock()) - && JoinBlock.getType().equals(Material.AIR) - && JoinBlock.getRelative(BlockFace.UP).getType().equals(Material.AIR)) { - if (JoinBlock.getRelative(BlockFace.DOWN).getType().equals(Material.LAVA)) { - JoinBlock.getRelative(BlockFace.DOWN).setType(Material.DIRT); - } - player.teleport(JoinBlock.getLocation().add(0.5, 0.1, 0.5)); - player.sendMessage("§a你被埋住了, 坐标已修正, 下次下线之前请小心!"); - break; - } - if (i == MaxHeight) { - player.teleport(JoinBlock.getLocation().add(0.5, 1.1, 0.5)); - player.sendMessage("§a你被埋住了, 坐标无法修正, 只好送你去了最高点, 自求多福吧少年~"); - } + if (i == MaxHeight) { + player.teleport(JoinBlock.getLocation().add(0.5, 1.1, 0.5)); + player.sendMessage("§a你被埋住了, 坐标无法修正, 只好送你去了最高点, 自求多福吧少年~"); } } }