Closed Loapu closed 4 years ago
I'll have a look at this when I can. By any chance, if you have the required permission node (as well as being OP), does it work?
Does not work either :/
Thanks for the response - This is a very bizarre bug and it may take some time to figure out why it's doing that
Don't worry, there is no hurry
Odd - I've been unable to replicate this bug. Here's the code I'm using:
new CommandAPICommand("crucius")
.withAliases(new String[] { "cr", "cruc" })
.withPermission(CommandPermission.fromString("crucius.basecommand"))
.executes((sender, args) -> {
if (sender instanceof Player) {
Player p = (Player) sender;
System.out.println("P");
}
sender.sendMessage("A");
if (sender.hasPermission("crucius.basecommand.help")) {
sender.sendMessage("B");
}
}).register();
I'm currently on a server without any permission plugins (e.g. LuckPerms) and I am an operator. I am able to run the command /crucius
with no problems, and both "A" and "B" are sent to me. Similarly, this works as intended when running it from the console.
Could it be a LuckPerms related issue?
Lemme check
I installed LuckPerms and ran the command (still being operator and not using LuckPerms to add any permissions) and it still yields the same result (it works as intended).
Alright, I installed Crucius fresh on a new Spigot 1.15.2 server, the same result. Crucius-0.2.0-pre.7.jar.zip Here is my jar file that I use. The source code is included. I do not know why this error comes up, the console doesn't give an answer either.
@Loapu
[18:46:56 ERROR]: Error occurred while enabling Crucius v0.2.0-pre.1 (Is it up to date?)
java.lang.NullPointerException: null
at java.util.Objects.requireNonNull(Unknown Source) ~[?:1.8.0_251]
at java.nio.file.Files.copy(Unknown Source) ~[?:1.8.0_251]
at de.theyphania.crucius.Crucius.loadSettings(Crucius.java:205) ~[?:?]
at de.theyphania.crucius.Crucius.loadResources(Crucius.java:118) ~[?:?]
at de.theyphania.crucius.Crucius.onEnableInner(Crucius.java:72) ~[?:?]
at de.theyphania.crucius.CruciusPlugin.onEnable(CruciusPlugin.java:66) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[spigot-1.15.2.jar:git-Spigot-a99063f-fad2494]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:351) [spigot-1.15.2.jar:git-Spigot-a99063f-fad2494]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) [spigot-1.15.2.jar:git-Spigot-a99063f-fad2494]
at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugin(CraftServer.java:464) [spigot-1.15.2.jar:git-Spigot-a99063f-fad2494]
at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugins(CraftServer.java:378) [spigot-1.15.2.jar:git-Spigot-a99063f-fad2494]
at net.minecraft.server.v1_15_R1.MinecraftServer.a(MinecraftServer.java:457) [spigot-1.15.2.jar:git-Spigot-a99063f-fad2494]
at net.minecraft.server.v1_15_R1.DedicatedServer.init(DedicatedServer.java:274) [spigot-1.15.2.jar:git-Spigot-a99063f-fad2494]
at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:784) [spigot-1.15.2.jar:git-Spigot-a99063f-fad2494]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_251]
Have you tried moving the command registration to the onLoad()
method? In my testing, I registered it there as opposed to the onEnable()
method
So, I moved the command registration to the onLoad()
method but it throws the same error. It seems to have a problem with the WrapperCommandSyntaxException
...
Crucius-0.2.0-pre.11.jar.zip
And for your error, the JAR-File is inside the zip folder. Renaming won't do it. (If this was what you did because I never had your exception :/)
Alright, so I downloaded the zip folder, extracted the .jar file into a 1.15.2 spigot server with the CommandAPI (v3.1, I'll explain a little further down) and LuckPerms (literally fresh install, haven't adjusted permissions or anything).
I logged in and ran the command /crucius
. In game, no messages were displayed.
So far, I've not been able to replicate the bug potentially related to permissions. The CommandAPI's handling of exceptions is indeed not amazing (exceptions are typically caught really early on and are handled in such a way that they're not outputted into the console), however I don't see anything that would indicate a permission-related issue.
I mentioned I'm running version 3.1 - this shouldn't be a cause of the issue because v3.1 and v3.0 are perfectly compatible with each other (v3.1 literally just adds 1 new argument (which you're not using) and adds more support for overriding suggestions (which you're also not doing)).
If we try to backtrace a bit we have this line
new LiteralMessage("You must be a " + type.getSimpleName().toLowerCase() + " to run this command")
inside
1.13-Command-API/1.13CommandAPI/commandapi-core/src/main/java/dev/jorel/commandapi/executors/IExecutorNormal.java
.
Could you please take a look at my de.theyphania.crucius.commands.CruciusCommand.java
file inside the Sources folder of the plugin jar?
The above mentioned type.getSimpleName().toLowerCase()
seems to give out this class name.
Regarding your error, delete the Crucius folder inside your plugin folder. The plugin has to generate the new settings file.
Alright, no matter what I do, I can't get your plugin to run without it erroring. Nonetheless, I took a look at IExecutorNormal
and have a feeling that it may be retrieving the wrong method to execute a command (although highly unlikely).
I modified the executor interfaces, so hopefully this version works?: CommandAPIv3.1_30_Jun2020(08-39-16PM).zip
It works as intended. What was the problem?
It works as intended. What was the problem?
I'm so glad that works! Thanks so much for your cooperation. Basically, in the CommandAPI, there are multiple different executor types (e.g. .executesPlayer()
, .executes()
, .executesEntity()
etc.). To ensure that the actual sender matches the programmed sender, it uses a sneaky bit of reflection to find the right command sender.
For example, if I registered a command as follows:
new CommandAPICommand("mycommand")
.executesPlayer((player, args) -> { ... })
.register()
Internally, it uses the PlayerCommandExecutor
, which has a method void run(Player sender, Object[] args) throws WrapperCommandSyntaxException;
. The reflection finds the first method and retrieves its parameter (in this case, Player
), thus knowing that the sender must be a player. When you run the command, it checks if you match Player
and if so, it runs the command as expected.
However, the bug was it wasn't finding the void run(T sender, Object[] args)
method (where T
is some CommandSender
) and was instead finding something else. I have no idea how it ended up finding something else, but I fixed it in this commit: 749ef9c6b57faf27095302d4a6c8dd183a070317
Once again, thanks so much! This was a very stressful bug to sort out since I couldn't replicate it on my local machine. By pointing this out:
If we try to backtrace a bit we have this line new LiteralMessage("You must be a " + type.getSimpleName().toLowerCase() + " to run this command") inside 1.13-Command-API/1.13CommandAPI/commandapi-core/src/main/java/dev/jorel/commandapi/executors/IExecutorNormal.java. The above mentioned type.getSimpleName().toLowerCase() seems to give out this class name.
You led me straight to the solution. I'll make sure to add you to the acknowledgements section in the documentation!
I am just glad I could help you ^^ I find your work amazing and hope to see this much more used by future plugins.
Hi 👋 I'm getting the same error now with the maven dependency 3.0 and Spigot 1.16.1 I saw the bug is already fixed but the only fixed Version is the provided jar file in your answer (btw. with this jar it works as expected) Ist it possible to publish this fix also in the mvn-repo branch? Since i use it as maven dependency, its kinda ugly to add a custom jar file (wich doesn't even have a build version) to the existing build pipeline in my project 😁
Would be nice if u can update it :)
Greetings Marc
EDIT: I added the source, just in case it helps in any way :P
LinkedHashMap<String, Argument> magicArguments = new LinkedHashMap<>();
new CommandAPICommand("magic")
.withArguments(magicArguments)
.withPermission(CommandPermission.OP)
.executes((sender, args) -> {
sender.sendMessage(Chat.color("Magic is running version v" + this.getDescription().getVersion(), ChatColor.GREEN));
}).register();
Hi, I am in the process of releasing version 3.1 which fixes this. I hope to release it within the next 24 hours
CommandAPI version 3.0
Minecraft version 1.15.2
Describe the bug When I (as a player with OP) try to run my command, it tells me "You must be a cruciuscommand to run this command"
My code This code reproduces the behavior:
Expected behavior Let me execute the command
Additional context The same problem persists when I try the command inside the console