Hello, is there a way, to use a simple location Code (Java): Location location = new Location(world, x, y, z, yaw, pitch); In a other class? I want to teleport me with a GUI click
make it static lol. Code (Text): public static Location LOCATION = new Location(world, x, y, z, yaw, pitch); Yourclass.LOCATION; //Access
You shouldn't advise people to abuse static like that. (unless OP wants to use it as a constant in which case it also should be final)
Not showing the syntax error ins't helping you solving this problem. Could you pls tell us what pops up if you hover over it
„Remove invalid modifiers“ PS: If it were so easy with just a static, I would not ask. That was the first thing I did
"Remove invalid modifiers" probably means that you defined this variable somewhere where you shouldn't. It's hard to tell tho without any context what so ever
Making static is not just making it available from all classes. Dependency injection is the only correct (proper) approach. Static makes it unique and only callable by class name. And that is a bad approach. A good usecase for static could be for for example messages that are hardcoded or singleton paterns
Since you do not provide any information one can only guess. location a) is defined inside a method, in this case: Code (Java): Class classWhereTheMethodIsInside { private Location location; public x methodThatContainsLocation(...) { this.location = new Location(world, x, y, z, yaw, pitch); } public Location getLoation() { return this.location; } } b) is not defined inside class please no c) is defined inside an interface please no d) is defined inside an enum go to a) e) anything I missed that could explain an invalid modifier?
The problem here is the lack of knowledge of basic Java and OOP. Even after s/he was told to make it static (which is btw the worst approach) s/he couldn't understand how to use it because of lack of knowledge and understanding OOP (you can't use this keyword inside methods, just on fields of objects) What you should use is dependency injection. (Just google it, it's pretty simple)
Lack of knowledge AND not explaining what the problem’s context is. If you don’t know how to code and want to learn from others then give all the information and let’s discuss it.
Update: Here is a tutorial of @MrDienns about dependency injection https://www.spigotmc.org/threads/tutorial-spigot-plugins-dependency-injection.295218/