Solved Set a string / register to config

Discussion in 'Plugin Help/Development/Requests' started by FreeMotion45, Oct 13, 2015.

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

    FreeMotion45

    Hello.

    The title says pretty much everything.
    So I followed tutorials and I used this :
    Code:
                        World world = p.getWorld();
                        double x = p.getLocation().getX();
                        double y = p.getLocation().getY();
                        double z = p.getLocation().getZ();
                        float yaw = p.getLocation().getYaw();
                        float pitch = p.getLocation().getPitch();
                        getConfig().set("global_x", x);
                        getConfig().set("global_y", y);
                        getConfig().set("global_z", z);
                        getConfig().set("global_yaw", yaw);
                        getConfig().set("global_pitch", pitch);
                        getConfig().set("global_world", world);
    Maybe I may be wrong somewhere. The command itself works fine. But it won't set the string of global_x to where the player is, (double x = p.getLocation().getX().

    In the config itself all the string parameters are like this:
    Code:
    global_x: enable_to_use
    global_y: enable_to_use
    global_z: enable_to_use
    global_yaw: enable_to_use
    global_pitch: enable_to_use
    global_world: enable_to_use
    And to get teleport the player to the location he set is to I use this :
    Code:
                double x = getConfig().getDouble("global_x");
                double z = getConfig().getDouble("global_z");
                double y = getConfig().getDouble("global_y");
                double pitch = getConfig().getDouble("global_pitch");
                double yaw = getConfig().getDouble("global_yaw");
                World world = (World) getConfig().get("world");
                Location gs = new Location(world, x, y, z);
                p.teleport(gs);
                p.getLocation().setYaw((float) yaw);
                p.getLocation().setPitch((float) pitch);
    Sorry if I sound like a super beginner.
     
  2. Offline

    DrkMatr1984

    Hmm, well, first thing I would do is put a debug message under double x = p.getLocation().getX(); that does a p.sendMessage(x.toString()); to make sure you are actually getting the x location. You may have to store your data also differently, because I think by default yml will try to store those values in a string format without doing Double.valueOf(double d); Try something like this :

    Code:
    World world = p.getWorld();
    double x = p.getLocation().getX();
    double y = p.getLocation().getY();
    double z = p.getLocation().getZ();
    float yaw = p.getLocation().getYaw();
    float pitch = p.getLocation().getPitch();
    getConfig().set("global_x", Double.valueOf(x));
    getConfig().set("global_y", Double.valueOf(y));
    getConfig().set("global_z", Double.valueOf(z));
    getConfig().set("global_yaw", Double.valueOf(yaw));
    getConfig().set("global_pitch", Double.valueOf(pitch));
    getConfig().set("global_world", world.toString());
    
    Then try to retrieve them same as you have, but do a
    World world = Bukkit.getServer().getWorld(getConfig().get("world"));
    instead of
    World world = (World) getConfig().get("world");

    Let me know if this helps!
     
  3. Offline

    FreeMotion45

    Hey I've done those steps, but it still doesn't work.
    I noticed it says in the console that is misread config.yml from the plugin jar file.
     
  4. Offline

    DrkMatr1984

    Hmmm, post the whole class.
     
  5. Offline

    Scorpionvssub

    Try getserver.getworld(getconfig.getstring("world")); with the right capitals and all ofcourse. as you try to get a string it might help to tell it to "get" a "string"
     
  6. Offline

    DrkMatr1984

    What this guy said might help also. But post ur whole class anyway if it doesn't work still.
     
  7. Offline

    Scorpionvssub

    @FreeMotion45

    The following is from a method i use for my parkour plugin which stores the xyz and world under the arena name, while serialize does that too i like to simplify it for myself but these work..

    if i set an arena using this it will store whatever the "name" is under /pk create <name> then the location i am standing.

    First is used to teleport to said arena name using the locations specified in config and second is set the location of the player using the pk create command. Should be self explainatory

    Code:
               double x = plugin.arenas.getDouble("arena." + name + ".x");
                double y = plugin.arenas.getDouble("arena." + name + ".y");
                double z = plugin.arenas.getDouble("arena." + name + ".z");
                World w = Bukkit.getWorld(plugin.arenas.getString("arena." + name + ".w"));
    Code:
            plugin.arenas.set("arena." + name + ".x", Double.valueOf(loc.getX()));
            plugin.arenas.set("arena." + name + ".y", Double.valueOf(loc.getY()));
            plugin.arenas.set("arena." + name + ".z", Double.valueOf(loc.getZ()));
            plugin.arenas.set("arena." + name + ".w", loc.getWorld().getName());
    Then the config returns this:
    Code:
      Adventure1:
        x: 3.5502862289866104
        y: 65.0
        z: 51.60202076154757
        w: ParkourArenas
     
  8. Offline

    FreeMotion45

    Okay so I got 1 thing right.
    Now I am have a problem that I need to get the world from the config. I use this :
    Code:
                        World world = getServer().getWorld("global_world");
                        Location gog = new Location(world, x, y, z, (float)yaw2, (float)pitch2);
                        p.teleport(gog);
    But I cant teleport the player to there :\
    Problem at :
    Code:
    p.teleport(gog);
    Problem is in the console not in the plugin.
    Code:
    [17:58:36 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'bsrgog' in plugin BasicSpawnReloaded v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[Bukkitserver.jar:git-Bukkit-efd6cb0]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[Bukkitserver.jar:git-Bukkit-efd6cb0]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:620) ~[Bukkitserver.jar:git-Bukkit-efd6cb0]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1106) [Bukkitserver.jar:git-Bukkit-efd6cb0]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:966) [Bukkitserver.jar:git-Bukkit-efd6cb0]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [Bukkitserver.jar:git-Bukkit-efd6cb0]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [Bukkitserver.jar:git-Bukkit-efd6cb0]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [Bukkitserver.jar:git-Bukkit-efd6cb0]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_60]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_60]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [Bukkitserver.jar:git-Bukkit-efd6cb0]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:673) [Bukkitserver.jar:git-Bukkit-efd6cb0]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [Bukkitserver.jar:git-Bukkit-efd6cb0]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [Bukkitserver.jar:git-Bukkit-efd6cb0]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [Bukkitserver.jar:git-Bukkit-efd6cb0]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_60]
    Caused by: java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer.teleport(CraftPlayer.java:460) ~[Bukkitserver.jar:git-Bukkit-efd6cb0]
            at org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity.teleport(CraftEntity.java:226) ~[Bukkitserver.jar:git-Bukkit-efd6cb0]
            at me.FreeMotion.BSR.bsrMain.onCommand(bsrMain.java:189) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[Bukkitserver.jar:git-Bukkit-efd6cb0]
            ... 15 more
    Thanks for helping :)
     
Thread Status:
Not open for further replies.

Share This Page