Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.mvplugins.multiverse.core.inject.PluginServiceLocatorFactory;
import org.mvplugins.multiverse.core.utils.StringFormatter;
import org.mvplugins.multiverse.inventories.commands.InventoriesCommand;
import org.mvplugins.multiverse.inventories.config.InventoriesConfig;
import org.mvplugins.multiverse.inventories.locale.Message;
import org.mvplugins.multiverse.inventories.locale.Messager;
import org.mvplugins.multiverse.inventories.locale.Messaging;
Expand Down Expand Up @@ -49,6 +50,8 @@ public static MultiverseInventories getPlugin() {

private PluginServiceLocator serviceLocator;

@Inject
private Provider<InventoriesConfig> configProvider;
@Inject
private Provider<MVCommandManager> commandManager;
@Inject
Expand All @@ -62,7 +65,6 @@ public static MultiverseInventories getPlugin() {
private ProfileContainerStore groupProfileContainerStore = null;
private final ImportManager importManager = new ImportManager(this);

private InventoriesConfig config = null;
private FlatFileProfileDataSource data = null;

private InventoriesDupingPatch dupingPatch;
Expand Down Expand Up @@ -251,7 +253,7 @@ private String logAndAddToPasteBinBuffer(String string) {
* @return the Config object which contains settings for this plugin.
*/
public InventoriesConfig getMVIConfig() {
return this.config;
return this.configProvider.get();
}

/**
Expand All @@ -260,8 +262,7 @@ public InventoriesConfig getMVIConfig() {
@Override
public void reloadConfig() {
try {
this.config = new InventoriesConfig(this, mvCoreConfig.get());
this.worldGroupManager = new YamlWorldGroupManager(this, this.config.getConfig());
this.worldGroupManager = new YamlWorldGroupManager(this, this.configProvider.get().getConfig());
this.worldProfileContainerStore = new WeakProfileContainerStore(this, ContainerType.WORLD);
this.groupProfileContainerStore = new WeakProfileContainerStore(this, ContainerType.GROUP);

Expand Down Expand Up @@ -363,3 +364,4 @@ public boolean isUsingSpawnChangeEvent() {
return usingSpawnChangeEvent;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.dumptruckman.minecraft.util.Logging;
import com.google.common.collect.Lists;
import org.mvplugins.multiverse.external.commentedconfiguration.CommentedConfiguration;
import org.mvplugins.multiverse.inventories.share.Sharables;
import org.mvplugins.multiverse.inventories.util.CommentedYamlConfiguration;
import org.mvplugins.multiverse.inventories.util.DeserializationException;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
Expand All @@ -24,12 +24,14 @@

final class YamlWorldGroupManager extends AbstractWorldGroupManager {

private final List<String> groupSectionComments = Collections.unmodifiableList(new ArrayList<String>() {{
add("# To ADD, DELETE, and EDIT groups use the command /mvinv group.");
add("# No support will be given for those who manually edit these groups.");
}});
private final String[] groupSectionComments = {
"# Multiverse-Inventories Groups",
"",
"# To ADD, DELETE, and EDIT groups use the command /mvinv group.",
"# No support will be given for those who manually edit these groups."
};

private final CommentedYamlConfiguration groupsConfig;
private final CommentedConfiguration groupsConfig;

YamlWorldGroupManager(final MultiverseInventories inventories, final Configuration config) throws IOException {
super(inventories);
Expand All @@ -44,19 +46,18 @@ final class YamlWorldGroupManager extends AbstractWorldGroupManager {
migrateGroups = true;
}
// Load the configuration file into memory
boolean supportsCommentsNatively = PaperLib.getMinecraftVersion() > 17;
groupsConfig = new CommentedYamlConfiguration(groupsConfigFile, !groupsConfigFileExists || !supportsCommentsNatively);
groupsConfig = new CommentedConfiguration(groupsConfigFile.toPath());
groupsConfig.load();

if (migrateGroups) {
migrateGroups(config);
}

groupsConfig.addComment("groups", groupSectionComments);
if (groupsConfig.getConfig().get("groups") == null) {
if (groupsConfig.get("groups") == null) {
this.getConfig().createSection("groups");
}

groupsConfig.getConfig().options().header("Multiverse-Inventories Groups");
// Saves the configuration from memory to file
groupsConfig.save();

Expand Down Expand Up @@ -86,7 +87,7 @@ private void migrateGroups(final Configuration config) {
}

private FileConfiguration getConfig() {
return this.groupsConfig.getConfig();
return this.groupsConfig;
}

private List<WorldGroup> getGroupsFromConfig() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.mvplugins.multiverse.inventories;
package org.mvplugins.multiverse.inventories.config;

import com.dumptruckman.minecraft.util.Logging;
import org.mvplugins.multiverse.core.config.MVCoreConfig;
import org.mvplugins.multiverse.external.commentedconfiguration.CommentedConfiguration;
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.inventories.MultiverseInventories;
import org.mvplugins.multiverse.inventories.share.Sharable;
import org.mvplugins.multiverse.inventories.share.Sharables;
import org.mvplugins.multiverse.inventories.share.Shares;
import org.mvplugins.multiverse.inventories.util.CommentedYamlConfiguration;
import io.papermc.lib.PaperLib;
import org.bukkit.configuration.file.FileConfiguration;

Expand All @@ -18,6 +21,7 @@
/**
* Provides methods for interacting with the configuration of Multiverse-Inventories.
*/
@Service
public final class InventoriesConfig {

/**
Expand Down Expand Up @@ -107,10 +111,11 @@ private List<String> getComments() {
}
}

private final CommentedYamlConfiguration config;
private final CommentedConfiguration config;
private final MultiverseInventories plugin;
private final MVCoreConfig mvCoreConfig;

@Inject
InventoriesConfig(MultiverseInventories plugin, MVCoreConfig mvCoreConfig) throws IOException {
this.plugin = plugin;
this.mvCoreConfig = mvCoreConfig;
Expand All @@ -128,13 +133,13 @@ private List<String> getComments() {
}

// Load the configuration file into memory
boolean supportsCommentsNatively = PaperLib.getMinecraftVersion() > 17;
config = new CommentedYamlConfiguration(configFile, !configFileExists || !supportsCommentsNatively);
config = new CommentedConfiguration(configFile.toPath());
config.load();

// Sets defaults config values
this.setDefaults();

config.getConfig().options().header("Multiverse-Inventories Settings");
config.addComment("settings", "# Multiverse-Inventories Settings", "");

// Saves the configuration from memory to file
config.save();
Expand All @@ -148,7 +153,7 @@ private List<String> getComments() {
*/
private void setDefaults() {
for (InventoriesConfig.Path path : InventoriesConfig.Path.values()) {
config.addComment(path.getPath(), path.getComments());
config.addComment(path.getPath(), path.getComments().toArray(new String[0]));
if (this.getConfig().get(path.getPath()) == null) {
if (path.getDefault() != null) {
Logging.fine("Config: Defaulting '" + path.getPath() + "' to " + path.getDefault());
Expand All @@ -173,8 +178,8 @@ private String getString(Path path) {
return this.getConfig().getString(path.getPath(), (String) path.getDefault());
}

FileConfiguration getConfig() {
return this.config.getConfig();
public FileConfiguration getConfig() {
return this.config;
}

/**
Expand Down Expand Up @@ -218,7 +223,7 @@ public boolean isFirstRun() {
*
* @param firstRun What to set the flag to in the config.
*/
void setFirstRun(boolean firstRun) {
public void setFirstRun(boolean firstRun) {
this.getConfig().set(Path.FIRST_RUN.getPath(), firstRun);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.mvplugins.multiverse.inventories.share;

import org.mvplugins.multiverse.inventories.InventoriesConfig;
import org.mvplugins.multiverse.inventories.config.InventoriesConfig;

import java.util.ArrayList;
import java.util.List;
Expand Down
Loading
Loading