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



    The title says pretty much everything.
    So I followed tutorials and I used this :
                        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:
    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 :
                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.getLocation().setYaw((float) yaw);
                p.getLocation().setPitch((float) pitch);
    Sorry if I sound like a super beginner.
  2. Offline


    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 :

    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


    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


    Hmmm, post the whole class.
  5. Offline


    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


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



    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

               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"));
            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:
        x: 3.5502862289866104
        y: 65.0
        z: 51.60202076154757
        w: ParkourArenas
  8. Offline


    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 :
                        World world = getServer().getWorld("global_world");
                        Location gog = new Location(world, x, y, z, (float)yaw2, (float)pitch2);
    But I cant teleport the player to there :\
    Problem at :
    Problem is in the console not in the plugin.
    [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( ~[Bukkitserver.jar:git-Bukkit-efd6cb0]
            at org.bukkit.command.SimpleCommandMap.dispatch( ~[Bukkitserver.jar:git-Bukkit-efd6cb0]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand( ~[Bukkitserver.jar:git-Bukkit-efd6cb0]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand( [Bukkitserver.jar:git-Bukkit-efd6cb0]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a( [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$ [Bukkitserver.jar:git-Bukkit-efd6cb0]
            at java.util.concurrent.Executors$ Source) [?:1.8.0_60]
            at 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( [Bukkitserver.jar:git-Bukkit-efd6cb0]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B( [Bukkitserver.jar:git-Bukkit-efd6cb0]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A( [Bukkitserver.jar:git-Bukkit-efd6cb0]
            at [Bukkitserver.jar:git-Bukkit-efd6cb0]
            at Source) [?:1.8.0_60]
    Caused by: java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer.teleport( ~[Bukkitserver.jar:git-Bukkit-efd6cb0]
            at org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity.teleport( ~[Bukkitserver.jar:git-Bukkit-efd6cb0]
            at me.FreeMotion.BSR.bsrMain.onCommand( ~[?:?]
            at org.bukkit.command.PluginCommand.execute( ~[Bukkitserver.jar:git-Bukkit-efd6cb0]
            ... 15 more
    Thanks for helping :)
Thread Status:
Not open for further replies.

Share This Page