3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-20 06:50:09 +01:00

Spigot: programmatically add Geyser permissions and fix reloading

Dieser Commit ist enthalten in:
Camotoy 2022-05-06 15:32:43 -04:00
Ursprung 05e98c3a10
Commit f38c1fbc0f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
8 geänderte Dateien mit 67 neuen und 35 gelöschten Zeilen

Datei anzeigen

@ -32,6 +32,8 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import me.lucko.commodore.CommodoreProvider;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.java.JavaPlugin;
import org.geysermc.common.PlatformType;
import org.geysermc.geyser.Constants;
@ -39,6 +41,7 @@ import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.adapters.spigot.SpigotAdapters;
import org.geysermc.geyser.command.CommandManager;
import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.configuration.GeyserConfiguration;
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.level.WorldManager;
@ -61,10 +64,16 @@ import java.io.IOException;
import java.net.SocketAddress;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
/**
* Determines if the plugin has been ran once before, including before /geyser reload.
*/
private static boolean INITIALIZED = false;
private GeyserSpigotCommandManager geyserCommandManager;
private GeyserSpigotConfiguration geyserConfig;
private GeyserSpigotInjector geyserInjector;
@ -232,13 +241,31 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
}
geyserLogger.debug("Using default world manager: " + this.geyserWorldManager.getClass());
}
PluginCommand pluginCommand = this.getCommand("geyser");
pluginCommand.setExecutor(new GeyserSpigotCommandExecutor(geyser));
if (!INITIALIZED) {
// Register permissions so they appear in, for example, LuckPerms' UI
// Re-registering permissions throws an error
for (Map.Entry<String, GeyserCommand> entry : geyserCommandManager.getCommands().entrySet()) {
GeyserCommand command = entry.getValue();
if (command.getAliases().contains(entry.getKey())) {
// Don't register aliases
continue;
}
Bukkit.getPluginManager().addPermission(new Permission(command.getPermission(),
GeyserLocale.getLocaleStringLog(command.getDescription()),
command.isSuggestedOpOnly() ? PermissionDefault.OP : PermissionDefault.TRUE));
}
// Events cannot be unregistered - re-registering results in duplicate firings
GeyserSpigotBlockPlaceListener blockPlaceListener = new GeyserSpigotBlockPlaceListener(geyser, this.geyserWorldManager);
Bukkit.getServer().getPluginManager().registerEvents(blockPlaceListener, this);
Bukkit.getServer().getPluginManager().registerEvents(new GeyserPistonListener(geyser, this.geyserWorldManager), this);
PluginCommand pluginCommand = this.getCommand("geyser");
pluginCommand.setExecutor(new GeyserSpigotCommandExecutor(geyser));
}
boolean brigadierSupported = CommodoreProvider.isSupported();
geyserLogger.debug("Brigadier supported? " + brigadierSupported);
@ -248,6 +275,8 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
// Check to ensure the current setup can support the protocol version Geyser uses
GeyserSpigotVersionChecker.checkForSupportedProtocol(geyserLogger, isViaVersion);
INITIALIZED = true;
}
@Override

Datei anzeigen

@ -9,34 +9,3 @@ commands:
geyser:
description: The main command for Geyser.
usage: /geyser <subcommand>
permissions:
geyser.command.help:
description: Shows help for all registered commands.
default: true
geyser.command.offhand:
description: Puts an items in your offhand.
default: true
geyser.command.advancements:
description: Shows the advancements of the player on the server.
default: true
geyser.command.tooltips:
description: Toggles showing advanced tooltips on your items.
default: true
geyser.command.statistics:
description: Shows the statistics of the player on the server.
default: true
geyser.command.settings:
description: Modify user settings
default: true
geyser.command.list:
description: List all players connected through Geyser.
default: op
geyser.command.dump:
description: Dumps Geyser debug information for bug reports.
default: op
geyser.command.reload:
description: Reloads the Geyser configurations. Kicks all players when used!
default: false
geyser.command.version:
description: Shows the current Geyser version and checks for updates.
default: op

Datei anzeigen

@ -86,4 +86,13 @@ public abstract class GeyserCommand {
public boolean isBedrockOnly() {
return false;
}
/**
* Used for permission defaults on server implementations.
*
* @return if this command is designated to be used only by server operators.
*/
public boolean isSuggestedOpOnly() {
return false;
}
}

Datei anzeigen

@ -145,4 +145,9 @@ public class DumpCommand extends GeyserCommand {
public List<String> getSubCommands() {
return Arrays.asList("offline", "full", "logs");
}
@Override
public boolean isSuggestedOpOnly() {
return true;
}
}

Datei anzeigen

@ -51,4 +51,9 @@ public class ListCommand extends GeyserCommand {
sender.sendMessage(message);
}
@Override
public boolean isSuggestedOpOnly() {
return true;
}
}

Datei anzeigen

@ -54,4 +54,9 @@ public class ReloadCommand extends GeyserCommand {
geyser.getSessionManager().disconnectAll("geyser.commands.reload.kick");
geyser.reload();
}
@Override
public boolean isSuggestedOpOnly() {
return true;
}
}

Datei anzeigen

@ -54,4 +54,9 @@ public class StopCommand extends GeyserCommand {
geyser.getBootstrap().onDisable();
}
@Override
public boolean isSuggestedOpOnly() {
return true;
}
}

Datei anzeigen

@ -100,4 +100,9 @@ public class VersionCommand extends GeyserCommand {
}
}
}
@Override
public boolean isSuggestedOpOnly() {
return true;
}
}