Skip to content

Commit

Permalink
[Configuration] Fix startup error when group name is a number (#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
NEZNAMY committed Dec 9, 2024
1 parent a83f985 commit bfde75d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class ConfigurationFile {
protected List<String> header;

/** Configuration file content */
@Getter @Setter protected Map<String, Object> values;
@Getter @Setter protected Map<Object, Object> values;

/** File to use */
@Getter protected final File file;
Expand Down Expand Up @@ -338,14 +338,14 @@ public void set(@NonNull String path, @Nullable Object value) {
* Value to save
* @return the first argument to allow chaining
*/
private Map<String, Object> set(@NonNull Map<String, Object> map, @NonNull String path, @Nullable Object value) {
private Map<Object, Object> set(@NonNull Map<Object, Object> map, @NonNull String path, @Nullable Object value) {
if (path.contains(".")) {
String keyWord = getRealKey(map, path.split("\\.")[0]);
Object subMap = map.get(keyWord);
if (!(subMap instanceof Map)) {
subMap = new LinkedHashMap<>();
}
map.put(keyWord, set((Map<String, Object>) subMap, path.substring(keyWord.length()+1), value));
map.put(keyWord, set((Map<Object, Object>) subMap, path.substring(keyWord.length()+1), value));
} else {
if (value == null) {
map.remove(getRealKey(map, path));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package me.neznamy.tab.shared.config.file;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

import me.neznamy.tab.shared.TAB;
import me.neznamy.tab.shared.TabConstants;
import me.neznamy.tab.shared.config.PropertyConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import me.neznamy.tab.shared.config.PropertyConfiguration;
import me.neznamy.tab.shared.TAB;
import org.yaml.snakeyaml.error.YAMLException;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;

/**
* This class represents a configuration file for properties (groups.yml or users.yml).
*/
Expand Down Expand Up @@ -45,7 +45,7 @@ public class YamlPropertyConfigurationFile extends YamlConfigurationFile impleme
public YamlPropertyConfigurationFile(@Nullable InputStream source, @NotNull File destination) throws IOException {
super(source, destination);
category = destination.getName().contains("groups") ? "group" : "user";
for (Map.Entry<String, Object> entry : getValues().entrySet()) {
for (Map.Entry<Object, Object> entry : getValues().entrySet()) {
if (entry.getKey().equals(PER_SERVER)) {
for (String server : serverGroups) {
for (String name : this.<String, Object>getMap(PER_SERVER + "." + server).keySet()) {
Expand All @@ -63,8 +63,8 @@ public YamlPropertyConfigurationFile(@Nullable InputStream source, @NotNull File
}
}
} else {
for (String property : this.<String, Object>getMap(entry.getKey()).keySet()) {
checkProperty(destination.getName(), category, entry.getKey(), property, null, null, true);
for (String property : this.<String, Object>getMap(entry.getKey().toString()).keySet()) {
checkProperty(destination.getName(), category, entry.getKey().toString(), property, null, null, true);
}
}
}
Expand Down Expand Up @@ -126,15 +126,16 @@ public void remove(@NotNull String name) {
public @NotNull Map<String, Map<String, Object>> getPerServerSettings(@NotNull String name) {
return convertMap(getMap(PER_SERVER), name);
}

@Override
public @NotNull Set<String> getAllEntries() {
Set<String> set = new HashSet<>(values.keySet());
Set<Object> set = new HashSet<>(values.keySet());
set.remove(PER_WORLD);
set.remove(PER_SERVER);
Map<String, Map<String, Map<String, String>>> perWorld = getMap(PER_WORLD);
perWorld.values().forEach(m -> set.addAll(m.keySet()));
Map<String, Map<String, Map<String, String>>> perServer = getMap(PER_SERVER);
perServer.values().forEach(m -> set.addAll(m.keySet()));
return set;
return set.stream().map(Object::toString).collect(Collectors.toSet());
}
}

0 comments on commit bfde75d

Please sign in to comment.