Fixed what Konicai asked

This commit is contained in:
ImDaBigBoss 2022-01-12 16:40:51 +01:00
parent cb18c969d7
commit 8bb8e48a55
7 changed files with 53 additions and 43 deletions

View File

@ -75,9 +75,7 @@ public class GeyserExtension {
}
/**
* Gets if the extension is enabled
*
* @return true if the extension is enabled
* Enables or disables the extension
*/
public void setEnabled(boolean value) {
if (this.enabled != value) {

View File

@ -123,6 +123,8 @@ public class GeyserImpl implements GeyserApi {
private final PlatformType platformType;
private final GeyserBootstrap bootstrap;
private final GeyserExtensionManager extensionManager;
private Metrics metrics;
private static GeyserImpl instance;
@ -155,7 +157,8 @@ public class GeyserImpl implements GeyserApi {
MessageTranslator.init();
MinecraftLocale.init();
GeyserExtensionManager.init();
extensionManager = new GeyserExtensionManager();
extensionManager.init();
start();
@ -200,6 +203,8 @@ public class GeyserImpl implements GeyserApi {
ResourcePack.loadPacks();
extensionManager.enableExtensions();
if (platformType != PlatformType.STANDALONE && config.getRemote().getAddress().equals("auto")) {
// Set the remote address to localhost since that is where we are always connecting
try {
@ -460,7 +465,7 @@ public class GeyserImpl implements GeyserApi {
ResourcePack.PACKS.clear();
GeyserExtensionManager.getInstance().disableExtensions();
extensionManager.disableExtensions();
bootstrap.getGeyserLogger().info(GeyserLocale.getLocaleStringLog("geyser.core.shutdown.done"));
}
@ -468,7 +473,6 @@ public class GeyserImpl implements GeyserApi {
@Override
public void reload() {
shutdown();
GeyserExtensionManager.getInstance().enableExtensions();
bootstrap.onEnable();
}
@ -514,6 +518,10 @@ public class GeyserImpl implements GeyserApi {
return bootstrap.getWorldManager();
}
public GeyserExtensionManager getExtensionManager() {
return extensionManager;
}
public static GeyserImpl getInstance() {
return instance;
}

View File

@ -127,8 +127,8 @@ public class DumpInfo {
this.flagsInfo = new FlagsInfo();
this.extensionInfo = new ArrayList<>();
for (GeyserExtension extension : GeyserExtensionManager.getInstance().getExtensions().values()) {
this.extensionInfo.add(new ExtensionInfo(extension.isEnabled(), extension.name(), extension.description().version(), extension.description().main(), extension.description().authors(), extension.description().apiVersion()));
for (GeyserExtension extension : GeyserImpl.getInstance().getExtensionManager().getExtensions().values()) {
this.extensionInfo.add(new ExtensionInfo(extension.isEnabled(), extension.name(), extension.description().version(), extension.description().apiVersion(), extension.description().main(), extension.description().authors()));
}
}
@ -289,8 +289,8 @@ public class DumpInfo {
public boolean enabled;
public String name;
public String version;
public String apiVersion;
public String main;
public List<String> authors;
public String apiVersion;
}
}

View File

@ -78,11 +78,11 @@ public class GeyserExtensionClassLoader extends URLClassLoader {
throw new ClassNotFoundException(name);
}
Class<?> result = classes.get(name);
if(result == null) {
if(checkGlobal) {
if (result == null) {
if (checkGlobal) {
result = loader.classByName(name);
}
if(result == null) {
if (result == null) {
result = super.findClass(name);
if (result != null) {
loader.setClass(name, result);

View File

@ -28,6 +28,10 @@ package org.geysermc.geyser.extension;
import org.geysermc.geyser.api.extension.exception.InvalidDescriptionException;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
public class GeyserExtensionDescription implements org.geysermc.geyser.api.extension.ExtensionDescription {
@ -37,7 +41,32 @@ public class GeyserExtensionDescription implements org.geysermc.geyser.api.exten
private String version;
private final List<String> authors = new ArrayList<>();
public GeyserExtensionDescription(InputStream inputStream) throws InvalidDescriptionException {
try {
InputStreamReader reader = new InputStreamReader(inputStream);
StringBuilder builder = new StringBuilder();
String temp;
BufferedReader bufferedReader = new BufferedReader(reader);
temp = bufferedReader.readLine();
while (temp != null) {
if (builder.length() != 0) {
builder.append("\n");
}
builder.append(temp);
temp = bufferedReader.readLine();
}
this.loadString(builder.toString());
} catch (IOException e) {
throw new InvalidDescriptionException(e);
}
}
public GeyserExtensionDescription(String yamlString) throws InvalidDescriptionException {
this.loadString(yamlString);
}
private void loadString(String yamlString) throws InvalidDescriptionException {
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(dumperOptions);

View File

@ -97,21 +97,7 @@ public class GeyserExtensionLoader implements ExtensionLoader {
}
stream = jarFile.getInputStream(descriptionEntry);
InputStreamReader reader = new InputStreamReader(stream);
StringBuilder builder = new StringBuilder();
String temp;
BufferedReader bufferedReader = new BufferedReader(reader);
temp = bufferedReader.readLine();
while (temp != null) {
if (builder.length() != 0) {
builder.append("\n");
}
builder.append(temp);
temp = bufferedReader.readLine();
}
return new GeyserExtensionDescription(builder.toString());
return new GeyserExtensionDescription(stream);
} catch (IOException e) {
throw new InvalidDescriptionException(e);
} finally {
@ -151,7 +137,7 @@ public class GeyserExtensionLoader implements ExtensionLoader {
}
void setClass(String name, final Class<?> clazz) {
if(!classes.containsKey(name)) {
if (!classes.containsKey(name)) {
classes.put(name,clazz);
}
}

View File

@ -28,33 +28,22 @@ package org.geysermc.geyser.extension;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.extension.ExtensionDescription;
import org.geysermc.geyser.api.extension.GeyserExtension;
import java.io.File;
import java.lang.reflect.Constructor;
import java.util.*;
import java.util.regex.Pattern;
public class GeyserExtensionManager {
private static GeyserExtensionManager geyserExtensionManager = null;
protected Map<String, GeyserExtension> extensions = new LinkedHashMap<>();
protected Map<Pattern, GeyserExtensionLoader> fileAssociations = new HashMap<>();
public static void init() {
public void init() {
GeyserImpl.getInstance().getLogger().info("Loading extensions...");
geyserExtensionManager = new GeyserExtensionManager();
geyserExtensionManager.registerInterface(GeyserExtensionLoader.class);
geyserExtensionManager.loadExtensions(new File("extensions"));
this.registerInterface(GeyserExtensionLoader.class);
this.loadExtensions(new File("extensions"));
String plural = geyserExtensionManager.extensions.size() == 1 ? "" : "s";
GeyserImpl.getInstance().getLogger().info("Loaded " + geyserExtensionManager.extensions.size() + " extension" + plural);
geyserExtensionManager.enableExtensions();
}
public static GeyserExtensionManager getInstance() {
return geyserExtensionManager;
GeyserImpl.getInstance().getLogger().info("Loaded " + this.extensions.size() + " extension(s)");
}
public GeyserExtension getExtension(String name) {