Get Banned...

Discussion in 'Plugin Development' started by XxZHALO13Xx, Aug 26, 2014.

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

    XxZHALO13Xx

    If someone does /ban USERNAME then how would i get the user name of the guy getting banned... i want a plugin where when u do /ban USERNAME REASON it broadcasts msg and tweets it.. ill do the tweeting.. have a thread on it. what bout that part tho..?
     
  2. Offline

    SmooshCakez

    Bukkit.getPlayer(String username);
     
  3. Offline

    reider45

    args[0] would be their name.
     
  4. Offline

    TheMcScavenger

    This is completely unrelated to the question, and depreciated in versions after 1.7.6.

    @OP: To get the username, you want to listen to the PlayerCommandPreprocessEvent, get the command executed, split the string returned by spaces, and get the first argument of the command (being the player), and all arguments after the name (being the reason). You can then broadcast it using the feature implemented in Bukkit.
     
  5. Offline

    mythbusterma

    TheMcScavenger

    For this purpose, there's nothing wrong with using Bukkit.getPlayer(String), as it was only deprecated to raise awareness for the UUID change, and using it while a player is online is perfectly acceptable.
     
  6. Offline

    TheMcScavenger

    I'm not saying you can't use the method, I'm only saying it's completely irrelevant, and you should try to switch over to UUIDs when you can. He's only wanting to listen to the ban command, he doesn't need to ban a player himself, meaning he won't even need a player, just a name.
     
  7. Offline

    mythbusterma

    TheMcScavenger

    Fair enough, it was pretty irrelevant to the OP's post.
     
  8. Offline

    SmooshCakez

    ...
     
  9. Offline

    TheMcScavenger

    It's great that you want to help people, but you really should learn the Bukkit API before you try to do so, because now you're simply confusing people with bad examples. The OP wants to get the username provided in the executed command. For this, there are two valid responses: the onCommand() method, and the PlayerCommandPreprocessEvent.

    Your reply "Bukkit.getPlayer(String username);", is a line of code that can be used to convert a username into a Player, which is not only irrelevant, as he just wants the username, but also depreciated in newer versions for a good reason.
     
    Konkz likes this.
  10. Offline

    Necrodoom

    TheMcScavenger its depreciated to raise awareness, as mythbusterma said... You can still use it perfectly fine to grab player from the username. While I agree that the method it self is irrelevant here, as target name is given in the command, you shouldn't try to say that the method is unusable in general.
     
  11. Offline

    Techy4198

    TheMcScavenger "The OP wants to get the username of the person who executed a command."
    WTF? He doesn't want to ban himself... Get some common sense man. He wants to get the player from '/ban <PLAYER>'.
     
  12. So many offtopic posts :p, this is what you need ^
     
  13. Offline

    TheMcScavenger

    I never said it was unusable, I simply said you shouldn't use it, because it's the truth. If you make plugins now, using names instead of UUIDs, your plugin will most likely have to be updated later on when name changes are implemented. While it isn't necessary for every plugin, I recommend it to everyone, simply because of the fact that it's not that difficult to do.
     
  14. Offline

    _Filip

    XXLuigiMario no it is not. There is literally NO reason to listen to that event.
     
  15. Offline

    Necrodoom

    TheMcScavenger Ah, what, no.
    You should store UUID in your files, yes, but when you use a player for instantaneous or extremely short checks (EX: command targeting for /kick for example), you can, and SHOULD, support name for user friendliness.
     
  16. Offline

    baugh70

    TheMcScavenger It's relevant if he wants to broadcast the player's name.
     
  17. Offline

    Necrodoom

    baugh70 the player name is already given.
     
  18. Offline

    XxZHALO13Xx

  19. Offline

    Necrodoom

    XxZHALO13Xx is the command defined by you? If so, grab it off the args array. Is it defined by another plugin? Listen to servercommand and playercommandpreprocess, split the command string and grab the name off the array.
     
Thread Status:
Not open for further replies.

Share This Page