Logic Improvement
This commit is contained in:
parent
31123081c7
commit
7a7b148a7d
38
src/main/java/fr/xephi/authme/events/GUICaptchaEvent.java
Normal file
38
src/main/java/fr/xephi/authme/events/GUICaptchaEvent.java
Normal file
@ -0,0 +1,38 @@
|
||||
package fr.xephi.authme.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static fr.xephi.authme.listener.GuiCaptchaHandler.closeReasonMap;
|
||||
|
||||
public class GUICaptchaEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final Player player;
|
||||
|
||||
public GUICaptchaEvent(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public boolean isCaptchaVerified(Player player){
|
||||
return closeReasonMap.containsKey(player);
|
||||
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -4,9 +4,9 @@ import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.earth2me.essentials.libs.checkerframework.checker.nullness.qual.NonNull;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.api.v3.AuthMeApi;
|
||||
import fr.xephi.authme.events.GUICaptchaEvent;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
@ -32,17 +32,16 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
import static org.bukkit.Bukkit.getLogger;
|
||||
import static org.bukkit.Bukkit.getServer;
|
||||
public class GuiCaptchaHandler implements Listener {
|
||||
public class GuiCaptchaHandler implements Listener{
|
||||
//define AuthMeApi
|
||||
private final AuthMeApi authmeApi = AuthMeApi.getInstance();
|
||||
private final Plugin plugin;
|
||||
|
||||
|
||||
//define timesLeft
|
||||
public int timesLeft = 3;
|
||||
//Use ConcurrentHashMap to store player and their close reason
|
||||
/* We used many async tasks so there is concurrent**/
|
||||
protected static ConcurrentHashMap<Player, String> closeReasonMap = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<Player, String> closeReasonMap = new ConcurrentHashMap<>();
|
||||
//define randomStringSet
|
||||
String randomSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz!@#%&*()_+";
|
||||
String randomString = "";
|
||||
@ -66,6 +65,7 @@ public class GuiCaptchaHandler implements Listener {
|
||||
if (AuthMe.settings.getProperty(HooksSettings.HOOK_FLOODGATE_PLAYER) && AuthMe.settings.getProperty(SecuritySettings.GUI_CAPTCHA_BE_COMPATIBILITY) && org.geysermc.floodgate.api.FloodgateApi.getInstance().isFloodgateId(event.getWhoClicked().getUniqueId()) && (getServer().getPluginManager().isPluginEnabled("floodgate") || getServer().getPluginManager().getPlugin("floodgate") != null)) {
|
||||
if (!closeReasonMap.containsKey(player)) {
|
||||
closeReasonMap.put(player,"verified");
|
||||
Bukkit.getPluginManager().callEvent(new GUICaptchaEvent(player));
|
||||
return;
|
||||
}
|
||||
return;
|
||||
@ -73,6 +73,7 @@ public class GuiCaptchaHandler implements Listener {
|
||||
if (currentItem != null && currentItem.getType().equals(Material.REDSTONE_BLOCK)){
|
||||
event.setCancelled(true);
|
||||
closeReasonMap.put(player, "verified");
|
||||
Bukkit.getPluginManager().callEvent(new GUICaptchaEvent(player));
|
||||
player.closeInventory();
|
||||
player.sendMessage("§a验证完成");
|
||||
} else {
|
||||
@ -93,6 +94,7 @@ public class GuiCaptchaHandler implements Listener {
|
||||
if (!authmeApi.isRegistered(name)) {
|
||||
if (AuthMe.settings.getProperty(HooksSettings.HOOK_FLOODGATE_PLAYER) && AuthMe.settings.getProperty(SecuritySettings.GUI_CAPTCHA_BE_COMPATIBILITY) && org.geysermc.floodgate.api.FloodgateApi.getInstance().isFloodgateId(event.getPlayer().getUniqueId()) && (getServer().getPluginManager().isPluginEnabled("floodgate") || getServer().getPluginManager().getPlugin("floodgate") != null)) {
|
||||
closeReasonMap.put(playerunreg, "verified");
|
||||
Bukkit.getPluginManager().callEvent(new GUICaptchaEvent(playerunreg));
|
||||
playerunreg.sendMessage("§a基岩版自动验证完成");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1,20 +1,22 @@
|
||||
package fr.xephi.authme.listener;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.api.v3.AuthMeApi;
|
||||
import fr.xephi.authme.events.GUICaptchaEvent;
|
||||
import fr.xephi.authme.events.LoginEvent;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import org.bukkit.Bukkit;
|
||||
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.Event;
|
||||
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;
|
||||
private final AuthMeApi authmeApi = AuthMeApi.getInstance();
|
||||
@ -25,57 +27,55 @@ public class LoginLocationFixListener implements Listener{
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (authmeApi.isRegistered(player.getName())) {
|
||||
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你被埋住了, 坐标无法修正, 只好送你去了最高点, 自求多福吧少年~");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user