3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-19 14:30:17 +01:00

Only register commands on Spigot if the extension has commands

Dieser Commit ist enthalten in:
Camotoy 2022-09-14 14:19:56 -04:00
Ursprung a99afe4418
Commit 6df8740955
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
7 geänderte Dateien mit 21 neuen und 92 gelöschten Zeilen

Datei anzeigen

@ -124,7 +124,7 @@ public interface Extension extends EventRegistrar {
*/
@NonNull
default ExtensionLoader extensionLoader() {
return Objects.requireNonNull(this.extensionManager().extensionLoader(this));
return Objects.requireNonNull(this.extensionManager().extensionLoader());
}
/**

Datei anzeigen

@ -34,7 +34,6 @@ import java.nio.file.Path;
* The extension loader is responsible for loading, unloading, enabling and disabling extensions
*/
public abstract class ExtensionLoader {
/**
* Gets if the given {@link Extension} is enabled.
*
@ -101,6 +100,6 @@ public abstract class ExtensionLoader {
* @param extensionManager the extension manager
*/
protected void register(@NonNull Extension extension, @NonNull ExtensionManager extensionManager) {
extensionManager.register(extension, this);
extensionManager.register(extension);
}
}

Datei anzeigen

@ -29,7 +29,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Collection;
import java.util.Map;
/**
* Manages Geyser {@link Extension}s
@ -59,15 +58,6 @@ public abstract class ExtensionManager {
*/
public abstract void disable(@NonNull Extension extension);
/**
* Gets the {@link ExtensionLoader} responsible for loading
* the given {@link Extension}.
*
* @return the extension loader for loading the given extension
*/
@Nullable
public abstract ExtensionLoader extensionLoader(@NonNull Extension extension);
/**
* Gets all the {@link Extension}s currently loaded.
*
@ -77,37 +67,19 @@ public abstract class ExtensionManager {
public abstract Collection<Extension> extensions();
/**
* Gets the {@link ExtensionLoader} with the given identifier.
* Gets the {@link ExtensionLoader}.
*
* @param identifier the identifier
* @return the extension loader at the given identifier
* @return the extension loader
*/
@Nullable
public abstract ExtensionLoader extensionLoader(@NonNull String identifier);
/**
* Registers an {@link ExtensionLoader} with the given identifier.
*
* @param identifier the identifier
* @param extensionLoader the extension loader
*/
public abstract void registerExtensionLoader(@NonNull String identifier, @NonNull ExtensionLoader extensionLoader);
/**
* Gets all the currently registered {@link ExtensionLoader}s.
*
* @return all the currently registered extension loaders
*/
@NonNull
public abstract Map<String, ExtensionLoader> extensionLoaders();
public abstract ExtensionLoader extensionLoader();
/**
* Registers an {@link Extension} with the given {@link ExtensionLoader}.
*
* @param extension the extension
* @param loader the loader
*/
public abstract void register(@NonNull Extension extension, @NonNull ExtensionLoader loader);
public abstract void register(@NonNull Extension extension);
/**
* Loads all extensions from the given {@link ExtensionLoader}.

Datei anzeigen

@ -62,12 +62,7 @@ import org.geysermc.geyser.platform.spigot.command.GeyserSpigotCommandManager;
import org.geysermc.geyser.platform.spigot.command.SpigotCommandSource;
import org.geysermc.geyser.platform.spigot.world.GeyserPistonListener;
import org.geysermc.geyser.platform.spigot.world.GeyserSpigotBlockPlaceListener;
import org.geysermc.geyser.platform.spigot.world.manager.GeyserSpigot1_12NativeWorldManager;
import org.geysermc.geyser.platform.spigot.world.manager.GeyserSpigot1_12WorldManager;
import org.geysermc.geyser.platform.spigot.world.manager.GeyserSpigotFallbackWorldManager;
import org.geysermc.geyser.platform.spigot.world.manager.GeyserSpigotLegacyNativeWorldManager;
import org.geysermc.geyser.platform.spigot.world.manager.GeyserSpigotNativeWorldManager;
import org.geysermc.geyser.platform.spigot.world.manager.GeyserSpigotWorldManager;
import org.geysermc.geyser.platform.spigot.world.manager.*;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.util.FileUtils;
@ -204,12 +199,14 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
}
}, this);
this.geyserCommandManager = new GeyserSpigotCommandManager(geyser);
this.geyserCommandManager.init();
// Because Bukkit locks its command map upon startup, we need to
// add our plugin commands in onEnable, but populating the executor
// can happen at any time
CommandMap commandMap = GeyserSpigotCommandManager.getCommandMap();
for (Extension extension : this.geyser.extensionManager().extensions()) {
for (Extension extension : this.geyserCommandManager.extensionCommands().keySet()) {
// Thanks again, Bukkit
try {
Constructor<PluginCommand> constructor = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
@ -245,9 +242,6 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
}
geyserLogger.debug("Spigot ping passthrough type: " + (this.geyserSpigotPingPassthrough == null ? null : this.geyserSpigotPingPassthrough.getClass()));
this.geyserCommandManager = new GeyserSpigotCommandManager(geyser);
this.geyserCommandManager.init();
boolean isViaVersion = Bukkit.getPluginManager().getPlugin("ViaVersion") != null;
if (isViaVersion) {
try {

Datei anzeigen

@ -147,7 +147,7 @@ public class GeyserImpl implements GeyserApi {
private final GeyserBootstrap bootstrap;
private final EventBus<EventRegistrar> eventBus;
private GeyserExtensionManager extensionManager;
private final GeyserExtensionManager extensionManager;
private Metrics metrics;
@ -173,6 +173,7 @@ public class GeyserImpl implements GeyserApi {
/* Load Extensions */
this.extensionManager = new GeyserExtensionManager();
this.extensionManager.init();
this.eventBus.fire(new GeyserPreInitializeEvent(this.extensionManager, this.eventBus));
}
public void initialize() {
@ -186,11 +187,6 @@ public class GeyserImpl implements GeyserApi {
logger.info("");
logger.info("******************************************");
/* Enable extensions */
this.extensionManager.enableExtensions();
this.eventBus.fire(new GeyserPreInitializeEvent(this.extensionManager, this.eventBus));
/* Initialize registries */
Registries.init();
BlockRegistries.init();

Datei anzeigen

@ -33,7 +33,6 @@ import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.session.GeyserSession;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -49,7 +48,7 @@ public abstract class GeyserCommand implements Command {
protected final String description;
protected final String permission;
private List<String> aliases = new ArrayList<>();
private List<String> aliases = Collections.emptyList();
public abstract void execute(@Nullable GeyserSession session, GeyserCommandSource sender, String[] args);

Datei anzeigen

@ -25,8 +25,6 @@
package org.geysermc.geyser.extension;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.GeyserImpl;
@ -39,36 +37,25 @@ import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class GeyserExtensionManager extends ExtensionManager {
private static final Key BASE_EXTENSION_LOADER_KEY = Key.key("geysermc", "base");
private final Map<Key, ExtensionLoader> extensionLoaderTypes = new Object2ObjectOpenHashMap<>();
private final GeyserExtensionLoader extensionLoader = new GeyserExtensionLoader();
private final Map<String, Extension> extensions = new LinkedHashMap<>();
private final Map<Extension, ExtensionLoader> extensionsLoaders = new LinkedHashMap<>();
public void init() {
GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.extensions.load.loading"));
extensionLoaderTypes.put(BASE_EXTENSION_LOADER_KEY, new GeyserExtensionLoader());
for (ExtensionLoader loader : this.extensionLoaders().values()) {
this.loadAllExtensions(loader);
}
loadAllExtensions(this.extensionLoader);
enableExtensions();
GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.extensions.load.done", this.extensions.size()));
}
@Override
public Extension extension(@NonNull String name) {
if (this.extensions.containsKey(name)) {
return this.extensions.get(name);
}
return null;
}
@Override
public void enable(@NonNull Extension extension) {
if (!extension.isEnabled()) {
@ -121,37 +108,19 @@ public class GeyserExtensionManager extends ExtensionManager {
}
}
@Override
public ExtensionLoader extensionLoader(@NonNull Extension extension) {
return this.extensionsLoaders.get(extension);
}
@NonNull
@Override
public Collection<Extension> extensions() {
return Collections.unmodifiableCollection(this.extensions.values());
}
@Nullable
@Override
public ExtensionLoader extensionLoader(@NonNull String identifier) {
return this.extensionLoaderTypes.get(Key.key(identifier));
public @Nullable ExtensionLoader extensionLoader() {
return this.extensionLoader;
}
@Override
public void registerExtensionLoader(@NonNull String identifier, @NonNull ExtensionLoader extensionLoader) {
this.extensionLoaderTypes.put(Key.key(identifier), extensionLoader);
}
@NonNull
@Override
public Map<String, ExtensionLoader> extensionLoaders() {
return this.extensionLoaderTypes.entrySet().stream().collect(Collectors.toMap(key -> key.getKey().asString(), Map.Entry::getValue));
}
@Override
public void register(@NonNull Extension extension, @NonNull ExtensionLoader loader) {
this.extensionsLoaders.put(extension, loader);
public void register(@NonNull Extension extension) {
this.extensions.put(extension.name(), extension);
}
}