commands
commands copied to clipboard
Could not find context resolver
I'm seeing really strange issues when I try to implement a command Interface on my BaseCommand
It just started to happen since I added BaseCommand implements ISkinCommand<CommandSender, Player, OnlinePlayer>
to my BaseCommand class.
This is the full class causing that error: https://github.com/SkinsRestorer/SkinsRestorerX/blob/c1840af58a68c199e53211390a25236f5aa2cee3/src/main/java/skinsrestorer/bukkit/commands/SkinCommand.java
This is where the error happens: https://github.com/SkinsRestorer/SkinsRestorerX/blob/c1840af58a68c199e53211390a25236f5aa2cee3/src/main/java/skinsrestorer/bukkit/SkinsRestorer.java#L169
What am I doing wrong?
I am fairly confident I know what is happening.
java.lang.reflect.Parameter;
is not able to properly get the type of your method parameter at runtime - related to the generics involved. Grabbing the type of the interface instead of the implementing class.
https://github.com/aikar/commands/blob/master/core/src/main/java/co/aikar/commands/CommandParameter.java#L72
As it stands, there would probably have to be some change to acf itself to support the behavior you are wanting. Looks like some research needs done in order to find the solution to this.
How to proceed from here. Either find an alternative to Parameter#getType()
that gets the implementing method's parameter type and PR to acf. OR just not do this.
@chickeneer Maybe something like this?
https://stackoverflow.com/a/1901275
Maybe... Some testing needs done given this information. Not 100% certain this gives the full solution. Could get as simple as replacing this.type = param.getType();
with this.type = param.getClass();
I can't even get anything to pass tests ¯_(ツ)_/¯
With this.type = param.getClass();
:
CommandManagerTests.initEach:48 » InvalidCommandContext Parameter Parameter of...
With this.type = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
:
CommandManagerTests.initEach:48 » ClassCast java.lang.Class cannot be cast to ...
Some comments on stackoverflow even say that something like this is not possible.. I have no idea
@chickeneer that's not right. .getclass() will return Parameter.class which is completely wrong. the BukkitRegisteredCommand is getting passed as a PARAMETER somewhere and that isn't correct. I can't see that in any of this?
gotta find where BRC is even getting injected as a parameter.
Derp. What was I thinking when I typed that. Definitely agree with the linked site not having the needed solution. Theoretically, the would be a plugin compile thing to prevent the type erasure for the generics.
Let me know if there's something I can try to solve this
I'm not sure where generics should even be a problem here. the error deals with parameters, and none of the parameters use generics.
No... I think generics is exactly the problem. It is extending the ISkinCommand interface https://github.com/SkinsRestorer/SkinsRestorerX/blob/c1840af58a68c199e53211390a25236f5aa2cee3/src/main/java/skinsrestorer/shared/interfaces/ISkinCommand.java#L13
Implemented here. https://github.com/SkinsRestorer/SkinsRestorerX/blob/c1840af58a68c199e53211390a25236f5aa2cee3/src/main/java/skinsrestorer/bukkit/commands/SkinCommand.java#L33
From what I can tell. Parameter#getType
is getting Object from the interface instead of the implementing class.
Hello,
I seem to be experiencing this same issue in my own plugin. Has a solution been found?