Get a players location on quit?

Discussion in 'Plugin Development' started by MordorKing78, Nov 5, 2014.

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

    MordorKing78

    So what I am trying to do is getting the location of a players that quits it this possible?

    My quit event. (I Could not think of a better way to do the Location so I just messed around and this worked.)
    Code:java
    1. public void onPlayerQuit(PlayerQuitEvent event) {
    2. C = new File(plugin.getDataFolder(), "Data.yml");
    3. CZ = YamlConfiguration.loadConfiguration(C);
    4. Player p = event.getPlayer();
    5. double X = p.getLocation().getX();
    6. double Y = p.getLocation().getY();
    7. double Z = p.getLocation().getZ();
    8. String world = p.getWorld().getName();
    9. CZ.set(p.getUniqueId() + ".X", Double.valueOf(X));
    10. CZ.set(p.getUniqueId() + ".Y", Double.valueOf(Y));
    11. CZ.set(p.getUniqueId() + ".Z", Double.valueOf(Z));
    12. CZ.set(p.getUniqueId() + ".World", world);
    13. SaveNC();
    14. }
    15. public void SaveNC(){
    16. try {
    17. CZ.save(C);
    18. } catch (IOException e) {
    19. // TODO Auto-generated catch block
    20. e.printStackTrace();
    21. }
    22. }
     
  2. Offline

    TheCodingCat

    why are you using Double.valueOf() when the variable is already a double! That is like casting String to ""
     
  3. Offline

    Barinade

    event.getPlayer().getLocation()
     
  4. Offline

    MordorKing78

    TheCodingCat Well, Actually Eclipse did that

    Barinade Can I put that in a Config file. And then if a player execute a command he will get teleported to that location
     
  5. MordorKing78 No you can't, Barinade likely didn't actually read your post. What you have looks fine to me (other than what TheCodingCat mentioned, I'd change that :p), does this not work?
     
  6. Offline

    MordorKing78

    AdamQpzm No, It did not work. I Tried it and it did not put anything in the Data.yml file.
    (Maybe smart to tell)
    I'm trying to do if you log off in a certain world your location will get saved. On login you will get teleported to the lobby. Then you can click on a Item that opens a GUI then you click on the Teleport me Back! button. ( [cake])
     
  7. MordorKing78 For a start, I'd suggest not loading the file & file configuration every time someone quits, there's no real need to do that - just load it in onEnable() if it's your main class, or in the constructor if it's not your main class :) If changing that still doesn't work, post your updated code and the errors you get (if any)
     
  8. Offline

    MordorKing78

    AdamQpzm What do you mean about the constr.? What constructor? :)
     
  9. MordorKing78 That's a pretty basic Java term, so if you don't know it, I'd recommend (re)learning the basics of Java because otherwise you'll just have problems, either from the Oracle tutorials or a Java book :) But I'm feeling generous so I'll tell you anyway: You probably already use constructors, they look something like this:

    PHP:
    public Listener(Main main) {
        
    this.main main;
    }
     
  10. Offline

    MordorKing78

    AdamQpzm I Know what a constructor is, But I don't see why that would change the problem
     
  11. Offline

    Watto

    MordorKing78

    It wouldn't but you're loading the configuration every time a player quits.. Which won't fix your problem but it's just something you should do to make your code better.
     
  12. Offline

    Luke_Lax

    I'm sorry for being off-topic but are you a 'dev' for 'MordorDev'?
     
  13. Offline

    MordorKing78

    Luke_Lax Its like 2 months ago I did java. But I just can get the job done. And im to lazy to find the problem. So why dont just post it to bukkit.org ;)

    To answer your question: Yes, I Am a dev for an Inactive Company. Requests will still be "solved" by another person. Not me :)
     
  14. Offline

    Luke_Lax


    Hm It's just I've seen you post here a couple times and I don't like seeing peoples kindness being abused because you'll be paid for their work essentially.

    I see you have removed that link from your signature which makes me believe even more that ^That^ is what you're doing :|

    (To everyone else his signature linked to http://www.mordordev.cf/ in which they charge people for plugins.)
     
  15. Offline

    RingOfStorms

    Honestly if someone helps someone else here on the public forums they've already given it away for free with no rights attached. Someone could take and sell all the code snippets from the forums and it really wouldn't matter. If people don't want their "hard work" taken then they won't post it in a public place.
     
  16. Offline

    Luke_Lax


    Yeah that's true and I understand but if you take from the community, it's nice to give back and help others and I know that some of these 'devs' that ask for money usually don't like to share/help, just from experience; I agree with your point though and that's the risk you take from helping here (if you want to call it a risk :p)
     
    MordorKing78 likes this.
  17. Offline

    MordorKing78

    Luke_Lax Yes, I Removed it because of this. Its inactive as a sloth. And I have been active for over 0.5 / 1 month now

    Why do you have to be so rude? Srsly man? Did I do something?
     
  18. Offline

    Luke_Lax

    I'm not being rude, sorry if you took it that way. I won't respond to this thread anymore to avoid any flaming.
     
Thread Status:
Not open for further replies.

Share This Page