[FORMATTED] Kick Players Automatically [FORMATTED]

Discussion in 'Archived: Plugin Requests' started by Mineacer, Nov 12, 2012.

  1. Offline

    Mineacer

    Plugin category:
    Simple plugin which allows a player to be kicked when they try to join the server with a custom message.

    Suggested name:
    AcerKick (Acer is the beginning on my server name).

    What I want:
    I'd wish to see a plugin which disables on joining to the server for a cause. Firstly, they would get kicked when they join the server with a custom message configurable in the config.yml. This is great to help switch server IPs, break-downs in your server and if you want to get a DESPERATE message across.

    I would love to see a feature implemented in the config which allows us to configure it to display a message when the player gets kicked automatically when they try to join. If this function was not there, I would be disappointed, and it would not be used in my server. :'(

    Ideas for commands:
    /acerkick activate - Toggles kicking of players automatically
    /acerkick deactivate - Disables kicking of players automatically

    Ideas for permissions:
    acerkick.bypass - Can join server when plugin is activated.

    When I'd like it by: ASAP PLEASE! :)
     
  2. Offline

    lol768

    Some code snippets for interested developers:

    Code:
    @EventHandler
    public void ppp (PlayerJoinEvent e) {
    if (e.getPlayer().hasPermission("acerkick.bypass") || !(getConfig().getBoolean("enabled")) {
    e.getPlayer().kickPlayer(getConfig().getString("message"));
    }
    }
    
    Code:
    //Disable/enable the kick mode:
    getConfig().set("enabled", false);
    getConfig().set("enabled", true);
    
    Code:
    //Set message
    StringBuilder buffer = new StringBuilder();
    for(int i = 0; i < args.length; i++)
    {
    buffer.append(' ').append(args[i]);
    }
    String msg = buffer.toString();
    getConfig().set("message", msg);
    
     
  3. Offline

    MYCRAFTisbest

    Unless your using whitelist, you could just use the whitelist command and activate it, kicking anyone not on the list.
     
  4. Offline

    Kodfod

    Well, here it is...

    http://www.kodfod.us/AcerKick.jar

    the config is setup like this:

    Code:
     kick:
      msg: The server is currently not accepting players at this time. Please try again later.
    bypass:
      join:
        msg: $player was allowed to join with the bypass.
    Both join and kick allow for $player for the players name to be inserted.

    and here is the source:
    Main Class:
    Code:java
    1. package us.kodfod.akick;
    2.  
    3. import java.io.File;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class Main extends JavaPlugin {
    12.  
    13. public static boolean locked;
    14.  
    15. @Override
    16. public void onDisable() {
    17. }
    18.  
    19. @Override
    20. public void onEnable() {
    21. Bukkit.getPluginManager().registerEvents(new Player(this), this);
    22. locked = false;
    23. try {
    24. File file = new File(this.getDataFolder()+"/config.yml");
    25. if (file.exists()) {
    26. return;
    27. } else {
    28. this.saveDefaultConfig();
    29. }
    30. } catch (Exception e) {
    31. this.saveDefaultConfig();
    32. }
    33. }
    34.  
    35. @Override
    36. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    37. if (cmd.getName().equalsIgnoreCase("akick")) {
    38. if (args.length == 1) {
    39. if (args[0].equalsIgnoreCase("on")) {
    40. if (locked) {
    41. sender.sendMessage(ChatColor.RED+"Server is already kicking players.");
    42. return true;
    43. }
    44. locked = !locked;
    45. sender.sendMessage(ChatColor.GREEN+"Server is now kicking players.");
    46. return true;
    47. }
    48. if (args[0].equalsIgnoreCase("off")) {
    49. if (locked) {
    50. sender.sendMessage(ChatColor.GREEN+"Server is now allowing players.");
    51. locked = !locked;
    52. return true;
    53. }
    54. sender.sendMessage(ChatColor.RED+"Server is not currently kicking players.");
    55. return true;
    56. }
    57. sender.sendMessage(ChatColor.RED+"Sorry try: /akick on|off");
    58. return true;
    59. } else {
    60. sender.sendMessage(ChatColor.RED+"Sorry try: /akick on|off");
    61. return true;
    62. }
    63. }
    64. return false;
    65. }
    66.  
    67. }


    PlayerListener:
    Code:Java
    1. package us.kodfod.akick;
    2.  
    3. import org.bukkit.event.EventHandler;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.player.PlayerJoinEvent;
    6. import org.bukkit.event.player.PlayerQuitEvent;
    7.  
    8. public class Player implements Listener {
    9.  
    10. Main plugin;
    11.  
    12. public Player(Main main) {
    13. plugin = main;
    14. }
    15. @EventHandler
    16. public void onJoin(PlayerJoinEvent e) {
    17. if (Main.locked) {
    18. if (e.getPlayer().hasPermission("akick.bypass")) {
    19. String cmsg = plugin.getConfig().getString("bypass.join.msg");
    20. String rmsg = cmsg.replace("$player", e.getPlayer().getName());
    21. e.setJoinMessage(rmsg);
    22. return;
    23. }
    24. String cmsg = plugin.getConfig().getString("kick.msg");
    25. String rmsg = cmsg.replace("$player", e.getPlayer().getName());
    26. e.getPlayer().kickPlayer(rmsg);
    27. e.setJoinMessage("");
    28. }
    29. return;
    30. }
    31. @EventHandler
    32. public void onQuit(PlayerQuitEvent e) {
    33. if (Main.locked) {
    34. e.setQuitMessage("");
    35. }
    36. return;
    37. }
    38. }
     
  5. Offline

    Mineacer

    Kodfod
    Thank you very much for the plugin.
    I will test it out after school.

    I appreciate all comments and in-put into this.
    I am grateful. :D
     
  6. Offline

    seiterseiter1

    I was just wondering since this was a kick plugin that is it possible to kick/ban someone with multiple lines of text for the kick message.
     
  7. Offline

    netherfoam

    Yes. Just place \n in the message where you want a new line.
     
  8. Offline

    seiterseiter1

    do you mean for this plugin or any kick/ban plugin?
     
  9. Offline

    Kodfod

    good question... *goes to test*

    yeah it no work....(at least this plugin and bukkit's kick....)

    However, I could easily add this
     
  10. Offline

    seiterseiter1

    Could you just make a simple kick and ban command as well using the multiple lines.
     
  11. Offline

    Mineacer

    Kodfod,
    A bit of a problem.
    I've tested the plugin, loving the /akick on:eek:ff command.
    However, when I type /akick on, it does work, but when a player tries to join the server, it says the DEFAULT message for kicking players, instead of my custom message.

    Also, does this kick support colours with the § symbol? Thank you.

    Ahh, it does not support the § symbol for colour kicks.
    Do not worry, I am fine without colours.
    Thanks for a great, functional plugin! :cool:

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

    Kodfod

    Well, the only thing you could use the Color symbols for is the join message.... the kick message wouldn't allow that.

    edit:
    So it does work?
     
  13. Offline

    Mineacer

    Kodfod,
    IF there is a way, is it possible for you to add a default on:eek:ff option in the config?
    I restart my server a lot, and the plugin is always automatically deactivated when on server restart.
    Is there a way to make it on by default of a server restart?

    Thanks!

    Kodfod,
    Just discovered a bug.
    The permission acerkick.bypass needs to be added.
    If that permission has been added, can you default it to the OP group please?

    Thanks!

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

    Kodfod

    the permission is akick.bypass

    edit: I could add to where it is locked on start up.
     
  15. Offline

    Mineacer

    Kodfod,
    Is it possible to turn on AcerKick on default when server starts?
    I don't really want to go into the server and type /akick on everytime. :p
     
  16. Offline

    Kodfod

    There we have it.

    http://www.kodfod.us/AcerKick.jar

    Download it and it delete you config or just add at the bottom:
    Code:
    StartLocked: true
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  17. Offline

    Mineacer

    Thank you!
     
  18. Offline

    Mineacer

    Kodfod,
    This plugin is working terrifically well. Thanks!
    However, I was wondering on something, possibly a bug.
    When I start my server and the plugin is activated..it seems to deactivate AFTER A WHILE.
    This can get frustrating because I would have to reactivate it every time. :'(

    P.S, do you have Skype? If so, add me: suprise.suprise (I am interested in you making custom plugins for me), if you want to. ;)

    Thank you.
     
  19. Offline

    Kodfod

    Mineacer
    I'm sorry but i will take a look into why it may be deactivating it self....

    and i can do some developing for you as long as i have time (the holiday season is really busy for me).
     

Share This Page