Solved Apostrophe not adding to config? ('T_T)

Discussion in 'Plugin Development' started by ZomBlade_Shadow, Jun 6, 2015.

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

    ZomBlade_Shadow

    Hi!
    I'm struggling alot, so imma need yo' help please!

    Basically I'm making a command, that sets an arena spawn, blablabla..

    AND when saving the world, I found out by testing, that when I don't have apostrophes to strings in the config, the world doesn't work.

    The code I use:
    Code:
          Player p = (Player) sender;
          String theworld = "'" + p.getWorld().getName() + "'"; //adding the apostrophes, because if I don't do that, no apostrophes appear.
          pl.spawncfg.set("Spawn." + "world", theworld);
          pl.spawncfg.set("Spawn." + "x", p.getLocation().getX());
          pl.spawncfg.set("Spawn." + "y", p.getLocation().getY());
          pl.spawncfg.set("Spawn." + "z", p.getLocation().getZ());
          pl.spawncfg.set("Spawn." + "yaw", p.getLocation().getYaw());
          pl.spawncfg.set("Spawn." + "pitch", p.getLocation().getPitch());
    The result of that:
    Code:
    Spawn:
      world: '''world'''  //Notice 3 FRIGGEN APOSTROPHES!
      x: -191.01642200351557
      y: 74.0
      z: 257.3366476924846
      yaw: 164.85855
      pitch: 90.0

    What I used before:
    Code:
          Player p = (Player) sender;
          pl.spawncfg.set("Spawn." + "world", p.getWorld().getName()); //Just the name
          pl.spawncfg.set("Spawn." + "x", p.getLocation().getX());
          pl.spawncfg.set("Spawn." + "y", p.getLocation().getY());
          pl.spawncfg.set("Spawn." + "z", p.getLocation().getZ());
          pl.spawncfg.set("Spawn." + "yaw", p.getLocation().getYaw());
          pl.spawncfg.set("Spawn." + "pitch", p.getLocation().getPitch());
    The result of that:
    Code:
    Spawn:
      world: world  //Notice NO FRIGGEN APOSTROPHES!
      x: -191.01642200351557
      y: 74.0
      z: 257.3366476924846
      yaw: 164.85855
      pitch: 90.0

    I just can't get it to put 1 apostrophe on each side D:

    like:
    Code:
    Spawn:
      world: 'world'  //I Need 1 apostrophe en each side for my code to work, anyone know how to?
    

    Thanks a LOT for your help!
     
  2. Offline

    Zombie_Striker

    @ZomBlade_Shadow
    Have you ever tried using the official way of using apostrophes ( " \' ")? Apostrophes are used to encapsulate chars normally.
     
  3. Offline

    ZomBlade_Shadow

    I still get the same 3 apostrophes on each side after doing
    String theworld = "\'" + p.getWorld().getName() + "\'";

    :/ Thanks for helping anyway!
     
  4. Offline

    xTigerRebornx

  5. Offline

    ZomBlade_Shadow

    I've been testing this for like hours now.
    When doing getServer().getWorld(string), it wont work if the world name doesn't have apostrophes in the config.
     
  6. Offline

    xTigerRebornx

    @ZomBlade_Shadow Can you show how you are getting the actual String from the config and what the config is at the time?
     
  7. Offline

    ZomBlade_Shadow

    That's not a problem, When I set the spawn, it doesn't work, but when I manually add apostrophes, it works.

    Anyone know how to? :/
     
  8. Offline

    Zombie_Striker

    @ZomBlade_Shadow
    Actually, I have no idea why you would need only one apostrophe for this. It's returning a string and unless the worlds name has apostrophes (which it shouldn't naturally), having none should be fine.

    Btw, are you saving the string using " " or ' '?
     
  9. Offline

    ZomBlade_Shadow

    I'm using ""
    I can't get it to work :/ any1 know how?
     
  10. Offline

    Zombie_Striker

    Does it work if it does not have the apostrophes? If you're using it as a string, you can add them after you get the name from the config. If you want to get a world, then you should not have them.
     
  11. Offline

    Konato_K

  12. Offline

    ZomBlade_Shadow

    Can you talk about it in detail pls?


    How exactly?
    Can you explain? :) I'm struggling

    REMOVE SORRY DOUBLE POST

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

    Zombie_Striker

    Do what you would normally do with that string, and see what happens. Does it work if you don't care about the apostrophes? What are you using the name of the world for? Does it work the way it is now if you don't care how it looks.
     
  14. Offline

    ZomBlade_Shadow

    IT doesn't work without apostrophes, so when I manually add them, it works

    Help pls :) still looking for it :/

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

    Konato_K

  16. Offline

    ZomBlade_Shadow

    I don't think you understood.
    I'm setting the name for a world, but the world has to be in between 2 apostrophes.
    When I do
    Code:
    "'" + p.getWorld().getName() + "'"
    I get 3 apostrophes on each side.
    When I do
    Code:
    p.getWorld().getName()
    I get no apostrophes.

    HOW do I put 1 apostrophes on each side?
     
  17. Offline

    Konato_K

  18. Offline

    ZomBlade_Shadow

    I've said it over and over x)
    Because it doesn't get the world if the name isn't in between.

    Can't anyone find a solution please? It's really urgent :c
     
  19. Offline

    Konato_K

    @ZomBlade_Shadow
    Code:
    Spawn:
      world: world
    parses fine for the default configuration API, how are you getting the value?
     
  20. Offline

    mythbusterma

  21. Offline

    ZomBlade_Shadow

    Thanks for that!
    But I HAVE to keep the Locations as a cfg file.
    I just need to know how to put those apostrophes, any1 know how?

    It's amazing how bukkit can do very complicated serializations, but yet there's a crappy bug in bukkit like adding an apostrophy.

    @Konato_K I'm getting it with getServer().getWorld(spawncfg.getString("Spawn." + "world"))

    spawncfg is the config file, no problems there
     
    Last edited: Jun 6, 2015
  22. Offline

    mythbusterma

    @ZomBlade_Shadow

    It's not anything to do with Bukkit or crappiness, it has to do with the YAML specification. Also, why can't you put it in a YAML file....?
     
  23. Offline

    ZomBlade_Shadow

    It's a yml file, yes.
    Isn't it maybe the way I get the string?
    Code:
    getServer().getWorld(spawncfg.getString("Spawn." + "world"))
     
  24. Offline

    mythbusterma

    @ZomBlade_Shadow

    You do realise that you're using "world" in that context as a string literal, correct?

    Also, you use the ConfigurationSerializable to create a standardised way of saving and loading from configuration files.
     
  25. @ZomBlade_Shadow You're trying to force YAML to put the apostrophes in, but it thinks you want actual apostrophes. That's why you're getting three, as a double apostrophe is how you escape an apostrophe in YAML, as has been suggested above.

    If you're having trouble retrieving the String, then it's probably the way you're trying to retrieve it that's at fault. Funnily enough, the YAML library knows the specification for YAML, and wouldn't save it in a format that it couldn't read ;)
     
  26. Offline

    ZomBlade_Shadow

    Thanks for the response =)
    I looked closely and though that if I do
    Code:
    pl.spawncfg.set("Spawn." + "world", p.getWorld().getName());
    and the name of the world saved was world:

    Code:
    Spawn:
      world: world
      x: -210.83673085215574
      y: 67.0
      z: 239.81046698830733
      yaw: -82.82616
      pitch: -10.757461
    
    It might actually interfere and get the second "world", here:

    Spawn:
    world: world
    x: -210.83673085215574
    y: 67.0
    z: 239.81046698830733
    yaw: -82.82616
    pitch: -10.757461


    And since it doesn't have children it'll return null?

    Yup, I was right, I saved it like this:

    Spawn:
    TheWorld: world
    x: -210.83673085215574
    y: 67.0
    z: 239.81046698830733
    yaw: -82.82616
    pitch: -10.757461


    And it works!
    Thanks everybody! :D
     
Thread Status:
Not open for further replies.

Share This Page