Best way to save a id with locations

Discussion in 'Plugin Development' started by DaanSander, Mar 27, 2015.

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

    DaanSander

    Hello i am trying to make a minigame plugin but what is the best way to save the mainlocation just 1

    i already tried this:
    Code:
    if(cmd.getName().equalsIgnoreCase("creata") && sender instanceof Player) {
                Player p = (Player) sender;
                int i = Integer.parseInt(args[0]);
                if(!Em.config.contains(args[0])) {
                    new Arena(i, p.getLocation());
                    Location loc = p.getLocation();
                    String world = p.getWorld().getName();
                    double x = loc.getX();
                    double y = loc.getY();
                    double z = loc.getZ();
                    Em.config.set(args[0], "spawn.");
                    Em.config.set("spawn.", "world");
                    Em.config.set("spawn.", "x.");
                    Em.config.set("spawn.", "y.");
                    Em.config.set("spawn.", "z.");
                    Em.config.set("world.", world);
                    Em.config.set("x.", x);
                    Em.config.set("y.", y);
                    Em.config.set("z.", z);
                    Em.plugin.saveConfig();
                    p.sendMessage(p.getLocation().toString());
                    return true;
                } else {
                    p.sendMessage("Name error");
                    return true;
                }
            }
    sorry for bad english
     
  2. Offline

    Jacc734

    What I do when I need to store location info is make a single class file that stores all the data in an class object, via Serialization, but I am usually working with multiple locations so that might not be the most efficient thing for you to do, but it is quick and painless for saving info.
    Example:
    Code:
    public class Rift implements Serializable {
       String world;
       int x, y, z;
       int radius;
       int riftID;
       
       Rift(int riftID, int x, int y, int z, int radius, String world) {
         this.x = x;
         this.y = y;
         this.z = z;
         this.radius = radius;
         this.world = world;
         this.riftID = riftID;
       }
    [code]
     
  3. Offline

    nverdier

    @DaanSander Just use FileConfiguration#set("x", loc.getX()), #set("y", loc.getY()) and so on.
     
Thread Status:
Not open for further replies.

Share This Page