Player kick message help!

Discussion in 'Plugin Development' started by Cystalize, Aug 12, 2012.

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

    Cystalize

    So I'm making a part of the plugin that disallows(kicks) the player if they try to connect to the server within a configurable amount of time. The kicking nor the kick message works.

    Code:
    package me.Cystalize.spamicide.listeners;
     
    import java.util.logging.Logger;
     
    import me.Cystalize.spamicide.Spamicide;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.event.player.PlayerKickEvent;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
     
    public class SpamPlayerListener
        implements Listener
    {
        public Logger logger = Logger.getLogger("Minecraft");
        public Spamicide plugin;
        public SpamPlayerListener(Spamicide instance) {
            plugin = instance;
            Bukkit.getServer().getPluginManager().registerEvents(this,  instance);
        }
       
        @EventHandler
        public void onPlayerLogin(PlayerQuitEvent event) {
            Player player = event.getPlayer();
            if (plugin.getConfig().getBoolean("Settings.Spam.LoginSpam.Enable", true)) {
                if (!player.hasPermission("spamicide.bypass.spam")) {
                    if (event.getPlayer().getLastPlayed() < plugin.getConfig().getLong("Settings.Spam.LoginSpam.ReconnectTimeLimit")) {
                        event.getPlayer().kickPlayer(ChatColor.GOLD + "[Spamicide]  " + ChatColor.RED + "You must wait " + plugin.getConfig().getLong("Settings.Spam.LoginSpam.ReconnectTimeLimit") + "seconds before reconnecting!");
                        return;
                    }
                }
            }
        }
    }


    Please help :3
     
  2. Why do you have PlayerQuitEvent as an argument?
     
  3. Offline

    Cystalize

    Because it based on when a player disconnects. The ReconnectTimeLimit determines when the player can reconnect to the server.
     
  4. Okay, well the line where you checked time is incorrect.
    It needs to save to a file the time they logged out.
    Then it needs to read that time, and check if the last played is greater than the read time + ReconnectTimeLimit.
     
  5. Offline

    Cystalize

    Oh okay. Other than that, are the kick settings/kick message correctly coded? How would I tell it to check the time that they logged out? I thought .getLastPlayed() would do the trick.
     
  6. Offline

    The_Coder

    Does this give you errors if it does please post them
     
  7. Offline

    Cystalize

    No errors in Eclipse or in the console. It just doesn't do anything.
     
  8. Offline

    Cystalize

    Yes I did. How would I make that?
     
  9. Offline

    The_Coder

  10. Do another PlayerQuitEvent listener to save the time and write the name and time to file. The_Coder has a link to making a YAML file internally. I think I have seen him post it.
     
  11. Offline

    Cystalize

    Alright thanks guys. I'll try and get back to you

    Okay wait. I sorta understand what to do. Basically I'm making a memory storage type thing right? Would I have to make a new class to do this? Could either of you code up an example for me please? I'm very new to Java.

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

    The_Coder

    I wish I could help but I don't have a IDE right now but tomarrow afternoon i will and then I will write the listener
     
  13. Offline

    Cystalize

    mmk thanks :D
     
  14. Offline

    The_Coder

  15. Offline

    Cystalize

Thread Status:
Not open for further replies.

Share This Page