From 14cc0abdc543fb87f2361332f8b10e4a1fdfd9c7 Mon Sep 17 00:00:00 2001 From: HaHaWTH Date: Fri, 13 Oct 2023 18:43:05 +0800 Subject: [PATCH] Add LoginLocationFixListener feature --- src/main/java/fr/xephi/authme/AuthMe.java | 4 ++ .../listener/LoginLocationFixListener.java | 72 +++++++++++++++++++ .../settings/properties/SecuritySettings.java | 9 +++ 3 files changed, 85 insertions(+) create mode 100644 src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index f0998ba7..8b10d60d 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -18,6 +18,7 @@ import fr.xephi.authme.initialization.SettingsProvider; import fr.xephi.authme.initialization.TaskCloser; import fr.xephi.authme.listener.BlockListener; import fr.xephi.authme.listener.EntityListener; +import fr.xephi.authme.listener.LoginLocationFixListener; import fr.xephi.authme.listener.PlayerListener; import fr.xephi.authme.listener.PlayerListener111; import fr.xephi.authme.listener.PlayerListener19; @@ -210,6 +211,9 @@ public class AuthMe extends JavaPlugin { if (settings.getProperty(SecuritySettings.ANTI_GHOST_PLAYERS)) { getServer().getPluginManager().registerEvents(new DoubleLoginFixListener((Plugin) this), this); } + if (settings.getProperty(SecuritySettings.LOGIN_LOC_FIX)) { + getServer().getPluginManager().registerEvents(new LoginLocationFixListener((Plugin) this), this); + } if (settings.getProperty(SecuritySettings.GUI_CAPTCHA) && getServer().getPluginManager().isPluginEnabled("ProtocolLib")) { getServer().getPluginManager().registerEvents(new GuiCaptchaHandler((Plugin) this), this); logger.info("(Alpha4)GUICaptcha Feature is enabled successfully!"); diff --git a/src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java b/src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java new file mode 100644 index 00000000..76f89cb5 --- /dev/null +++ b/src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java @@ -0,0 +1,72 @@ +package fr.xephi.authme.listener; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.settings.properties.SecuritySettings; +import org.bukkit.ChatColor; +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.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.plugin.Plugin; + +public class LoginLocationFixListener implements Listener{ + private final Plugin plugin; + public LoginLocationFixListener(Plugin plugin) { + this.plugin = plugin; + } + BlockFace[] faces = {BlockFace.WEST, BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.SOUTH_EAST, BlockFace.SOUTH_WEST, BlockFace.NORTH_EAST, BlockFace.NORTH_WEST}; + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + 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.NETHER_PORTAL) && !JoinLocation.getBlock().getRelative(BlockFace.UP).getType().equals(Material.NETHER_PORTAL)) { + 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(); + 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你被埋住了, 坐标无法修正, 只好送你去了最高点, 自求多福吧少年~"); + } + } + } + } +} diff --git a/src/main/java/fr/xephi/authme/settings/properties/SecuritySettings.java b/src/main/java/fr/xephi/authme/settings/properties/SecuritySettings.java index 0d37a247..09766c6f 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/SecuritySettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/SecuritySettings.java @@ -43,6 +43,15 @@ public final class SecuritySettings implements SettingsHolder { @Comment("Which world's player data should be deleted?(Enter the world *FOLDER* name where your players first logged in)") public static final Property DELETE_PLAYER_DATA_WORLD = newProperty("3rdPartyFeature.captcha.purgeWorldFolderName","world"); + @Comment("Should we enable the new LoginLocationFix feature?") + public static final Property LOGIN_LOC_FIX = newProperty("3rdPartyFeature.fixes.loginLocationFix.enabled", false); + + @Comment("Should we fix the location when players logged in the portal?") + public static final Property LOGIN_LOC_FIX_SUB_PORTAL = newProperty("3rdPartyFeature.fixes.loginLocationFix.fixPortalStuck", false); + + @Comment("Should we fix the location when players logged in the portal?") + public static final Property LOGIN_LOC_FIX_SUB_UNDERGROUND = newProperty("3rdPartyFeature.fixes.loginLocationFix.fixGroundStuck", false); + // @Comment({"Should we kick the players when they failed captcha too many times?", // "(Minimum value is 1)(Default: 3)"}) // public static final Property GUI_CAPTCHA_MAX_TRY = newProperty("3rdPartyFeature.captcha.maxTryTimes",3);