Solved Saving a location and teleporting to it...

Discussion in 'Plugin Development' started by zwoosks, Aug 13, 2018.

Thread Status:
Not open for further replies.
  1. Hi guys! I'm making a plugin that requieres to save a location and then when you want to acces to that location you have to acces to config.yml and pass the variables to the Location object.

    The code: https://pastebin.com/ifbRyuvv

    Exactly I'm having problems because when I save a location and I try to acces it, the game teleports me to: (X:0, Y: 0, Z: 0

    Please help me! :)
     
  2. Offline

    timtower Administrator Administrator Moderator

    @zwoosks Because the location that you save probably doesn't make an X, Y and Z.
    It probably makes something else (just look in the config for it)
     
  3. I don't think so, the config.yml file is this:
    Code:
    users:
      zwoosks:
        ==: org.bukkit.Location
        world: asd
        x: -33.27910662145903
        y: 82.90382702707727
        z: 99.57957980460318
        pitch: 29.699993
        yaw: 19.500006
    
     
  4. Offline

    timtower Administrator Administrator Moderator

    @zwoosks That is a Location object, not something where you can get X, Y and Z.
    You need to get the Location from the config using get and then cast to Location (if it allows that)
    Or you need to store and load the x, y and z yourself.
     
  5. Pardon me if I do noob questins, I am new at this:
    how can I get the object? I have not understood well your question :rolleyes:


    I've just tried to get the object right this but it doesn't work:
    Code:
    Location welocation = (Location)getConfig().getList("users." + toTCPPlayer.getName().toLowerCase());
                                  
                                    player.teleport(welocation);
     
    Last edited: Aug 14, 2018
  6. Offline

    johnny boy

    might I add when you use getList it actually needs to be a list, and what you're trying to get is not a list. You need the path instead directly to it, so it would be users.user.x users.user.y users.user.z. if you want it to be a list add - before everything (I'm pretty sure). Have a look here for an example of a list: https://bukkit.org/threads/get-arraylist-of-config-yml.135118/
     
  7. Offline

    timtower Administrator Administrator Moderator

    @zwoosks What is stored is not a list. It is a single object.
     
  8. I did not explain it well, sorry :eek:. I only want to pass the object thtat is saved in the config.yml file to a Location object. I put ".getList()" but becausa I thought that it could get the object.
     
  9. Offline

    timtower Administrator Administrator Moderator

    @zwoosks That is why we have get("path")
     
  10. I've tryed it and no result.
    Code:
    Code:
    String pathX = "users." + toTCPPlayer.getName().toLowerCase() + ".x";
                                    String pathY = "users." + toTCPPlayer.getName().toLowerCase() + ".y";
                                    String pathZ = "users." + toTCPPlayer.getName().toLowerCase() + ".z";
                                   
                                    String pathWorld = "users." + toTCPPlayer.getName().toLowerCase() + ".world";
                                   
                                   
                                   
                                   
                                    String pathPitch = "users." + toTCPPlayer.getName().toLowerCase() + ".pitch";
                                    String pathYaw = "users." + toTCPPlayer.getName().toLowerCase() + ".yaw";
                                   
                                    String locWorldString = getConfig().getString(pathWorld);
                                    Double locX = getConfig().getDouble(pathX);
                                    Double locY = getConfig().getDouble(pathY);
                                    Double locZ = getConfig().getDouble(pathZ);
                                   
                                    float locPitch = (float)getConfig().getDouble(pathPitch);
                                    float locYaw = (float)getConfig().getDouble(pathYaw);
                                   
                                   
                                    Location l = new Location(Bukkit.getWorld(locWorldString), locX, locY, locZ, locPitch, locYaw);
    Error in minecraft chat: "An internal error ocurred while attempting to perform this command"

    Cmd error:
    [12:29:37 INFO]: zwoosks issued server command: /createcustomtp
    [12:29:45 INFO]: zwoosks issued server command: /customtp zwoosks
    [12:29:45 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'cust
    omtp' in plugin CustomTP v1.0
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra
    ftbukkit-1.8.jar:git-Bukkit-7019900e]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    0) ~[craftbukkit-1.8.jar:git-Bukkit-7019900e]
    at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServe
    r.java:625) ~[craftbukkit-1.8.jar:git-Bukkit-7019900e]
    at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:1058) [craftbukkit-1.8.jar:git-Bukkit-7019900e]
    at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    :919) [craftbukkit-1.8.jar:git-Bukkit-7019900e]
    at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(SourceFile:37) [craft
    bukkit-1.8.jar:git-Bukkit-7019900e]
    at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(SourceFile:9) [craftb
    ukkit-1.8.jar:git-Bukkit-7019900e]
    at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [cra
    ftbukkit-1.8.jar:git-Bukkit-7019900e]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_171]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_171]
    at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    56) [craftbukkit-1.8.jar:git-Bukkit-7019900e]
    at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:2
    84) [craftbukkit-1.8.jar:git-Bukkit-7019900e]
    at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:6
    09) [craftbukkit-1.8.jar:git-Bukkit-7019900e]
    at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :517) [craftbukkit-1.8.jar:git-Bukkit-7019900e]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_171]
    Caused by: java.lang.IllegalArgumentException: Name cannot be null
    at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[craftbu
    kkit-1.8.jar:git-Bukkit-7019900e]
    at org.bukkit.craftbukkit.v1_8_R1.CraftServer.getWorld(CraftServer.java:
    959) ~[craftbukkit-1.8.jar:git-Bukkit-7019900e]
    at org.bukkit.Bukkit.getWorld(Bukkit.java:504) ~[craftbukkit-1.8.jar:git
    -Bukkit-7019900e]
    at me.zwoosks.CustomTP.onCommand(CustomTP.java:111) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit-1.8.jar:git-Bukkit-7019900e]
    ... 14 more
    >
     
  11. Offline

    timtower Administrator Administrator Moderator

    @zwoosks If you do that then you need to save the location yourself, you can't get the X from the Location like that.
    You could try this:
    Code:
    Location loc = (Location)getConfig().get(path);
     
  12. Th
    Thanks! Now it works perfectly :)
     
  13. Offline

    KarimAKL

    @zwoosks Remember to change the title prefix to solved.
     
  14. Okay
     
Thread Status:
Not open for further replies.

Share This Page