Kick player when they join server if not OP.

Discussion in 'Plugin Development' started by dakoslug, Nov 26, 2011.

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

    Jogy34

    you never know it could be but if it isn't they should still be able to tell you what's wrong.
     
  2. Offline

    dakoslug

    true
     
  3. Offline

    Technius

    Have fun... I fixed it for you, dako. Should be in your inbox.
     
  4. Offline

    dakoslug

    after my latest messagE?
     
  5. Offline

    Sagacious_Zed Bukkit Docs

    I took your description and wrote this.
    Upon turning on maintenance mode, it should kick everyone. Otherwise, if it is on maintenance mode, only ops can join.

    Code:
    public class Main extends JavaPlugin {
    
        private static final Logger log = Logger.getLogger(Main.class.getCanonicalName());
        private static final String m = "maintenance";
        private final PlayerListener pl = new PlayerListener() {
    
            @Override
            public void onPlayerLogin(PlayerLoginEvent event) {
                if (getConfig().getBoolean(m) && !event.getPlayer().isOp()) {
                    event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m);
                }
            }
        };
    
        public void onDisable() {
            log.info("EmergencyDowntime Disabled");
        }
    
        public void onEnable() {
            final FileConfiguration c = getConfig();
            c.addDefault(m, false);
            c.addDefault("kick-message", m);
            getCommand(m).setExecutor(new CommandExecutor() {
    
                public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
                    if (sender.hasPermission(m)) {
                        if (args.length == 1) {
                            c.set(m, Boolean.parseBoolean(args[0]));
                        } else {
                            c.set(m, !c.getBoolean(m));
                        }
                        saveConfig();
                        Bukkit.broadcastMessage(m + " mode set to " + c.getBoolean(m));
                        if (c.getBoolean(m)) {
                            for (Player p : Bukkit.getOnlinePlayers()) {
                                if (!p.isOp()) {
                                    p.kickPlayer(c.getString("kick-message"));
                                }
                            }
                        }
                    } else {
                        sender.sendMessage("You do not have permission to send the server into maintenance mode.");
                    }
                    return true;
                }
            });
    
            final PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Type.PLAYER_LOGIN, pl, Priority.Normal, this);
            log.info("EmergencyDowntime Disabled");
        }
    }
     
  6. Offline

    dakoslug

    Otherwise? What do you mean? I want this to happen. When MaintenceMode is initiated kick all non-ops out and stop them from entering.
     
  7. Offline

    Sagacious_Zed Bukkit Docs

    Otherwise, because it won't constantly kick non ops. i.e. it wont kick someone who is deop but op at the beginning of maintenance.
     
  8. Offline

    dakoslug

    So, when somebody get's deop'd it will not kick them during Maintenance?
     
  9. Offline

    Sagacious_Zed Bukkit Docs

    If you looked through that code, you can see that no they don't
     
  10. Offline

    dakoslug

    Is their a playerlistener for the deop action ?
     
  11. Offline

    Sagacious_Zed Bukkit Docs

    Not directly, afaik, could be wrong, lots of events in there.
     
  12. Offline

    dakoslug

    Omfg. I'm a pure utter idiot! I figured out what was wrong. I forgot to return the boolean property as true when command was initialized.

    Somehow..That was what was wrong from the beggining..

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

    Jogy34

    So is it fixed now?

    also can you post your fix because I am curious as to what part you are talking about?
     
  14. Offline

    dakoslug

    It's fixed now :D. But just one question I can't do downtime-full in console how can I enable that?
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
        {
            if(commandLabel.equalsIgnoreCase("downtime-full"))
            {
                for (Player player : getServer().getOnlinePlayers())
                {
                    if (player.isOp() )
                    {
                        player.sendMessage("Warning: Server is in downtime!");
                        EmergencyDowntimeplayerListener.downtimefull = true;
                        kickplayers();
                    }
                    else
                    {
                        player.sendMessage("You don't have permission to use this command!");
                    }
                }
                return true;
            }
            return false;
        }
    
    private void kickplayers() {
         for (Player player : getServer().getOnlinePlayers())
             if (player.isOp())
             {
             player.sendMessage("Server is in downtime! As op you may remain!");
             }
         else
         {
             player.kickPlayer("Server needs downtime! Come back later!");
             EmergencyDowntimeplayerListener.downtimefull = true;
         }
        }
    The fix was if(player.IsOp()){
    }
    EmergencyDowntimeplayerListener.downtimefull = true; }
    else
    {
    player.getKickall.blah.blah ("Server on downtime")
    EmergencyDowntimeplayerListener.downtimefull = true;
    }

    Fix was bolded.
    But it created another problem with non-ops able to use that command which i fixed. But now console cant initialize downtime. Could you perhaps help me one last time :D Pretty please XD/
     
  15. Offline

    Jogy34

    first of all to stop non-ops from using the command just do
    Code:
    if(commandLabel.equalsIgnoreCase("downtime-full") && sender.isOp())
     
  16. Offline

    dakoslug

    Thanks dude! That will PROBABLY be all. You are awesome.
     
  17. Offline

    Jogy34

    Anytime you need help with something like this just tag me and if i can help then i probably will otherwise I'll point you to someone who can.
     
    dakoslug likes this.
  18. Offline

    dakoslug

    Crap when I do a command in console, the non-op player gets a You don't have permission to use this!
    And there has to be a person inside the server (non-op) in order for the playerlistener to work.
    *sighs* one problem fixed another arises.
     
  19. Offline

    ArcheCane

    That's java for you. ;)
     
    dakoslug likes this.
  20. Offline

    Jogy34

    here are a few fixes:

    Change this:
    Code:
    if(commandLabel.equalsIgnoreCase("downtime-full") && sender.isOp())
      {
     for (Player player : getServer().getOnlinePlayers())
     {
     if (player.isOp() )
    {
    player.sendMessage("Warning: Server is in downtime!");
    EmergencyDowntimeplayerListener.downtimefull = true;
     kickplayers();
     }
    else
    {
    player.sendMessage("You don't have permission to use this command!");
     }
     }
     return true;
     }
    
    To this:
    Code:
    if(commandLabel.equalsIgnoreCase("downtime-full") && sender.isOp())
    {
    EmergencyDowntimeplayerListener.downtimefull = true;
    for (Player player : getServer().getOnlinePlayers())
    {
    if (player.isOp() )
    {
    player.sendMessage("Warning: Server is in downtime!");
    kickplayers();
    }
    }
    return true;
    }
    
    What that will do:
    removing the else will stop the message from appearing which it didn't really do anything in the first place and moving the 'EmergencyDowntimeplayerListener.downtimefull = true;' will make it so that there doesn't have to be any non-ops on the server to reach this.
     
  21. Offline

    dakoslug

    Will this work perfectly ?

    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
        {
            }
            if(commandLabel.equalsIgnoreCase("downtime-full") && sender.isOp())
            {
            EmergencyDowntimeplayerListener.downtimefull = true;
            for (Player player : getServer().getOnlinePlayers())
            {
            if (player.isOp() )
            {
            player.sendMessage("Warning: Server is in downtime!");
            kickplayers();
            }
            }
            return true;
            }
            return false ;}
            
     
  22. Offline

    Jogy34

    @dakoslug I don't know. You should probably test it to see if it works and then say something if there are any problems with it.
     
  23. Offline

    dakoslug

    darkoslug lololol :p

    It won't run kickPlayers()

    My plugin is ultra weird.
    It started working now.

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

    douglas_srs

    Hey, would u give me that plugin and maybe the source? I need it to my server =p
     
  25. Offline

    dakoslug

Thread Status:
Not open for further replies.

Share This Page