VIP Kicks Random Player - Able To Bypass Full Server

Discussion in 'Plugin Development' started by BajanAmerican, Aug 9, 2013.

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

    BajanAmerican

    Hey guys, I am having trouble with my VIP kicking part of my plugin. I do not understand what is going on and the "You cannot join during game" part is working, but the VIP one is not. Everything is checked right, my name is in the VIP arraylist so I do not see why it is not working. Any help? Thanks!
    Code:java
    1. @EventHandler
    2. public void playerPreJoin(PlayerLoginEvent event) {
    3. Player player = event.getPlayer();
    4. int count = Bukkit.getOnlinePlayers().length;
    5. World world = Bukkit.getWorld("world");
    6. Location Spawn = new Location(world, -4, 50, -4);
    7. if ((CauldronWars.gameState.getState().equalsIgnoreCase(GameState.IN_GAME))
    8. || (CauldronWars.hasStarted)) {
    9. event.disallow(PlayerLoginEvent.Result.KICK_FULL,
    10. "§4§lYou Cannot Join During Game!");
    11. }
    12. if (CauldronWars.hasStarted && player.isOp()) {
    13. event.allow();
    14. player.teleport(Spawn);
    15. player.setGameMode(GameMode.CREATIVE);
    16. }
    17. if (!CauldronWars.hasStarted) {
    18. if(player.isBanned()){
    19. event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.DARK_RED + "You Have Been Banned. Bye-Bye.");
    20. return;
    21. }
    22. if((count <= plugin.getServer().getMaxPlayers())){
    23. if(CauldronWars.vips.contains(player.getName())){
    24. Random r = new Random();
    25. event.setResult(PlayerLoginEvent.Result.ALLOWED);
    26. Player[] players = Bukkit.getServer().getOnlinePlayers();
    27. Player rndPlayer = players[r.nextInt(0)];
    28. rndPlayer.kickPlayer(ChatColor.DARK_RED + "A VIP has signed in!");
    29. } else {
    30. event.disallow(PlayerLoginEvent.Result.KICK_FULL, "§4§lTHE SERVER IS FULL!");
    31. }
    32. }
    33. }
    34. }
     
  2. Offline

    Everdras

    Code:java
    1. if((count <= plugin.getServer().getMaxPlayers())){


    Should be

    Code:java
    1. if((count > plugin.getServer().getMaxPlayers())){
     
  3. Offline

    BajanAmerican

    Still doesn't work :/
     
  4. Offline

    Ivan

    You do realize that random.nextInt(0) will always return 0, making the random useless :p
     
    Loogeh likes this.
  5. Offline

    Seadragon91


    That will throw a Exception: "java.lang.IllegalArgumentException: n must be positive".

    If you want have random numbers numbers from for example 0-3, then you need add 4 to the method.
     
  6. Offline

    Ivan

    That's even worse if that's the case.
     
  7. Offline

    Loogeh

    Also, if you want to only kick someone who isn't a VIP just getting a random player could kick another VIP.
     
Thread Status:
Not open for further replies.

Share This Page