Skip to content

Commit

Permalink
代码格式调整:统一代码风格,修复部分事件监听器方法格式问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
shulng committed May 29, 2024
1 parent bb68ad6 commit 215cfa4
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions src/main/java/cc/baka9/catseedlogin/bukkit/Listeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

public class Listeners implements Listener {

private boolean playerIsNotMinecraftPlayer(Player p) {
private boolean playerIsNotMinecraftPlayer(Player p){
return !p.getClass().getName().matches("org\\.bukkit\\.craftbukkit.*?\\.entity\\.CraftPlayer");
}

@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event){
if (playerIsNotMinecraftPlayer(event.getPlayer())) return;
if (LoginPlayerHelper.isLogin(event.getPlayer().getName())) return;
String input = event.getMessage().toLowerCase();
Expand All @@ -39,7 +39,7 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
}

@EventHandler
public void onPlayerLogin(AsyncPlayerPreLoginEvent event) {
public void onPlayerLogin(AsyncPlayerPreLoginEvent event){
if (!Cache.isLoaded) {
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "服务器还在初始化..");
return;
Expand Down Expand Up @@ -71,35 +71,35 @@ public void onPlayerLogin(AsyncPlayerPreLoginEvent event) {
}

@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event) {
public void onPlayerChat(AsyncPlayerChatEvent event){
if (playerIsNotMinecraftPlayer(event.getPlayer())) return;
if (LoginPlayerHelper.isLogin(event.getPlayer().getName())) return;
event.setCancelled(true);
}

@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
public void onPlayerInteract(PlayerInteractEvent event){
if (playerIsNotMinecraftPlayer(event.getPlayer())) return;
if (LoginPlayerHelper.isLogin(event.getPlayer().getName())) return;
event.setCancelled(true);
}

@EventHandler
public void onInventoryOpen(InventoryOpenEvent event) {
public void onInventoryOpen(InventoryOpenEvent event){
if (LoginPlayerHelper.isLogin(event.getPlayer().getName())) return;
event.setCancelled(true);
}

@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
public void onInventoryClick(InventoryClickEvent event){
if (!(event.getWhoClicked() instanceof Player) || LoginPlayerHelper.isLogin(event.getWhoClicked().getName()))
return;
event.setCancelled(true);
}

//登陆之前不能攻击
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
public void onEntityDamageByEntity(EntityDamageByEntityEvent event){
if (!(event.getDamager() instanceof Player)) return;
if (playerIsNotMinecraftPlayer((Player) event.getDamager())) return;
if (LoginPlayerHelper.isLogin(event.getDamager().getName())) return;
Expand All @@ -108,7 +108,7 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {

//登陆之前不会受到伤害
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
public void onEntityDamage(EntityDamageEvent event){
if (Config.Settings.BeforeLoginNoDamage) {

Entity entity = event.getEntity();
Expand All @@ -124,22 +124,22 @@ public void onEntityDamage(EntityDamageEvent event) {
}

@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent event) {
public void onPlayerTeleport(PlayerTeleportEvent event){
if (Config.Settings.CanTpSpawnLocation && event.getTo().equals(Config.Settings.SpawnLocation)) return;
if (playerIsNotMinecraftPlayer(event.getPlayer())) return;
if (LoginPlayerHelper.isLogin(event.getPlayer().getName())) return;
event.setCancelled(true);
}

@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
public void onPlayerDropItem(PlayerDropItemEvent event){
if (playerIsNotMinecraftPlayer(event.getPlayer())) return;
if (LoginPlayerHelper.isLogin(event.getPlayer().getName())) return;
event.setCancelled(true);
}

@EventHandler
public void onEntityPickupItem(EntityPickupItemEvent event) {
public void onEntityPickupItem(EntityPickupItemEvent event){
if (!(event.getEntity() instanceof Player)) return;
Player player = (Player) event.getEntity();
if (playerIsNotMinecraftPlayer(player)) return;
Expand All @@ -148,7 +148,7 @@ public void onEntityPickupItem(EntityPickupItemEvent event) {
}

@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
public void onPlayerMove(PlayerMoveEvent event){
Player player = event.getPlayer();
if (playerIsNotMinecraftPlayer(player)) return;
if (LoginPlayerHelper.isLogin(player.getName())) return;
Expand All @@ -167,7 +167,7 @@ public void onPlayerMove(PlayerMoveEvent event) {
}

@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
public void onPlayerQuit(PlayerQuitEvent event){
Player player = event.getPlayer();
if (LoginPlayerHelper.isLogin(player.getName())) {
if (!player.isDead() || Config.Settings.DeathStateQuitRecordLocation) {
Expand All @@ -180,7 +180,7 @@ public void onPlayerQuit(PlayerQuitEvent event) {
}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
public void onPlayerJoin(PlayerJoinEvent event){
Player p = event.getPlayer();
if (Config.Settings.BedrockLoginBypass && LoginPlayerHelper.isFloodgatePlayer(p)) {
p.sendMessage(Config.Language.BEDROCK_LOGIN_BYPASS);
Expand All @@ -194,7 +194,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {

//id只能下划线字母数字
@EventHandler
public void onPlayerPreLogin(AsyncPlayerPreLoginEvent event) {
public void onPlayerPreLogin(AsyncPlayerPreLoginEvent event){
String name = event.getName();
if (Config.Settings.LimitChineseID) {
if (!name.matches("^\\w+$")) {
Expand All @@ -203,23 +203,21 @@ public void onPlayerPreLogin(AsyncPlayerPreLoginEvent event) {
}
}
if (Config.Settings.FloodgatePrefixProtect && Bukkit.getPluginManager().getPlugin("floodgate") != null) {
if (Config.Settings.BedrockLoginBypass && Bukkit.getPluginManager().getPlugin("floodgate") != null) {
String prefix = FloodgateApi.getInstance().getPlayerPrefix();
if (event.getName().startsWith(prefix) && !FloodgateApi.getInstance().isFloodgatePlayer(event.getUniqueId())) {
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER,
"非法的基岩版玩家名称,请非基岩版玩家的名称不要以" + prefix + "开头");
}
}
if (name.length() < Config.Settings.MinLengthID) {
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER,
"你的游戏名太短了,至少需要 " + Config.Settings.MinLengthID + " 个字符的长度");
}
if (name.length() > Config.Settings.MaxLengthID) {
String prefix = FloodgateApi.getInstance().getPlayerPrefix();
if (event.getName().startsWith(prefix) && !FloodgateApi.getInstance().isFloodgatePlayer(event.getUniqueId())) {
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER,
"你的游戏名太长了,最长只能到达 " + Config.Settings.MaxLengthID + " 个字符的长度");
"非法的基岩版玩家名称,请非基岩版玩家的名称不要以" + prefix + "开头");
}

}
if (name.length() < Config.Settings.MinLengthID) {
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER,
"你的游戏名太短了,至少需要 " + Config.Settings.MinLengthID + " 个字符的长度");
}
if (name.length() > Config.Settings.MaxLengthID) {
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER,
"你的游戏名太长了,最长只能到达 " + Config.Settings.MaxLengthID + " 个字符的长度");
}

}
}

}

0 comments on commit 215cfa4

Please sign in to comment.