Solved Delete Value From YamlConfiguration

Discussion in 'Plugin Development' started by Meatiex, Jan 2, 2015.

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

    Meatiex

    How would I remove a value from a YamlConfiguration()?

    I want to be able to delete warps
    Here is my code:
    Code:
        public static void create(String warp, Location loc) {
             try {
                 YamlConfiguration c = YamlConfiguration.loadConfiguration(new File(System.getProperty("user.dir") + "/plugins/Project4/", "warps.yml"));
                    c.set(warp + ".world", loc.getWorld().getName());
                    c.set(warp + ".x", loc.getX());
                    c.set(warp + ".y", loc.getY());
                    c.set(warp + ".z", loc.getZ());
                    c.set(warp + ".yaw", loc.getYaw());
                    c.set(warp + ".pitch", loc.getPitch());
                    c.save(new File(System.getProperty("user.dir") + "/plugins/Project4/", "warps.yml"));
                } catch (Exception e) {}
        }
       
        public static Location read(String warp) {
            try {
            YamlConfiguration c = YamlConfiguration.loadConfiguration(new File(System.getProperty("user.dir") + "/plugins/Project4/", "warps.yml"));
           
            World world = Bukkit.getWorld(c.get(warp + ".world").toString());
            double x = Double.parseDouble(c.get(warp + ".x").toString());
            double y = Double.parseDouble(c.get(warp + ".y").toString());
            double z = Double.parseDouble(c.get(warp + ".z").toString());
            float yaw = Float.parseFloat(c.get(warp + ".yaw").toString());
            float pitch = Float.parseFloat(c.get(warp + ".pitch").toString());
           
            Location loc = new Location(world, x, y, z);
            loc.setPitch(pitch);
            loc.setYaw(yaw);
            return loc;
           
        } catch (Exception e) {}
            return null;
        }
     
  2. Offline

    Skionz

    Meatiex likes this.
  3. Offline

    Meatiex

    Thanks :D
     
  4. Offline

    teej107

    @Meatiex Set the thread to solved then?
     
    Meatiex likes this.
Thread Status:
Not open for further replies.

Share This Page