feat: add the ability to disable HuskSync commands

feat/data-edit-commands 3.6.1
William 5 months ago
parent a8ca3314d8
commit 268b279fdf
No known key found for this signature in database

@ -80,7 +80,7 @@ public abstract class PluginCommand extends Command {
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()));
@ -119,7 +119,9 @@ public abstract class PluginCommand extends Command {
@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);
}
}

@ -25,6 +25,7 @@ import de.exlll.configlib.Configuration;
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;
@ -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")
@ -182,7 +186,7 @@ public class Settings {
}
// Synchronization settings
@Comment("Redis settings")
@Comment("Data syncing settings")
private SynchronizationSettings synchronization = new SynchronizationSettings();
@Getter
@ -294,4 +298,10 @@ public class Settings {
}
}
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));
}
}

@ -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)
@ -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

Loading…
Cancel
Save