Merge remote-tracking branch 'upstream/master' into feature/cloud

# Conflicts:
#	bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java
#	gradle/libs.versions.toml
This commit is contained in:
Konicai 2023-10-01 16:52:14 -04:00
commit c73b9de121
No known key found for this signature in database
GPG Key ID: 710D09287708C823
7 changed files with 60 additions and 32 deletions

View File

@ -14,7 +14,7 @@ The ultimate goal of this project is to allow Minecraft: Bedrock Edition users t
Special thanks to the DragonProxy project for being a trailblazer in protocol translation and for all the team members who have joined us here!
### Currently supporting Minecraft Bedrock 1.20.0 - 1.20.31 and Minecraft Java 1.20/1.20.1.
### Currently supporting Minecraft Bedrock 1.20.0 - 1.20.31 and Minecraft Java 1.20.2
## Setting Up
Take a look [here](https://wiki.geysermc.org/geyser/setup/) for how to set up Geyser.

View File

@ -36,13 +36,13 @@ import java.util.Collection;
public abstract class ExtensionManager {
/**
* Gets an extension with the given name.
* Gets an extension by the given ID.
*
* @param name the name of the extension
* @return an extension with the given name
* @param id the ID of the extension
* @return an extension with the given ID
*/
@Nullable
public abstract Extension extension(@NonNull String name);
public abstract Extension extension(@NonNull String id);
/**
* Enables the given {@link Extension}.

View File

@ -28,6 +28,7 @@ package org.geysermc.geyser;
import javax.swing.*;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.Scanner;
@ -60,7 +61,7 @@ public class GeyserMain {
helpStream = GeyserMain.class.getClassLoader().getResourceAsStream("languages/run-help/en_US.txt");
}
Scanner help = new Scanner(helpStream).useDelimiter("\\Z");
Scanner help = new Scanner(helpStream, StandardCharsets.UTF_8).useDelimiter("\\Z");
String line = "";
while (help.hasNext()) {
line = help.next();

View File

@ -27,6 +27,7 @@ package org.geysermc.geyser.extension;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.extension.Extension;
import org.geysermc.geyser.api.extension.ExtensionDescription;
import org.geysermc.geyser.api.extension.exception.InvalidExtensionException;
@ -39,14 +40,17 @@ import java.nio.file.Path;
public class GeyserExtensionClassLoader extends URLClassLoader {
private final GeyserExtensionLoader loader;
private final ExtensionDescription description;
private final Object2ObjectMap<String, Class<?>> classes = new Object2ObjectOpenHashMap<>();
private boolean warnedForExternalClassAccess;
public GeyserExtensionClassLoader(GeyserExtensionLoader loader, ClassLoader parent, Path path) throws MalformedURLException {
public GeyserExtensionClassLoader(GeyserExtensionLoader loader, ClassLoader parent, Path path, ExtensionDescription description) throws MalformedURLException {
super(new URL[] { path.toUri().toURL() }, parent);
this.loader = loader;
this.description = description;
}
public Extension load(ExtensionDescription description) throws InvalidExtensionException {
public Extension load() throws InvalidExtensionException {
try {
Class<?> jarClass;
try {
@ -76,22 +80,32 @@ public class GeyserExtensionClassLoader extends URLClassLoader {
}
protected Class<?> findClass(String name, boolean checkGlobal) throws ClassNotFoundException {
if (name.startsWith("org.geysermc.geyser.") || name.startsWith("net.minecraft.")) {
throw new ClassNotFoundException(name);
}
Class<?> result = this.classes.get(name);
if (result == null) {
result = super.findClass(name);
if (result == null && checkGlobal) {
result = this.loader.classByName(name);
// Try to find class in current extension
try {
result = super.findClass(name);
} catch (ClassNotFoundException ignored) {
// If class is not found in current extension, check in the global class loader
// This is used for classes that are not in the extension, but are in other extensions
if (checkGlobal) {
if (!warnedForExternalClassAccess) {
GeyserImpl.getInstance().getLogger().warning("Extension " + this.description.name() + " loads class " + name + " from an external source. " +
"This can change at any time and break the extension, additionally to potentially causing unexpected behaviour!");
warnedForExternalClassAccess = true;
}
result = this.loader.classByName(name);
}
}
if (result != null) {
// If class is found, cache it
this.loader.setClass(name, result);
this.classes.put(name, result);
} else {
// If class is not found, throw exception
throw new ClassNotFoundException(name);
}
this.classes.put(name, result);
}
return result;
}

View File

@ -66,26 +66,38 @@ public class GeyserExtensionLoader extends ExtensionLoader {
}
Path parentFile = path.getParent();
Path dataFolder = parentFile.resolve(description.name());
// Extension folders used to be created by name; this changes them to the ID
Path oldDataFolder = parentFile.resolve(description.name());
Path dataFolder = parentFile.resolve(description.id());
if (Files.exists(oldDataFolder) && Files.isDirectory(oldDataFolder) && !oldDataFolder.equals(dataFolder)) {
try {
Files.move(oldDataFolder, dataFolder, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new InvalidExtensionException("Failed to move data folder for extension " + description.name(), e);
}
}
if (Files.exists(dataFolder) && !Files.isDirectory(dataFolder)) {
throw new InvalidExtensionException("The folder " + dataFolder + " is not a directory and is the data folder for the extension " + description.name() + "!");
}
final GeyserExtensionClassLoader loader;
try {
loader = new GeyserExtensionClassLoader(this, getClass().getClassLoader(), path);
loader = new GeyserExtensionClassLoader(this, getClass().getClassLoader(), path, description);
} catch (Throwable e) {
throw new InvalidExtensionException(e);
}
this.classLoaders.put(description.name(), loader);
this.classLoaders.put(description.id(), loader);
final Extension extension = loader.load(description);
final Extension extension = loader.load();
return this.setup(extension, description, dataFolder, new GeyserExtensionEventBus(GeyserImpl.getInstance().eventBus(), extension));
}
private GeyserExtensionContainer setup(Extension extension, GeyserExtensionDescription description, Path dataFolder, ExtensionEventBus eventBus) {
GeyserExtensionLogger logger = new GeyserExtensionLogger(GeyserImpl.getInstance().getLogger(), description.name());
GeyserExtensionLogger logger = new GeyserExtensionLogger(GeyserImpl.getInstance().getLogger(), description.id());
return new GeyserExtensionContainer(extension, dataFolder, description, this, logger, eventBus);
}
@ -152,7 +164,8 @@ public class GeyserExtensionLoader extends ExtensionLoader {
GeyserExtensionDescription description = this.extensionDescription(path);
String name = description.name();
if (extensions.containsKey(name) || extensionManager.extension(name) != null) {
String id = description.id();
if (extensions.containsKey(id) || extensionManager.extension(id) != null) {
GeyserImpl.getInstance().getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.extensions.load.duplicate", name, path.toString()));
return;
}
@ -169,8 +182,8 @@ public class GeyserExtensionLoader extends ExtensionLoader {
return;
}
extensions.put(name, path);
loadedExtensions.put(name, this.loadExtension(path, description));
extensions.put(id, path);
loadedExtensions.put(id, this.loadExtension(path, description));
} catch (Exception e) {
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_with_name", path.getFileName(), path.toAbsolutePath()), e);
}

View File

@ -52,8 +52,8 @@ public class GeyserExtensionManager extends ExtensionManager {
}
@Override
public Extension extension(@NonNull String name) {
return this.extensions.get(name);
public Extension extension(@NonNull String id) {
return this.extensions.get(id);
}
@Override
@ -83,7 +83,7 @@ public class GeyserExtensionManager extends ExtensionManager {
if (!extension.isEnabled()) {
extension.setEnabled(true);
GeyserImpl.getInstance().eventBus().register(extension, extension);
GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.extensions.enable.success", extension.description().name()));
GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.extensions.enable.success", extension.name()));
}
}
@ -98,7 +98,7 @@ public class GeyserExtensionManager extends ExtensionManager {
GeyserImpl.getInstance().eventBus().unregisterAll(extension);
extension.setEnabled(false);
GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.extensions.disable.success", extension.description().name()));
GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.extensions.disable.success", extension.name()));
}
}
@ -121,6 +121,6 @@ public class GeyserExtensionManager extends ExtensionManager {
@Override
public void register(@NonNull Extension extension) {
this.extensions.put(extension.name(), extension);
this.extensions.put(extension.description().id(), extension);
}
}

View File

@ -14,7 +14,7 @@ protocol-connection = "3.0.0.Beta1-20230908.171156-105"
raknet = "1.0.0.CR1-20230703.195238-9"
blockstateupdater="1.20.30-20230918.203831-4"
mcauthlib = "d9d773e"
mcprotocollib = "1.20.2-1-20230926.224810-3"
mcprotocollib = "1.20.2-1-20231001.173210-4"
adventure = "4.14.0"
adventure-platform = "4.3.0"
junit = "5.9.2"
@ -24,7 +24,7 @@ jline = "3.21.0"
terminalconsoleappender = "1.2.0"
folia = "1.19.4-R0.1-SNAPSHOT"
viaversion = "4.0.0"
adapters = "1.9-SNAPSHOT"
adapters = "1.10-SNAPSHOT"
cloud = "1.8.4"
commodore = "2.2"
bungeecord = "a7c6ede"