Skip to content

Commit 49bdb56

Browse files
authored
Merge pull request #3209 from Multiverse/feat/bukkit-yml
Implement bukkit-yml-path config option
2 parents 064e4a0 + a4e7282 commit 49bdb56

File tree

6 files changed

+51
-25
lines changed

6 files changed

+51
-25
lines changed

src/main/java/org/mvplugins/multiverse/core/MultiverseCore.java

-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
import io.vavr.control.Try;
1414
import jakarta.inject.Inject;
1515
import jakarta.inject.Provider;
16-
import org.bukkit.Bukkit;
1716
import org.bukkit.configuration.file.FileConfiguration;
1817
import org.bukkit.configuration.serialization.ConfigurationSerialization;
19-
import org.bukkit.plugin.ServicePriority;
2018
import org.jetbrains.annotations.NotNull;
2119
import org.jvnet.hk2.annotations.Service;
2220

src/main/java/org/mvplugins/multiverse/core/config/CoreConfig.java

+8
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,14 @@ public Try<Void> setShowLegacyAliases(boolean showLegacyAliases) {
495495
return configHandle.set(configNodes.showLegacyAliases, showLegacyAliases);
496496
}
497497

498+
public Try<Void> setBukkitYmlPath(String bukkitYmlPath) {
499+
return configHandle.set(configNodes.bukkitYmlPath, bukkitYmlPath);
500+
}
501+
502+
public String getBukkitYmlPath() {
503+
return configHandle.get(configNodes.bukkitYmlPath);
504+
}
505+
498506
/**
499507
* {@inheritDoc}
500508
*/

src/main/java/org/mvplugins/multiverse/core/config/CoreConfigNodes.java

+8
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,15 @@ private <N extends Node> N node(N node) {
364364
.comment("")
365365
.build());
366366

367+
final ConfigNode<String> bukkitYmlPath = node(ConfigNode.builder("misc.bukkit-yml-path", String.class)
368+
.comment("Change this if you use a custom path for the bukkit.yml file with `--bukkit-settings` startup flag.")
369+
.comment("Note: this config option needs a server restart to take effect.")
370+
.defaultValue("bukkit.yml")
371+
.name("bukkit-yml-path")
372+
.build());
373+
367374
final ConfigNode<Integer> globalDebug = node(ConfigNode.builder("misc.global-debug", Integer.class)
375+
.comment("")
368376
.comment("This is our debug flag to help identify issues with Multiverse.")
369377
.comment("If you are having issues with Multiverse, please set this to 3 and then post your log to pastebin.com")
370378
.comment("Otherwise, there's no need to touch this. If not instructed by a wiki page or developer.")

src/main/java/org/mvplugins/multiverse/core/config/handle/BaseConfigurationHandle.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public abstract class BaseConfigurationHandle<C extends ConfigurationSection> {
3030
protected final @Nullable Logger logger;
3131
protected final @NotNull NodeGroup nodes;
3232
protected final @Nullable ConfigMigrator migrator;
33-
protected final @NotNull Map<Node, Object> nodeValueMap;
33+
protected final @NotNull Map<ValueNode, Object> nodeValueMap;
3434

3535
protected C config;
3636

@@ -80,9 +80,12 @@ protected void setUpNodes() {
8080
if (node instanceof ValueNode valueNode) {
8181
var value = deserializeNodeFromConfig(valueNode);
8282
nodeValueMap.put(valueNode, value);
83-
valueNode.onSetValue(value, value);
8483
}
8584
});
85+
86+
nodeValueMap.forEach((valueNode, value) -> {
87+
valueNode.onSetValue(value, value);
88+
});
8689
}
8790

8891
protected <T> T deserializeNodeFromConfig(ValueNode<T> node) {

src/main/java/org/mvplugins/multiverse/core/utils/FileUtils.java

+29-21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import java.io.File;
1111
import java.io.IOException;
12+
import java.lang.management.ManagementFactory;
1213
import java.nio.file.*;
1314
import java.nio.file.attribute.BasicFileAttributes;
1415
import java.util.Collections;
@@ -19,9 +20,11 @@
1920
import com.dumptruckman.minecraft.util.Logging;
2021
import io.vavr.control.Try;
2122
import jakarta.inject.Inject;
23+
import org.bukkit.Bukkit;
2224
import org.jetbrains.annotations.NotNull;
2325
import org.jetbrains.annotations.Nullable;
2426
import org.jvnet.hk2.annotations.Service;
27+
import org.mvplugins.multiverse.core.config.CoreConfig;
2528

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

@@ -31,32 +34,16 @@
3134
@Service
3235
public final class FileUtils {
3336

37+
private final CoreConfig config;
3438
private final File serverFolder;
35-
private final File bukkitYml;
36-
private final File serverProperties;
39+
private File bukkitYml;
40+
private File serverProperties;
3741

3842
@Inject
39-
FileUtils() {
43+
FileUtils(CoreConfig config) {
44+
this.config = config;
4045
this.serverFolder = new File(System.getProperty("user.dir"));
4146
Logging.finer("Server folder: " + this.serverFolder);
42-
this.bukkitYml = findFileFromServerDirectory("bukkit.yml");
43-
this.serverProperties = findFileFromServerDirectory("server.properties");
44-
}
45-
46-
private @Nullable File findFileFromServerDirectory(String fileName) {
47-
File[] files;
48-
try {
49-
files = this.serverFolder.listFiles((file, s) -> s.equalsIgnoreCase(fileName));
50-
} catch (Exception e) {
51-
Logging.severe("Could not read from server directory. Unable to locate file: %s", fileName);
52-
Logging.severe(e.getMessage());
53-
return null;
54-
}
55-
if (files != null && files.length == 1) {
56-
return files[0];
57-
}
58-
Logging.warning("Unable to locate file from server directory: %s", fileName);
59-
return null;
6047
}
6148

6249
/**
@@ -74,6 +61,10 @@ public File getServerFolder() {
7461
* @return The bukkit.yml file if exist, else null.
7562
*/
7663
public @Nullable File getBukkitConfig() {
64+
if (this.bukkitYml == null) {
65+
this.bukkitYml = findFileFromServerDirectory(config.getBukkitYmlPath());
66+
Logging.finer("Bukkit.yml: " + this.bukkitYml);
67+
}
7768
return this.bukkitYml;
7869
}
7970

@@ -83,9 +74,26 @@ public File getServerFolder() {
8374
* @return The server.properties file if exist, else null.
8475
*/
8576
public @Nullable File getServerProperties() {
77+
if (this.serverProperties == null) {
78+
this.serverProperties = findFileFromServerDirectory("server.properties");
79+
Logging.finer("server.properties: %s", this.serverProperties);
80+
}
8681
return this.serverProperties;
8782
}
8883

84+
private @Nullable File findFileFromServerDirectory(String fileName) {
85+
if (this.serverFolder == null) {
86+
Logging.warning("Unable to locate server directory.");
87+
return null;
88+
}
89+
File file = new File(this.serverFolder, fileName);
90+
if (!file.exists()) {
91+
Logging.warning("Unable to locate file from server directory: %s", fileName);
92+
return null;
93+
}
94+
return file;
95+
}
96+
8997
/**
9098
* Deletes the given folder completely.
9199
*

src/test/resources/configs/fresh_config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ command:
3838
show-legacy-aliases: false
3939

4040
misc:
41+
bukkit-yml-path: bukkit.yml
4142
global-debug: 0
4243
debug-permissions: false
4344
silent-start: false

0 commit comments

Comments
 (0)