diff --git a/advanced-achievements-plugin/src/main/java/com/hm/achievement/config/ConfigurationParser.java b/advanced-achievements-plugin/src/main/java/com/hm/achievement/config/ConfigurationParser.java index dfe5e4270..033fb184c 100644 --- a/advanced-achievements-plugin/src/main/java/com/hm/achievement/config/ConfigurationParser.java +++ b/advanced-achievements-plugin/src/main/java/com/hm/achievement/config/ConfigurationParser.java @@ -306,6 +306,7 @@ private void parseAchievement(Category category, String subcategory, long thresh throw new PluginLoadError( "Achievement with path (" + path + ") is missing its Message parameter in config.yml."); } + String rewardPath = mainConfig.isConfigurationSection(path + ".Reward") ? path + ".Reward" : path + ".Rewards"; Achievement achievement = new AchievementBuilder() .name(section.getString("Name")) @@ -316,7 +317,7 @@ private void parseAchievement(Category category, String subcategory, long thresh .threshold(threshold) .category(category) .subcategory(subcategory) - .rewards(rewardParser.parseRewards(path)) + .rewards(rewardParser.parseRewards(rewardPath)) .build(); achievementMap.put(achievement); } diff --git a/advanced-achievements-plugin/src/main/java/com/hm/achievement/config/RewardParser.java b/advanced-achievements-plugin/src/main/java/com/hm/achievement/config/RewardParser.java index d262ca5ac..6903445f4 100644 --- a/advanced-achievements-plugin/src/main/java/com/hm/achievement/config/RewardParser.java +++ b/advanced-achievements-plugin/src/main/java/com/hm/achievement/config/RewardParser.java @@ -75,10 +75,7 @@ public Economy getEconomy() { } public List parseRewards(String path) { - ConfigurationSection configSection = mainConfig.getConfigurationSection(path + ".Reward"); - if (configSection == null) { - configSection = mainConfig.getConfigurationSection(path + ".Rewards"); - } + ConfigurationSection configSection = mainConfig.getConfigurationSection(path); List rewards = new ArrayList<>(); if (configSection != null) { if (economy != null && configSection.contains("Money")) { diff --git a/advanced-achievements-plugin/src/test/java/com/hm/achievement/config/RewardParserTest.java b/advanced-achievements-plugin/src/test/java/com/hm/achievement/config/RewardParserTest.java index 7964b65b0..282637cba 100644 --- a/advanced-achievements-plugin/src/test/java/com/hm/achievement/config/RewardParserTest.java +++ b/advanced-achievements-plugin/src/test/java/com/hm/achievement/config/RewardParserTest.java @@ -64,7 +64,7 @@ void shouldParseMoneyRewardSingular() throws Exception { mainConfig.load(Paths.get(getClass().getClassLoader().getResource("reward-parser/money-1.yml").toURI()).toFile()); when(economy.currencyNameSingular()).thenReturn("coin"); - List rewards = underTest.parseRewards(""); + List rewards = underTest.parseRewards("Reward"); assertEquals(1, rewards.size()); Reward reward = rewards.get(0); @@ -79,7 +79,7 @@ void shouldParseMoneyRewardPlural() throws Exception { mainConfig.load(Paths.get(getClass().getClassLoader().getResource("reward-parser/money-2.yml").toURI()).toFile()); when(economy.currencyNamePlural()).thenReturn("coins"); - List rewards = underTest.parseRewards(""); + List rewards = underTest.parseRewards("Reward"); assertEquals(1, rewards.size()); Reward reward = rewards.get(0); @@ -93,7 +93,7 @@ void shouldParseMoneyRewardPlural() throws Exception { void shouldParseItemReward() throws Exception { mainConfig.load(Paths.get(getClass().getClassLoader().getResource("reward-parser/item.yml").toURI()).toFile()); - List rewards = underTest.parseRewards(""); + List rewards = underTest.parseRewards("Reward"); assertEquals(1, rewards.size()); Reward reward = rewards.get(0); @@ -113,7 +113,7 @@ void shouldParseSingleCommandReward() throws Exception { when(player.getWorld()).thenReturn(world); when(world.getName()).thenReturn("Nether"); - List rewards = underTest.parseRewards(""); + List rewards = underTest.parseRewards("Reward"); assertEquals(1, rewards.size()); Reward reward = rewards.get(0); @@ -132,7 +132,7 @@ void shouldParseMultipleCommandRewards() throws Exception { when(player.getWorld()).thenReturn(world); when(world.getName()).thenReturn("Nether"); - List rewards = underTest.parseRewards(""); + List rewards = underTest.parseRewards("Reward"); assertEquals(1, rewards.size()); Reward reward = rewards.get(0); @@ -148,7 +148,7 @@ void shouldParseMultipleCommandRewards() throws Exception { void shouldParseExperienceReward() throws Exception { mainConfig.load(Paths.get(getClass().getClassLoader().getResource("reward-parser/experience.yml").toURI()).toFile()); - List rewards = underTest.parseRewards(""); + List rewards = underTest.parseRewards("Reward"); assertEquals(1, rewards.size()); Reward reward = rewards.get(0); @@ -165,7 +165,7 @@ void shouldParseMaxHealthReward() throws Exception { when(player.getAttribute(any())).thenReturn(healthAttribute); when(healthAttribute.getBaseValue()).thenReturn(1.0); - List rewards = underTest.parseRewards(""); + List rewards = underTest.parseRewards("Reward"); assertEquals(1, rewards.size()); Reward reward = rewards.get(0); @@ -181,7 +181,7 @@ void shouldParseMaxOxygenReward() throws Exception { mainConfig.load(Paths.get(getClass().getClassLoader().getResource("reward-parser/max-oxygen.yml").toURI()).toFile()); when(player.getMaximumAir()).thenReturn(5); - List rewards = underTest.parseRewards(""); + List rewards = underTest.parseRewards("Reward"); assertEquals(1, rewards.size()); Reward reward = rewards.get(0); diff --git a/advanced-achievements-plugin/src/test/resources/reward-parser/commands.yml b/advanced-achievements-plugin/src/test/resources/reward-parser/commands.yml index df79d1057..0d815517d 100644 --- a/advanced-achievements-plugin/src/test/resources/reward-parser/commands.yml +++ b/advanced-achievements-plugin/src/test/resources/reward-parser/commands.yml @@ -1,4 +1,4 @@ -Rewards: +Reward: Commands: Display: - 'display 1'