Solved Which data base should i choose in my plugin?

Discussion in 'Plugin Development' started by f1oating, Aug 11, 2023.

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

    f1oating

    Hi, i want to create a /sethome plugin, but i need to store a data of players sethomes in a file. What file type shoud i choose ? For example: json, sqlite, txt and other. Maybe you also could help me how better write data in this file ? my idea:
    playername:
    x:
    y:
    z:
    world:

    What can go wrong with my blueprint of data writting ?
    I am ukranian, sorry for my english. I hope you understand what i mean.
     
  2. Online

    timtower Administrator Administrator Moderator

    f1oating likes this.
  3. Offline

    f1oating

  4. Offline

    Strahan

    I agree with timtower, just use yaml. However don't do the data like this. You lose precision, and there is no need to manually serialize it as Location implements ConfigurationSerializable. In other words, just read/write the Location object directly. Like:
    Code:
    switch (cmd.getName().toLowerCase()) {
    case "spawn":
      Location spawn = plugin.getConfig().getLocation("spawn");
      if (spawn == null) {
        player.sendMessage("I'm sorry, I cannot send you to spawn at this time!");
        return true;
      }
    
      player.teleport(spawn);
      break;
    
    case "setspawn":
      plugin.getConfig().set("spawn", player.getLocation());
      player.sendMessage("Spawn set!");
      break;
    }
    If you are developing for Minecraft that is old, it may not have the getLocation method. In that case, you just need to do a little more work:
    Code:
    Object spawn = plugin.getConfig().get("spawn");
    if (!(spawn instanceof Location)) {
      // throw error
    }
    
    player.teleport((Location)spawn);
     
    f1oating likes this.
  5. Offline

    f1oating

    @Strahan thank you, could you also say me what library should i use to work with yaml , and data structure to store plyers homes?
     
  6. Offline

    Strahan

    It's built in. The plugin instance has a "getConfig()" method which exposes the configuration object you can use to manipulate the file.
     
Thread Status:
Not open for further replies.

Share This Page