Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-20 06:50:09 +01:00
Fix: Don't rename extensions while the extension directory is being walked (#4197)
Dieser Commit ist enthalten in:
Ursprung
3fdd6b41d0
Commit
3f0e366bac
@ -43,9 +43,9 @@ import java.io.Reader;
|
|||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class GeyserExtensionLoader extends ExtensionLoader {
|
public class GeyserExtensionLoader extends ExtensionLoader {
|
||||||
@ -148,47 +148,46 @@ public class GeyserExtensionLoader extends ExtensionLoader {
|
|||||||
Map<String, GeyserExtensionContainer> loadedExtensions = new LinkedHashMap<>();
|
Map<String, GeyserExtensionContainer> loadedExtensions = new LinkedHashMap<>();
|
||||||
|
|
||||||
Pattern[] extensionFilters = this.extensionFilters();
|
Pattern[] extensionFilters = this.extensionFilters();
|
||||||
try (Stream<Path> entries = Files.walk(extensionsDirectory)) {
|
List<Path> extensionPaths = Files.walk(extensionsDirectory).toList();
|
||||||
entries.forEach(path -> {
|
extensionPaths.forEach(path -> {
|
||||||
if (Files.isDirectory(path)) {
|
if (Files.isDirectory(path)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Pattern filter : extensionFilters) {
|
||||||
|
if (!filter.matcher(path.getFileName().toString()).matches()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
GeyserExtensionDescription description = this.extensionDescription(path);
|
||||||
|
|
||||||
|
String name = description.name();
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Pattern filter : extensionFilters) {
|
// Completely different API version
|
||||||
if (!filter.matcher(path.getFileName().toString()).matches()) {
|
if (description.majorApiVersion() != Geyser.api().majorApiVersion()) {
|
||||||
return;
|
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_version", name, description.apiVersion()));
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// If the extension requires new API features, being backwards compatible
|
||||||
GeyserExtensionDescription description = this.extensionDescription(path);
|
if (description.minorApiVersion() > Geyser.api().minorApiVersion()) {
|
||||||
|
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_version", name, description.apiVersion()));
|
||||||
String name = description.name();
|
return;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Completely different API version
|
|
||||||
if (description.majorApiVersion() != Geyser.api().majorApiVersion()) {
|
|
||||||
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_version", name, description.apiVersion()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the extension requires new API features, being backwards compatible
|
|
||||||
if (description.minorApiVersion() > Geyser.api().minorApiVersion()) {
|
|
||||||
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_version", name, description.apiVersion()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
for (GeyserExtensionContainer container : loadedExtensions.values()) {
|
for (GeyserExtensionContainer container : loadedExtensions.values()) {
|
||||||
this.extensionContainers.put(container.extension(), container);
|
this.extensionContainers.put(container.extension(), container);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren