Ban event? How can you tell when a player gets banned.

Discussion in 'Plugin Development' started by ttocskcaj, Jun 26, 2011.

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

    ttocskcaj

    I want to write a plugin that will send a request to an external web API when a player is banned.
    I haven't been able to find anything in the javadocs that will let me do something when a player is banned though.
    Is there a way? If not could it be added?

    We're using MCBans, if that makes a difference.

    Thanks.
     
  2. Offline

    Baummann

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String cmdLine, String[] split) {
    2. if (cmd.getName().equalsIgnoreCase("ban")) {
    3. if (sender instanceof Player) {
    4. Player player = (Player) sender; //That's the current player
    5. Player t = getServer().matchPlayer(split[0]).get(0); //That's the player which should be banned
    6. //Do whatever you want
    7. return true;
    8. //Stops the server from further proccessing on the command
    9. }
    10. }
    11. }
     
  3. Offline

    Weltall 7

    @Baummann
    1. doesn't a plugin only receive onCommands from commands in the plugin.yml file?
    2. you code won't detect players banned via console.
    3. matchPlayer returns a list of Players, use getPlayer instead
     
  4. Offline

    Baummann

    1. Add it to the plugin.yml file
    2. Add an else statement
    3. matchPlayer(split[0]).get(0); does work, too.
     
  5. Offline

    Weltall 7

    1. Doesn't overriding a command prevent it from being executed by other plugins / bukkit?
    2. or simply remove the if statement
    3. Still, getPlayer is better as it only matches the exact player name. Thus you know whether the player actually exists and would be banned as a result of the command.

    You may ask the developer(s) of that plugin for help, especially as it uses it's own ban command and ban handling.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 17, 2016
  6. Offline

    Shamebot

    Actually getPlayer(..) works with partial names, too.
     
  7. Offline

    Weltall 7

    I hope this is not true...
     
  8. Offline

    Shamebot

    Code:java
    1. public Player getPlayer(final String name) {
    2. Player[] players = getOnlinePlayers();
    3.  
    4. Player found = null;
    5. String lowerName = name.toLowerCase();
    6. int delta = Integer.MAX_VALUE;
    7. for (Player player : players) {
    8. if (player.getName().toLowerCase().startsWith(lowerName)) {
    9. int curDelta = player.getName().length() - lowerName.length();
    10. if (curDelta < delta) {
    11. found = player;
    12. delta = curDelta;
    13. }
    14. if (curDelta == 0) break;
    15. }
    16. }
    17. return found;
    18. }
     
  9. Offline

    Weltall 7

    Ouch.
    And not even using toLowerCase(Locale.ENGLISH). (ok, no big problem as long as you don't change the server's language)
    But I mostly dislike the lack of documentation. Sometimes I want to know whether a method accepts null or can return null...
     
  10. Offline

    Shamebot

    That's why I prefer github.
     
    tips48 likes this.
  11. Offline

    zonedabone

    Here's an idea. Check out the code and see what the kick reason is when a player is banned, and then hook into plawyerkickevent and check if it's because of a ban. (Or you could just search the kick message for ban to support other plugins)
     
  12. Offline

    ttocskcaj

    Hmm I never thought of doing it with onCommand lol.
    I'll give it a go later. Thanks.
     
Thread Status:
Not open for further replies.

Share This Page