Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix comment duplication in config files on 1.18 #483

Merged
merged 2 commits into from
Jan 24, 2022
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
19 changes: 14 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<url>https://repo.onarandombox.com/content/groups/public</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
Expand Down Expand Up @@ -173,8 +173,7 @@ and adjust the build number accordingly -->
<relocations>
<relocation>
<pattern>com.dumptruckman.minecraft.util.Logging</pattern>
<shadedPattern>com.onarandombox.multiverseinventories.utils.InvLogging
</shadedPattern>
<shadedPattern>com.onarandombox.multiverseinventories.utils.InvLogging</shadedPattern>
</relocation>
<relocation>
<pattern>com.dumptruckman.minecraft.util.DebugLog</pattern>
Expand All @@ -186,7 +185,11 @@ and adjust the build number accordingly -->
</relocation>
<relocation>
<pattern>net.minidev.json</pattern>
<shadedPattern>com.onarandombox.multiverseinventories.util.json</shadedPattern>
<shadedPattern>com.onarandombox.multiverseinventories.utils.json</shadedPattern>
</relocation>
<relocation>
<pattern>io.papermc.lib</pattern>
<shadedPattern>com.onarandombox.multiverseinventories.utils.paperlib</shadedPattern>
</relocation>
</relocations>
</configuration>
Expand Down Expand Up @@ -225,6 +228,12 @@ and adjust the build number accordingly -->
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.onarandombox.multiverseadventure</groupId>
<artifactId>Multiverse-Adventure</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.onarandombox.multiverseinventories.share.Sharables;
import com.onarandombox.multiverseinventories.share.Shares;
import com.onarandombox.multiverseinventories.util.CommentedYamlConfiguration;
import io.papermc.lib.PaperLib;
import org.bukkit.configuration.file.FileConfiguration;

import java.io.File;
Expand Down Expand Up @@ -104,8 +105,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 +115,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 = PaperLib.getMinecraftVersion() > 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 @@ -5,6 +5,7 @@
import com.onarandombox.multiverseinventories.share.Sharables;
import com.onarandombox.multiverseinventories.util.CommentedYamlConfiguration;
import com.onarandombox.multiverseinventories.util.DeserializationException;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.Configuration;
Expand All @@ -30,19 +31,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 = PaperLib.getMinecraftVersion() > 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 @@ -84,13 +84,16 @@ public boolean setUp() {

// Initialize the Mock server.
mockServer = mock(Server.class);
JavaPluginLoader mockPluginLoader = mock(JavaPluginLoader.class);
new ReflectionMemberAccessor().set(JavaPluginLoader.class.getDeclaredField("server"), mockPluginLoader, mockServer);
when(mockServer.getName()).thenReturn("TestBukkit");
when(mockServer.getVersion()).thenReturn("git-TestBukkit-0 (MC: 1.18.1)");
Logger.getLogger("Minecraft").setParent(Util.logger);
when(mockServer.getLogger()).thenReturn(Util.logger);
when(mockServer.getWorldContainer()).thenReturn(worldsDirectory);

// Initialize the Mock Plugin Loader.
JavaPluginLoader mockPluginLoader = mock(JavaPluginLoader.class);
new ReflectionMemberAccessor().set(JavaPluginLoader.class.getDeclaredField("server"), mockPluginLoader, mockServer);

// Return a fake PDF file.
PluginDescriptionFile pdf = spy(new PluginDescriptionFile("Multiverse-Inventories", "2.4-test",
"com.onarandombox.multiverseinventories.MultiverseInventories"));
Expand Down Expand Up @@ -141,12 +144,7 @@ public boolean setUp() {
world2File.mkdirs();
MockWorldFactory.makeNewMockWorld("world2", Environment.NORMAL, WorldType.NORMAL);

// Initialize the Mock server.
mockServer = mock(Server.class);
when(mockServer.getName()).thenReturn("TestBukkit");
Logger.getLogger("Minecraft").setParent(Util.logger);
when(mockServer.getLogger()).thenReturn(Util.logger);
when(mockServer.getWorldContainer()).thenReturn(worldsDirectory);
// Finish initializing.
when(plugin.getServer()).thenReturn(mockServer);
when(core.getServer()).thenReturn(mockServer);
when(mockServer.getPluginManager()).thenReturn(mockPluginManager);
Expand Down