Skip to content

Commit b5b435d

Browse files
committed
Improve check logic
1 parent 395f8f8 commit b5b435d

File tree

1 file changed

+44
-46
lines changed

1 file changed

+44
-46
lines changed

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

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,57 +23,55 @@ public LoginLocationFixListener(Plugin plugin) {
2323
@EventHandler
2424
public void onPlayerJoin(PlayerJoinEvent event) {
2525
Player player = event.getPlayer();
26-
if (!authmeApi.isRegistered(player.getName()) || !authmeApi.isAuthenticated(player)) {
27-
Material material = Material.matchMaterial("PORTAL");
28-
if(material == null){
29-
material = Material.matchMaterial("PORTAL_BLOCK");
30-
} else {
31-
material = Material.matchMaterial("NETHER_PORTAL");
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;
3236
}
33-
Location JoinLocation = player.getLocation().getBlock().getLocation().add(0.5, 0.1, 0.5);
34-
if (AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_PORTAL)) {
35-
if (!JoinLocation.getBlock().getType().equals(material) && !JoinLocation.getBlock().getRelative(BlockFace.UP).getType().equals(material)) {
36-
return;
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;
3744
}
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);
3861
Block JoinBlock = JoinLocation.getBlock();
39-
boolean solved = false;
40-
for (BlockFace face : faces) {
41-
if (JoinBlock.getRelative(face).getType().equals(Material.AIR) && JoinBlock.getRelative(face).getRelative(BlockFace.UP).getType().equals(Material.AIR)) {
42-
player.teleport(JoinBlock.getRelative(face).getLocation().add(0.5, 0.1, 0.5));
43-
solved = true;
44-
break;
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);
4567
}
68+
player.teleport(JoinBlock.getLocation().add(0.5, 0.1, 0.5));
69+
player.sendMessage("§a你被埋住了, 坐标已修正, 下次下线之前请小心!");
70+
break;
4671
}
47-
if (!solved) {
48-
JoinBlock.getRelative(BlockFace.UP).breakNaturally();
49-
JoinBlock.breakNaturally();
50-
}
51-
player.sendMessage("§a你在登录时卡在了地狱门, 现已修正");
52-
} else if (AuthMe.settings.getProperty(SecuritySettings.LOGIN_LOC_FIX_SUB_UNDERGROUND)) {
53-
Material UpType = JoinLocation.getBlock().getRelative(BlockFace.UP).getType();
54-
World world = player.getWorld();
55-
int MaxHeight = world.getMaxHeight();
56-
int MinHeight = world.getMinHeight();
57-
if (!UpType.isOccluding() && !UpType.equals(Material.LAVA)) {
58-
return;
59-
}
60-
for (int i = MinHeight; i <= MaxHeight; i++) {
61-
JoinLocation.setY(i);
62-
Block JoinBlock = JoinLocation.getBlock();
63-
if ((JoinBlock.getRelative(BlockFace.DOWN).getType().isBlock())
64-
&& JoinBlock.getType().equals(Material.AIR)
65-
&& JoinBlock.getRelative(BlockFace.UP).getType().equals(Material.AIR)) {
66-
if (JoinBlock.getRelative(BlockFace.DOWN).getType().equals(Material.LAVA)) {
67-
JoinBlock.getRelative(BlockFace.DOWN).setType(Material.DIRT);
68-
}
69-
player.teleport(JoinBlock.getLocation().add(0.5, 0.1, 0.5));
70-
player.sendMessage("§a你被埋住了, 坐标已修正, 下次下线之前请小心!");
71-
break;
72-
}
73-
if (i == MaxHeight) {
74-
player.teleport(JoinBlock.getLocation().add(0.5, 1.1, 0.5));
75-
player.sendMessage("§a你被埋住了, 坐标无法修正, 只好送你去了最高点, 自求多福吧少年~");
76-
}
72+
if (i == MaxHeight) {
73+
player.teleport(JoinBlock.getLocation().add(0.5, 1.1, 0.5));
74+
player.sendMessage("§a你被埋住了, 坐标无法修正, 只好送你去了最高点, 自求多福吧少年~");
7775
}
7876
}
7977
}

0 commit comments

Comments
 (0)