Skip to content

Commit

Permalink
only add comments to config files when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
nicegamer7 committed Jan 10, 2022
1 parent 5c07f2f commit cb3801b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ private List<String> getComments() {
}
}

private CommentedYamlConfiguration config;
private MultiverseInventories plugin;
private final CommentedYamlConfiguration config;
private final MultiverseInventories plugin;

InventoriesConfig(MultiverseInventories plugin) throws IOException {
this.plugin = plugin;
Expand All @@ -114,15 +114,17 @@ private List<String> getComments() {
Logging.fine("Created data folder.");
}

// Check if the config file exists. If not, create it.
// Check if the config file exists. If not, create it.
File configFile = new File(plugin.getDataFolder(), "config.yml");
if (!configFile.exists()) {
boolean configFileExists = configFile.exists();
if (!configFileExists) {
Logging.fine("Created config file.");
configFile.createNewFile();
}

// Load the configuration file into memory
config = new CommentedYamlConfiguration(configFile, true);
boolean supportsCommentsNatively = Integer.parseInt(this.plugin.getServer().getBukkitVersion().split("\\.")[1]) > 17;
config = new CommentedYamlConfiguration(configFile, !configFileExists || !supportsCommentsNatively);

// Sets defaults config values
this.setDefaults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ public InventoriesConfig getMVIConfig() {
public void reloadConfig() {
try {
this.config = new InventoriesConfig(this);
this.worldGroupManager = new YamlWorldGroupManager(this, new File(getDataFolder(), "groups.yml"),
((InventoriesConfig) config).getConfig());
this.worldGroupManager = new YamlWorldGroupManager(this, this.config.getConfig());
this.worldProfileContainerStore = new WeakProfileContainerStore(this, ContainerType.WORLD);
this.groupProfileContainerStore = new WeakProfileContainerStore(this, ContainerType.GROUP);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,23 @@ final class YamlWorldGroupManager extends AbstractWorldGroupManager {
}});

private final CommentedYamlConfiguration groupsConfig;
private final File groupsConfigFile;

YamlWorldGroupManager(final MultiverseInventories inventories, final File groupConfigFile, final Configuration config)
throws IOException {
YamlWorldGroupManager(final MultiverseInventories inventories, final Configuration config) throws IOException {
super(inventories);
this.groupsConfigFile = new File(plugin.getDataFolder(), "groups.yml");

// Check if the group config file exists. If not, create it and migrate group data.
// Check if the group config file exists. If not, create it and migrate group data.
boolean groupsConfigFileExists = this.groupsConfigFile.exists();
boolean migrateGroups = false;
if (!groupConfigFile.exists()) {
if (!groupsConfigFile.exists()) {
Logging.fine("Created groups file.");
groupConfigFile.createNewFile();
groupsConfigFile.createNewFile();
migrateGroups = true;
}
// Load the configuration file into memory
groupsConfig = new CommentedYamlConfiguration(groupConfigFile, true);
boolean supportsCommentsNatively = Integer.parseInt(this.plugin.getServer().getBukkitVersion().split("\\.")[1]) > 17;
groupsConfig = new CommentedYamlConfiguration(groupsConfigFile, !groupsConfigFileExists || !supportsCommentsNatively);

if (migrateGroups) {
migrateGroups(config);
Expand Down

0 comments on commit cb3801b

Please sign in to comment.