Add features to delete bot join data

This commit is contained in:
HaHaWTH 2023-09-29 16:13:48 +08:00
parent 6800356f10
commit 95342ae054
2 changed files with 78 additions and 32 deletions

View File

@ -27,9 +27,10 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import java.io.File;
import java.util.Objects; import java.util.Objects;
import java.util.Random; import java.util.Random;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level; import java.util.logging.Level;
@ -53,19 +54,8 @@ public class GuiCaptchaHandler implements Listener {
Random howManyRandom = new Random(); Random howManyRandom = new Random();
// public int tryTimesReset(){
// int tmp = 1;
// if (AuthMe.settings.getProperty(SecuritySettings.GUI_CAPTCHA_MAX_TRY) < 1){
// return tmp;
// }
// if (AuthMe.settings.getProperty(SecuritySettings.GUI_CAPTCHA_MAX_TRY) >= 1){
// tmp = AuthMe.settings.getProperty(SecuritySettings.GUI_CAPTCHA_MAX_TRY);
// return tmp;
// }
// return 3;
// }
int howLongIsRandomString = (howManyRandom.nextInt(3) + 1); int howLongIsRandomString = (howManyRandom.nextInt(3) + 1);
public GuiCaptchaHandler(Plugin plugin) { public GuiCaptchaHandler(Plugin plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
@ -78,6 +68,10 @@ public class GuiCaptchaHandler implements Listener {
// 获取点击事件的容器 // 获取点击事件的容器
if (!authmeApi.isRegistered(player.getName()) && !closeReasonMap.containsKey(player)) { if (!authmeApi.isRegistered(player.getName()) && !closeReasonMap.containsKey(player)) {
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 (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");
return;
}
return; return;
} }
if (Objects.requireNonNull(event.getCurrentItem()).getType().equals(Material.REDSTONE_BLOCK)) { if (Objects.requireNonNull(event.getCurrentItem()).getType().equals(Material.REDSTONE_BLOCK)) {
@ -212,16 +206,62 @@ public class GuiCaptchaHandler implements Listener {
} }
} }
private boolean shouldDeletePlayerData(Player player) {
if (!closeReasonMap.containsKey(player)){
return true;
}else {
return false;
}
}
private void deletePlayerData(UUID playerUUID) {
// 获取服务器的存储文件夹路径
File serverFolder = Bukkit.getServer().getWorldContainer();
String worldFolderName = AuthMe.settings.getProperty(SecuritySettings.DELETE_PLAYER_DATA_WORLD);
// 构建playerdata文件夹路径
File playerDataFolder = new File(serverFolder, worldFolderName+File.separator+"playerdata");
// 构建玩家数据文件路径
File playerDataFile = new File(playerDataFolder, playerUUID + ".dat");
// 删除玩家数据文件
if (playerDataFile.exists()) {
playerDataFile.delete();
}
}
private void deletePlayerStats(UUID playerUUID) {
// 获取服务器的存储文件夹路径
File serverFolder = Bukkit.getServer().getWorldContainer();
String worldFolderName = AuthMe.settings.getProperty(SecuritySettings.DELETE_PLAYER_DATA_WORLD);
// 构建stats文件夹路径
File statsFolder = new File(serverFolder, worldFolderName+File.separator+"stats");
// 构建玩家统计数据文件路径
File statsFile = new File(statsFolder, playerUUID + ".json");
// 删除玩家统计数据文件
if (statsFile.exists()) {
statsFile.delete();
}
}
@EventHandler @EventHandler
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
String name = player.getName(); String name = player.getName();
UUID playerUUID = event.getPlayer().getUniqueId();
if (!authmeApi.isRegistered(name)) { if (!authmeApi.isRegistered(name)) {
if(shouldDeletePlayerData(player) && AuthMe.settings.getProperty(SecuritySettings.DELETE_UNVERIFIED_PLAYER_DATA)){
deletePlayerData(playerUUID);
deletePlayerStats(playerUUID);
return;
}
closeReasonMap.remove(player); closeReasonMap.remove(player);
} }
} }
} }

View File

@ -37,6 +37,12 @@ public final class SecuritySettings implements SettingsHolder {
"(Requires floodgate and hookFloodgate: true)"}) "(Requires floodgate and hookFloodgate: true)"})
public static final Property<Boolean> GUI_CAPTCHA_BE_COMPATIBILITY = newProperty("3rdPartyFeature.captcha.ignoreBedrock",false); public static final Property<Boolean> GUI_CAPTCHA_BE_COMPATIBILITY = newProperty("3rdPartyFeature.captcha.ignoreBedrock",false);
@Comment("Should we delete playerdata and stats when they didn't finish the captcha?")
public static final Property<Boolean> DELETE_UNVERIFIED_PLAYER_DATA = newProperty("3rdPartyFeature.captcha.delPlayerData",false);
@Comment("Which world's playerdata should be deleted?(Enter the world *FOLDER* name where your player first logged in)")
public static final Property<String> DELETE_PLAYER_DATA_WORLD = newProperty("3rdPartyFeature.captcha.delPlayerData","world");
// @Comment({"Should we kick the players when they failed captcha too many times?", // @Comment({"Should we kick the players when they failed captcha too many times?",
// "(Minimum value is 1)(Default: 3)"}) // "(Minimum value is 1)(Default: 3)"})
// public static final Property<Integer> GUI_CAPTCHA_MAX_TRY = newProperty("3rdPartyFeature.captcha.maxTryTimes",3); // public static final Property<Integer> GUI_CAPTCHA_MAX_TRY = newProperty("3rdPartyFeature.captcha.maxTryTimes",3);