No need to remove

This commit is contained in:
HaHaWTH 2023-11-25 00:30:54 +08:00
parent 8db8d0f6da
commit c170c70639

View File

@ -23,7 +23,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -46,7 +45,6 @@ import static org.bukkit.Bukkit.getServer;
public class GuiCaptchaHandler implements Listener { public class GuiCaptchaHandler implements Listener {
//define AuthMeApi //define AuthMeApi
private final AuthMeApi authmeApi = AuthMeApi.getInstance(); private final AuthMeApi authmeApi = AuthMeApi.getInstance();
StringBuilder sb = new StringBuilder();
@Inject @Inject
private BukkitService bukkitService; private BukkitService bukkitService;
@Inject @Inject
@ -74,7 +72,7 @@ public class GuiCaptchaHandler implements Listener {
Random howManyRandom = new Random(); Random howManyRandom = new Random();
int howLongIsRandomString; int howLongIsRandomString = (howManyRandom.nextInt(3) + 1);
public GuiCaptchaHandler() { public GuiCaptchaHandler() {
} }
@ -85,25 +83,10 @@ public class GuiCaptchaHandler implements Listener {
return settings.getProperty(HooksSettings.HOOK_FLOODGATE_PLAYER) && settings.getProperty(SecuritySettings.GUI_CAPTCHA_BE_COMPATIBILITY) && org.geysermc.floodgate.api.FloodgateApi.getInstance().isFloodgateId(uuid) && getServer().getPluginManager().getPlugin("floodgate") != null; return settings.getProperty(HooksSettings.HOOK_FLOODGATE_PLAYER) && settings.getProperty(SecuritySettings.GUI_CAPTCHA_BE_COMPATIBILITY) && org.geysermc.floodgate.api.FloodgateApi.getInstance().isFloodgateId(uuid) && getServer().getPluginManager().getPlugin("floodgate") != null;
} }
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(PlayerLoginEvent event) {
bukkitService.runTaskAsynchronously(() -> {
randomString = "";
howLongIsRandomString = (howManyRandom.nextInt(3) + 1);
sb = new StringBuilder();
for (int i = 0; i < howLongIsRandomString; i++) { private void removePacketListeners() {
//生成随机索引号 ProtocolLibrary.getProtocolManager().removePacketListener(windowPacketListener);
int index = randomItemSet.nextInt(randomSet.length()); ProtocolLibrary.getProtocolManager().removePacketListener(chatPacketListener);
// 从字符串中获取由索引 index 指定的字符
char randomChar = randomSet.charAt(index);
// 将字符追加到字符串生成器
sb.append(randomChar);
}
});
} }
@EventHandler @EventHandler
@ -132,25 +115,29 @@ public class GuiCaptchaHandler implements Listener {
String name = playerunreg.getName(); String name = playerunreg.getName();
if (!authmeApi.isRegistered(name) && !isNpc(playerunreg)) { if (!authmeApi.isRegistered(name) && !isNpc(playerunreg)) {
String ip = getPlayerIp(playerunreg); String ip = getPlayerIp(playerunreg);
if (whiteList.isEmpty() || !whiteList.contains(authmeApi.getCountryCode(ip))) { if (!whiteList.isEmpty()) {
if (whiteList.contains(authmeApi.getCountryCode(ip))) {
return;
}
}
if (isBedrockPlayer(playerunreg.getUniqueId())) { if (isBedrockPlayer(playerunreg.getUniqueId())) {
closeReasonMap.put(playerunreg, "verified"); closeReasonMap.put(playerunreg, "verified");
messages.send(playerunreg, MessageKey.GUI_CAPTCHA_VERIFIED_AUTO_BEDROCK); messages.send(playerunreg, MessageKey.GUI_CAPTCHA_VERIFIED_AUTO_BEDROCK);
return; return;
} }
bukkitService.runTaskAsynchronously(() -> { bukkitService.runTaskAsynchronously(() -> {
// StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
// howLongIsRandomString = (howManyRandom.nextInt(3) + 1); howLongIsRandomString = (howManyRandom.nextInt(3) + 1);
// for (int i = 0; i < howLongIsRandomString; i++) { for (int i = 0; i < howLongIsRandomString; i++) {
// //生成随机索引号 //生成随机索引号
// int index = randomItemSet.nextInt(randomSet.length()); int index = randomItemSet.nextInt(randomSet.length());
//
// // 从字符串中获取由索引 index 指定的字符 // 从字符串中获取由索引 index 指定的字符
// char randomChar = randomSet.charAt(index); char randomChar = randomSet.charAt(index);
//
// // 将字符追加到字符串生成器 // 将字符追加到字符串生成器
// sb.append(randomChar); sb.append(randomChar);
// } }
bukkitService.runTask(() -> { bukkitService.runTask(() -> {
randomString = sb.toString(); randomString = sb.toString();
@ -238,7 +225,6 @@ public class GuiCaptchaHandler implements Listener {
}); });
} }
} }
}
private void deletePlayerData(UUID playerUUID) { private void deletePlayerData(UUID playerUUID) {
// 获取服务器的存储文件夹路径 // 获取服务器的存储文件夹路径
@ -294,8 +280,10 @@ public class GuiCaptchaHandler implements Listener {
deleteAuthMePlayerData(playerUUID); deleteAuthMePlayerData(playerUUID);
} }
}, 100L); }, 100L);
removePacketListeners();
return; return;
} }
removePacketListeners();
closeReasonMap.remove(player); closeReasonMap.remove(player);
} }
} }