Skip to content

Commit

Permalink
Deleted deprecated method QuestPackage#getRawString(String)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolf2323 committed Jan 20, 2025
1 parent 8556da8 commit 771fbd7
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 56 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/betonquest/betonquest/Journal.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/betonquest/betonquest/id/ID.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 771fbd7

Please sign in to comment.