-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Print warning if people try to call JavaPlugin#getCommand with paper plugins #9685
Conversation
@@ -4857,6 +4857,10 @@ index 0000000000000000000000000000000000000000..45bd29b70782e29eb11c36eaca0f940a | |||
+ .build(); | |||
+ } | |||
+ | |||
+ if (!node.node("commands").virtual()) { | |||
+ org.slf4j.LoggerFactory.getLogger(pluginConfiguration.getName()).warn("Defining commands in paper-plugin.yml is not supported! - Commands will not be available!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could probably link to the docs page (https://docs.papermc.io/paper/dev/getting-started/paper-plugins#commands) that explains what to do instead.
That is a good point. But I think the one thing has little to do with the other. You can see it in the Discord that people are even too lazy to read JavaDocs so we cannot assume that they read the docs. The best thing we can do is give them a hint that they did something wrong on our side. |
There are already plugins published on Modrinth using the paper-plugin.yml. I recall viewing this myself. With all due respect, one should not publish an API to a popular project without expecting its use. The adoption of Paper plugins began as soon as a newfangled API for declaring plugin metadata was released. These shifts are not necessarily misguided, as the original impetus for Paper plugins outlined several use-cases which remain relevant: #7955 |
We do expect usage of the API, hence we published it. To collect feedback on it as we further improve it. Developers that publish such plugins need to be aware of those restrictions and risks and what those might mean for their users, hence we mostly expected this API to be used in private plugin development as updating to changes to paper plugins becomes a lot easier. Tho given how common the question became regarding command definition in paper-plugin.yml, this is clearly not the case as it seems that a lot of people have started using paper plugins without the required insights into the unstable API and its limitations. Which is why I 100% agree with your Issue about actively warning to further raise the fact, that they are trying to use unstable API incorrectly. If we have to go as far as printing a warning for paper plugins in general, I am unsure of. |
Personally, I have more than 10 public plugins made based on a |
In my opinion its generally wrong to say that "it wont help much". If we have the opportunity to make it more user-friendly we should use that opportunity I dont think a warning doesn't hurt anybody. Another idea that had already been mentioned is that we could throw an exception instead of just printing a warning. That way 90% would actually read the message. But I am generally against this approach since it would be kind of weird to ONLY throw it if a In my opinion a much better approach would be a Maybe it would also be an idea to modify the exception message if someone tries to call |
With my comment about a warning I was only referring to a general warning comment for loading paper plugins, sorry if that wasn't clear. I am 100% on board with a warning/exception for an invalid yaml format in the paper-plugin.yml. |
cant we have a general yaml format and throw if the format doesnt match? special casing this feels strange |
usually it isn't really a problem to have random tags in the config. |
A generic exception like "invalid section found in paper-plugin.yml" would just again bring the people to the discord asking what they should use instead. |
What if, instead of checking the @Nullable
public PluginCommand getCommand(@NotNull String name) {
// Paper start - print warning if paper plugin
if (getResource("paper-plugin.yml") != null) {
this.logger.warning("---------------------------------WARNING--------------------------------");
this.logger.warning(" Defining commands in paper-plugin.yml is unsupported! ");
this.logger.warning(" Please refer to the docs for proper command initialization! ");
this.logger.warning("https://docs.papermc.io/paper/dev/getting-started/paper-plugins#commands");
this.logger.warning(" Command will not be initialized! ");
this.logger.warning("---------------------------------WARNING--------------------------------");
return null;
}
// Paper end
...
} |
that seems the nicer way for that particular usecase |
i changed it to if (!(pluginMeta instanceof PluginDescriptionFile)) {
this.logger.warning("---------------------------------WARNING--------------------------------");
this.logger.warning(" Defining commands in paper-plugin.yml is unsupported! ");
this.logger.warning(" Please refer to the docs for proper command initialization! ");
this.logger.warning("https://docs.papermc.io/paper/dev/getting-started/paper-plugins#commands");
this.logger.warning(" Command will not be initialized! ");
this.logger.warning("---------------------------------WARNING--------------------------------");
return null;
} I am not sure if I should throw an exception instead of returning null. |
Updated it to reflect discussed changes. The only downside is that it doesn't respond to |
I really dislike the notion of this; There are still some Qs over what we want to do long term here, ideally we wanna move away from the broken bukkit command system, however, the expectation of there still being an easy to use command system still exists, etc, etc; it's not 100% decided that such a commands block will never exist, I think that this issue would generally be better off solved with documentation and such Not to mention, this would generally cause issues with plugins querying other plugins for commands, etc |
Generally I agree with you but good luck getting new people to read the docs. As I have mentioned before this is solely for the purpose of hinting new devs that they are doing something wrong. This can always be removed in the future but to be honest, there are too much plugin tutorials and people will use those tutorials to develope Paper Plugins in the future. So getting people away from the old system will never really work until we remove the methods entirely. And until then I think its a good idea to print such a warning. This is also not final but in my opinion its important and more user-friendly to add this (or in another form). |
Except this ends up leaking warnings to other plugin invocations of this stuff, which imho makes this a no go on this solution |
I think I am closing this in favor of minecraft-dev/MinecraftDev#2122 since it got merged recently. If you ignore this warning there is really nothing else we can do. If someone still thinks this is something worth adding (in another form than how it works at the moment) just let me know :) |
This PR adds a simple warning if a
commands
section has been found in thepaper-plugin.yml
file.I am taking suggestions for the warning message since I don't know if I should include how to register commands with Paper Plugins.
I also did not know which logger I should use since I don't think a plugin logger has already been created at the time where the warning is printed.
Which brings me to the next point:
Currently the warning is printed before the server is started:
I don't think there is a way of printing the warning during the plugin load period (unless we add a boolean or something) since I don't think it is not possible to get the node after the
PaperPluginMeta#create()
method.Closes #9669