From 3e80f841edfe6ad00f7395ff6bf05b6065a7cb80 Mon Sep 17 00:00:00 2001 From: Shuiling <1668589925@qq.com> Date: Fri, 20 Sep 2024 03:53:13 -0700 Subject: [PATCH] =?UTF-8?q?feat(Config):=20=E6=B7=BB=E5=8A=A0NamePattern?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cc/baka9/catseedlogin/bukkit/Config.java | 25 ++++++++++-------- .../baka9/catseedlogin/bukkit/Listeners.java | 26 +++++++++---------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/main/java/cc/baka9/catseedlogin/bukkit/Config.java b/src/main/java/cc/baka9/catseedlogin/bukkit/Config.java index daaff12..b1ef953 100644 --- a/src/main/java/cc/baka9/catseedlogin/bukkit/Config.java +++ b/src/main/java/cc/baka9/catseedlogin/bukkit/Config.java @@ -1,29 +1,29 @@ package cc.baka9.catseedlogin.bukkit; -import java.io.BufferedInputStream; import java.io.File; +import java.util.Map; +import java.util.List; +import java.util.Optional; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; -import java.lang.reflect.Field; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; +import java.lang.reflect.Field; import java.util.regex.Pattern; +import java.io.InputStreamReader; +import java.io.BufferedInputStream; import java.util.stream.Collectors; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.ConcurrentHashMap; +import org.bukkit.World; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.Location; -import org.bukkit.World; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; /** * 加载/保存/重载 yml配置文件 @@ -95,6 +95,7 @@ public static class Settings { public static boolean CanTpSpawnLocation; public static List CommandWhiteList = new ArrayList<>(); public static int AutoKick; + public static String NamePattern; // 死亡状态退出游戏是否记录退出位置 (玩家可以通过死亡时退出服务器然后重新进入,再复活,登录返回死亡地点) public static boolean DeathStateQuitRecordLocation; public static boolean FloodgatePrefixProtect; @@ -115,6 +116,7 @@ public static void load(){ ReenterInterval = config.getLong("ReenterInterval", resourceConfig.getLong("ReenterInterval")); AfterLoginBack = config.getBoolean("AfterLoginBack", resourceConfig.getBoolean("AfterLoginBack")); CanTpSpawnLocation = config.getBoolean("CanTpSpawnLocation", resourceConfig.getBoolean("CanTpSpawnLocation")); + NamePattern = config.getString("NamePattern", resourceConfig.getString("NamePattern", "^\\w+$")); List commandWhiteList = config.getStringList("CommandWhiteList"); if (commandWhiteList.isEmpty()) { commandWhiteList = resourceConfig.getStringList("CommandWhiteList"); @@ -151,6 +153,7 @@ public static void save(){ config.set("CommandWhiteList", CommandWhiteList.stream().map(Pattern::toString).collect(Collectors.toList())); config.set("DeathStateQuitRecordLocation", DeathStateQuitRecordLocation); config.set("FloodgatePrefixProtect", FloodgatePrefixProtect); + config.set("NamePattern", NamePattern); try { config.save(new File(CatSeedLogin.instance.getDataFolder(), "settings.yml")); } catch (IOException e) { diff --git a/src/main/java/cc/baka9/catseedlogin/bukkit/Listeners.java b/src/main/java/cc/baka9/catseedlogin/bukkit/Listeners.java index a390754..fa77868 100644 --- a/src/main/java/cc/baka9/catseedlogin/bukkit/Listeners.java +++ b/src/main/java/cc/baka9/catseedlogin/bukkit/Listeners.java @@ -6,28 +6,28 @@ import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.geysermc.floodgate.api.FloodgateApi; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.entity.EntityPickupItemEvent; -import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryOpenEvent; -import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.geysermc.floodgate.api.FloodgateApi; +import cc.baka9.catseedlogin.bukkit.task.Task; import cc.baka9.catseedlogin.bukkit.database.Cache; import cc.baka9.catseedlogin.bukkit.object.LoginPlayer; import cc.baka9.catseedlogin.bukkit.object.LoginPlayerHelper; -import cc.baka9.catseedlogin.bukkit.task.Task; public class Listeners implements Listener { @@ -190,7 +190,7 @@ public void onPlayerJoin(PlayerJoinEvent event) { @EventHandler public void onPlayerPreLogin(AsyncPlayerPreLoginEvent event) { String name = event.getName(); - if (Config.Settings.LimitChineseID && !name.matches("^\\w+$")) { + if (Config.Settings.LimitChineseID && !name.matches(Config.Settings.NamePattern)) { event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "请使用由数字,字母和下划线组成的游戏名,才能进入游戏"); return; }