Skip to content

Commit 3112308

Browse files
committed
Improve check logic
1 parent b5b435d commit 3112308

File tree

1 file changed

+48
-44
lines changed

1 file changed

+48
-44
lines changed

src/main/java/fr/xephi/authme/listener/LoginLocationFixListener.java

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package fr.xephi.authme.listener;
22
import fr.xephi.authme.AuthMe;
33
import fr.xephi.authme.api.v3.AuthMeApi;
4+
import fr.xephi.authme.events.LoginEvent;
45
import fr.xephi.authme.settings.properties.SecuritySettings;
56
import org.bukkit.Location;
67
import org.bukkit.Material;
78
import org.bukkit.World;
89
import org.bukkit.block.Block;
910
import org.bukkit.block.BlockFace;
1011
import org.bukkit.entity.Player;
12+
import org.bukkit.event.Event;
1113
import org.bukkit.event.EventHandler;
1214
import org.bukkit.event.Listener;
1315
import org.bukkit.event.player.PlayerJoinEvent;
@@ -23,55 +25,57 @@ public LoginLocationFixListener(Plugin plugin) {
2325
@EventHandler
2426
public void onPlayerJoin(PlayerJoinEvent event) {
2527
Player player = event.getPlayer();
26-
Material material = Material.matchMaterial("PORTAL");
27-
if(material == null){
28-
material = Material.matchMaterial("PORTAL_BLOCK");
29-
} else {
30-
material = Material.matchMaterial("NETHER_PORTAL");
31-
}
32-
Location JoinLocation = player.getLocation().getBlock().getLocation().add(0.5, 0.1, 0.5);
33-
if (AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_PORTAL)) {
34-
if (!JoinLocation.getBlock().getType().equals(material) && !JoinLocation.getBlock().getRelative(BlockFace.UP).getType().equals(material)) {
35-
return;
28+
if (authmeApi.isRegistered(player.getName())) {
29+
Material material = Material.matchMaterial("PORTAL");
30+
if (material == null) {
31+
material = Material.matchMaterial("PORTAL_BLOCK");
32+
} else {
33+
material = Material.matchMaterial("NETHER_PORTAL");
3634
}
37-
Block JoinBlock = JoinLocation.getBlock();
38-
boolean solved = false;
39-
for (BlockFace face : faces) {
40-
if (JoinBlock.getRelative(face).getType().equals(Material.AIR) && JoinBlock.getRelative(face).getRelative(BlockFace.UP).getType().equals(Material.AIR)) {
41-
player.teleport(JoinBlock.getRelative(face).getLocation().add(0.5, 0.1, 0.5));
42-
solved = true;
43-
break;
35+
Location JoinLocation = player.getLocation().getBlock().getLocation().add(0.5, 0.1, 0.5);
36+
if (AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_PORTAL)) {
37+
if (!JoinLocation.getBlock().getType().equals(material) && !JoinLocation.getBlock().getRelative(BlockFace.UP).getType().equals(material)) {
38+
return;
4439
}
45-
}
46-
if (!solved) {
47-
JoinBlock.getRelative(BlockFace.UP).breakNaturally();
48-
JoinBlock.breakNaturally();
49-
}
50-
player.sendMessage("§a你在登录时卡在了地狱门, 现已修正");
51-
} else if (AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_UNDERGROUND)) {
52-
Material UpType = JoinLocation.getBlock().getRelative(BlockFace.UP).getType();
53-
World world = player.getWorld();
54-
int MaxHeight = world.getMaxHeight();
55-
int MinHeight = world.getMinHeight();
56-
if (!UpType.isOccluding() && !UpType.equals(Material.LAVA)) {
57-
return;
58-
}
59-
for (int i = MinHeight; i <= MaxHeight; i++) {
60-
JoinLocation.setY(i);
6140
Block JoinBlock = JoinLocation.getBlock();
62-
if ((JoinBlock.getRelative(BlockFace.DOWN).getType().isBlock())
63-
&& JoinBlock.getType().equals(Material.AIR)
64-
&& JoinBlock.getRelative(BlockFace.UP).getType().equals(Material.AIR)) {
65-
if (JoinBlock.getRelative(BlockFace.DOWN).getType().equals(Material.LAVA)) {
66-
JoinBlock.getRelative(BlockFace.DOWN).setType(Material.DIRT);
41+
boolean solved = false;
42+
for (BlockFace face : faces) {
43+
if (JoinBlock.getRelative(face).getType().equals(Material.AIR) && JoinBlock.getRelative(face).getRelative(BlockFace.UP).getType().equals(Material.AIR)) {
44+
player.teleport(JoinBlock.getRelative(face).getLocation().add(0.5, 0.1, 0.5));
45+
solved = true;
46+
break;
6747
}
68-
player.teleport(JoinBlock.getLocation().add(0.5, 0.1, 0.5));
69-
player.sendMessage("§a你被埋住了, 坐标已修正, 下次下线之前请小心!");
70-
break;
7148
}
72-
if (i == MaxHeight) {
73-
player.teleport(JoinBlock.getLocation().add(0.5, 1.1, 0.5));
74-
player.sendMessage("§a你被埋住了, 坐标无法修正, 只好送你去了最高点, 自求多福吧少年~");
49+
if (!solved) {
50+
JoinBlock.getRelative(BlockFace.UP).breakNaturally();
51+
JoinBlock.breakNaturally();
52+
}
53+
player.sendMessage("§a你在登录时卡在了地狱门, 现已修正");
54+
} else if (AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_UNDERGROUND)) {
55+
Material UpType = JoinLocation.getBlock().getRelative(BlockFace.UP).getType();
56+
World world = player.getWorld();
57+
int MaxHeight = world.getMaxHeight();
58+
int MinHeight = world.getMinHeight();
59+
if (!UpType.isOccluding() && !UpType.equals(Material.LAVA)) {
60+
return;
61+
}
62+
for (int i = MinHeight; i <= MaxHeight; i++) {
63+
JoinLocation.setY(i);
64+
Block JoinBlock = JoinLocation.getBlock();
65+
if ((JoinBlock.getRelative(BlockFace.DOWN).getType().isBlock())
66+
&& JoinBlock.getType().equals(Material.AIR)
67+
&& JoinBlock.getRelative(BlockFace.UP).getType().equals(Material.AIR)) {
68+
if (JoinBlock.getRelative(BlockFace.DOWN).getType().equals(Material.LAVA)) {
69+
JoinBlock.getRelative(BlockFace.DOWN).setType(Material.DIRT);
70+
}
71+
player.teleport(JoinBlock.getLocation().add(0.5, 0.1, 0.5));
72+
player.sendMessage("§a你被埋住了, 坐标已修正, 下次下线之前请小心!");
73+
break;
74+
}
75+
if (i == MaxHeight) {
76+
player.teleport(JoinBlock.getLocation().add(0.5, 1.1, 0.5));
77+
player.sendMessage("§a你被埋住了, 坐标无法修正, 只好送你去了最高点, 自求多福吧少年~");
78+
}
7579
}
7680
}
7781
}

0 commit comments

Comments
 (0)