Fix NPE in extension loader

This commit is contained in:
Eoghanmc22 2020-09-14 18:17:15 -04:00
parent 64bb92a295
commit 8bbd62a3ed

View File

@ -1,10 +1,6 @@
package net.minestom.server.extensions;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.*;
import lombok.extern.slf4j.Slf4j;
import net.minestom.server.extras.selfmodification.MinestomOverwriteClassLoader;
import org.jetbrains.annotations.NotNull;
@ -12,23 +8,14 @@ import org.jetbrains.annotations.Nullable;
import org.slf4j.LoggerFactory;
import org.spongepowered.asm.mixin.Mixins;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.zip.ZipFile;
@Slf4j
@ -87,13 +74,19 @@ public class ExtensionManager {
// Get ExtensionDescription (authors, version etc.)
Extension.ExtensionDescription extensionDescription;
{
String version = extensionDescriptionJson.get("version").getAsString();
if (version == null) {
log.error("Extension '{}' did not specify a version.", extensionName);
log.error("Extension '{}' will continue to load but should specify a plugin version.", extensionName);
String version;
if (!extensionDescriptionJson.has("version")) {
log.warn("Extension '{}' did not specify a version.", extensionName);
log.warn("Extension '{}' will continue to load but should specify a plugin version.", extensionName);
version = "Not Specified";
}
List<String> authors = Arrays.asList(new Gson().fromJson(extensionDescriptionJson.get("authors"), String[].class));
} else
version = extensionDescriptionJson.get("version").getAsString();
List<String> authors;
if (!extensionDescriptionJson.has("")) {
authors = new ArrayList<>();
} else
authors = Arrays.asList(new Gson().fromJson(extensionDescriptionJson.get("authors"), String[].class));
extensionDescription = new Extension.ExtensionDescription(extensionName, version, authors);
}