Skip to content

Commit

Permalink
Fix possible issues with config serialization and deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
MetallicGoat committed Apr 5, 2024
1 parent ab3e1de commit b5aaf01
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions src/main/java/me/metallicgoat/tweaksaddon/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,9 @@
import de.marcely.bedwars.tools.Helper;
import de.marcely.bedwars.tools.VarParticle;
import de.marcely.bedwars.tools.YamlConfigurationDescriptor;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.Getter;
import me.metallicgoat.tweaksaddon.utils.Console;
import me.metallicgoat.tweaksaddon.MBedwarsTweaksPlugin;
import me.metallicgoat.tweaksaddon.utils.Console;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
Expand All @@ -39,6 +20,19 @@
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.*;
import java.util.stream.Collectors;

public class ConfigManager {

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -266,8 +260,14 @@ else if (type == Set.class)
return null;

// Any type of Set or List
for (Object object : strings)
collection.add(deserializeObject(field, listType, (String) object, object));
for (Object object : strings) {
final Object deserializeObject = deserializeObject(field, listType, (String) object, object);

if (deserializeObject != null)
collection.add(deserializeObject);
else
Console.printConfigWarn("Failed to deserialize object in list/set in the config, with the name of " + object, "Main");
}

return collection;

Expand Down Expand Up @@ -352,7 +352,8 @@ else if (type == Set.class)

// Any type of List or Set
for (Object object : objectList)
lines.add((String) serializeObject(null, listType, object));
if (object != null)
lines.add((String) serializeObject(null, listType, object));

return lines;

Expand Down

0 comments on commit b5aaf01

Please sign in to comment.