Solved "The constructor Location is undefined"

Discussion in 'Plugin Development' started by arjanforgames, Oct 1, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    arjanforgames

    First item in the main class (Inside "public class Core extends JavaPlugin implements Listener"):
    Code:java
    1. public Location GameOneLocation;


    Code:java
    1. public void onEnable(){
    2.  
    3. getServer().getPluginManager().registerEvents(this, this);
    4.  
    5. World world = (World) getConfig().get("Path.world");
    6. Location X = (Location) getConfig().get("Path.X");
    7. Location Y = (Location) getConfig().get("Path.Y");
    8. Location Z = (Location) getConfig().get("Path.Z");
    9. GameOneLocation = new Location(world, X, Y, Z); // ERROR LINE
    10.  
    11. this.saveDefaultConfig();
    12. }


    The error line is in the title.
    Any help?
     
  2. Offline

    The_Doctor_123

    First of all, you cannot cast the world name to a world. You will need to use Bukkit.getWorld(String). You're also casting what it seems to be, integers, to a location.. No. You cannot do that, how would the program even know if you're talking about the x, y, z, yaw, or pitch?

    Secondly, the Location constructor takes a World, int, int, and int.
     
    MrSnare likes this.
  3. Offline

    Fozie

    Emm the problem is that you trying to cast integers to Location
    and Strings to World do instead
    Code:java
    1. GameOneLocation =new Location(Bukkit.getWorld( getConfig().get("Path.world")), getConfig().get("Path.X", getConfig().get("Path.Y", getConfig().get("Path.Z");
     
  4. Offline

    arjanforgames

    Fozie

    I get: "The method getWorld(String) in the type Bukkit is not applicable for the arguments (Object) "
     
  5. Offline

    The_Doctor_123

    arjanforgames
    Do you know any Java?

    You need to cast the object you're getting to a String. Actually, there's a getString() method in FileConfiguration.
     
    Hutchmaster99 likes this.
  6. Offline

    Hutchmaster99

    Can you post the code you have now?
     
  7. Offline

    arjanforgames

    Code:java
    1. public Location GameOneLocation;
    2.  
    3. public void onEnable(){
    4.  
    5. getServer().getPluginManager().registerEvents(this, this);
    6.  
    7. GameOneLocation =new Location(Bukkit.getWorld( getConfig().get("Path.world")), getConfig().get("Path.X", getConfig().get("Path.Y", getConfig().get("Path.Z");
    8.  
    9. this.saveDefaultConfig();
    10. }
     
  8. Offline

    The_Doctor_123

  9. Offline

    arjanforgames

    Im a beginner. Help me up :/
     
  10. Offline

    The_Doctor_123

    arjanforgames
    If you're starting Java, you must learn the language itself before getting into any 3rd party APIs, like Bukkit. I suggest buying a book, like Java For Dummies. Makes it a whole lot easier to learn the language than watching YouTube videos and such.
     
  11. Offline

    arjanforgames

    My god... This is a forum to help people?
    Why not give me the code and a brief explanation? I'm here to learn bukkit.
     
  12. Offline

    Hoolean

    Hey arjanforgames ! May I politely recommend that after you've done this plugin you learn a bit more Java, as most of the questions you are asking are simple Java questions rather than ones to do with the Bukkit API, which this forum is about.

    I guarantee it will help you and make it a ton easier to make plugins.

    In the meantime, feel free to post these things but you'll find it a lot easier if you learn a bit more Java first. :)

    EDIT: Oops, while I was writing this two other people ninja'd me! :p
     
  13. Offline

    The_Doctor_123

    arjanforgames
    You're correct. This is a forum to help people understand the BUKKIT API better. You're asking about basic OOP concepts.
     
  14. Offline

    arjanforgames

    Whenever I allow java to auto-correct "cast" to String I get that messed up fucking error.
    "The constructor Location(World, Object) is undefined"
     
  15. Offline

    Hoolean

    Eclipse's auto-correct options rely on you to know to pick the right one, which involves knowing Java.

    I suggest you read Fozie 's solution:
     
  16. Offline

    The_Doctor_123

    arjanforgames
    That is your editor doing that.. Editors will not know what you're trying to do. That is why YOU should code it yourself.

    Also, language.
     
  17. Offline

    arjanforgames

    Hoolean,

    If you read my reply you probably noticed I AM using his line of code.
    But maybe I should learn the basics, well I certainly do and I DO want to but is it that hard to give the code?
    I mean..

    Mom: No you can't have a cookie
    Kid: Why?
    Mom: Learn to make your own instead..

    You should at least give him a sample before he starts making his own right?
     
  18. Offline

    Techy4198

    The_Doctor_123 likes this.
  19. Offline

    The_Doctor_123

    1Rogue likes this.
  20. Offline

    Nateb1121

    This is not a forum to spoon feed you code, be a little mature and realize we're trying to help you by not spoon feeding you stuff. Your're the type of person who doesn't want to learn, you're just here to copy and paste code, hope the Eclipse can fix any possibly syntax error in the world, then tell your friends you know how to program. Learn the basics, show the initiative to learn and not ask for all code to be handed out. Doctor gave you everything you could possibly need in his first reply. You need to take the responsibility to know what you're talking about and be able to accept help, not a hand out. This forum is for help, not handouts. It's obvious to any programmer when someone pretends to know what they're talking about. If you legitimately don't understand, it'd be obvious to us all, but right now the only thing obvious is you don't know Java at the level you need to.

    You need to know Java before you go messing with APIs. Start with an IDE that does NOT do auto-completion like Dr. Java. Learn the basics, then move up and then try to play ball with the community here.


    Kid: Mom, I made these cookies, but what's wrong with them?
    Mom: You didn't use any milk.
    Kid: Just give me cookies.
     
  21. Offline

    1Rogue


    If you want a sample, then here:
    http://docs.oracle.com/javase/tutorial/java/concepts/

    I guarantee that if you take the time to learn the core concepts (which you are lacking), then you will understand the source of your own error.
     
  22. Offline

    arjanforgames

    Code:java
    1. GameOneLocation = new Location(Bukkit.getWorld(getConfig().get("Path.world").toString()), getConfig().get("Path.X").toString(), getConfig().get("Path.Y").toString(), getConfig().get("Path.Z").toString());


    "The constructor Location(World, Object) is undefined"
     
  23. Offline

    Nateb1121

    getConfig().get() returns an object. Like we said, learn Java, and use the API. My God.
     
  24. Offline

    arjanforgames

    Why wouldn't this work then? Im converting it to a string right?
    Code:java
    1. getConfig().get.("Path.world").toString()
     
  25. Offline

    The_Doctor_123

    arjanforgames
    toString() doesn't function the way you'd think. It returns some ID of the object.
     
  26. Offline

    arjanforgames

    Code:java
    1. FileConfiguration config = getConfig();

    Code:java
    1. GameOneLocation = new Location(Bukkit.getWorld(config.getString("Path.world")), config.getString("Path.X"), config.getString("Path.Y"), config.getString("Path.Z"));


    It won't matter, "The constructor Location(World, Object) is undefined", will always be there.

    EDIT:
    If I make it like this:
    Code:java
    1. String test = config.getString("Path.X");
    2.  
    3. GameOneLocation = new Location(Bukkit.getWorld(config.getString("Path.world")), test);


    The string is undefined.
     
  27. Offline

    The_Doctor_123

    arjanforgames
    You are not understanding a thing.. what you're asking goes all the way back up to my first post.

    Please just stop following this path before you damage yourself any further. Learn Java from tutorials or a book and this will make a whole lot more sense.
     
  28. Offline

    arjanforgames

    https://forums.bukkit.org/threads/read-strings-from-config.90270/

    Can't you just answer me like r0306.

    Really. I don't see why you just wouldn't give me that little code snippet.
    Do you really... No I just don't no. Why?
    I mean I'm asking you to help me with a function so it would be nice if you tell me how I would succesfully convert into into a usable string for the Location. Instead your keep telling me to learn Java and read books.
    Wtf? You could have just helped me and this wouldn't have taken so long.
     
    spiderking220 likes this.
  29. Offline

    The_Doctor_123

    arjanforgames
    These forums are to help people with Bukkit, not teach people the basics of Java. You need to put in some dedication to what you want to do. Does a new engineer make rockets?
     
  30. Offline

    arjanforgames

    Well, the point is. Before my last reply I found out by myself how it was done although I wanted you to give me the code snippet.
    Seems you are really not wanting to give me any letter of code.

    -Solved.
     
    spiderking220 likes this.
Thread Status:
Not open for further replies.

Share This Page