3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

Move extensions folder to Geyser's config folder (#3202)

* Move extensions folder to Geyser's config folder

* Move directory field
Dieser Commit ist enthalten in:
Konicai 2022-08-04 17:55:12 -04:00 committet von GitHub
Ursprung 684b9c2361
Commit 67e3bf1f8d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -43,19 +43,18 @@ import java.nio.file.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Stream; import java.util.stream.Stream;
@RequiredArgsConstructor @RequiredArgsConstructor
public class GeyserExtensionLoader extends ExtensionLoader { public class GeyserExtensionLoader extends ExtensionLoader {
private static final Path EXTENSION_DIRECTORY = Paths.get("extensions");
private static final Pattern API_VERSION_PATTERN = Pattern.compile("^\\d+\\.\\d+\\.\\d+$"); private static final Pattern API_VERSION_PATTERN = Pattern.compile("^\\d+\\.\\d+\\.\\d+$");
private static final Pattern[] EXTENSION_FILTERS = new Pattern[] { Pattern.compile("^.+\\.jar$") }; private static final Pattern[] EXTENSION_FILTERS = new Pattern[] { Pattern.compile("^.+\\.jar$") };
private final Object2ReferenceMap<String, Class<?>> classes = new Object2ReferenceOpenHashMap<>(); private final Object2ReferenceMap<String, Class<?>> classes = new Object2ReferenceOpenHashMap<>();
private final Map<String, GeyserExtensionClassLoader> classLoaders = new HashMap<>(); private final Map<String, GeyserExtensionClassLoader> classLoaders = new HashMap<>();
private final Map<Extension, GeyserExtensionContainer> extensionContainers = new HashMap<>(); private final Map<Extension, GeyserExtensionContainer> extensionContainers = new HashMap<>();
private final Path extensionsDirectory = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("extensions");
public GeyserExtensionContainer loadExtension(Path path, GeyserExtensionDescription description) throws InvalidExtensionException, InvalidDescriptionException { public GeyserExtensionContainer loadExtension(Path path, GeyserExtensionDescription description) throws InvalidExtensionException, InvalidDescriptionException {
if (path == null) { if (path == null) {
@ -127,15 +126,15 @@ public class GeyserExtensionLoader extends ExtensionLoader {
@Override @Override
protected void loadAllExtensions(@NonNull ExtensionManager extensionManager) { protected void loadAllExtensions(@NonNull ExtensionManager extensionManager) {
try { try {
if (Files.notExists(EXTENSION_DIRECTORY)) { if (Files.notExists(extensionsDirectory)) {
Files.createDirectory(EXTENSION_DIRECTORY); Files.createDirectory(extensionsDirectory);
} }
Map<String, Path> extensions = new LinkedHashMap<>(); Map<String, Path> extensions = new LinkedHashMap<>();
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(EXTENSION_DIRECTORY)) { try (Stream<Path> entries = Files.walk(extensionsDirectory)) {
entries.forEach(path -> { entries.forEach(path -> {
if (Files.isDirectory(path)) { if (Files.isDirectory(path)) {
return; return;