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
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
import io.vavr.control.Try;
import jakarta.inject.Inject;
import jakarta.inject.Provider;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.plugin.ServicePriority;
import org.jetbrains.annotations.NotNull;
import org.jvnet.hk2.annotations.Service;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,14 @@ public Try<Void> setShowLegacyAliases(boolean showLegacyAliases) {
return configHandle.set(configNodes.showLegacyAliases, showLegacyAliases);
}

public Try<Void> setBukkitYmlPath(String bukkitYmlPath) {
return configHandle.set(configNodes.bukkitYmlPath, bukkitYmlPath);
}

public String getBukkitYmlPath() {
return configHandle.get(configNodes.bukkitYmlPath);
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,15 @@ private <N extends Node> N node(N node) {
.comment("")
.build());

final ConfigNode<String> bukkitYmlPath = node(ConfigNode.builder("misc.bukkit-yml-path", String.class)
.comment("Change this if you use a custom path for the bukkit.yml file with `--bukkit-settings` startup flag.")
.comment("Note: this config option needs a server restart to take effect.")
.defaultValue("bukkit.yml")
.name("bukkit-yml-path")
.build());

final ConfigNode<Integer> globalDebug = node(ConfigNode.builder("misc.global-debug", Integer.class)
.comment("")
.comment("This is our debug flag to help identify issues with Multiverse.")
.comment("If you are having issues with Multiverse, please set this to 3 and then post your log to pastebin.com")
.comment("Otherwise, there's no need to touch this. If not instructed by a wiki page or developer.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class BaseConfigurationHandle<C extends ConfigurationSection> {
protected final @Nullable Logger logger;
protected final @NotNull NodeGroup nodes;
protected final @Nullable ConfigMigrator migrator;
protected final @NotNull Map<Node, Object> nodeValueMap;
protected final @NotNull Map<ValueNode, Object> nodeValueMap;

protected C config;

Expand Down Expand Up @@ -80,9 +80,12 @@ protected void setUpNodes() {
if (node instanceof ValueNode valueNode) {
var value = deserializeNodeFromConfig(valueNode);
nodeValueMap.put(valueNode, value);
valueNode.onSetValue(value, value);
}
});

nodeValueMap.forEach((valueNode, value) -> {
valueNode.onSetValue(value, value);
});
}

protected <T> T deserializeNodeFromConfig(ValueNode<T> node) {
Expand Down
50 changes: 29 additions & 21 deletions src/main/java/org/mvplugins/multiverse/core/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Collections;
Expand All @@ -19,9 +20,11 @@
import com.dumptruckman.minecraft.util.Logging;
import io.vavr.control.Try;
import jakarta.inject.Inject;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.core.config.CoreConfig;

import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES;

Expand All @@ -31,32 +34,16 @@
@Service
public final class FileUtils {

private final CoreConfig config;
private final File serverFolder;
private final File bukkitYml;
private final File serverProperties;
private File bukkitYml;
private File serverProperties;

@Inject
FileUtils() {
FileUtils(CoreConfig config) {
this.config = config;
this.serverFolder = new File(System.getProperty("user.dir"));
Logging.finer("Server folder: " + this.serverFolder);
this.bukkitYml = findFileFromServerDirectory("bukkit.yml");
this.serverProperties = findFileFromServerDirectory("server.properties");
}

private @Nullable File findFileFromServerDirectory(String fileName) {
File[] files;
try {
files = this.serverFolder.listFiles((file, s) -> s.equalsIgnoreCase(fileName));
} catch (Exception e) {
Logging.severe("Could not read from server directory. Unable to locate file: %s", fileName);
Logging.severe(e.getMessage());
return null;
}
if (files != null && files.length == 1) {
return files[0];
}
Logging.warning("Unable to locate file from server directory: %s", fileName);
return null;
}

/**
Expand All @@ -74,6 +61,10 @@ public File getServerFolder() {
* @return The bukkit.yml file if exist, else null.
*/
public @Nullable File getBukkitConfig() {
if (this.bukkitYml == null) {
this.bukkitYml = findFileFromServerDirectory(config.getBukkitYmlPath());
Logging.finer("Bukkit.yml: " + this.bukkitYml);
}
return this.bukkitYml;
}

Expand All @@ -83,9 +74,26 @@ public File getServerFolder() {
* @return The server.properties file if exist, else null.
*/
public @Nullable File getServerProperties() {
if (this.serverProperties == null) {
this.serverProperties = findFileFromServerDirectory("server.properties");
Logging.finer("server.properties: %s", this.serverProperties);
}
return this.serverProperties;
}

private @Nullable File findFileFromServerDirectory(String fileName) {
if (this.serverFolder == null) {
Logging.warning("Unable to locate server directory.");
return null;
}
File file = new File(this.serverFolder, fileName);
if (!file.exists()) {
Logging.warning("Unable to locate file from server directory: %s", fileName);
return null;
}
return file;
}

/**
* Deletes the given folder completely.
*
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/configs/fresh_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ command:
show-legacy-aliases: false

misc:
bukkit-yml-path: bukkit.yml
global-debug: 0
debug-permissions: false
silent-start: false
Expand Down