Command Refers to Custom Username

Discussion in 'Plugin Development' started by mttprvst13, Jun 18, 2015.

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

    mttprvst13

    Hey, all. I am developing a plugin that changes a player's username. The only thing I have left to do is to have other player's commands reference to the players new username. Is there anyway to do that?
     
  2. if the command is being handled in your plugin, you just make an extra method that takes in the custom playername and iterates through all the online players and sees if the custom name of that player matches with the playername given and returns the right player. Then in the onCommand where you handle your command, you just use that method to get the player from the custom name. If the command is being handled in another plugin, you will need to get the source and change it for yourself, else you can't as far as I know. This is all just an idea, and I haven't tested this, but I think you maybe could get it to work
     
  3. Offline

    Drkmaster83

    Hmm... Honestly, depends on how you're storing the username.

    I suppose this isn't a guaranteed fix (or really a good way of going about it), but this is the only way I can think of doing it rather easily. It worked for me, but this strictly relies on displaynames. If you have your own way of storing the user's alternative name, you must implement it properly into this:
    http://pastie.org/private/7nwzrqwsigarqfqiztz0jw

    I kinda went overboard, but I did this because I wanted a challenge. I successfully completed my task. The only thing that gets around this code is when other plugins don't put their commands in the plugin.yml.

    Edit: This is designed to replace the name in a command ONLY if it's a registered command to the server. Any command and its aliases will be recognized by this algorithm so long as said commands/aliases are in ANY plugin.yml of ANY of the plugins running on the server.

    Edit2: Afterthought, though... not sure how it is with case-sensitivity of aliases and commands, so go ahead and give that a try. Hopefully I programmed case-insensitivity into it.
     
    Last edited: Jun 19, 2015
Thread Status:
Not open for further replies.

Share This Page