YML Manager

Discussion in 'Plugin Development' started by Fhbgsdhkfbl, Jun 17, 2016.

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

    Fhbgsdhkfbl

    So one of my friends coded a YMLManager and FileManager for me, and I'm using it for my housepoints plugin, can someone explain to me why it's not creating the files but instead of just saving it? I can't use it on my public server, only on my test server cause the way the hoster manages files

    Yml Manager:
    Code:
    package me.Fhbgsdhkfbll.Points;
    
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.util.Set;
    
    import org.bukkit.configuration.InvalidConfigurationException;
    import org.bukkit.configuration.file.YamlConfiguration;
    
    public class YamlFile extends YamlConfiguration {
    
        private File              file;
        private YamlConfiguration configuration;
        private int               saveQue, count;
    
        public YamlFile(File file){
            this.file = file;
            configuration = new YamlConfiguration();
            saveQue = 0;
            count = saveQue;
            reload();
        }
    
        public YamlFile(File file, int saveQue){
            this.file = file;
            this.saveQue = saveQue;
            count = 0;
            configuration = new YamlConfiguration();
            reload();
        }
    
        /**
         * Gets an object from the file at the specified path.
         */
        @Override
        public Object get(String path){
            return configuration.get(path);
        }
    
        /**
         * Gets a boolean from the file at the specified path.
         */
        @Override
        public boolean getBoolean(String path){
            return configuration.getBoolean(path);
        }
    
        public float getFloat(String path){
            try {
                return Float.parseFloat(configuration.getString(path));
            } catch(Exception e) {
                System.err.println("Error getting float from config:");
                System.err.println(" File: " + file.getPath().toString());
                System.err.println(" Path: " + path);
                e.printStackTrace();
            }
            return 0f;
        }
    
        /**
         * Gets a double from the file at the specified path.
         */
        @Override
        public double getDouble(String path){
            return configuration.getDouble(path);
        }
    
        /**
         * Gets an int from the file at the specified path.
         */
        @Override
        public int getInt(String path){
            return configuration.getInt(path);
        }
    
        /**
         * Gets a String from the file at the specified path.
         */
        @Override
        public String getString(String path){
            return configuration.getString(path);
        }
    
        /**
         * Reloads the file tied to the YamlFile.
         */
        public void reload(){
            try {
                configuration.load(file);
            } catch(FileNotFoundException e) {
                e.printStackTrace();
            } catch(IOException e) {
                e.printStackTrace();
            } catch(InvalidConfigurationException e) {
                e.printStackTrace();
            }
        }
    
        /**
         * Saves any updated information to the file.
         */
        public void save(){
            try {
                configuration.save(file);
            } catch(IOException e) {
                e.printStackTrace();
            }
        }
    
        /**
         * Adds/Updates information to the file at the specified path
         */
        @Override
        public void set(String path, Object item){
            configuration.set(path, item);
            if(count == saveQue) {
                save();
                reload();
                count = 0;
            } else {
                count++;
            }
        }
    
        /**
         * Gets the nodes from a yaml file.
         * @param path What to search in.
         * @param deep True if you want to go down multiple levels.
         * @return Returns a set of the keys (and their children if deep is true).
         */
        public Set<String> getKeys(String path, boolean deep){
            return configuration.getConfigurationSection(path).getKeys(deep);
        }
    
    }
    FileManager:
    Code:
    package me.Fhbgsdhkfbll.Points;
    
    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class FileManager {
        public static boolean debugInfo = false;
    
        public static String  dataFolder;
       
        public static void init(JavaPlugin plugin){
            dataFolder = new FileManager().getDataFolderPath(plugin);
        }
       
        public String getDataFolderPath(JavaPlugin plugin){
            try{
                if(new File(plugin.getDataFolder().getParent()).exists() && plugin.getDataFolder().getParentFile().isDirectory())
                    return plugin.getDataFolder().toString().replaceAll("\\", "/");
            }catch(Exception e){}
           
            String[] split = getClass().getProtectionDomain().getCodeSource().getLocation().toString().split("/");
            String path = "";
            for(String dir : split){
                if(new File(path + dir).isDirectory()){
                    path += dir + "/";
                }
            }
            return "/" + path +  split[split.length - 1].substring(0, split[split.length - 1].length() - 4);
        }
    
        /**
         * @param path - Create folders down the path provided
         * @return The result of making the directories
         */
        public static boolean createFolders(String path){
            File f = new File(dataFolder + "/" + path);
            Boolean b = f.mkdirs();
            return b;
        }
    
        public static boolean deleteFile(String path){
            File f = new File(dataFolder + "/" + path);
    
            if(f.isFile()) {
                return f.delete();
            }
    
            return false;
        }
    
        /**
         * @param path - Path of the file to check.
         * @return Whether the file exists or not.
         */
        public static boolean fileExists(String path){
            File f = new File(dataFolder + "/" + path);
    
            Boolean b = f.exists();
            return b;
        }
    
        /**
         * @param path - Path to the file as a string
         * @return The file unless there was an error
         */
        public static File getFile(String path, Boolean create){
            File f = new File(dataFolder + "/" + path);
    
            try {
                if(create) {
                    String[] dirs = (dataFolder + "/" + path).split("/");
                    String tempPath = "";
                    File tempFile;
                    for(String dir : dirs){
                        if(!fileExists(dir) && !dir.contains(".")){
                            tempFile = new File(String.format("%s/%s", tempPath, dir));
                            tempFile.mkdir();
                        }
                        tempPath += dir + "/";
                    }
                    f.createNewFile();
                }
                return f;
            } catch(IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    
        /**
         * @param path
         * @return A list of files in the directory
         */
        public static File[] getFolderFiles(String path){
            File directory = new File(dataFolder + "/" + path);
    
            if(directory.isDirectory()) {
    
                ArrayList<File> files = new ArrayList<File>();
    
                for(File f : directory.listFiles()) {
                    if(!f.isDirectory())
                        files.add(f);
                }
    
                return files.toArray(new File[files.size()]);
    
            }
    
            return null;
        }
    
        /**
         * @param path
         * @return A list of the folders in the directory
         */
        public static File[] getFolderFolders(String path){
            File directory = new File(dataFolder + "/" + path);
    
            if(directory.isDirectory()) {
    
                ArrayList<File> folders = new ArrayList<File>();
    
                for(File f : directory.listFiles()) {
                    if(f.isDirectory())
                        folders.add(f);
                }
    
                return folders.toArray(new File[folders.size()]);
    
            }
    
            return null;
        }
    
    }
    
    And my onEnable

    Code:
    public void onEnable(){
            instance = this;
            houses = new ArrayList<String>();
            houses.add("Slytherin");
            houses.add("Gryffindor");
            houses.add("Ravenclaw");
            houses.add("Hufflepuff");
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            FileManager.init(this);
            // Initialize the file if it doesn't exist
            if(!FileManager.fileExists("signs.yml")) {
                FileManager.getFile("signs.yml", true);
            }
            if(!FileManager.fileExists("points.yml")) {
                YamlFile file = new YamlFile(FileManager.getFile("points.yml", true));
                for(String s : houses)
                    file.set(s, 0);
            }
            if(!FileManager.fileExists("strings.yml")) {
                YamlFile file = new YamlFile(FileManager.getFile("strings.yml", true));
                file.set("enter_valid_house", enterValidHouse);
                file.set("points_added_to_house", addedTo);
                file.set("points_removed_from_house", removedFrom);
                file.set("greater_than_zero", greaterThanZero);
                file.set("sign_created", signCreated);
            }else{
                YamlFile file = new YamlFile(FileManager.getFile("strings.yml", false));
                enterValidHouse = file.getString("enter_valid_house");
                addedTo = file.getString("points_added_to_house");
                removedFrom = file.getString("points_removed_from_house");
                greaterThanZero = file.getString("greater_than_zero");
                signCreated = file.getString("sign_created");
            }
            if(!FileManager.fileExists("config.yml")) {
                YamlFile file = new YamlFile(FileManager.getFile("config.yml", true));
                file.set("staff_permission", permission);
                file.set("sign_command", signCommand);
            }else{
                YamlFile file = new YamlFile(FileManager.getFile("config.yml", false));
                permission = file.getString("staff_permission");
                signCommand = file.getString("sign_command");
            }
        }
     
  2. Offline

    Zombie_Striker

    @Fhbgsdhkfbl
    As has been said in the previous thread, you cannot create a file because of the Host. That is beyond what any plugins can do.

    To save values to a config, you need to save the config right after you make any changes to the config. From what I see ,you are only calling the set method, and you not the save method. Add "file.save()" after you set any value to the config.
     
  3. Offline

    Fhbgsdhkfbl

    @Zombie_Striker
    Well I did that, and I get this error still
    Code:
    17.06 15:26:22 [Server] WARN at java.lang.Thread.run(Thread.java:745)
    17.06 15:26:22 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557)
    17.06 15:26:22 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654)
    17.06 15:26:22 [Server] WARN at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374)
    17.06 15:26:22 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715)
    17.06 15:26:22 [Server] WARN at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44)
    17.06 15:26:22 [Server] WARN at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    17.06 15:26:22 [Server] WARN at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    17.06 15:26:22 [Server] WARN at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13)
    17.06 15:26:22 [Server] WARN at net.minecraft.server.v1_8_R3.PacketPlayInBlockDig.a(SourceFile:10)
    17.06 15:26:22 [Server] WARN at net.minecraft.server.v1_8_R3.PacketPlayInBlockDig.a(SourceFile:40)
    17.06 15:26:22 [Server] WARN at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:623)
    17.06 15:26:22 [Server] WARN at net.minecraft.server.v1_8_R3.PlayerInteractManager.a(PlayerInteractManager.java:121)
    17.06 15:26:22 [Server] WARN at net.minecraft.server.v1_8_R3.PlayerInteractManager.breakBlock(PlayerInteractManager.java:286)
    17.06 15:26:22 [Server] WARN at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487)
    17.06 15:26:22 [Server] WARN at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502)
    17.06 15:26:22 [Server] WARN at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    17.06 15:26:22 [Server] WARN at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306)
    17.06 15:26:22 [Server] WARN at java.lang.reflect.Method.invoke(Method.java:497)
    17.06 15:26:22 [Server] WARN at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    17.06 15:26:22 [Server] WARN at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    17.06 15:26:22 [Server] WARN at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    17.06 15:26:22 [Server] WARN at me.Fhbgsdhkfbll.Points.HousePoints.signBreak(HousePoints.java:293)
    17.06 15:26:22 [Server] WARN at me.Fhbgsdhkfbll.Points.YamlFile.<init>(YamlFile.java:22)
    17.06 15:26:22 [Server] WARN at me.Fhbgsdhkfbll.Points.YamlFile.reload(YamlFile.java:90)
    17.06 15:26:22 [Server] WARN at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:167)
    17.06 15:26:22 [Server] WARN at java.io.FileInputStream.<init>(FileInputStream.java:138)
    17.06 15:26:22 [Server] WARN at java.io.FileInputStream.open(FileInputStream.java:195)
    17.06 15:26:22 [Server] WARN at java.io.FileInputStream.open0(Native Method)
    17.06 15:26:22 [Server] WARN java.io.FileNotFoundException: /plugins/HousePoints/signs.yml (No such file or directory)
    17.06 15:26:22 [Multicraft] Skipped 491 lines due to rate limit (30/s)
    17.06 15:26:21 [Server] WARN at com.google.common.io.Files.createParentDirs(Files.java:645)
    17.06 15:26:21 [Server] WARN java.io.IOException: Unable to create parent directories of /plugins/HousePoints/signs.yml
    17.06 15:26:21 [Server] WARN at java.lang.Thread.run(Thread.java:745)
    17.06 15:26:21 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557)
    17.06 15:26:21 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654)
    17.06 15:26:21 [Server] WARN at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374)
    17.06 15:26:21 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715)
    17.06 15:26:21 [Server] WARN at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44)
    17.06 15:26:21 [Server] WARN at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    17.06 15:26:21 [Server] WARN at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    17.06 15:26:21 [Server] WARN at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13)
    17.06 15:26:21 [Server] WARN at net.minecraft.server.v1_8_R3.PacketPlayInUpdateSign.a(SourceFile:11)
    17.06 15:26:21 [Server] WARN at net.minecraft.server.v1_8_R3.PacketPlayInUpdateSign.a(SourceFile:49)
    17.06 15:26:21 [Server] WARN at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1864)
    17.06 15:26:21 [Server] WARN at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487)
    17.06 15:26:21 [Server] WARN at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502)
    17.06 15:26:21 [Server] WARN at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    17.06 15:26:21 [Server] WARN at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306)
    17.06 15:26:21 [Server] WARN at java.lang.reflect.Method.invoke(Method.java:497)
    17.06 15:26:21 [Server] WARN at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    17.06 15:26:21 [Server] WARN at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    17.06 15:26:21 [Server] WARN at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    17.06 15:26:21 [Server] WARN at me.Fhbgsdhkfbll.Points.HousePoints.signPlace(HousePoints.java:257)
    17.06 15:26:21 [Server] WARN at me.Fhbgsdhkfbll.Points.YamlFile.<init>(YamlFile.java:22)
    17.06 15:26:21 [Server] WARN at me.Fhbgsdhkfbll.Points.YamlFile.reload(YamlFile.java:90)
    17.06 15:26:21 [Server] WARN at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:167)
    17.06 15:26:21 [Server] WARN at java.io.FileInputStream.<init>(FileInputStream.java:138)
    17.06 15:26:21 [Server] WARN at java.io.FileInputStream.open(FileInputStream.java:195)
    17.06 15:26:21 [Server] WARN at java.io.FileInputStream.open0(Native Method)
    17.06 15:26:21 [Server] WARN java.io.FileNotFoundException: /plugins/HousePoints/signs.yml (No such file or directory)
    I put file.save(); in some of the methods in the main class, still not creating the files.
     
  4. Offline

    Zombie_Striker

    The error is being caused when you try to reload the config. Can you post the config and can you find out what "file" in YMALFile is equal to?
     
  5. Offline

    Fhbgsdhkfbl

    @Zombie_Striker
    https://gyazo.com/fd6ff046bcd4459b34cee5bba66ee731
    It says it creates the sign, but throws the error, I get this error upon enable
    Code:
    17.06 15:52:07 [Server] WARN at java.io.UnixFileSystem.createFileExclusively(Native Method)
    17.06 15:52:07 [Server] WARN java.io.IOException: No such file or directory
    17.06 15:52:07 [Server] WARN at java.lang.Thread.run(Thread.java:745)
    17.06 15:52:07 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525)
    17.06 15:52:07 [Server] WARN at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263)
    17.06 15:52:07 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333)
    17.06 15:52:07 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378)
    17.06 15:52:06 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414)
    17.06 15:52:06 [Server] WARN at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317)
    17.06 15:52:06 [Server] WARN at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357)
    17.06 15:52:06 [Server] WARN at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405)
    17.06 15:52:06 [Server] WARN at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340)
    17.06 15:52:06 [Server] WARN at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321)
    17.06 15:52:06 [Server] WARN at me.Fhbgsdhkfbll.Points.HousePoints.onEnable(HousePoints.java:61)
    17.06 15:52:06 [Server] WARN at me.Fhbgsdhkfbll.Points.FileManager.getFile(FileManager.java:84)
    17.06 15:52:06 [Server] WARN at java.io.File.createNewFile(File.java:1012)
    17.06 15:52:06 [Server] WARN at java.io.UnixFileSystem.createFileExclusively(Native Method)
    17.06 15:52:06 [Server] WARN java.io.IOException: No such file or directory
    17.06 15:52:06 [Server] INFO Enabling HousePoints v1.0
    And those errors on the lines are:

    Code:
    if(!FileManager.fileExists("signs.yml")) {
                FileManager.getFile("signs.yml", true); //Line 61
            }
    Code:
    public static File getFile(String path, Boolean create){
            File f = new File(dataFolder + "/" + path);
    
            try {
                if(create) {
                    String[] dirs = (dataFolder + "/" + path).split("/");
                    String tempPath = "";
                    File tempFile;
                    for(String dir : dirs){
                        if(!fileExists(dir) && !dir.contains(".")){
                            tempFile = new File(String.format("%s/%s", tempPath, dir));
                            tempFile.mkdir();
                        }
                        tempPath += dir + "/";
                    }
                    f.createNewFile(); //Line 84
                }
                return f;
            } catch(IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    To answer your question, it doesn't create any file upon enabling,
    I hope this is the correct thing for the second part of your question
    Code:
     private File              file;
        private YamlConfiguration configuration;
        private int               saveQue, count;
    
        public YamlFile(File file){
            this.file = file;
            configuration = new YamlConfiguration();
            saveQue = 0;
            count = saveQue;
            reload();
        }
    
        public YamlFile(File file, int saveQue){
            this.file = file;
            this.saveQue = saveQue;
            count = 0;
            configuration = new YamlConfiguration();
            reload();
        }
    
     
  6. Offline

    Zombie_Striker

    @Fhbgsdhkfbl
    Although "/" should work on all windows systems, It should be replaced with File.separator.

    Can you please add the following bit of code to your onEnabled so that it runs before all other methods. Since I assume the config is located at "plugin/<pluginname>/signs.yml":
    Code:
    File file = new File(getDataFolder()+File.seperator+"signs.yml");
    
    Bukkit.broadcast("Does the file exist? : "+file.exists());
    This will broadcast if that file exists. If you start up the server, check the console. If you have to reload, it should broadcast to all players online. If it prints out false, then it simply cannot find the file. If it prints out true, then it may be an issue with the separator or the path's name.
     
  7. Offline

    Fhbgsdhkfbl

    @Zombie_Striker

    Still same error:
    Code:
    17.06 16:43:38 [Server] WARN at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340)
    17.06 16:43:38 [Server] WARN at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321)
    17.06 16:43:38 [Server] WARN at me.Fhbgsdhkfbll.Points.HousePoints.onEnable(HousePoints.java:65)
    17.06 16:43:38 [Server] WARN at me.Fhbgsdhkfbll.Points.FileManager.getFile(FileManager.java:84)
    17.06 16:43:38 [Server] WARN at java.io.File.createNewFile(File.java:1012)
    17.06 16:43:38 [Server] WARN at java.io.UnixFileSystem.createFileExclusively(Native Method)
    17.06 16:43:38 [Server] WARN java.io.IOException: No such file or directory
    17.06 16:43:38 [Server] WARN at java.lang.Thread.run(Thread.java:745)
    17.06 16:43:38 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525)
    17.06 16:43:38 [Server] WARN at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263)
    17.06 16:43:38 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333)
    17.06 16:43:38 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378)
    17.06 16:43:38 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414)
    17.06 16:43:38 [Server] WARN at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317)
    17.06 16:43:38 [Server] WARN at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357)
    17.06 16:43:38 [Server] WARN at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405)
    17.06 16:43:38 [Server] WARN at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340)
    17.06 16:43:38 [Server] WARN at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321)
    17.06 16:43:38 [Server] WARN at me.Fhbgsdhkfbll.Points.HousePoints.onEnable(HousePoints.java:61)
    17.06 16:43:38 [Server] WARN at me.Fhbgsdhkfbll.Points.FileManager.getFile(FileManager.java:84)
    17.06 16:43:38 [Server] WARN at java.io.File.createNewFile(File.java:1012)
    17.06 16:43:38 [Server] WARN at java.io.UnixFileSystem.createFileExclusively(Native Method)
    17.06 16:43:38 [Server] WARN java.io.IOException: No such file or directory
    17.06 16:43:38 [Server] INFO Enabling HousePoints v1.0
    I changed everything that had "/" to File.seperator in my Manager
    Code:
    package me.Fhbgsdhkfbll.Points;
    
    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class FileManager {
        public static boolean debugInfo = false;
    
        public static String  dataFolder;
       
        public static void init(JavaPlugin plugin){
            dataFolder = new FileManager().getDataFolderPath(plugin);
        }
       
        public String getDataFolderPath(JavaPlugin plugin){
            try{
                if(new File(plugin.getDataFolder().getParent()).exists() && plugin.getDataFolder().getParentFile().isDirectory())
                    return plugin.getDataFolder().toString().replaceAll("\\", "/");
            }catch(Exception e){}
           
            String[] split = getClass().getProtectionDomain().getCodeSource().getLocation().toString().split("/");
            String path = "";
            for(String dir : split){
                if(new File(path + dir).isDirectory()){
                    path += dir + "/";
                }
            }
            return "/" + path +  split[split.length - 1].substring(0, split[split.length - 1].length() - 4);
        }
    
        /**
         * @param path - Create folders down the path provided
         * @return The result of making the directories
         */
        public static boolean createFolders(String path){
            File f = new File(dataFolder + File.separator + path);
            Boolean b = f.mkdirs();
            return b;
        }
    
        public static boolean deleteFile(String path){
            File f = new File(dataFolder + File.separator + path);
    
            if(f.isFile()) {
                return f.delete();
            }
    
            return false;
        }
    
        /**
         * @param path - Path of the file to check.
         * @return Whether the file exists or not.
         */
        public static boolean fileExists(String path){
            File f = new File(dataFolder + File.separator + path);
    
            Boolean b = f.exists();
            return b;
        }
    
        /**
         * @param path - Path to the file as a string
         * @return The file unless there was an error
         */
        public static File getFile(String path, Boolean create){
            File f = new File(dataFolder + File.separator + path);
    
            try {
                if(create) {
                    String[] dirs = (dataFolder + File.separator + path).split(File.separator);
                    String tempPath = "";
                    File tempFile;
                    for(String dir : dirs){
                        if(!fileExists(dir) && !dir.contains(".")){
                            tempFile = new File(String.format("%s/%s", tempPath, dir));
                            tempFile.mkdir();
                        }
                        tempPath += dir + "/";
                    }
                    f.createNewFile(); //Line 84
                }
                return f;
            } catch(IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    
        /**
         * @param path
         * @return A list of files in the directory
         */
        public static File[] getFolderFiles(String path){
            File directory = new File(dataFolder + File.separator + path);
    
            if(directory.isDirectory()) {
    
                ArrayList<File> files = new ArrayList<File>();
    
                for(File f : directory.listFiles()) {
                    if(!f.isDirectory())
                        files.add(f);
                }
    
                return files.toArray(new File[files.size()]);
    
            }
    
            return null;
        }
    
        /**
         * @param path
         * @return A list of the folders in the directory
         */
        public static File[] getFolderFolders(String path){
            File directory = new File(dataFolder + File.separator + path);
    
            if(directory.isDirectory()) {
    
                ArrayList<File> folders = new ArrayList<File>();
    
                for(File f : directory.listFiles()) {
                    if(f.isDirectory())
                        folders.add(f);
                }
    
                return folders.toArray(new File[folders.size()]);
    
            }
    
            return null;
        }
    
    }
    
    Also it's not broadcasting any messages upon enabling:
    Code:
     if(!FileManager.fileExists("signs.yml")) {
                FileManager.getFile("signs.yml", true);
                Bukkit.broadcastMessage("Does the file exist? :" + FileManager.fileExists("signs.yml"));
            }
            if(!FileManager.fileExists("points.yml")) {
                YamlFile file = new YamlFile(FileManager.getFile("points.yml", true));
                for(String s : houses)
                    file.set(s, 0);
                Bukkit.broadcastMessage("Does the file exist? :" + FileManager.fileExists("points.yml"));
            }
            if(!FileManager.fileExists("strings.yml")) {
                YamlFile file = new YamlFile(FileManager.getFile("strings.yml", true));
                file.set("enter_valid_house", enterValidHouse);
                file.set("points_added_to_house", addedTo);
                file.set("points_removed_from_house", removedFrom);
                file.set("greater_than_zero", greaterThanZero);
                file.set("sign_created", signCreated);
                Bukkit.broadcastMessage("Does the file exist? :" + FileManager.fileExists("string.yml"));
            }else{
                YamlFile file = new YamlFile(FileManager.getFile("strings.yml", false));
                enterValidHouse = file.getString("enter_valid_house");
                addedTo = file.getString("points_added_to_house");
                removedFrom = file.getString("points_removed_from_house");
                greaterThanZero = file.getString("greater_than_zero");
                signCreated = file.getString("sign_created");
                Bukkit.broadcastMessage("Does the file exist? :" + FileManager.fileExists("string.yml"));
            }
            if(!FileManager.fileExists("config.yml")) {
                YamlFile file = new YamlFile(FileManager.getFile("config.yml", true));
                file.set("staff_permission", permission);
                file.set("sign_command", signCommand);
                Bukkit.broadcastMessage("Does the file exist? :" + FileManager.fileExists("config.yml"));
            }else{
                YamlFile file = new YamlFile(FileManager.getFile("config.yml", false));
                permission = file.getString("staff_permission");
                signCommand = file.getString("sign_command");
                Bukkit.broadcastMessage("Does the file exist? :" + FileManager.fileExists("config.yml"));
            }
        }
     
  8. Offline

    Zombie_Striker

    @Fhbgsdhkfbl
    Can you tell me what it broadcasted? Does it say that the file existed?
     
  9. Offline

    Fhbgsdhkfbl

    @Zombie_Striker
    Nothing was broadcasted, didn't say the file existed.
    I don't have an issue with other files, it's just when I try to create a sign to display the amount of points of each house, it'll throw an error saying the file doesn't exist, but when I try and give points to the houses, it'll work perfectly, it's just the signs.
     
  10. Offline

    Zombie_Striker

    @Fhbgsdhkfbl
    I honestly do not know. In order for the message to not be broadcasted, then that would mean that the file does not exist. Hate to ask this, but are you sure that file exists? At that location with that exact name?
     
  11. Online

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page