Solved Saving a config on player disconnecting

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

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

    MordorKing78

    So what I'm trying to do is when a player disconnects in a world ("String.World") his location will get saved.

    (I Think I already posted this but I couldnt find it again so.. Sorry if I did already!!! : English is not my main language)

    Some code I tried:
    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. }
     
  2. Offline

    Skionz

    MordorKing78 What doesn't work about it? And why are you attempting to turn X, Y, and Z into doubles if they already are doubles? Shouldn't you be getting a syntax error?
     
  3. Offline

    MordorKing78

    Skionz No. I Don't.. I'm using this method on a /setlobby command and that works fine.
    It just does save or its not there in the config.
     
  4. Offline

    Skionz

    My bad, the valueOf method can take a double as a parameter as well as a string. What is SaveNC()? And can you try debugging to check if the method is event being called.

    Its also good practice to keep the first letter of variable names and method names lowercase such as doStuff() instead of DoStuff(). It can confuse other developers because usually classes are capitalized.
     
  5. Offline

    MordorKing78

    What I'm trying to do:
    So I have this world (Lobby). When a player logs of in the lobby his location will not get saved. But when he is in the "Skim" world his location when he disconnects will get saved. When he gets back he will get teleported to the main lobby. Then he clicks on a emerald thats in his inventory (Right Click). Then he gets teleported to the saved location.

    (Do you understand :D?)

    Skionz
    SaveNC();
    is this:
    Code:java
    1. public void SaveNC(){
    2. try {
    3. CZ.save(C);
    4. } catch (IOException e) {
    5. // TODO Auto-generated catch block
    6. e.printStackTrace();
    7. }
    8. }

    Its just a saving method. PS: Il keep it in mind for the next time. :p (saveNC)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  6. Offline

    Skionz

    Do a simple check to see if the player's world's name equals "Skim" but I still need you too debug to see if your event is being called.
     
  7. Offline

    MordorKing78

    X Noobish Post FTW X
     
  8. Offline

    Skionz

    Print messages to the console
     
  9. Offline

    MordorKing78

    Skionz Just tried this, System.out.println("Player just log off.");
    But didn't do anything.. But I dont understand why.. Because I have another event in that class and that event just works..
     
  10. Offline

    Skionz

    MordorKing78 likes this.
  11. Offline

    Gater12

    MordorKing78
    Do you have your EventHandler annotation on, mate?
     
    MordorKing78 likes this.
  12. Offline

    MordorKing78

    Gater12 Skionz Are you shitting me.. :O I hate my life.. XD

    Here you go 2x [cake]
    If you like healthy food here is some [wheatsprout]salad
     
    Skionz likes this.
Thread Status:
Not open for further replies.

Share This Page