mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
check more parameters
This commit is contained in:
parent
4c00b11b08
commit
3f903205d6
5 changed files with 28 additions and 9 deletions
|
|
@ -33,8 +33,8 @@ import org.geysermc.geyser.api.util.TriState;
|
|||
* Fired by anything that wishes to gather permission nodes and defaults.
|
||||
* <p>
|
||||
* This event is not guaranteed to be fired, as certain Geyser platforms do not have a native permission system.
|
||||
* It can be expected to fire on Geyser-Spigot, Geyser-NeoForge and Geyser-Standalone.
|
||||
* It may still be fired on other platforms due to a 3rd party.
|
||||
* It can be expected to fire on Geyser-Spigot, Geyser-NeoForge, Geyser-Standalone, and Geyser-ViaProxy
|
||||
* It may be fired by a 3rd party regardless of the platform.
|
||||
*/
|
||||
public interface GeyserRegisterPermissionsEvent extends Event {
|
||||
|
||||
|
|
|
|||
|
|
@ -33,11 +33,16 @@ import org.geysermc.geyser.api.event.lifecycle.GeyserRegisterPermissionsEvent;
|
|||
import org.geysermc.geyser.api.util.TriState;
|
||||
import org.geysermc.geyser.platform.neoforge.mixin.PermissionNodeMixin;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class GeyserNeoForgePermissionHandler {
|
||||
|
||||
public void onPermissionGather(PermissionGatherEvent.Nodes event) {
|
||||
GeyserImpl.getInstance().eventBus().fire(
|
||||
(GeyserRegisterPermissionsEvent) (permission, defaultValue) -> {
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
Objects.requireNonNull(defaultValue, "permission default for " + permission);
|
||||
|
||||
if (permission.isBlank()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ import java.io.IOException;
|
|||
import java.net.SocketAddress;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
|
||||
|
|
@ -291,6 +292,9 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
|
|||
// Re-registering permissions without removing it throws an error
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
geyser.eventBus().fire((GeyserRegisterPermissionsEvent) (permission, def) -> {
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
Objects.requireNonNull(def, "permission default for " + permission);
|
||||
|
||||
if (permission.isBlank()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -302,8 +306,8 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
|
|||
|
||||
Permission existingPermission = pluginManager.getPermission(permission);
|
||||
if (existingPermission != null) {
|
||||
geyserLogger.debug("permission " + permission + " with a default of " +
|
||||
existingPermission.getDefault() + " is being overriden by " + permissionDefault);
|
||||
geyserLogger.debug("permission " + permission + " with default " +
|
||||
existingPermission.getDefault() + " is being overridden by " + permissionDefault);
|
||||
|
||||
pluginManager.removePermission(permission);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ public class CommandRegistry implements EventRegistrar {
|
|||
registerBuiltInCommand(new OffhandCommand("offhand", "geyser.commands.offhand.desc", "geyser.command.offhand"));
|
||||
registerBuiltInCommand(new DumpCommand(geyser, "dump", "geyser.commands.dump.desc", "geyser.command.dump"));
|
||||
registerBuiltInCommand(new VersionCommand(geyser, "version", "geyser.commands.version.desc", "geyser.command.version"));
|
||||
registerBuiltInCommand(new SettingsCommand( "settings", "geyser.commands.settings.desc", "geyser.command.settings"));
|
||||
registerBuiltInCommand(new SettingsCommand("settings", "geyser.commands.settings.desc", "geyser.command.settings"));
|
||||
registerBuiltInCommand(new StatisticsCommand("statistics", "geyser.commands.statistics.desc", "geyser.command.statistics"));
|
||||
registerBuiltInCommand(new AdvancementsCommand("advancements", "geyser.commands.advancements.desc", "geyser.command.advancements"));
|
||||
registerBuiltInCommand(new AdvancedTooltipsCommand("tooltips", "geyser.commands.advancedtooltips.desc", "geyser.command.tooltips"));
|
||||
|
|
@ -141,6 +141,7 @@ public class CommandRegistry implements EventRegistrar {
|
|||
};
|
||||
this.geyser.eventBus().fire(defineCommandsEvent);
|
||||
|
||||
// Stuff that needs to be done on a per-extension basis
|
||||
for (Map.Entry<Extension, Map<String, GeyserCommand>> entry : this.extensionCommands.entrySet()) {
|
||||
Extension extension = entry.getKey();
|
||||
|
||||
|
|
@ -161,7 +162,7 @@ public class CommandRegistry implements EventRegistrar {
|
|||
}
|
||||
|
||||
// Wait for the right moment (depends on the platform) to register permissions.
|
||||
// Listen late so that extensions can register permissions before this class does
|
||||
// Listen late so that it's easier for extensions to register permissions before this class does
|
||||
geyser.eventBus().subscribe(this, GeyserRegisterPermissionsEvent.class, this::onRegisterPermissions, PostOrder.LATE);
|
||||
}
|
||||
|
||||
|
|
@ -185,10 +186,15 @@ public class CommandRegistry implements EventRegistrar {
|
|||
}
|
||||
|
||||
protected void register(GeyserCommand command, Map<String, GeyserCommand> commands) {
|
||||
command.register(cloud);
|
||||
String root = command.rootCommand();
|
||||
String name = command.name();
|
||||
if (commands.containsKey(name)) {
|
||||
throw new IllegalArgumentException("Command with root=%s, name=%s already registered".formatted(root, name));
|
||||
}
|
||||
|
||||
commands.put(command.name(), command);
|
||||
geyser.getLogger().debug(GeyserLocale.getLocaleStringLog("geyser.commands.registered", command.name()));
|
||||
command.register(cloud);
|
||||
commands.put(name, command);
|
||||
geyser.getLogger().debug(GeyserLocale.getLocaleStringLog("geyser.commands.registered", root + " " + name));
|
||||
|
||||
for (String alias : command.aliases()) {
|
||||
commands.put(alias, command);
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import org.incendo.cloud.internal.CommandRegistrationHandler;
|
|||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class StandaloneCloudCommandManager extends CommandManager<GeyserCommandSource> {
|
||||
|
|
@ -84,6 +85,9 @@ public class StandaloneCloudCommandManager extends CommandManager<GeyserCommandS
|
|||
*/
|
||||
public void fireRegisterPermissionsEvent() {
|
||||
geyser.getEventBus().fire((GeyserRegisterPermissionsEvent) (permission, def) -> {
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
Objects.requireNonNull(def, "permission default for " + permission);
|
||||
|
||||
if (permission.isBlank()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue