Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2025-01-11 15:41:08 +01:00
Fixed what Konicai asked
Dieser Commit ist enthalten in:
Ursprung
cb18c969d7
Commit
8bb8e48a55
@ -75,9 +75,7 @@ public class GeyserExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets if the extension is enabled
|
* Enables or disables the extension
|
||||||
*
|
|
||||||
* @return true if the extension is enabled
|
|
||||||
*/
|
*/
|
||||||
public void setEnabled(boolean value) {
|
public void setEnabled(boolean value) {
|
||||||
if (this.enabled != value) {
|
if (this.enabled != value) {
|
||||||
|
@ -123,6 +123,8 @@ public class GeyserImpl implements GeyserApi {
|
|||||||
private final PlatformType platformType;
|
private final PlatformType platformType;
|
||||||
private final GeyserBootstrap bootstrap;
|
private final GeyserBootstrap bootstrap;
|
||||||
|
|
||||||
|
private final GeyserExtensionManager extensionManager;
|
||||||
|
|
||||||
private Metrics metrics;
|
private Metrics metrics;
|
||||||
|
|
||||||
private static GeyserImpl instance;
|
private static GeyserImpl instance;
|
||||||
@ -155,7 +157,8 @@ public class GeyserImpl implements GeyserApi {
|
|||||||
MessageTranslator.init();
|
MessageTranslator.init();
|
||||||
MinecraftLocale.init();
|
MinecraftLocale.init();
|
||||||
|
|
||||||
GeyserExtensionManager.init();
|
extensionManager = new GeyserExtensionManager();
|
||||||
|
extensionManager.init();
|
||||||
|
|
||||||
start();
|
start();
|
||||||
|
|
||||||
@ -200,6 +203,8 @@ public class GeyserImpl implements GeyserApi {
|
|||||||
|
|
||||||
ResourcePack.loadPacks();
|
ResourcePack.loadPacks();
|
||||||
|
|
||||||
|
extensionManager.enableExtensions();
|
||||||
|
|
||||||
if (platformType != PlatformType.STANDALONE && config.getRemote().getAddress().equals("auto")) {
|
if (platformType != PlatformType.STANDALONE && config.getRemote().getAddress().equals("auto")) {
|
||||||
// Set the remote address to localhost since that is where we are always connecting
|
// Set the remote address to localhost since that is where we are always connecting
|
||||||
try {
|
try {
|
||||||
@ -460,7 +465,7 @@ public class GeyserImpl implements GeyserApi {
|
|||||||
|
|
||||||
ResourcePack.PACKS.clear();
|
ResourcePack.PACKS.clear();
|
||||||
|
|
||||||
GeyserExtensionManager.getInstance().disableExtensions();
|
extensionManager.disableExtensions();
|
||||||
|
|
||||||
bootstrap.getGeyserLogger().info(GeyserLocale.getLocaleStringLog("geyser.core.shutdown.done"));
|
bootstrap.getGeyserLogger().info(GeyserLocale.getLocaleStringLog("geyser.core.shutdown.done"));
|
||||||
}
|
}
|
||||||
@ -468,7 +473,6 @@ public class GeyserImpl implements GeyserApi {
|
|||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void reload() {
|
||||||
shutdown();
|
shutdown();
|
||||||
GeyserExtensionManager.getInstance().enableExtensions();
|
|
||||||
bootstrap.onEnable();
|
bootstrap.onEnable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -514,6 +518,10 @@ public class GeyserImpl implements GeyserApi {
|
|||||||
return bootstrap.getWorldManager();
|
return bootstrap.getWorldManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GeyserExtensionManager getExtensionManager() {
|
||||||
|
return extensionManager;
|
||||||
|
}
|
||||||
|
|
||||||
public static GeyserImpl getInstance() {
|
public static GeyserImpl getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
@ -127,8 +127,8 @@ public class DumpInfo {
|
|||||||
this.flagsInfo = new FlagsInfo();
|
this.flagsInfo = new FlagsInfo();
|
||||||
|
|
||||||
this.extensionInfo = new ArrayList<>();
|
this.extensionInfo = new ArrayList<>();
|
||||||
for (GeyserExtension extension : GeyserExtensionManager.getInstance().getExtensions().values()) {
|
for (GeyserExtension extension : GeyserImpl.getInstance().getExtensionManager().getExtensions().values()) {
|
||||||
this.extensionInfo.add(new ExtensionInfo(extension.isEnabled(), extension.name(), extension.description().version(), extension.description().main(), extension.description().authors(), extension.description().apiVersion()));
|
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 boolean enabled;
|
||||||
public String name;
|
public String name;
|
||||||
public String version;
|
public String version;
|
||||||
|
public String apiVersion;
|
||||||
public String main;
|
public String main;
|
||||||
public List<String> authors;
|
public List<String> authors;
|
||||||
public String apiVersion;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,10 @@ package org.geysermc.geyser.extension;
|
|||||||
import org.geysermc.geyser.api.extension.exception.InvalidDescriptionException;
|
import org.geysermc.geyser.api.extension.exception.InvalidDescriptionException;
|
||||||
import org.yaml.snakeyaml.DumperOptions;
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class GeyserExtensionDescription implements org.geysermc.geyser.api.extension.ExtensionDescription {
|
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 String version;
|
||||||
private final List<String> authors = new ArrayList<>();
|
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 {
|
public GeyserExtensionDescription(String yamlString) throws InvalidDescriptionException {
|
||||||
|
this.loadString(yamlString);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadString(String yamlString) throws InvalidDescriptionException {
|
||||||
DumperOptions dumperOptions = new DumperOptions();
|
DumperOptions dumperOptions = new DumperOptions();
|
||||||
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||||
Yaml yaml = new Yaml(dumperOptions);
|
Yaml yaml = new Yaml(dumperOptions);
|
||||||
|
@ -97,21 +97,7 @@ public class GeyserExtensionLoader implements ExtensionLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stream = jarFile.getInputStream(descriptionEntry);
|
stream = jarFile.getInputStream(descriptionEntry);
|
||||||
|
return new GeyserExtensionDescription(stream);
|
||||||
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());
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new InvalidDescriptionException(e);
|
throw new InvalidDescriptionException(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -28,33 +28,22 @@ package org.geysermc.geyser.extension;
|
|||||||
import org.geysermc.geyser.GeyserImpl;
|
import org.geysermc.geyser.GeyserImpl;
|
||||||
import org.geysermc.geyser.api.extension.ExtensionDescription;
|
import org.geysermc.geyser.api.extension.ExtensionDescription;
|
||||||
import org.geysermc.geyser.api.extension.GeyserExtension;
|
import org.geysermc.geyser.api.extension.GeyserExtension;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class GeyserExtensionManager {
|
public class GeyserExtensionManager {
|
||||||
private static GeyserExtensionManager geyserExtensionManager = null;
|
|
||||||
|
|
||||||
protected Map<String, GeyserExtension> extensions = new LinkedHashMap<>();
|
protected Map<String, GeyserExtension> extensions = new LinkedHashMap<>();
|
||||||
protected Map<Pattern, GeyserExtensionLoader> fileAssociations = new HashMap<>();
|
protected Map<Pattern, GeyserExtensionLoader> fileAssociations = new HashMap<>();
|
||||||
|
|
||||||
public static void init() {
|
public void init() {
|
||||||
GeyserImpl.getInstance().getLogger().info("Loading extensions...");
|
GeyserImpl.getInstance().getLogger().info("Loading extensions...");
|
||||||
|
|
||||||
geyserExtensionManager = new GeyserExtensionManager();
|
this.registerInterface(GeyserExtensionLoader.class);
|
||||||
geyserExtensionManager.registerInterface(GeyserExtensionLoader.class);
|
this.loadExtensions(new File("extensions"));
|
||||||
geyserExtensionManager.loadExtensions(new File("extensions"));
|
|
||||||
|
|
||||||
String plural = geyserExtensionManager.extensions.size() == 1 ? "" : "s";
|
GeyserImpl.getInstance().getLogger().info("Loaded " + this.extensions.size() + " extension(s)");
|
||||||
GeyserImpl.getInstance().getLogger().info("Loaded " + geyserExtensionManager.extensions.size() + " extension" + plural);
|
|
||||||
|
|
||||||
geyserExtensionManager.enableExtensions();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GeyserExtensionManager getInstance() {
|
|
||||||
return geyserExtensionManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GeyserExtension getExtension(String name) {
|
public GeyserExtension getExtension(String name) {
|
||||||
|
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren