Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add config option to enable-networking
  • Loading branch information
willkroboth committed Nov 5, 2025
commit 327bdbd743d36c822a94df0a507ef76609e45b9a
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public abstract class CommandAPIConfig<Impl
boolean usePluginNamespace = false;
String namespace = null;

boolean makeNetworkingExceptionsWarnings;
boolean enableNetworking = false;
boolean makeNetworkingExceptionsWarnings = false;

/**
* Sets verbose output logging for the CommandAPI if true.
Expand Down Expand Up @@ -112,6 +113,18 @@ public Impl setNamespace(String namespace) {
return instance();
}

/**
* Sets whether the CommandAPI's networking functionality should be enabled.
* This is currently only useful for allowing command requirements on Velocity.
*
* @param enabled whether networking should be enabled
* @return this CommandAPIConfig
*/
public Impl enableNetworking(boolean enabled) {
this.enableNetworking = enabled;
return instance();
}

/**
* Sets whether the CommandAPI should throw an exception if it cannot send or receive a packet.
* If true, the problem will be logged as a warning instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static <CommandSource> String getRawArgumentInput(CommandContext<CommandS
private static final Map<ClassCache, Field> FIELDS = new HashMap<>();

final CommandAPIPlatform<Argument, CommandSender, Source> platform;
private CommandAPIMessenger<?, ?> messenger;
private CommandAPIMessenger<?, ?> messenger = null;

final TreeMap<String, CommandPermission> registeredPermissions = new TreeMap<>();
final List<RegisteredCommand> registeredCommands; // Keep track of what has been registered for type checking
Expand Down Expand Up @@ -154,13 +154,17 @@ private void checkDependencies() {

public void onEnable() {
platform.onEnable();
// Setting up the network messenger usually requires registering
// events, which often does not work until onEnable
messenger = platform.setupMessenger();

if (CommandAPI.getConfiguration().isNetworkingEnabled()) {
// Setting up the network messenger usually requires registering
// events, which often does not work until onEnable
messenger = platform.setupMessenger();
}
}

public void onDisable() {
messenger.close();
if (messenger != null) messenger.close();

platform.onDisable();
CommandAPIHandler.resetInstance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class InternalConfig {
// The default command namespace
private final String namespace;

// Whether we should turn on networking
private final boolean enableNetworking;

// Whether we should log networking exceptions as warnings
private final boolean makeNetworkingExceptionsWarnings;

Expand All @@ -58,6 +61,7 @@ public InternalConfig(CommandAPIConfig<?> config) {
this.messageMissingExecutorImplementation = config.missingExecutorImplementationMessage;
this.dispatcherFile = config.dispatcherFile;
this.namespace = config.namespace;
this.enableNetworking = config.enableNetworking;
this.makeNetworkingExceptionsWarnings = config.makeNetworkingExceptionsWarnings;
}

Expand Down Expand Up @@ -98,6 +102,13 @@ public String getNamespace() {
return namespace;
}

/**
* @return Whether networking should be enabled
*/
public boolean isNetworkingEnabled() {
return enableNetworking;
}

/**
* @return Whether networking exceptions are logged as warnings
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static ProtocolVersionTooOldException whileSending(Object target, int pro
return new ProtocolVersionTooOldException(
"Tried to send a packet to " + target + ", which is using protocol version " + protocolVersion + ". " +
"This system is using version " + CommandAPIProtocol.PROTOCOL_VERSION + ". " +
"That version is too old to receive the packet. " +
"That version is too old to receive the packet, or CommandAPI networking is not enabled. " +
reason,
protocolVersion, reason
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public abstract class CommandAPIBukkit<Source> implements BukkitPlatform<Source>
// References to utility classes
private static CommandAPIBukkit<?> bukkit;
protected static InternalBukkitConfig config;
private BukkitCommandAPIMessenger messenger;
private BukkitCommandAPIMessenger messenger = null;

protected JavaPlugin plugin;
protected NMS<Source> nms;
Expand Down Expand Up @@ -391,7 +391,13 @@ public BukkitCommandAPIMessenger setupMessenger() {

@Override
public BukkitCommandAPIMessenger getMessenger() {
return messenger;
if (messenger != null) {
return messenger;
} else {
throw new IllegalStateException("Tried to access the plugin messenger, but it was null." +
" Plugin messages are only possible after calling CommandAPI#onEnable." +
" Also ensure that the \"enable-networking\" config option is \"true\".");
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public static DefaultBukkitConfig createDefaultPaperConfig() {
options.put("fallback-to-latest-nms", FALLBACK_TO_LATEST_NMS(true));
options.put("skip-initial-datapack-reload", SKIP_RELOAD_DATAPACKS); // TODO: Remove once the Paper plugin utilizes the bootstrapper
options.put("hook-paper-reload", HOOK_PAPER_RELOAD); // TODO: Remove once the Paper plugin utilizes the bootstrapper
options.put("enable-networking", ENABLE_NETWORKING);
options.put("make-networking-exceptions-warnings", MAKE_NETWORKING_EXCEPTIONS_WARNINGS);
options.put("plugins-to-convert", PLUGINS_TO_CONVERT);
options.put("other-commands-to-convert", OTHER_COMMANDS_TO_CONVERT);
Expand All @@ -91,6 +92,7 @@ public static DefaultBukkitConfig createDefaultSpigotConfig() {
options.put("create-dispatcher-json", CREATE_DISPATCHER_JSON);
options.put("fallback-to-latest-nms", FALLBACK_TO_LATEST_NMS(false));
options.put("skip-initial-datapack-reload", SKIP_RELOAD_DATAPACKS);
options.put("enable-networking", ENABLE_NETWORKING);
options.put("make-networking-exceptions-warnings", MAKE_NETWORKING_EXCEPTIONS_WARNINGS);
options.put("plugins-to-convert", PLUGINS_TO_CONVERT);
options.put("other-commands-to-convert", OTHER_COMMANDS_TO_CONVERT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void onLoad() {
.dispatcherFile(fileConfig.getBoolean("create-dispatcher-json") ? new File(getDataFolder(), "command_registration.json") : null)
.hookPaperReload(fileConfig.getBoolean("hook-paper-reload")) // TODO: Remove once this utilizes the bootstrapper
.skipInitialDatapackReload(fileConfig.getBoolean("skip-initial-datapack-reload")) // TODO: Remove once this utilizes the bootstrapper
.enableNetworking(fileConfig.getBoolean("enable-networking"))
.makeNetworkingExceptionsWarnings(fileConfig.getBoolean("make-networking-exceptions-warnings"));

for (String pluginName : fileConfig.getStringList("skip-sender-proxy")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void onLoad() {
.missingExecutorImplementationMessage(fileConfig.getString("messages.missing-executor-implementation"))
.dispatcherFile(fileConfig.getBoolean("create-dispatcher-json") ? new File(getDataFolder(), "command_registration.json") : null)
.skipReloadDatapacks(fileConfig.getBoolean("skip-initial-datapack-reload"))
.enableNetworking(fileConfig.getBoolean("enable-networking"))
.makeNetworkingExceptionsWarnings(fileConfig.getBoolean("make-networking-exceptions-warnings"));

for (String pluginName : fileConfig.getStringList("skip-sender-proxy")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class CommandAPIVelocity implements CommandAPIPlatform<Argument<?>, Comma
private static CommandAPIVelocity instance;
private static InternalVelocityConfig config;

private VelocityCommandAPIMessenger messenger;
private VelocityCommandAPIMessenger messenger = null;
private CommandManager commandManager;
private CommandDispatcher<CommandSource> dispatcher;

Expand Down Expand Up @@ -112,7 +112,13 @@ public VelocityCommandAPIMessenger setupMessenger() {
}

public VelocityCommandAPIMessenger getMessenger() {
return messenger;
if (messenger != null) {
return messenger;
} else {
throw new IllegalStateException("Tried to access the plugin messenger, but it was null." +
" Plugin messages are only possible after calling CommandAPI#onEnable." +
" Also ensure that the \"enable-networking\" config option is \"true\".");
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public CommandAPIMain(ProxyServer server, Logger logger, @DataDirectory Path dat
.silentLogs(configYAML.node("silent-logs").getBoolean())
.missingExecutorImplementationMessage(configYAML.node("messages", "missing-executor-implementation").getString())
.dispatcherFile(configYAML.node("create-dispatcher-json").getBoolean() ? new File(dataDirectory.toFile(), "command_registration.json") : null)
.enableNetworking(configYAML.node("enable-networking").getBoolean())
.makeNetworkingExceptionsWarnings(configYAML.node("make-networking-exceptions-warnings").getBoolean());

// Load
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static DefaultVelocityConfig createDefault() {
options.put("silent-logs", SILENT_LOGS);
options.put("messages.missing-executor-implementation", MISSING_EXECUTOR_IMPLEMENTATION);
options.put("create-dispatcher-json", CREATE_DISPATCHER_JSON);
options.put("enable-networking", ENABLE_NETWORKING);
options.put("make-networking-exceptions-warnings", MAKE_NETWORKING_EXCEPTIONS_WARNINGS);

Map<String, CommentedSection> sections = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public abstract class DefaultConfig {
}, false
);

public static final CommentedConfigOption<Boolean> ENABLE_NETWORKING = new CommentedConfigOption<>(
new String[]{
"Turn on the CommandAPI's plugin messaging functionality (default: false)",
"If \"false\", the CommandAPI will not listen to incoming plugin messages",
"and attempts to send plugin messages will fail. Enabling networking by",
"setting this to \"true\" is currently only useful for allowing command",
"requirements on Velocity."
}, false
);

public static final CommentedConfigOption<Boolean> MAKE_NETWORKING_EXCEPTIONS_WARNINGS = new CommentedConfigOption<>(
new String[]{
"Turn exceptions while sending and receiving packets into warnings (default: false)",
Expand Down
Loading