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

    So is there a problem or is it working right?
     
  2. Offline

    dakoslug

    Theres a problem, Downtime isn't set on and its kicking non-ops. :S
     
  3. Offline

    Jogy34

    have you made sure your methods that you use to check for downtime return false by default?
     
  4. Offline

    dakoslug

    Ok will try.

    We forgot to add the if statement to check of DowntimeFull = true

    I can't seem to get it work :mad:

    Code:
    //By Dakoslug Alpha Build version 3
    //Y U DECOMPILE THIS? YOU GOT PERMISSION RIGHT?
    package me.dakoslug.EmergencyDowntime;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.event.Event.Type;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerLoginEvent.Result;
    
    public class EmergencyDowntimeplayerListener extends PlayerListener {
         private EmergencyDowntime plugin;
          public EmergencyDowntimeplayerListener(EmergencyDowntime instance)
          {
              plugin = instance;
          }
        public void onPlayerLogin(PlayerLoginEvent event) {
        if (EmergencyDowntimeCheck.DowntimeFull())
        {
            event.allow();
        }
        else
        {
            if (!event.getPlayer().isOp()) {
    
              event.disallow(PlayerLoginEvent.Result.KICK_OTHER, plugin.getConfig().getString("Kickmessage"));
            }
            }
        }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
  5. Offline

    Jogy34

    post your DowntimeFull() method
     
  6. Offline

    dakoslug

    Code:
    package me.dakoslug.EmergencyDowntime;
    public class EmergencyDowntimeCheck
    {
    public static boolean DowntimeFull = false;
    
        public static boolean IsServerOnDowntimeFull(boolean status) //well is it?
                {
                    boolean DowntimeFull = status;
                    return DowntimeFull;
                }
    
        public static boolean IsServerAlreadyOnDowntime()
                {
                    return DowntimeFull;
                }
    
        public static boolean DowntimeFull() {
    
            return false;
        }
    }
     
  7. Offline

    Jogy34

    Well I see a big problem here:
    Code:
    public static boolean DowntimeFull() {
              return false;
         }
    
    This will ONLY RETURN FALSE no matter what the circumstances.
     
  8. Offline

    dakoslug

    which should be true?

    So would return DowntimeFull() work?

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

    Jogy34

    since the variable that is being modified is DowntimeFull it should probably be:
    Code:
    return DowntimeFull;
     
  10. Offline

    dakoslug

    And should the listener file stay like this

    Code:
    //By Dakoslug Alpha Build version 3
    //Y U DECOMPILE THIS? YOU GOT PERMISSION RIGHT?
    package me.dakoslug.EmergencyDowntime;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.event.Event.Type;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerLoginEvent.Result;
    
    public class EmergencyDowntimeplayerListener extends PlayerListener {
         private EmergencyDowntime plugin;
          public EmergencyDowntimeplayerListener(EmergencyDowntime instance)
          {
              plugin = instance;
          }
        public void onPlayerLogin(PlayerLoginEvent event) {
        if (EmergencyDowntimeCheck.DowntimeFull() == true)
        {
            event.allow();
        }
        else
        {
            if (!event.getPlayer().isOp()) {
    
              event.disallow(PlayerLoginEvent.Result.KICK_OTHER, plugin.getConfig().getString("Kickmessage"));
            }
            }
        }
    }
    
     
  11. Offline

    Jogy34

    yes but shouldn't it be:
    Code:
    if (EmergencyDowntimeCheck.DowntimeFull() == false)
    Since you are checking if the EmergancyDowntime is off to allow them in.
     
  12. Offline

    dakoslug

    LOL. I don't know I got so confused with what other people where saying :S
     
  13. Offline

    Jogy34

    no offense but if you couldn't spot the problem with this
    Code:
    public static boolean DowntimeFull()
     {
     return false;
    }
    
    then you were either tired and weren't thinking (happens to me sometimes) or you really need to learn some more java
     
  14. Offline

    dakoslug

    Non taking, but I think Eclispe was giving me errors and in the meanwhile I just did it said would "fix it".
    The error came from another class file different from DowntimeFull so I didn't read the changes. :/
    Or I was thinking :/

    And I'm working passed midnight :p

    WTF. I was almost certain that the neccesary changes you made would work.
    It's allow non-ops in again.

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

    Jogy34

    Try getting rid of that class and putting the method in the main class and just have it change a variable when the command it typed which the method returns.
     
  16. Offline

    dakoslug

    Main Class
    Code:
    public class EmergencyDowntime extends JavaPlugin {
        public static boolean DowntimeFull = false;
        Logger log = Logger.getLogger("Minecraft");
        private EmergencyDowntimeplayerListener loginlistener = new EmergencyDowntimeplayerListener(this);
        public void onEnable(){
            loadConfiguration();
            log.info("EmergencyDowntime is enabled and ready to start! v1.0.0");
            EmergencyDowntimeplayerListener loginlistener = new EmergencyDowntimeplayerListener(this);
                      getServer().getPluginManager().registerEvent(Event.Type.PLAYER_LOGIN, this.loginlistener, Event.Priority.Highest,this);
         }
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if(cmd.getName().equalsIgnoreCase("downtime-full")){ // If the player typed /downtime then do the following...
                  {
                  for (Player player : getServer().getOnlinePlayers())
                      if (player.isOp())
                    {
                      player.sendMessage("Server is now on downtime!");
                      DowntimeFull = true;
                    }
                    else
                    {
                      player.kickPlayer(getConfig().getString("Kickmessage"));
    
                    }
    
                  }
    
            }
                return false;
                }
    Is that what you wanteD?
     
  17. Offline

    Jogy34

    1. Get rid of this line in your onEnable ONLY:
    Code:
    EmergencyDowntimeplayerListener loginlistener = new EmergencyDowntimeplayerListener(this);
    
    2.add this under your everything:
    Code:
    public static boolean getDowntime()
    {
    return DowntimeFull;
    }
    
    And then change it to
    Code:
    if(EmergencyDowntime.Downtime())
    
    in your other class
     
  18. Offline

    dakoslug

    Do you mean
    Code:
    if(EmergencyDowntime.getDowntime())
    and should I get rid of
    Code:
    getServer().getPluginManager().registerEvent(Event.Type.PLAYER_LOGIN, this.loginlistener, Event.Priority.Highest,this);
     
  19. Offline

    Jogy34

    1.Yes
    2.no you need that you were just initializing the same thing twice within 2 different scopes.
     
  20. Offline

    dakoslug

    If that's the case;

    Description Resource Path Location Type
    loginlistener cannot be resolved or is not a field EmergencyDowntime.java /EmergencyDowntime/src/me/dakoslug/EmergencyDowntime line 24 Java Problem

    NVM I failed/

    Now any changes to my Listener?
    Code:
    package me.dakoslug.EmergencyDowntime;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.event.Event.Type;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerLoginEvent.Result;
    
    public class EmergencyDowntimeplayerListener extends PlayerListener {
         private EmergencyDowntime plugin;
          public EmergencyDowntimeplayerListener(EmergencyDowntime instance)
          {
              plugin = instance;
          }
        public void onPlayerLogin(PlayerLoginEvent event) {
            if(EmergencyDowntime.getDowntime())
            {
                    if (!event.getPlayer().isOp())
                    {
                    event.disallow(PlayerLoginEvent.Result.KICK_OTHER, plugin.getConfig().getString("Kickmessage"));
                    }
                    else
                    {
    
                    }
                }
            else
            {
                event.allow();
            }
        }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
  21. Offline

    Jogy34

    nope, looks fine. I hope it finally works :eek:[lava][diamondore]
     
  22. Offline

    dakoslug

    ... :mad::mad::mad:
    Im sorry, you helped me alot, but it still doesn't work.
    You think I'm doing something wrong? Try looking at the small details.
     
  23. Offline

    Jogy34

    The only thing I can think of is to change this:
    Code:
    if (!event.getPlayer().isOp())
    {
    event.disallow(PlayerLoginEvent.Result.KICK_OTHER, plugin.getConfig().getString("Kickmessage"));
    }
    else
    {
    }
    
    To this:
    Code:
    if (event.getPlayer().isOp())
    {
    event.allow();
    }
    else
    {
    event.disallow(PlayerLoginEvent.Result.KICK_OTHER, plugin.getConfig().getString("Kickmessage"));
    }
    
    EDIT:
    If that doesn't work then it has to be something wrong with bukkit. If it still doesn't work when the RB comes out then you should take it up with a Bukkit Dev.
     
  24. Offline

    dakoslug

    Before I start another test the listener should be like this?
    Code:
    //By Dakoslug Alpha Build version 3
    //Y U DECOMPILE THIS? YOU GOT PERMISSION RIGHT?
    package me.dakoslug.EmergencyDowntime;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.event.Event.Type;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerLoginEvent.Result;
    
    public class EmergencyDowntimeplayerListener extends PlayerListener {
         private EmergencyDowntime plugin;
          public EmergencyDowntimeplayerListener(EmergencyDowntime instance)
          {
              plugin = instance;
          }
        public void onPlayerLogin(PlayerLoginEvent event) {
            if(EmergencyDowntime.getDowntime())
            {
                if (event.getPlayer().isOp())
                {
                    event.allow();
                    }
                    else
                    {
                    event.disallow(PlayerLoginEvent.Result.KICK_OTHER, plugin.getConfig().getString("Kickmessage"));
                    }
                    {
    
                    }
                }
            else
            {
                event.allow();
            }
        }
    }
     
  25. Offline

    Jogy34

    Yes I hope it works [creeper][creeper] :eek:[lava][creeper][creeper][creeper][diamondore]

    P.S. I like the comments at the top even though I don't think comments show up in most de-compilers.

    P.S.S @Technius that's a preference thing. I know plenty of people who like to close if's with an else even if there isn't anything needed in it.
     
  26. Offline

    Technius

    It should be like this:
    Code:Java
    1.  
    2. //By Dakoslug Alpha Build version 3
    3. //Y U DECOMPILE THIS? YOU GOT PERMISSION RIGHT?
    4. package me.dakoslug.EmergencyDowntime;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.Event.Priority;
    8. import org.bukkit.event.Event.Type;
    9. import org.bukkit.event.player.PlayerJoinEvent;
    10. import org.bukkit.event.player.PlayerListener;
    11. import org.bukkit.event.player.PlayerLoginEvent;
    12. import org.bukkit.event.player.PlayerLoginEvent.Result;
    13.  
    14. public class EmergencyDowntimeplayerListener extends PlayerListener {
    15. private EmergencyDowntime plugin;
    16. public EmergencyDowntimeplayerListener(EmergencyDowntime instance)
    17. {
    18. plugin = instance;
    19. }
    20. public void onPlayerLogin(PlayerLoginEvent event)
    21. {
    22. if(EmergencyDowntime.getDowntime())
    23. {
    24. if (event.getPlayer().isOp())
    25. {
    26. event.allow();
    27. }
    28. else
    29. {
    30. event.disallow(PlayerLoginEvent.Result.KICK_OTHER, plugin.getConfig().getString("Kickmessage"));
    31. }
    32. }
    33. }
    34. }

    The else added at the end of the first if block isn't needed, because players would be allowed in anyways. And there were extra brackets. I could rewrite this whole thing in a few minutes if you let me...
     
  27. Offline

    dakoslug

    aw XD
     
  28. Offline

    Jogy34

    exe dee
     
  29. Offline

    dakoslug

    No work, Im starting to think to take up you're original offer on the Playermove
     
  30. Offline

    Jogy34

    Just wait until a new RB comes out for 1.0 and if it still doesn't work then tag a Bukkit developer.
     
  31. Offline

    dakoslug

    It's a bukkit bug?
     
Thread Status:
Not open for further replies.

Share This Page