From 29f2a3dfaab27ad80571b7bc5923a261b6169137 Mon Sep 17 00:00:00 2001 From: Kermina Awad Date: Tue, 11 Jan 2022 00:18:42 -0500 Subject: [PATCH 1/2] remove duplicate section in TestInstanceCreator --- .../util/TestInstanceCreator.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/onarandombox/multiverseinventories/util/TestInstanceCreator.java b/src/test/java/com/onarandombox/multiverseinventories/util/TestInstanceCreator.java index 57a5b743..b3e5af80 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/util/TestInstanceCreator.java +++ b/src/test/java/com/onarandombox/multiverseinventories/util/TestInstanceCreator.java @@ -84,13 +84,15 @@ 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"); 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")); @@ -141,12 +143,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); From b7ca32dc9051d6fe464f6bb68aa59d6c27e7ea20 Mon Sep 17 00:00:00 2001 From: Kermina Awad Date: Sat, 22 Jan 2022 12:13:03 -0500 Subject: [PATCH 2/2] only add comments to config files when needed --- pom.xml | 19 ++++++++++++++----- .../InventoriesConfig.java | 13 ++++++++----- .../MultiverseInventories.java | 3 +-- .../YamlWorldGroupManager.java | 15 +++++++++------ .../util/TestInstanceCreator.java | 1 + 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index ece7ae1c..1e8f053b 100644 --- a/pom.xml +++ b/pom.xml @@ -17,8 +17,8 @@ https://repo.onarandombox.com/content/groups/public - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://papermc.io/repo/repository/maven-public/ jitpack.io @@ -173,8 +173,7 @@ and adjust the build number accordingly --> com.dumptruckman.minecraft.util.Logging - com.onarandombox.multiverseinventories.utils.InvLogging - + com.onarandombox.multiverseinventories.utils.InvLogging com.dumptruckman.minecraft.util.DebugLog @@ -186,7 +185,11 @@ and adjust the build number accordingly --> net.minidev.json - com.onarandombox.multiverseinventories.util.json + com.onarandombox.multiverseinventories.utils.json + + + io.papermc.lib + com.onarandombox.multiverseinventories.utils.paperlib @@ -225,6 +228,12 @@ and adjust the build number accordingly --> + + io.papermc + paperlib + 1.0.7 + compile + com.onarandombox.multiverseadventure Multiverse-Adventure diff --git a/src/main/java/com/onarandombox/multiverseinventories/InventoriesConfig.java b/src/main/java/com/onarandombox/multiverseinventories/InventoriesConfig.java index 14a66cae..867e1a97 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/InventoriesConfig.java +++ b/src/main/java/com/onarandombox/multiverseinventories/InventoriesConfig.java @@ -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; @@ -104,8 +105,8 @@ private List getComments() { } } - private CommentedYamlConfiguration config; - private MultiverseInventories plugin; + private final CommentedYamlConfiguration config; + private final MultiverseInventories plugin; InventoriesConfig(MultiverseInventories plugin) throws IOException { this.plugin = plugin; @@ -114,15 +115,17 @@ private List 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(); diff --git a/src/main/java/com/onarandombox/multiverseinventories/MultiverseInventories.java b/src/main/java/com/onarandombox/multiverseinventories/MultiverseInventories.java index 83d0262a..d3d37d1c 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/MultiverseInventories.java +++ b/src/main/java/com/onarandombox/multiverseinventories/MultiverseInventories.java @@ -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); diff --git a/src/main/java/com/onarandombox/multiverseinventories/YamlWorldGroupManager.java b/src/main/java/com/onarandombox/multiverseinventories/YamlWorldGroupManager.java index e70f4417..a4ce12cf 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/YamlWorldGroupManager.java +++ b/src/main/java/com/onarandombox/multiverseinventories/YamlWorldGroupManager.java @@ -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; @@ -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); diff --git a/src/test/java/com/onarandombox/multiverseinventories/util/TestInstanceCreator.java b/src/test/java/com/onarandombox/multiverseinventories/util/TestInstanceCreator.java index b3e5af80..82fb2bc5 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/util/TestInstanceCreator.java +++ b/src/test/java/com/onarandombox/multiverseinventories/util/TestInstanceCreator.java @@ -85,6 +85,7 @@ public boolean setUp() { // Initialize the Mock server. mockServer = mock(Server.class); 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);