Solved method won't work!

Discussion in 'Plugin Development' started by Kermit_23, Dec 6, 2016.

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

    Kermit_23

    When ever a player tries to connect, this method (isOnWhitelist) would check if joined player is on the "custom" whitelist, if so, allow him, if not, kick! But when the player joins and it ain't on the whitelist, it would always let him connect!

    Here isOnWhitelist
    PHP:
        public boolean isOnWhitelist(String playerName) {
            if (
    cfg.getConfig().getBoolean("Settings.Whitelist.enabled")) {
                for (
    String player getWhitelist().getStringList("Whitelisted-Players")) {
                    if (
    player.compareToIgnoreCase(playerName) == 0) {
                        
    System.out.println(ChatColor.RED "Whitelist-Test-True");
                        return 
    true;
                    }
                }
            }
            
    System.out.println(ChatColor.RED "Whitelist-Test-False");
            return 
    false;
        }
    And here is my listener
    PHP:
        @EventHandler (priority EventPriority.HIGHEST)
        public 
    void onWhitelistLogin(PlayerLoginEvent event) {
            
    String playerName event.getPlayer().getName();
            if (
    wm.isWhitelistActive() && !wm.isOnWhitelist(playerName)) {
                
    System.out.println("KICKINGKICKING!");
                
    event.disallow(PlayerLoginEvent.Result.KICK_OTHERChatColor.translateAlternateColorCodes('&'cfg.getConfig().getString("Messages.whitelist-kick")));
                
    setCountNonWhitelisted(getCountNonWhitelisted() + 1);
            }
            if (!
    wm.isWhitelistActive() && event.getPlayer().isOnline()) {
                
    System.out.println("ADDING TO WHITELIST");
                
    wm.addPlayerToWhitelist(playerName);
            }
        }
     
  2. Offline

    Zombie_Striker

    @Kermit_23
    I see you have been debugging. Can you posted what gets printed when you join the server?
     
  3. Offline

    Kermit_23

    It prints "Whitelist-Test-False" (red) without the plugin name.
    @Zombie_Striker
     
  4. Why not just equalsIgnoreCase? Also you REALLY should use UUIDs, remember names can change!
     
  5. Offline

    Kermit_23

    I was going to add UUIDS, but i saw that the method doesn't work and i just got stuck here before adding it.
    @bwfcwalshy
    EDIT: Ok, so i did what bwfcwalshy said and now it output true if on whitelist, but it still lets other users to join!
     
    Last edited: Dec 6, 2016
  6. @Kermit_23 Have you debugged?

    Is that true?

    What names does that return?

    Is that true? Try with String#equalsIgnoreCase as well

    Is that true?

    You're checking if they are online during login?!?!?!?
    Also you add to the whitelist on login, sure you aren't just in the whitelist?
     
  7. Offline

    Kermit_23

    @bwfcwalshy
    1. yes it is true
    2. returns my name
    3. tried with equalsIgnoreCase and it returned true
    4. yes it is true
    5. lol, i'm so stupid!!! thx for telling me

    EDIT: Log string:
    1.

    HTML:
    [20:45:15] [User Authenticator #1/INFO]: UUID of player AName is c4020c2c-0e86-3ae3-80a5-9216b2551374
    [20:45:16] [Server thread/INFO]: §cWhitelist-Test-True
    [20:45:16] [Server thread/INFO]: AName[/127.0.0.1:52781] logged in with entity id 272 at ([world]-459.00733615181866, 69.0, 90.44316230856118)
    2.
    HTML:
    [20:47:48] [User Authenticator #2/INFO]: UUID of player WoEYIq6bemFieOEh is 442045c4-1359-3856-bcb1-47c6707198fd
    [20:47:48] [Server thread/INFO]: §cWhitelist-Test-False
     
  8. @Kermit_23 You're welcome! Please mark the thread as solved.
     
  9. Offline

    Kermit_23

    @bwfcwalshy
    it outputs true but it didn't fix the problem of players being able to connect even if whitelist is on...
     
  10. Looks like it didn't allow WoEYIq6bemFieOEh online so it does work?

    And may I ask why you are masking names? Don't think anyone here cares at all.
     
  11. Offline

    Kermit_23

    @bwfcwalshy
    those aren't masked names. yes it outputs false, but the player was still able to connect even if the whitelist was activated
     
  12. @Kermit_23 Then the disallow is causing issues. This might be due to offline mode but not sure. Try with PlayerJoinEvent and kick a tick later, this should work fine.
     
  13. Offline

    Kermit_23

    @bwfcwalshy
    doesn't work, but i saw that if i set the whitelist to true on enable, it detects it as false
    code:
    PHP:
        //tried to set it to true onEnable, but it still detects it as false
        
    public boolean whitelistActive false;
    PHP:
        public boolean isWhitelistActive() {
            return 
    whitelistActive;
        }

        public 
    void setWhitelistActive(boolean isWhitelistActive) {
            
    whitelistActive isWhitelistActive;
        }
    EDIT: Just came from school and moved the whitelist code to the main class, tested and... working! Thank you guys for your time spent writing to me!
     
    Last edited: Dec 7, 2016
Thread Status:
Not open for further replies.

Share This Page