Skip to content

Commit

Permalink
feat: add the ability to disable HuskSync commands
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Jun 18, 2024
1 parent a8ca331 commit 268b279
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected <S> ArgumentElement<S, User> user(@NotNull String name) {
return new ArgumentElement<>(name, reader -> {
final String username = reader.readString();
return plugin.getDatabase().getUserByName(username).orElseThrow(
() -> CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader)
() -> CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader)
);
}, (context, builder) -> {
plugin.getOnlineUsers().forEach(u -> builder.suggest(u.getUsername()));
Expand Down Expand Up @@ -119,7 +119,9 @@ public PluginCommand supply(@NotNull HuskSync plugin) {

@NotNull
public static PluginCommand[] create(@NotNull HuskSync plugin) {
return Arrays.stream(values()).map(type -> type.supply(plugin)).toArray(PluginCommand[]::new);
return Arrays.stream(values()).map(type -> type.supply(plugin))
.filter(command -> !plugin.getSettings().isCommandDisabled(command))
.toArray(PluginCommand[]::new);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import net.william278.husksync.command.PluginCommand;
import net.william278.husksync.data.DataSnapshot;
import net.william278.husksync.data.Identifier;
import net.william278.husksync.database.Database;
Expand Down Expand Up @@ -75,6 +76,9 @@ public class Settings {
@Comment("Whether to cancel game event packets directly when handling locked players if ProtocolLib or PacketEvents is installed")
private boolean cancelPackets = true;

@Comment("Add HuskSync commands to this list to prevent them from being registered (e.g. ['userdata'])")
@Getter(AccessLevel.NONE)
private List<String> disabledCommands = Lists.newArrayList();

// Database settings
@Comment("Database settings")
Expand Down Expand Up @@ -182,7 +186,7 @@ public static class RedisSentinel {
}

// Synchronization settings
@Comment("Redis settings")
@Comment("Data syncing settings")
private SynchronizationSettings synchronization = new SynchronizationSettings();

@Getter
Expand Down Expand Up @@ -294,4 +298,10 @@ public EventListener.Priority getEventPriority(@NotNull EventListener.ListenerTy
}
}

public boolean isCommandDisabled(@NotNull PluginCommand command) {
return disabledCommands.stream().map(c -> c.startsWith("/") ? c.substring(1) : c)
.anyMatch(c -> c.equalsIgnoreCase(command.getName()) || command.getAliases().contains(c));
}


}
4 changes: 3 additions & 1 deletion docs/Config-File.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ debug_logging: true
enable_plan_hook: true
# Whether to cancel game event packets directly when handling locked players if ProtocolLib or PacketEvents is installed
cancel_packets: true
# Add HuskSync commands to this list to prevent them from being registered (e.g. ['userdata'])
disabled_commands: []
# Database settings
database:
# Type of database to use (MYSQL, MARIADB, POSTGRES, MONGO)
Expand Down Expand Up @@ -76,7 +78,7 @@ redis:
# List of host:port pairs
nodes: []
password: ''
# Redis settings
# Data syncing settings
synchronization:
# The data synchronization mode to use (LOCKSTEP or DELAY). LOCKSTEP is recommended for most networks.
# Docs: https://william278.net/docs/husksync/sync-modes
Expand Down

0 comments on commit 268b279

Please sign in to comment.