diff --git a/src/main/java/org/betonquest/betonquest/Journal.java b/src/main/java/org/betonquest/betonquest/Journal.java index ad8d706cea..10bd2be107 100644 --- a/src/main/java/org/betonquest/betonquest/Journal.java +++ b/src/main/java/org/betonquest/betonquest/Journal.java @@ -229,12 +229,12 @@ public void generateTexts(final String lang) { final ConfigurationSection journal = pack.getConfig().getConfigurationSection("journal"); if (journal != null && journal.contains(pointerName)) { if (journal.isConfigurationSection(pointerName)) { - text = pack.getRawString("journal." + pointerName + "." + lang); + text = pack.getConfig().getString("journal." + pointerName + "." + lang); if (text == null) { - text = pack.getRawString("journal." + pointerName + "." + Config.getLanguage()); + text = pack.getConfig().getString("journal." + pointerName + "." + Config.getLanguage()); } } else { - text = pack.getRawString("journal." + pointerName); + text = pack.getConfig().getString("journal." + pointerName); } } else { log.warn(pack, "No defined journal entry " + pointerName + " in package " + pack.getQuestPath()); diff --git a/src/main/java/org/betonquest/betonquest/api/config/quest/QuestPackage.java b/src/main/java/org/betonquest/betonquest/api/config/quest/QuestPackage.java index c0005a7a53..92534746a8 100644 --- a/src/main/java/org/betonquest/betonquest/api/config/quest/QuestPackage.java +++ b/src/main/java/org/betonquest/betonquest/api/config/quest/QuestPackage.java @@ -4,7 +4,6 @@ import org.betonquest.betonquest.api.config.ConfigAccessor; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; -import org.jetbrains.annotations.Nullable; import java.io.FileNotFoundException; import java.io.IOException; @@ -65,8 +64,4 @@ public interface QuestPackage { * @throws FileNotFoundException thrown if the file for the new {@link ConfigAccessor} could not be found */ ConfigAccessor getOrCreateConfigAccessor(String relativePath) throws InvalidConfigurationException, FileNotFoundException; - - @Nullable - @Deprecated - String getRawString(String address); } diff --git a/src/main/java/org/betonquest/betonquest/config/QuestCanceler.java b/src/main/java/org/betonquest/betonquest/config/QuestCanceler.java index 8b5e88d633..c809996053 100644 --- a/src/main/java/org/betonquest/betonquest/config/QuestCanceler.java +++ b/src/main/java/org/betonquest/betonquest/config/QuestCanceler.java @@ -100,7 +100,7 @@ public QuestCanceler(final VariableProcessor variableProcessor, final QuestPacka } // get the item final String itemString = section.getString("item"); - item = itemString == null ? pack.getRawString("items.cancel_button") : itemString; + item = itemString == null ? pack.getConfig().getString("items.cancel_button") : itemString; // parse it to get the data events = parseID(section, "events", EventID::new); conditions = parseID(section, "conditions", ConditionID::new); diff --git a/src/main/java/org/betonquest/betonquest/config/quest/QuestPackageImpl.java b/src/main/java/org/betonquest/betonquest/config/quest/QuestPackageImpl.java index 4824dda41b..c4cff8a3ef 100644 --- a/src/main/java/org/betonquest/betonquest/config/quest/QuestPackageImpl.java +++ b/src/main/java/org/betonquest/betonquest/config/quest/QuestPackageImpl.java @@ -5,9 +5,7 @@ import org.betonquest.betonquest.api.config.ConfigAccessorFactory; import org.betonquest.betonquest.api.config.quest.QuestPackage; import org.betonquest.betonquest.api.logger.BetonQuestLogger; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; -import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.FileNotFoundException; @@ -38,35 +36,4 @@ public QuestPackageImpl(final BetonQuestLogger log, final ConfigAccessorFactory public boolean hasTemplate(final String templatePath) { return getTemplates().contains(templatePath); } - - @Override - @Nullable - @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") - public String getRawString(final String address) { - final String[] parts = address.split("\\."); - if (parts.length < 2) { - return null; - } - final String path = parts[0]; - int startPath = 1; - ConfigurationSection section = getConfig().getConfigurationSection(path); - if (section != null && "conversations".equals(path)) { - if (parts.length < 3) { - return null; - } - section = section.getConfigurationSection(parts[1]); - startPath = 2; - } - if (section == null) { - return null; - } - final StringBuilder restPath = new StringBuilder(); - for (int i = startPath; i < parts.length; i++) { - restPath.append(parts[i]); - if (i < parts.length - 1) { - restPath.append('.'); - } - } - return section.getString(restPath.toString(), null); - } } diff --git a/src/main/java/org/betonquest/betonquest/conversation/ConversationData.java b/src/main/java/org/betonquest/betonquest/conversation/ConversationData.java index a0c5b35bc4..0d26310c3b 100644 --- a/src/main/java/org/betonquest/betonquest/conversation/ConversationData.java +++ b/src/main/java/org/betonquest/betonquest/conversation/ConversationData.java @@ -141,27 +141,27 @@ public ConversationData(final BetonQuest plugin, final ConversationID conversati } if (convSection.isConfigurationSection("quester")) { for (final String lang : convSection.getConfigurationSection("quester").getKeys(false)) { - final String questerName = new VariableString(variableProcessor, pack, pack.getRawString("conversations." + convName + ".quester." + lang)).getValue(null); + final String questerName = new VariableString(variableProcessor, pack, pack.getConfig().getString("conversations." + convName + ".quester." + lang)).getValue(null); quester.put(lang, ChatColor.translateAlternateColorCodes('&', questerName)); } } else { - final String questerName = new VariableString(variableProcessor, pack, pack.getRawString("conversations." + convName + ".quester")).getValue(null); + final String questerName = new VariableString(variableProcessor, pack, pack.getConfig().getString("conversations." + convName + ".quester")).getValue(null); quester.put(Config.getLanguage(), ChatColor.translateAlternateColorCodes('&', questerName)); } if (convSection.isConfigurationSection("prefix")) { for (final String lang : convSection.getConfigurationSection("prefix").getKeys(false)) { - final String pref = pack.getRawString("conversations." + convName + ".prefix." + lang); + final String pref = pack.getConfig().getString("conversations." + convName + ".prefix." + lang); if (pref != null && !pref.isEmpty()) { prefix.put(lang, new VariableString(variableProcessor, pack, pref).getValue(null)); } } } else { - final String pref = pack.getRawString("conversations." + convName + ".prefix"); + final String pref = pack.getConfig().getString("conversations." + convName + ".prefix"); if (pref != null && !pref.isEmpty()) { prefix.put(Config.getLanguage(), new VariableString(variableProcessor, pack, pref).getValue(null)); } } - final String stop = pack.getRawString("conversations." + convName + ".stop"); + final String stop = pack.getConfig().getString("conversations." + convName + ".stop"); blockMovement = Boolean.parseBoolean(stop); final String rawConvIOs = new VariableString(variableProcessor, pack, pack.getConfig().getString("conversations." + convName + ".conversationIO", @@ -279,7 +279,7 @@ private CrossConversationReference resolvePointer(final QuestPackage pack, final } private void parseOptions(final QuestPackage pack, final ConfigurationSection convSection) throws QuestException, ObjectNotFoundException { - final String rawFinalEvents = pack.getRawString("conversations." + convName + ".final_events"); + final String rawFinalEvents = pack.getConfig().getString("conversations." + convName + ".final_events"); if (rawFinalEvents != null && !rawFinalEvents.isEmpty()) { final String[] array = new VariableString(variableProcessor, pack, rawFinalEvents).getValue(null).split(","); for (final String identifier : array) { @@ -355,7 +355,7 @@ private void validateNpcOptions() throws QuestException, ObjectNotFoundException * @throws QuestException when the conversation could not be resolved */ private void loadStartingOptions(final QuestPackage pack) throws QuestException, ObjectNotFoundException { - final String rawStartingOptions = pack.getRawString("conversations." + convName + ".first"); + final String rawStartingOptions = pack.getConfig().getString("conversations." + convName + ".first"); if (rawStartingOptions == null || rawStartingOptions.isEmpty()) { throw new QuestException("Starting options are not defined"); } @@ -805,7 +805,7 @@ private void parseText(final String name, final OptionType type, final Configura } private void addConversationText(final String name, final OptionType type, final String lang, final String suffix) throws QuestException { - final String convText = Utils.format(pack.getRawString("conversations." + conversationName + "." + type.getIdentifier() + "." + name + ".text" + suffix)); + final String convText = Utils.format(pack.getConfig().getString("conversations." + conversationName + "." + type.getIdentifier() + "." + name + ".text" + suffix)); if (convText == null) { throw new QuestException("No text for " + name + " " + type.getReadable()); } diff --git a/src/main/java/org/betonquest/betonquest/id/ID.java b/src/main/java/org/betonquest/betonquest/id/ID.java index 911a65fafa..325bbf9168 100644 --- a/src/main/java/org/betonquest/betonquest/id/ID.java +++ b/src/main/java/org/betonquest/betonquest/id/ID.java @@ -86,7 +86,7 @@ protected ID(@Nullable final QuestPackage pack, final String identifier) throws */ protected ID(@Nullable final QuestPackage pack, final String identifier, final String section, final String readable) throws ObjectNotFoundException { this(pack, identifier); - final String rawInstruction = this.pack.getRawString(section + "." + this.identifier); + final String rawInstruction = this.pack.getConfig().getString(section + "." + this.identifier); if (rawInstruction == null) { throw new ObjectNotFoundException(readable + " '" + getFullID() + "' is not defined"); } diff --git a/src/test/java/org/betonquest/betonquest/api/schedule/ScheduleBaseTest.java b/src/test/java/org/betonquest/betonquest/api/schedule/ScheduleBaseTest.java index b00cc37b04..83d8a73b2b 100644 --- a/src/test/java/org/betonquest/betonquest/api/schedule/ScheduleBaseTest.java +++ b/src/test/java/org/betonquest/betonquest/api/schedule/ScheduleBaseTest.java @@ -1,5 +1,6 @@ package org.betonquest.betonquest.api.schedule; +import org.betonquest.betonquest.api.bukkit.config.custom.multi.MultiConfiguration; import org.betonquest.betonquest.exception.ObjectNotFoundException; import org.betonquest.betonquest.exception.QuestException; import org.betonquest.betonquest.logger.util.BetonQuestLoggerService; @@ -24,8 +25,10 @@ protected Schedule createSchedule() throws QuestException { @Override protected void prepareConfig() { - lenient().when(questPackage.getRawString("events.bell_ring")).thenReturn("folder bell_lever_toggle,bell_lever_toggle period:0.5"); - lenient().when(questPackage.getRawString("events.notify_goodNight")).thenReturn("notify &6Good night, sleep well!"); + final MultiConfiguration mockConfig = mock(MultiConfiguration.class); + lenient().when(questPackage.getConfig()).thenReturn(mockConfig); + lenient().when(mockConfig.getString("events.bell_ring")).thenReturn("folder bell_lever_toggle,bell_lever_toggle period:0.5"); + lenient().when(mockConfig.getString("events.notify_goodNight")).thenReturn("notify &6Good night, sleep well!"); lenient().when(section.getString("time")).thenReturn("22:00"); lenient().when(section.getString("events")).thenReturn("bell_ring,notify_goodNight"); @@ -64,7 +67,7 @@ void testEventsNotSet() { @Test void testEventsNotFound() { - when(questPackage.getRawString("events.bell_ring")).thenReturn(null); + when(questPackage.getConfig().getString("events.bell_ring")).thenReturn(null); final QuestException exception = assertThrows(QuestException.class, this::createSchedule, "Schedule should throw instruction parse exception for invalid event names"); assertInstanceOf(ObjectNotFoundException.class, exception.getCause(), "Cause should be ObjectNotFoundException"); } diff --git a/src/test/java/org/betonquest/betonquest/schedule/ScheduleTypeTest.java b/src/test/java/org/betonquest/betonquest/schedule/ScheduleTypeTest.java index 7a8e17a7b2..3ebd1fe9ac 100644 --- a/src/test/java/org/betonquest/betonquest/schedule/ScheduleTypeTest.java +++ b/src/test/java/org/betonquest/betonquest/schedule/ScheduleTypeTest.java @@ -1,5 +1,6 @@ package org.betonquest.betonquest.schedule; +import org.betonquest.betonquest.api.bukkit.config.custom.multi.MultiConfiguration; import org.betonquest.betonquest.api.config.quest.QuestPackage; import org.betonquest.betonquest.api.schedule.FictiveTime; import org.betonquest.betonquest.api.schedule.Schedule; @@ -45,9 +46,11 @@ class ScheduleTypeTest { @BeforeEach void prepareConfig() { - lenient().when(questPackage.getRawString("events.bell_ring")) + final MultiConfiguration mockConfig = mock(MultiConfiguration.class); + lenient().when(questPackage.getConfig()).thenReturn(mockConfig); + lenient().when(mockConfig.getString("events.bell_ring")) .thenReturn("folder bell_lever_toggle,bell_lever_toggle period:0.5"); - lenient().when(questPackage.getRawString("events.notify_goodNight")) + lenient().when(mockConfig.getString("events.notify_goodNight")) .thenReturn("notify &6Good night, sleep well!"); lenient().when(scheduleID.getPackage()).thenReturn(questPackage);