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 11, 2022
1 parent 29f2a3d commit 9c1aca9
Show file tree
Hide file tree
Showing 4 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 @@ -30,19 +30,21 @@ final class YamlWorldGroupManager extends AbstractWorldGroupManager {

private final CommentedYamlConfiguration groupsConfig;

YamlWorldGroupManager(final MultiverseInventories inventories, final File groupConfigFile, final Configuration config)
throws IOException {
YamlWorldGroupManager(final MultiverseInventories inventories, final Configuration config) throws IOException {
super(inventories);

// 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.
File groupsConfigFile = new File(plugin.getDataFolder(), "groups.yml");
boolean groupsConfigFileExists = 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
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public boolean setUp() {
// Initialize the Mock server.
mockServer = mock(Server.class);
when(mockServer.getName()).thenReturn("TestBukkit");
when(mockServer.getBukkitVersion()).thenReturn("1.18.1-R0.1-SNAPSHOT");
Logger.getLogger("Minecraft").setParent(Util.logger);
when(mockServer.getLogger()).thenReturn(Util.logger);
when(mockServer.getWorldContainer()).thenReturn(worldsDirectory);
Expand Down

0 comments on commit 9c1aca9

Please sign in to comment.