[英]Java boolean issue
private static final Pattern namePattern =
Pattern.compile("[a-zA-Z0-9_-]{3,12}");
if (player.getName().length() < 3 ||
player.getName().length() > 12 ||
namePattern.matcher(player.getName()).matches()) {
player.ban("[Autoban] Character-name PE", true);
return;
}
The code is kinda obvious, I hope 我希望代码很明显
If the players name is longer than 12 or shorter then 3, or have any symbols that shouldnt be ia name = BAM, ban! 如果玩家的名字超过12个或少于3个,或者有任何不应该是ia name = BAM的符号,请禁止!
but even thought my player name is like Chaos or test, it gets autobanned by this code. 但甚至以为我的播放器名称就像混沌或测试一样,它会被该代码自动禁止。 idk if the namepattern Pattern blocks characters aswell, I just it to block symbols like
"!#&%¤/&%(/)(/(=)$@£$@£{€@£
yeh... What am I doing wrong :(? idk如果namepattern Pattern也阻止了字符,我只是阻止诸如
"!#&%¤/&%(/)(/(=)$@£$@£{€@£
yeeh ...做错了:(?
I think you meant (!namePattern.matcher(player.getName()).matches())
. 我想你的意思是
(!namePattern.matcher(player.getName()).matches())
。
Also, you could've use only the regex match: [a-zA-Z0-9_-]{3,12}
since it checks for length. 另外,您可以只使用正则表达式匹配项:
[a-zA-Z0-9_-]{3,12}
因为它会检查长度。
Edit: 编辑:
You can use such a function 你可以使用这样的功能
public void banIfNeeded(Player player)
{
Pattern namePattern = Pattern.compile("[a-zA-Z0-9_-]{3,12}");
if(!namePattern.matcher(player.getName()).matches()) {
System.out.print("Banned");
// Ban somehow
}
}
As @bkail commented (thanks!), there's no need for the ^
and \\z
so I removed them :) 正如@bkail所评论的(谢谢!),不需要
^
和\\z
所以我删除了它们:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.