StaticFX / DiscordBotBungee

12 stars 8 forks source link

Mysql errors, improper file management #1

Closed zmspiler closed 4 years ago

zmspiler commented 4 years ago

Unfortunately, the code you have written is a mess. I have tried fixing it, but there is no point as most of the plugin is not even functioning as intended. What is the reason for not documenting/commenting your code?

1. You are saving a file that has been loaded once at the start. That means if you change literally anything in your config file as the server is running, it will be overwritten by the file loaded upon startup, as you are saving it within your onDisable() method because you want to modify the setuped value (open the file when needed...) 2. In your SQL queries, you are using the word Rank, which is a reserved keyword.

There may very well be a lot more issues than said here.

StaticFX commented 4 years ago

Hey thank you for your critic. Actually its my first open code ever so im not really in to commenting things out yet so i hope you can forgive me that. Also i never heard that Rank is a researved keyword, so thank you for that information. In newer commits i will try to sort my code a bit up, so its easier to understand it and also will comment it you.

StaticFX commented 4 years ago

Ouh and what parts are not working correctly? Can you maybe send me a stacktrace? I will try to fix it.

StaticFX commented 4 years ago

Also if you want you can tell me what i can write better in my code, so i can get better over time.

zmspiler commented 4 years ago

Sorry, I do not have the stack trace anymore, as I scrapped the proxy. If I have time, I will open a PR, as I have fixed the problem with loading configuration files.

StaticFX commented 4 years ago

Ok i will look into it thank you.

zmspiler commented 4 years ago

Unfortunately, I will not have time to fix and publish the changes as I am working on other projects.

Here are the bugs that I found in the code

1. In your Main class, the configuration that was loaded upon startup is being saved when the plugin is disabled.

@Override
public void onDisable() {
    jda.shutdownNow();
    if(ConfigFileManager.INSTANCE.isSetuped()) {
        DataBaseConnection.INSTANCE.closeConnection();
    }
    ConfigFileManager.INSTANCE.saveFile();
    VerifyFileManager.INSTANCE.saveFile();
}

This means that whatever I change while the proxy is running/plugin is loaded will be discarded upon unload. That happens because the file and its content are loaded once in ConfigFileManager and never again.

private File file = new File(Main.getInstance().getDataFolder().getAbsolutePath(), "config.yml");
public void saveFile() {
    try {
        ConfigurationProvider.getProvider(YamlConfiguration.class).save(conf,file);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Hence, the changes are always overwritten. You should also take a look at your VerifyFileManager class, as there are some similar issues.

2. Rank is a reserved SQL keyword which shouldn't be used as it causes errors (replace with something else like PlayerRank or whatever)

Thats about it for the issues I've discovered.

Best of luck.

StaticFX commented 4 years ago

Thank you for your time and effort. I will try to fix this, so you can edit the config while the plugin is running.