Solved PlayerPreLoginEvent Help

Discussion in 'Plugin Development' started by CONTREKEE, Mar 5, 2015.

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

    CONTREKEE

    Do you guys have any idea why this isn't working?

    Code:
        @EventHandler
        public void BanMan(PlayerPreLoginEvent e) {
           
            if(e.getResult() == Result.KICK_BANNED) {
                for(Player players : Bukkit.getOnlinePlayers()){
                    if(!players.isOp() || !players.hasPermission("staff")) {
                        return;
                    }else {
                        if(players.isOp() || players.hasPermission("staff")) {
                            players.sendMessage("&cJoin&fNotify &7> &7".replaceAll("&", "§") + e.getName() + " &chas attempted to join.".replaceAll("&", "§"));
                            players.sendMessage(e.getAddress().getHostName());
                        }
                    }
                   
                }
               
               
               
            }
           
           
        }
     
  2. Offline

    Regablith

    Any errors? If not, try putting "debug" into console after every method.
     
  3. Offline

    pie_flavor

    @CONTREKEE What's not working about it?
    And by the way, a good way to work with color codes is to set up a method
    Code:
    String c(String s) {
      return ChatColor.translateAlternateColorCodes('&',s);
    }
    and then all you do is put c(message) instead of message.
     
  4. Offline

    CONTREKEE

    @Regablith @pie_flavor

    So, the method only goes where the System.out.Print("0000000000000000000000000000") is.
    Here is the code again.

    Code:
        @EventHandler
        public void BanMan(PlayerPreLoginEvent e) {
           
           
            System.out.print("0000000000000000000000000000000000000000000000000");
            if(e.getResult() == Result.KICK_BANNED) {
                System.out.print("111111111111111111111111111111111111111111111111111111");
                for(Player players : Bukkit.getOnlinePlayers()){
                    if(!players.isOp() || !players.hasPermission("staff")) {
                        System.out.print("2222222222222222222222222222222222222222222222");
                        return;
                    }else {
                        if(players.isOp() || players.hasPermission("staff")) {
                            System.out.print("33333333333333333333333333333333333333333333333");
                            players.sendMessage("&cJoin&fNotify &7> &7".replaceAll("&", "§") + e.getName() + " &chas attempted to join.".replaceAll("&", "§"));
                            players.sendMessage(e.getAddress().getHostName());
                        }
                    }
                   
                }
               
               
               
            }
           
           
        }
     
  5. Offline

    pie_flavor

    @CONTREKEE First of all, getLogger().info(message) is better and more consistent with bukkit. Second, perhaps the handling hasn't started yet. Try checking if the player himself is banned instead of checking for the result. Alternatively, set a BukkitRunnable to run your code after a couple ticks.
     
  6. Offline

    CONTREKEE

    @pie_flavor How would I get the player in this instance? I can only get their name IP and UUID.
     
  7. Offline

    1Rogue

    if it's not going past 0, then printing the result of e.getResult() would probably be a good start
     
  8. Offline

    pie_flavor

    @CONTREKEE if (Bukkit.getOfflinePlayer(e.getUniqueId()).isBanned()) {
     
  9. @CONTREKEE Try using PlayerLoginEvent instead of using PlayerPreLoginEvent.
     
  10. Offline

    CONTREKEE

    @CodePlaysMinecraft If the player is banned they wouldn't be able to login. So that wouldnt work.
     
Thread Status:
Not open for further replies.

Share This Page