How to handle Playernames which begin with a space?

Discussion in 'Plugin Development' started by DxDy, Apr 26, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    DxDy

    Had this problem today. Since bukkit eliminates seemingly unnecessary spaces from command parameters virtually no commands will work on the user.

    How do deal with this from the perspective of a plugin developer?

    Example: Name is " Venom_20"
    http://www.glizer.net/usrnotes/index.php?data= Venom_20&sub=reputation

    I'm sorry if giving this example is against the guidelines and I'm willing to remove it if it offends anyone, but I felt the need to supply an example.
     
  2. Offline

    TGRHavoc

    DxDy
    I'm sorry, what is it you're trying to ask exactly?
     
  3. Offline

    DxDy

    Well, that bukkit removes the whitespaces from commands when parsing the args was very useful when people couldn't use whitespaces in their names.

    But since they can now, what am I supposed to do?

    In order to handle those players in my Commands I would need to hook the CommandPreprocessEvent which defeats the entire purpose of Bukkit handling commmands in the first place.

    To give an example:
    Suppose I wanted to do something with the player. /money pay Name 300
    That will not work, because bukkit will give me as args:
    Code:
    { "pay", "Name", "300" } instead of { "pay", " Name", "300"}
    The only solution I can think of would be the one I mentioned above, but I also mentioned why that would be very stupid to say the least.
     
  4. Offline

    mrgreen33gamer

    Lol, dude, I think everyone here that has viewed this topic does not understand what your requesting or what help your trying to get..
     
  5. Offline

    TGRHavoc

    mrgreen33gamer
    Apparently if a player has the name "<SPACE>Name" the space will be removed and he wants to know how to get around this.... I didn't even know that you could have spaces in the name.
     
  6. Offline

    Slikey

    DxDy Thanks for pointing out that problem.. I wasn't aware of the problems with whitespaces yet.. I think that this will cause some problems..
    A trick (that isn't nice at all) would be, that you iterate over all players and remove their whitespaces too, before comparing. so
    /give MyMom stone 3
    would call the player My Mom, because you compare "My Mom" -> "MyMom" and then it fits.

    Just a workaround to still use the commands.. :(
     
  7. Offline

    afistofirony

    DxDy Names cannot begin with or otherwise contain spaces. The regular expression used for validating username input would be (in simplest form)

    Code:
    \w{2,16}
    That translates to "2 to 16 uppercase or lowercase letters, numbers, and underscores." Thus, spaces cannot be used in valid Minecraft accounts and it seems the only reason they would be allowed on your server is if you are running in offline mode.

    However, if you want an actual solution for this, try checking if the argument before the name argument is an empty string. For example, you could have an array with the contents

    Code:
    { "pay", "", "Name", "300" } 
    If you do, just add that space to the beginning of the name.
     
  8. Offline

    DxDy

    I can most cetainly assure you that we are NOT running on online-mode = false. I can also assure you that the player who came online DID have a whitespace as the first character in his name.

    Code:
    [13:51:37] [User Authenticator #26/INFO]: UUID of player  Venom_20 is 07f106fa
     
  9. Offline

    afistofirony

    Strange. Well, I suppose you'll have to use a plugin which does not require the beginning of the name (like Essentials). If you're writing a plugin, see my solution above. :p
     
  10. Offline

    xTigerRebornx

    DxDy If you weren't running offline-mode, the Player's UUID would be a valid one, which in this case, it doesn't look like it is one.
     
  11. Offline

    DxDy

    It is a valid UUID, I just copied only the part with the name and not the rest of the UUID ;) There is a full and valid UUID in the server logfile. Also the fact that the User is glizer-registered shows that he was on an online-mode server.
     
  12. Offline

    xTigerRebornx

    DxDy Ah, its odd that someone would have a whitespace in their name...
     
  13. Offline

    RawCode

    ban players with invalid names.

    everything very simple.
     
    ampayne2 likes this.
Thread Status:
Not open for further replies.

Share This Page