Solved Setting gamemode via onEnable() not working

Discussion in 'Plugin Development' started by nathdabomb, Apr 14, 2018.

Thread Status:
Not open for further replies.
  1. Code:
     public void setupReload() {
            Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    
                @Override
                public void run() {
                    for (Player p : Bukkit.getOnlinePlayers()) {
                       
                        Player e = p.getPlayer();
    
                        String Join = cfgm.getPlayers().getString("users." + e.getUniqueId().toString() + ".quit-gamemode");
                       
                        p.sendMessage("Debug GAMEMODE: " + Join);
                       
                        if (Join == null) {
                            e.setGameMode(Bukkit.getServer().getDefaultGameMode());
                            e.sendMessage("Debug Set Gamemode: NULL");
                        } else if (Join == "CREATIVE") {
                            e.setGameMode(GameMode.CREATIVE);
                            e.sendMessage("Debug Set Gamemode: " + Join);
                        } else if (Join == "ADVENTURE") {
                            e.setGameMode(GameMode.ADVENTURE);
                            e.sendMessage("Debug Set Gamemode: " + Join);
                        } else if (Join == "SURVIVAL") {
                            e.setGameMode(GameMode.SURVIVAL);
                            e.sendMessage("Debug Set Gamemode: " + Join);
                        } else if (Join == "SPECTATOR") {
                            e.setGameMode(GameMode.SPECTATOR);
                            e.sendMessage("Debug Set Gamemode: " + Join);
                        }
                    }
                }
           
            }, 60L);
        }
    The code above is the code that is ran when the onEnable() function is fired.

    The main reason I wanted this to happen is so when a player reloads the server it will get all online players
    and set the gamemode to the gamemode they had, I do this with a configuration file.
    I added messages that fire on debug and at the moment of testing it comes up with only the first debug message showing your gamemode, so that rules out that the config is the problem so I believe the problem is the if statement.

    I get NO error messages in the console or in the logs, so I have reason to believe that the if statement is the problem

    Any help with this will be appreciated. Thank you.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @nathdabomb Strings are compared with equals, not with ==
     
  3. This solved the problem! Thank you so much.
     
Thread Status:
Not open for further replies.

Share This Page