Skip to content
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
4 changes: 2 additions & 2 deletions AdvancedCore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
<dependency>
<groupId>com.bencodez</groupId>
<artifactId>simpleapi</artifactId>
<version>1.0.2-20260905.234759-10</version>
<version>1.0.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -513,4 +513,4 @@
</build>
</profile>
</profiles>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import com.bencodez.advancedcore.AdvancedCorePlugin;
import com.bencodez.advancedcore.api.misc.files.FilesManager;
import com.bencodez.advancedcore.bukkit.rewards.BukkitRewardConfigReader;
import com.bencodez.advancedcore.core.rewards.RewardConfigReader;
import com.bencodez.simpleapi.file.CaseInsensitiveSection;

import lombok.Getter;
Expand All @@ -26,6 +28,10 @@ public class RewardFileData {

private ConfigurationSection configData;

// Resolve through the public getter on each read, including after reloads
// and for subclasses that supply their own configuration section.
private final RewardConfigReader rewardConfig = new BukkitRewardConfigReader(this::getConfigData);

/** The data file. */
private File dataFile;

Expand Down Expand Up @@ -79,22 +85,19 @@ public void createSection(String path) {
* @return the chance
*/
public double getChance() {
return getConfigData().getDouble("Chance");
return rewardConfig.getChance();
}

public Set<String> getChoices() {
if (getConfigData().isConfigurationSection("Choices")) {
return getConfigData().getConfigurationSection("Choices").getKeys(false);
}
return new HashSet<>();
return rewardConfig.getChoices();
}

public ConfigurationSection getChoicesItem(String choice) {
return getConfigData().getConfigurationSection("Choices." + choice + ".DisplayItem");
}

public String getChoicesRewardsPath(String choice) {
return "Choices." + choice + ".Rewards";
return rewardConfig.getChoicesRewardsPath(choice);
}

/**
Expand All @@ -104,11 +107,7 @@ public String getChoicesRewardsPath(String choice) {
*/
@SuppressWarnings("unchecked")
public ArrayList<String> getCommandsConsole() {
if (getConfigData().isList("Commands")) {
return (ArrayList<String>) getConfigData().getList("Commands", new ArrayList<>());
}
return (ArrayList<String>) getConfigData().getList("Commands.Console", new ArrayList<>());

return (ArrayList<String>) rewardConfig.getCommandsConsole();
}

/**
Expand All @@ -118,7 +117,7 @@ public ArrayList<String> getCommandsConsole() {
*/
@SuppressWarnings("unchecked")
public ArrayList<String> getCommandsPlayer() {
return (ArrayList<String>) getConfigData().getList("Commands.Player", new ArrayList<>());
return (ArrayList<String>) rewardConfig.getCommandsPlayer();
}

public ConfigurationSection getConfigData() {
Expand All @@ -138,7 +137,7 @@ public File getDataFile() {
* @return the delayed enabled
*/
public boolean getDelayedEnabled() {
return getConfigData().getBoolean("Delayed.Enabled");
return rewardConfig.getDelayedEnabled();
}

/**
Expand All @@ -147,11 +146,11 @@ public boolean getDelayedEnabled() {
* @return the delayed hours
*/
public int getDelayedHours() {
return getConfigData().getInt("Delayed.Hours");
return rewardConfig.getDelayedHours();
}

public int getDelayedMilliSeconds() {
return getConfigData().getInt("Delayed.MilliSeconds");
return rewardConfig.getDelayedMilliSeconds();
}

/**
Expand All @@ -160,11 +159,11 @@ public int getDelayedMilliSeconds() {
* @return the delayed minutes
*/
public int getDelayedMinutes() {
return getConfigData().getInt("Delayed.Minutes");
return rewardConfig.getDelayedMinutes();
}

public int getDelayedSeconds() {
return getConfigData().getInt("Delayed.Seconds");
return rewardConfig.getDelayedSeconds();
}

/**
Expand All @@ -186,15 +185,15 @@ public ConfigurationSection getDisplayItem() {
* @return the choice rewards enabled
*/
public boolean getEnableChoices() {
return getConfigData().getBoolean("EnableChoices");
return rewardConfig.getEnableChoices();
}

public FileConfiguration getFileData() {
return fileData;
}

public boolean getForceOffline() {
return getConfigData().getBoolean("ForceOffline");
return rewardConfig.getForceOffline();
}

/**
Expand Down Expand Up @@ -352,7 +351,7 @@ public String getPermission() {

@SuppressWarnings("unchecked")
public ArrayList<String> getPriority() {
return (ArrayList<String>) getConfigData().getList("Priority", new ArrayList<>());
return (ArrayList<String>) rewardConfig.getPriority();
}

/**
Expand All @@ -361,7 +360,7 @@ public ArrayList<String> getPriority() {
* @return the require permission
*/
public boolean getRequirePermission() {
return getConfigData().getBoolean("RequirePermission");
return rewardConfig.getRequirePermission();
}

/**
Expand All @@ -370,22 +369,11 @@ public boolean getRequirePermission() {
* @return the reward type
*/
public String getRewardType() {
String str = getConfigData().getString("RewardType", "BOTH");
if (str != null) {
if (str.equalsIgnoreCase("online")) {
return "ONLINE";
}
if (str.equalsIgnoreCase("offline")) {
return "OFFLINE";
} else {
return "BOTH";
}
}
return "BOTH";
return rewardConfig.getRewardType();
}

public String getServer() {
return getConfigData().getString("Server", "");
return rewardConfig.getServer();
}

/**
Expand All @@ -394,7 +382,7 @@ public String getServer() {
* @return the timed enabled
*/
public boolean getTimedEnabled() {
return getConfigData().getBoolean("Timed.Enabled");
return rewardConfig.getTimedEnabled();
}

/**
Expand All @@ -403,7 +391,7 @@ public boolean getTimedEnabled() {
* @return the timed hour
*/
public int getTimedHour() {
return getConfigData().getInt("Timed.Hour");
return rewardConfig.getTimedHour();
}

/**
Expand All @@ -412,7 +400,7 @@ public int getTimedHour() {
* @return the timed minute
*/
public int getTimedMinute() {
return getConfigData().getInt("Timed.Minute");
return rewardConfig.getTimedMinute();
}

/**
Expand All @@ -422,17 +410,15 @@ public int getTimedMinute() {
*/
@SuppressWarnings("unchecked")
public ArrayList<String> getWorlds() {

return (ArrayList<String>) getConfigData().getList("Worlds", new ArrayList<>());

return (ArrayList<String>) rewardConfig.getWorlds();
}

public boolean hasRewardFile() {
return dataFile != null;
}

public boolean isDirectlyDefinedReward() {
return getConfigData().getBoolean("DirectlyDefinedReward");
return rewardConfig.isDirectlyDefinedReward();
}

public boolean isRewardFile() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.bencodez.advancedcore.bukkit.rewards;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;

import org.bukkit.configuration.ConfigurationSection;

import com.bencodez.advancedcore.core.rewards.RewardConfigReader;
import com.bencodez.simpleapi.bukkit.config.BukkitStructuredConfigView;

/**
* Keeps native Bukkit getter/default and raw-list behavior while the reward
* paths and interpretation live in the shared reader. It deliberately does not
* add a case-insensitive wrapper: the supplied section already owns that policy.
*/
public final class BukkitRewardConfigReader extends RewardConfigReader {
private final Supplier<? extends ConfigurationSection> source;

public BukkitRewardConfigReader(Supplier<? extends ConfigurationSection> source) {
super(() -> new BukkitStructuredConfigView(source.get()));
this.source = Objects.requireNonNull(source, "source");
}

private ConfigurationSection section() {
return Objects.requireNonNull(source.get(), "configuration");
}

// Explicit fallback overloads do not have the same default-tree behavior
// as these legacy no-fallback Bukkit getters.
@Override
protected boolean readBoolean(String path) {
return section().getBoolean(path);
}

@Override
protected int readInt(String path) {
return section().getInt(path);
}

@Override
protected double readDouble(String path) {
return section().getDouble(path);
}

@Override
protected boolean isList(String path) {
return section().isList(path);
}

@Override
protected List<?> readList(String path) {
// No copying, filtering, coercion or change to the legacy ArrayList
// cast in RewardFileData. The empty fallback is fresh on every read.
return section().getList(path, new ArrayList<>());
}
}
Loading
Loading