Java Errors
https://sourceb.in/7HPeL01Jtk
Hey, I am currently learning java for the first time, and I was experiencing some errors, and I was hoping if I could get assistance regarding them. Thanks!

68 Replies
⌛ This post has been reserved for your question.
Hey @shazim! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
I was following a tutorial and I got these errors. Lmk what I did wrong, along with a guide to fix it (would really help!)
Send your code bro
I did

sourcebin is like pastebin
package me.shazim.shazimsPlugin;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
This message has been formatted automatically. You can disable this using
/preferences.I was following this tutorial: https://youtu.be/NubWqnpNZ98?si=aEncgzkM_jG0a9ko
Kody Simpson
YouTube
Spigot Plugin Development - 6 - Commands Part 2
In this episode, I show you how to make commands for your Minecraft plugins in classes outside of the main plugin class. #Spigot #SpigotTutorial #MinecraftPlugins
Code: https://github.com/Spigot-Plugin-Development-Tutorial/commands-part-2
⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin...
Ok gimme like an hour I can't do anything while on my phone. Gonna have lunch, Mark my practice exam then help you, sorry I can't do it now
Lol all good
@shazim please forgive my tone, I mean no disrespect.
the first thing I see is
that's not quite how Java works. contrary to many languages, Java doesn't have named parameters, so you can't do
name: "godmode".... some IDEs show the parameter names but this is just for your convenience. also, trying to call the setExecutor() method on a String object wont work, as the method doesn't belong to the String class.
instead you should pass "godmode" as the parameter to the getCommand() method and then call the setExecutor() method on that
also, Java is having an issue with the GodCommand class itself, it can't find it. make sure you have a file called GodCommand.java with a class GodCommand.
presumably, you'll need the GodCommand class to implement the org.bukkit.command.CommandExecutor interface and override its onCommand() method. at least thats how paper does it so I'm assuming its the same.
next is an easy fix. you used ChatColor.RED but haven't imported the ChatColor class. add import org.bukkit.ChatColor; to the top of your file and you'll be all good.
also your code has some extra whitespace. remove the unnecessary empty lines. you missed a closing bracket } at the end of the onCommand() method, making Java think the onDisable() method is also a part of it, and that goes against a million Java syntax rules hence the multiple warnings.
some of the other things your IDE is warning you about are things like your use of
which is a little convoluted. a little tip for you, you can actually combine these into just one line:
hope that helps somewhat 🙂 let me know if you're still having problems after you fix these issues, I'll be happy to help!
also, may I just say that your work is mighty impressive. learning Java for the first time and you start with a bukkit mod? crazy! I take my hat off to you!💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.thanks so much man!
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Thank you so much for the support, at the moment it is a bit early for me, however I’ll definitely try this out! I did have one question I wanted to follow-up once I can review and fix my code. Again, thank you so much for the support.
Hey @reiwa, thanks for the support again.
I am still getting some errors regarding this.
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
let me send the errors
hey! no worries 🙂
I'll take a look when I get some time today 👍
alr, thanks so much
I forgot to put the bracket in, which fixed alot of the errors for the main file
- Im still have issues with it trying to find the GodCommand class
- "Missing return statement" at the bracket
- Warnings within
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
missing return statement means you got to return something even though you covered all the if cases
so you can just add at the end of your on command function
or false
depending on your use case
as for cannot resolve symbol god command it means the code cant see the godcommand class
so you either need to import it or make it
・yes, you need to add
import me.shazim.shazimsPlugin.commands.GodCommand; to ShazimsPlugin.java otherwise Java can't "see" it
・also, for the return statement, the onCommand() method returns a boolean but not all code paths return one. if we go through the if block, we see that if the command is not "die", then the method exits without returning anything at all, which goes against its definition. actually, even if the command is "die", you're not explicitly returning true after handling.
you need to add return true; after successfully handling the command and return false; if there was a problem. something like this:
・also you're getting caution messages about @NotNull because bukkit insists that certain parameters, such as sender, command, etc. not be null (otherwise how are you going to get anything to run) but you're not explicity telling or getting Java to check that these parameters will not be null. IntelliJ is therefore warning you that you're opening yourself up to potential NullPointerExceptions when you try to compile (or worse, run) your code.
the solution is to excplicity tell Java that those parameters will not be null with something like import org.jetbrains.annotations.NotNull;. then add @NotNull before each parameter that IntelliJ is warning you about. idk if that makes sense but I can explain better if you don't manage to do it.
this is not technically an error, which is why its only showing as orange in IntelliJ and not red, but its better to implement null safety in your program.
・similarly, the line getCommand("godmode").setExecutor(new GodCommand()); is potentially problematic, because if getCommand("godmode") returns null (for example if it can't be found or theres a mistake in the plugin.yml file, then that line will throw an NullPointerException. instead you should explicitly check to see if the godmode command can be found first, then attempt to use setExecutor(). i don't want to give you too much help incase it was something you were looking to fix on your own.
okay lets have a look at the GodCommand file...I am still new, so some of these errors (like this) I still dont know how to fix lol
i can certainly help you out, i just didnt want to step on your toes
ill write out the solution (its not hard) and explain it to you 🙂
Alright, thanks so much again <3
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
to fix this, we need to explicitly check if
getCommand("godmode") returns what we expect it to before we move on. the solution here is to split up this line getCommand("godmode").setExecutor(new GodCommand()); into two.
first we declare it with PluginCommand godModeCommand = getCommand("godmode");
this will allow us to check if its null with a simple if check
something like that should suffice 🙂 this is not technically necessary for your code to function but it will save you a headache down the roaad if you accidentally edit your plugin.yml file
okay, first thing I spot in your GodCommand.java is a slight typo
you have used setInvulerable(). it should be setInvulnerable() (you missed the n)Also for the null thing, when I try to implement the package, I am getting this error (shown in attachment) about jetbrains. Additonally, if I already have
@Override, do I replace it with @NotNull?
then leave out the @NotNull for now itll cause you too many problems, we can fix it later if it becomes a problem
and no
dont change @Override
okay also in
GodCommand.java, line 21, you need to put a ; at the end of the line. Java is very unforgiving about that.Lol yeah I just noticed that
and lastly (at least from what I can see here) you need to add
import org.bukkit.command.Command; to the top of your GodCommand.java file, or java wont be able to see the Command class, which it needs 🙂
i know i just gave you a wall of text but hopefully that helpsThe wall of text does really help lol
im so glad!
im really having fun on this, bukkit (well paper but same same) is something I know about so I feel like i'm actually useful for once haha
lol, you've been really helpful
one last thing for the GodCommand.java, is there a method for not being Invulerable?
meaning you want to make the person vulnerable again?
Yeah, for godmode
yeah you just put
false
p.setInvulnerable(false);
but I notice you already have that
Yeah
you didnt fix the typo
you have
setInvulerable() but you need to add an n
use setInvulnerable()
then it will work @shazim 🙂Thank you so much <3
For aliases, do I put it like this?

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
yes that looks right 🙂
also its spelled
ìmmortal with 2 M'sAnd I would put it as
god, godcommand, and-more
?no
im so good at not putting typos frfr
like this
This?

looks good to me
Alright, thanks again :D
no worries! glad to have helped! feel free to ask any other questions you have about Java or problems you run into with you plugin 🙂
Also, one last question (sorry for all of tyhe problems), whats the difference between gradle and maven, and how do they wrok
*work
oh my god
the eternal question
the short answer is idk but if you ask in a new question an expert will come and give you all the details
Also should I be concerned about this?
well, i do know but idk how to really explain it to you sorry

you're fine
yeah i mean its not aplugin problem but a build issue, so you'll have to take that up with someone who knows what they're doing
Java is just telling you it cant find files it needs to build your plugin
idk how to fix it tho
oh
alright
how can I give you a thanks
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
or review or whatever lol
its probably a misconfiguration in your
pom.xml or build.gradle files
i have no idea haha
your thanks are enough 🙂lol
i just noticed, java is expecting JDK 21. make sure
File > Project Structure... > Project > Project SDK is set to 21. thats the only thing I can think of. if its not that your out of my depth. good luck tho!when you close the post i think theres an option after that to thank the user that was helping
at least it used to be that way
oh yeah there is
Post Closed
This post has been closed by <@810632160418988053>.