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

    dakoslug

    So what are my nessessary changes?

    oh wait you mean monitor? Shiz

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

    Jogy34

    ya. Whoops.
     
  3. Offline

    dakoslug

    So I would have to change my playerlistener? or some other class? Can you specify which line?
     
  4. Offline

    DDoS

    Here's a listener to kick non op players (haven't tested it):

    PHP:
    public class NOKPlayerListener extends PlayerListener {

        public 
    void onPlayerLogin(PlayerLoginEvent event) {

            if (!
    event.getPlayer().isOp()) {

                
    event.disallow(PlayerLoginEvent.Result.KICK_OTHER"Maintenance and stuff");

            }
        }
    }
    Remember to register it in your onEnable();
     
  5. Offline

    dakoslug

    Isn't it already registered?
     
  6. Offline

    Jogy34

    you should have this above your onEnable:
    Code:
    private EmergencyDowntimeplayerListener loginlistener = new EmergencyDowntimeplayerListener(this);
    
    And this in your onEnable:
    Code:
    getServer().getPluginManager().registerEvent(Event.Type.PLAYER_LOGIN, this.loginlistener, Event.Priority.Highest, this);
     
  7. Offline

    dakoslug

    Instead of
    Can I do
    Code:
    getServer().getPluginManager().registerEvent(Type.PLAYER_LOGIN, this.loginlistener, Priority.Highest, this);
    because event is not regonized.
     
  8. Offline

    DDoS


    The class I posted has no constructor, no need to pass 'this' to it when creating a new instance.

    No. Import the package...

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

    dakoslug

    I already did, still gives be a red underline.
    I imported already the following

    import org.bukkit.event.Event.Priority;
    import org.bukkit.event.Event.Type;
     
  10. Offline

    Jogy34

    @DDoS the player listener has already been sorted out its just initializing it that he needs to worry about as far as I can see in his code.

    @dakoslug ya that should be fine.
     
  11. Offline

    dakoslug

    lol what I meant was I already imported it, but im still getting errors.
     
  12. Offline

    Jogy34

    come to think of it you should just be importing

    import org.bukkit.event.Event;
     
  13. Offline

    dakoslug

    Description Resource Path Location Type
    The import org.bukkit.event.Event collides with another import statement EmergencyDowntime.java /EmergencyDowntime/src/me/dakoslug/EmergencyDowntime line 17 Java Problem
     
  14. Offline

    Jogy34

    show me all of your imports
     
  15. Offline

    dakoslug

    import java.awt.Event;
    import java.util.logging.Logger;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.event.Event.Type;
    import org.bukkit.event.Listener;
    import org.bukkit.Bukkit;
    import org.bukkit.Server;
    import org.bukkit.event.Event;
    import me.dakoslug.EmergencyDowntime.EmergencyDowntimeplayerListener;
     
  16. Offline

    Jogy34

    import java.util.logging.Logger;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.plugin.java.JavaPlugin;

    Try it with just these
     
  17. Offline

    dakoslug

    Get rid of my playerLisner import?Ok, and I have a red underline on RegisterEvent

     
  18. Offline

    Jogy34

    Sorry I forgot about that one.
     
  19. Offline

    dakoslug

    The register event?

    Description Resource Path Location Type
    The method registerEvent(Event.Type, Listener, Event.Priority, Plugin) in the type PluginManager is not applicable for the arguments (Event.Type, EmergencyDowntimeplayerListener, Event.Priority) EmergencyDowntime.java /EmergencyDowntime/src/me/dakoslug/EmergencyDowntime line 20 Java Problem

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

    Jogy34

    post your onEnable
     
  21. Offline

    dakoslug

    public void onEnable(){
    loadConfiguration();
    log.info("EmergencyDowntime is enabled and ready to start! v1.0.0");
    loginlistener = new EmergencyDowntimeplayerListener(this);
    getServer().getPluginManager().registerEvent(Event.Type.PLAYER_LOGIN, this.loginlistener, Event.Priority.Highest);
    }

    NVM FIXED. I was doing Ddos's suggestion

    When I use this as my ENTIRE playerlistener, I get
    Description Resource Path Location Type
    The constructor EmergencyDowntimeplayerListener(EmergencyDowntime) is undefined EmergencyDowntime.java /EmergencyDowntime/src/me/dakoslug/EmergencyDowntime line 18 Java Problem

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

    Jogy34

    So It's easier to fix you should put the entire initialization of the listener in the same place or in a custom method.
     
  23. Offline

    DDoS

    Did you remove 'this' from them constructor arguments in your main class? Post line 18 of your main class.
     
  24. Offline

    dakoslug

    If i remove this, it's asking me to remove private.
     
  25. Offline

    Jogy34

    o ya if you have the 'this' part in it then you wither need to make a constructor or get rid of the 'this'

    put this at the top of your player listener:
    Code:
     private EmergencyDowntime plugin;
      public EmergencyDowntimeplayerListener(EmergencyDowntime instance)
      {
    	  plugin = instance;
      }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
  26. Offline

    dakoslug

    And get rid of this?

    I mean keep*

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

    Jogy34

    keep the 'this'
     
  28. Offline

    dakoslug

    Ok now, I hope the final last problem is that it kicks non-ops out of joining server even when downtime isn't on.
     
  29. Offline

    Jogy34

    So you have no errors in the actual code but it isn't working right?
     
  30. Offline

    dakoslug

    Just stops non-ops from entering when downtime is enabled. No errors yes.
     
Thread Status:
Not open for further replies.

Share This Page