Skip to content

Commit

Permalink
refactor: pass ExecutableCommand to sync filter
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxuum committed Aug 3, 2024
1 parent 672b4bb commit 3699fe8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions packages/core/src/server/registry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Players } from "@rbxts/services";
import { CommandOptions, GroupOptions } from "../shared";
import { BaseCommand, CommandGroup } from "../shared/core/command";
import {
BaseCommand,
CommandGroup,
ExecutableCommand,
} from "../shared/core/command";
import { BaseRegistry } from "../shared/core/registry";
import { SyncData } from "../shared/network";
import { ArrayUtil, ReadonlyDeep } from "../shared/util/data";
Expand Down Expand Up @@ -36,7 +40,9 @@ export class ServerRegistry extends BaseRegistry<ReadonlyDeep<ServerConfig>> {
for (const [_, command] of this.commands) {
const path = command.getPath();
if (syncedCommands.has(path.toString())) continue;
if (!this.config.syncFilter(player, command)) continue;
if (!this.config.syncFilter(player, command as ExecutableCommand)) {
continue;
}

syncedCommands.set(path.toString(), {
...(command.options as CommandOptions),
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/server/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { CommandContextData, SharedConfig } from "../shared";
import { BaseCommand } from "../shared/core/command";
import { ExecutableCommand } from "../shared/core/command";
import { SyncData } from "../shared/network";

export interface ServerConfig extends SharedConfig {
network: ServerNetworkConfig;
syncFilter: (player: Player, command: BaseCommand) => boolean;
syncFilter: (player: Player, command: ExecutableCommand) => boolean;
}

export interface ServerNetworkConfig {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/core/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export abstract class BaseCommand {

export class ExecutableCommand extends BaseCommand {
private readonly callback: CommandCallback;
private readonly guards: ReadonlyArray<CommandGuard>;
readonly guards: ReadonlyArray<CommandGuard>;

constructor(
config: ReadonlyDeep<SharedConfig>,
Expand Down

0 comments on commit 3699fe8

Please sign in to comment.