How to Store a Position in SQL/Config File?

Discussion in 'Spigot Plugin Development' started by RoiEX, May 19, 2016.

  1. Hi there,
    I'm currently developing - well my first spigot plugin (don't get this wrong - it's not me beginning to learn java, it's me beginning to learn the Spigot API), and I wondered how I could store a Position of a in game location in a SQL Database...
    2 Things:
    1. I know that there are some plugins which leave it up to you if you want to use SQL (e.g. if you don't provide any SQL server it will not use one). Is this a Thing done by default, or is this just the developer using a config file or whatever instead?
    2. Now we're coming to my problem:
    • I want to create a Minigame which leaves it up to you to build the Map. For this Minigame I need let's call it Spawnpoints which are stored in a Collection of Location objects. To Construct a Location object I need 2 Things - The x,y,z Coordinates and the World... The Coordinates are easy to store since they're just numbers, but how would I store the world Object, so my "Spawnpoints" will still work properly on multiworld servers?
     
  2. 1. This is done manually by the developer. You can handle that the way you want
    2. Worlds have a unique (in theory) name. You can therefore only store that name in the SQL database, and when you load it you can use .getWorld(worldname)
     
    • Like Like x 1
    • Agree Agree x 1
  3. Ah Thanks. That's exactly what I needed.
     
  4. Store the worldname,x,y,z,yaw,pitch however you want and then create a new Location object
    Code (Text):
    Location loc = new Location(Bukkit.getWorld(worldName), x, y, z, yaw, pitch);
     
  5. Yes I know ^^ But I actually don't need a pitch and yaw
     
  6. You can do something like that:


    Code (Text):
    Location loc;

    loc.getX;

    // You could repeat this for everything you need to store.
    I would write a function for that so you can repeat the whole task easily.