Its a simple plugin Ill just do one tonight, based on the old one >_< Anyone know ? Someone help me EDIT by Moderator: merged posts, please use the edit button instead of double posting.
@Mrchasez Instead of blacklisting you should whitelist. It works best. For example, loop through all characters in the name and only allow names: - longer than 3 chars - at least two a-z, A-Z - abcdefghijklmnopqrstuv, capitals, 012345689, /\-=() allowed (more is possible) Blacklisting is generally not a good idea, better come up with an allowed format and build upon that. EDIT Also, you can't get the address from within the onPlayerLogin event. Use onPlayerJoin and kick.
I am suspecting you are wrong with your regex: $^[A-Za-z0-9_]+$ The way I'm seeing it, this check will always fail, because $ = end of string. So you have a regex checking if the first character is the end of a string, which it will never be. And I find you negation to be wrong. You can do one of these two: Code: else if (username.matches(".*[^A-Za-z0-9_].*")) { return true; } OR Code: else if (!username.matches("^[A-Za-z0-9_]+$")) { return true; } Notice the first one, you are checking for a negation, so in your case you shouldn't check for string start/end (which you were trying with the $ sign). Also the negation must be inside the square brackets, and you don't need to specify the repetition plus sign. The other example adds an boolean not infront of the check, and then checks whether the user matches, and here I'm using the ^ and $ as start/end of string notation. Both of these should get you going... You might want to debug using some log.info og console.println thrown into your code. If you had debugged this else if statement, you'd probably had noticed that this never translates to true, and thus never blocks anybody. Edit: Go away fieldmaster ... Beat me to it... Edit2: I think me and fieldmaster is saying two different things, but we are pointing out the flaw in the same place Edit3: Edited my first example, as fieldmasters example is correct in this case. (Didn't really put much into it that he wasn't using the Regex object but rather String.matches.) Edit4: Going further with fieldmasters suggestion of shortening you could write your entire illigal check as follow: Code: public boolean isIlligal(String username) { return !username.matches("^[A-Za-z0-9_]{1,16}$"); }
@Mrchasez nope. See this: Code: if (plugin.checkpermissions(Event.getPlayer(), "illegalname.see")) { player.sendMessage("§c"+Event.getPlayer().getName()+" ("+Event.getPlayer().getAddress().getHostName().toString()+") is kicked for il Code: Event.getPlayer().getAddress().getHostName().toString() Event.getPlayer().getAddress() returns null, causing a nullreferenceexception to occur. This is why I mentioned using onPlayerJoin instead of onPlayerLogin.
Address shouldn't do that in login. Especially since the address is detected in prelogin. It should pass that through to Login.