-
-
Notifications
You must be signed in to change notification settings - Fork 74
Some updates to networking #642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev/dev
Are you sure you want to change the base?
Conversation
I did convince myself and changed the config option to be |
Why not have a option to disable the communication attempt directly instead of ignoring the error? |
|
I didn't think correctly, making this as disable-warning is good, sorry. |
No problem :) I wasn't exactly sure what you meant before |
But why is it that the error is downgraded to a warning? I mean, if you set a config option to disable an exception I'd except it to be completely silenced. I understand that you still want a warning because something went wrong, but then why have a config option in the first place? |
My thoughts were based on this test setup I made. Set<Player> canUse = new HashSet<>();
new CommandAPICommand("toggle")
.executesPlayer(info -> {
Player player = info.sender();
if (canUse.contains(player)) {
canUse.remove(player);
} else {
canUse.add(player);
}
CommandAPI.updateRequirements(player);
boolean useState = canUse.contains(player);
player.sendPlainMessage("Can use: " + useState);
})
.register();
new CommandAPICommand("test")
.withRequirement(source -> {
if (!(source instanceof Player player)) return true;
return canUse.contains(player);
})
.executes(info -> {
info.sender().sendPlainMessage("Success!");
})
.register(); The difference between an exception and a warning is that the exception interrupts the control flow. In this example, if The warning message can also be ignored by turning on the I guess another option which does not show the warning is the user checking in advance whether the method would fail: if (player.getCurrentServer()
.map(server -> CommandAPIVelocity.get().getMessenger()
.getConnectionProtocolVersion(server) > 0
)
.orElse(false)
) {
CommandAPI.updateRequirements(player);
} else {
// `updateRequirements` would have failed
} This does give the most control to the developer what to do. I concede it isn't very good though since it's not documented and very implementation dependent, so a developer wouldn't know to do this and it could change. Maybe this logic could be put into a Do you have use case where a different solution would make more sense? |
I did not think of that. Well then I have nothing to say. Apologies |
👍 No problem! Thanks for clarifying. |
I just realized that this needs a docs PR to update the default config to include the new value. |
Some updates to the networking logic as suggested by @Timongcraft on Discord.
The
CommandAPI
Bukkit plugin now providesCommandAPINetworking
. So, if a plugin depends onCommandAPINetworking
, it will be able to load ifCommandAPINetworking
orCommandAPI
is present. This makes sense, sinceCommandAPI
provides the same networking support thatCommandAPINetworking
does. Provides also allows plugins to load classes fromCommandAPI
like they would fromCommandAPINetworking
, which technically doesn't apply here sinceCommandAPINetworking
has some unique classes not present inCommandAPI
. I don't currently expect anyone to load classes fromCommandAPINetworking
though, so this is not a problem right now.CommandAPI
Bukkit andcommandapi
Velocity both now have thereport-failed-packet-sends
config option. By default this istrue
, and the CommandAPI will throw a runtime exception if it cannot send a packet because the receiver doesn't have a new enough CommandAPI networking implementation. If set tofalse
, these attempts will fail silently. Technically, Bukkit doesn't use this option since it doesn't send any packets right now, but it was easy enough to do this way with the config system, and it might be used eventually. Bukkit Networking doesn't have this option and will always throw since it also doesn't currently send any packets, and I didn't bother adding a config file to that.Looking for feedback on whether
report-failed-packet-sends: false
should log a warning/error message instead of failing silently. It would be less intrusive than an unhandled exception, and it could still be turned off withverbose-outputs
orsilent-logs
. In this case, the option name should probably be changed to something likeerror-on-failed-packet-sends
. (After typing that I kinda convinced myself a warning which you can turn off withsilent-logs
is the best option :P)