Solved My plugin doesn't work

Discussion in 'Plugin Development' started by EloGamerr, Jun 14, 2016.

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

    EloGamerr

    Hi. I did plugin to bann the players who are OP but not in my list so I did
    this: http://pastebin.com/iK09dKwW

    The problem is that when I tried this plugin there is an error on this line : p.kickPlayer("Vous avez été banni");
    It can't kick the player I don't know why, the bann and the deop work both but not the kick so the player can play until he disconnects.
     
  2. Offline

    Irantwomiles

    Do you mind formatting the code.
     
  3. Offline

    Zombie_Striker

    @EloGamerr
    Format your code. It will be easier to read.
    This does not look like Bukkit's Scheduler. Unless you run this synchronously with the main thread, You cannot access bukkit's methods in an async thread. If this thread is async, use Bukkit's Scheduler to make it sync.

    Instead of checking for something, and the letting it go to an else statement, You should invert the if statement and remove the else.
    I can't image that your config would have a path such as "krlmp7EloGamerrfgths", because that looks too unintelligible and would need to be very specific for this to be right. Are you sure this is the correct path?
     
    Irantwomiles likes this.
  4. Offline

    EloGamerr

    Yes, it's the correct path, I did this for more security, I have to put this letters every time before and after the name.
     
  5. Offline

    timtower Administrator Administrator Moderator

  6. Offline

    ElieTGM

    Why the heck would you do a scheduler? Just check on a join that; if a player is op; ban him:

    Code:
    @EventHandler
    public void banJoinOP(PlayerJoinEvent e) {
     
              Player p = e.getPlayer();
    
               if(p.isOp()) {
               
               p.kickPlayer("Banni");
               
               p.setBanned(true);
         }
    }
    
     
  7. Offline

    timtower Administrator Administrator Moderator

    @ElieTGM Because people can use commands while they are joined.
     
  8. Offline

    ElieTGM

    Then he could use PlayerLoginEvent; as shown in the code below:

    Code:
        @EventHandler(priority = EventPriority.HIGH)
        public void join(PlayerLoginEvent event) {
                           
                              Player p = event.getPlayer();
                              if(p.isOp()) {
    
                        event.setKickMessage("Banni!");
                        event.setResult(PlayerLoginEvent.Result.KICK_BANNED);
    
                        }
    
            }
     
  9. Offline

    timtower Administrator Administrator Moderator

    @ElieTGM And what if they are on the server for 5 minutes and somebody gives them OP then?
     
  10. Offline

    ElieTGM

    PlayerLoginEvent will ban every player that has op on joining the server. They won't even spawn.
     
  11. Offline

    timtower Administrator Administrator Moderator

    Somebody is on the server and can give people op.
    Player2 joins.
    After 5 minutes player1 decides to give player2 OP. Login and join won't catch that, timers will.
     
  12. Offline

    ElieTGM

    How did that player bypass the login event since he's op in the first place?
     
  13. Offline

    timtower Administrator Administrator Moderator

    You don't need to have OP if you have the permission to run /op
     
  14. Offline

    ElieTGM

    Then check if he's op or has the permission bukkit.command.op ? :p
     
  15. Offline

    timtower Administrator Administrator Moderator

    @ElieTGM I can come up with loads of ways to bypass those things.
    Timers are best for this.
     
  16. Offline

    EloGamerr

    For the config :
    Code:
    Option:
      active: true
    OP: krlmp7EloGamerr2fgths
        krlmp7EloGamerrfgths
    I used Bukkit.Sheduler and I used if(getConfig().getStringList().contains(pn), now it works.

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

    mine-care

    @ElieTGM
    Even if you corss the permission out or even if you override the command entirely there is a way someone can give OP to someone else. For instance through code using player#setOP(true); or even if you overwrite that somehow, you can still access the method addOp in the NMS class Server and add ops.. In other words it is really hard to cross out all the possible ways a player can receive OP rights, thus the scheduler is a suitable solution. On the other hand, if the OP wanted to cross out the surface techniques of giving OP, they could do the PlayerJoinEvent check and also overwrite the Bukkit command class 'OpCommand' (possible through reflection) to perform their checks.
     
Thread Status:
Not open for further replies.

Share This Page