HousePoints error (Another)

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

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

    Fhbgsdhkfbl

    So, I finished a housepoints plugin, and I get an erorr when i try and create a sign,

    It works fine on my personal server but when I try it on my public server I get this error

    Code:
    11.06 18:36:40 [Server] WARN java.io.FileNotFoundException: /plugins/HousePoints/housesigns.yml (No such file or directory)
    11.06 18:36:40 [Server] WARN at java.io.FileInputStream.open0(Native Method)
    11.06 18:36:40 [Server] WARN at java.io.FileInputStream.open(FileInputStream.java:195)
    11.06 18:36:40 [Server] WARN at java.io.FileInputStream.<init>(FileInputStream.java:138)
    11.06 18:36:40 [Server] WARN at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:167)
    11.06 18:36:40 [Server] WARN at me.Fhbgsdhkfbll.Points.YamlFile.reload(YamlFile.java:90)
    11.06 18:36:40 [Server] WARN at me.Fhbgsdhkfbll.Points.YamlFile.set(YamlFile.java:119)
    11.06 18:36:40 [Server] WARN at me.Fhbgsdhkfbll.Points.HousePoints.signPlace(HousePoints.java:255)
    11.06 18:36:40 [Server] WARN at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    11.06 18:36:40 [Server] WARN at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    11.06 18:36:40 [Server] WARN at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    11.06 18:36:40 [Server] WARN at java.lang.reflect.Method.invoke(Method.java:498)
    11.06 18:36:40 [Server] WARN at us.Myles.PWP.TransparentListeners.PerWorldPluginLoader$1.execute(PerWorldPluginLoader.java:120)
    11.06 18:36:40 [Server] WARN at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    11.06 18:36:40 [Server] WARN at us.Myles.PWP.TransparentListeners.PWPRegisteredListener.callEvent(PWPRegisteredListener.java:30)
    11.06 18:36:40 [Server] WARN at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502)
    11.06 18:36:40 [Server] WARN at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487)
    11.06 18:36:40 [Server] WARN at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1864)
    11.06 18:36:40 [Server] WARN at net.minecraft.server.v1_8_R3.PacketPlayInUpdateSign.a(SourceFile:49)
    11.06 18:36:40 [Server] WARN at net.minecraft.server.v1_8_R3.PacketPlayInUpdateSign.a(SourceFile:11)
    11.06 18:36:40 [Server] WARN at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13)
    11.06 18:36:40 [Server] WARN at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    11.06 18:36:40 [Server] WARN at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    11.06 18:36:40 [Server] WARN at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44)
    11.06 18:36:40 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715)
    11.06 18:36:40 [Server] WARN at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374)
    11.06 18:36:40 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654)
    11.06 18:36:40 [Server] WARN at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557)
    11.06 18:36:40 [Server] WARN at java.lang.Thread.run(Thread.java:745)
    11.06 18:36:40 [Server] WARN java.io.IOException: Unable to create parent directories of /plugins/HousePoints/housesigns.yml
    11.06 18:36:40 [Server] WARN at com.google.common.io.Files.createParentDirs(Files.java:645)
    11.06 18:36:40 [Server] WARN at org.bukkit.configuration.file.FileConfiguration.save(FileConfiguration.java:101)
    11.06 18:36:40 [Server] WARN at me.Fhbgsdhkfbll.Points.YamlFile.save(YamlFile.java:105)
    11.06 18:36:40 [Server] WARN at me.Fhbgsdhkfbll.Points.YamlFile.set(YamlFile.java:118)
    11.06 18:36:40 [Server] WARN at me.Fhbgsdhkfbll.Points.HousePoints.signPlace(HousePoints.java:256)
    11.06 18:36:40 [Server] WARN at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    11.06 18:36:40 [Server] WARN at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    11.06 18:36:40 [Server] WARN at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    11.06 18:36:40 [Server] WARN at java.lang.reflect.Method.invoke(Method.java:498)
    11.06 18:36:40 [Server] WARN at us.Myles.PWP.TransparentListeners.PerWorldPluginLoader$1.execute(PerWorldPluginLoader.java:120)
    11.06 18:36:40 [Server] WARN at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    11.06 18:36:40 [Server] WARN at us.Myles.PWP.TransparentListeners.PWPRegisteredListener.callEvent(PWPRegisteredListener.java:30)
    11.06 18:36:40 [Server] WARN at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502)
    11.06 18:36:40 [Server] WARN at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487)
    Code:
    @EventHandler
        public void signPlace(SignChangeEvent event){
            if(!event.getPlayer().hasPermission(permission))
                return;
            Player player = event.getPlayer();
            String line1 = event.getLine(0);
            String line2 = event.getLine(1);
            if(line1 == null)
                return;
            if(line1.equalsIgnoreCase("{{House Points}}")){
                if(line2 == null)
                    return;
                line2 = line2.toUpperCase().substring(0, 1) + line2.toLowerCase().substring(1);
                if(!houses.contains(line2)){
                    player.sendMessage(enterValidHouse);
                    return;
                }
                YamlFile file = new YamlFile(FileManager.getFile("housesigns.yml", false));
                Location loc = event.getBlock().getLocation();
                String path = String.format("%s%s%s%s", loc.getWorld().getUID().toString(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
                file.set(path + ".world_name", loc.getWorld().getName()); //line 255
                file.set(path + ".sign_creator", player.getName());
                file.set(path + ".uuid", loc.getWorld().getUID().toString());
                file.set(path + ".x", loc.getBlockX());
                file.set(path + ".y", loc.getBlockY());
                file.set(path + ".z", loc.getBlockZ());
                file.set(path + ".house", line2);
                try {
                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, new Runnable() {
                        public void run(){
                            try {
                                updateSigns();
                            } catch(Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }, 2);
                } catch(Exception e) {
                    e.printStackTrace();
                }
                updateSigns();
                player.sendMessage(String.format(signCreated, line2));
            }
        }
     
  2. Offline

    Zombie_Striker

    Your problem is that you're trying to access a file that does not exist. Make sure the file exists before you try to modify it, and if it does not exist, create it.
     
  3. Offline

    Fhbgsdhkfbl

    Code:
    if(!FileManager.fileExists("housesigns.yml")) {
                FileManager.getFile("housesigns.yml", true);
            }
    @Zombie_Striker

    it creates it if it doesn't exist
     
  4. Offline

    Zombie_Striker

    @Fhbgsdhkfbl
    Where are these lines located? If you have written the FileManager yourself, then can you post the code for those two methods?
     
  5. Offline

    Fhbgsdhkfbl

    I just don't understand why it works on my test server, but not my actual server?

    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;
        }
    
    }
    
    there's my filemanager class

    Code:
    package me.Fhbgsdhkfbll.Points;
    
    
    import java.util.ArrayList;
    import java.util.UUID;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.block.Sign;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class HousePoints extends JavaPlugin implements Listener, CommandExecutor{
    
        private static HousePoints instance;
        private static ArrayList<String> houses;
        private static String permission = "housepoints.staff";
        private static String signCommand = "{{House Points}}";
        private static String pluginUsing = ChatColor.RED + "A plugin may not have set HousePoints as a dependency, but is attempting to use it";
        private static String enterValidHouse = ChatColor.RED + "You didn't enter a valid House!";
        private static String addedTo = ChatColor.GREEN + "" + ChatColor.ITALIC + "%s points have been added to %s.";
        private static String removedFrom = ChatColor.RED + "" + ChatColor.ITALIC + "%s points have been removed from %s.";
        private static String greaterThanZero = ChatColor.RED + "Please enter a value other than 0!";
        private static String signCreated = ChatColor.GREEN + "Sign created for %s!";
        private static String signDestroyed = ChatColor.RED + "Sign for %s destroyed!";
        private static String noPermission = ChatColor.RED + "You don't have permission to break House point signs!";
       
        public static String[] getHouses(){
            if(houses == null){
                Bukkit.getConsoleSender().sendMessage(pluginUsing);
                return null;
            }
            String[] s = new String[houses.size()];
            for(int i=0;i<houses.size();i++)
                s[i] = houses.get(i);
            return s;
        }
       
        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("housesigns.yml")) {
                FileManager.getFile("housesigns.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");
            }
        }
       
        public void onDisable(){
            YamlFile file = new YamlFile(FileManager.getFile("housepoints.yml", false));
            file.save();
        }
       
        @EventHandler
        public void onChat(AsyncPlayerChatEvent event){
            if(!event.getPlayer().hasPermission("housepoints.staff"))
                return;
            String a = "";
            String b = "";
            String c = "";
            String d = "";
            for(String s : ChatColor.stripColor(event.getMessage()).split(" ")){
                a = b;
                b = c;
                c = d;
                d = s.toLowerCase();
                if(d.length() > 8 && (c.equalsIgnoreCase("to") || c.equalsIgnoreCase("from")) && b.equalsIgnoreCase("points") && getHouse(d) != null){
                    try{
                        d = getHouse(d);
                        int value = Integer.parseInt(a);
                        if(c.equalsIgnoreCase("to")){
                            modifyHousePoints(d, value);
                            event.getPlayer().sendMessage(String.format(addedTo, a, d));
                        }else if(c.equalsIgnoreCase("from")){
                            modifyHousePoints(d, -value);
                            event.getPlayer().sendMessage(String.format(removedFrom, a, d));
                        }
                    }catch(Exception e){} //means that 'a' wasn't an integer.
                }
            }
           
        }
       
        private String getHouse(String s){
            for(String str : houses){
                if(s.toLowerCase().startsWith(str.toLowerCase())){
                    return str;
                }
            }
            return null;
        }
       
        /**
         * Gets the House points for the House.
         * @param house The Houses you want points for.
         * @return Returns the House points for the House. May return -100,000,000 if there was an error.
         */
        public static int getHousePoints(String house){
            if(houses == null){
                Bukkit.getConsoleSender().sendMessage(pluginUsing);
                return -100000000;
            }
            try{
                house = house.toUpperCase().substring(0, 1) + house.toLowerCase().substring(1);
                YamlFile file = new YamlFile(FileManager.getFile("points.yml", false));
                return file.getInt(house);
            }catch(Exception e){
                Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "ERROR while retrieving House points!");
                e.printStackTrace();
                return -100000000;
            }
        }
       
        /**
         * Will modify the House points in the points.yml and then update all signs in the signs.yml
         * @param house The House you would like to modify the points of.
         * @param amount The amount to modify them by.
         */
        public static boolean modifyHousePoints(String house, int amount){
            if(houses == null){
                Bukkit.getConsoleSender().sendMessage(pluginUsing);
                return false;
            }
            try{
                house = house.toUpperCase().substring(0, 1) + house.toLowerCase().substring(1);
                YamlFile file = new YamlFile(FileManager.getFile("points.yml", false));
                file.set(house, file.getInt(house) + amount);
                updateSigns();
                return true;
            }catch(Exception e){
                Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "ERROR while modifying House points!");
                e.printStackTrace();
                return false;
            }
        }
       
        /**
         * Updates all the signs in the sign.yml
         * @return Returns true if it successfully updated all the signs
         */
        public static boolean updateSigns(){
            if(houses == null){
                Bukkit.getConsoleSender().sendMessage(pluginUsing);
                return false;
            }
            try{
                YamlFile file = new YamlFile(FileManager.getFile("housesigns.yml", false));
                if(file.getKeys("", false) == null)
                    return false;
                boolean delete = true;
                YamlFile points = new YamlFile(FileManager.getFile("points.yml", false));
                for(String s : file.getKeys("", false)){
                    World world = Bukkit.getServer().getWorld(UUID.fromString(file.getString(s + ".uuid")));
                    Block b = world.getBlockAt(new Location(world, file.getDouble(s + ".x"), file.getDouble(s + ".y"),file.getDouble(s + ".z")));
                    if(b.getState() instanceof Sign){
                        Sign sign = (Sign) b.getState();
                        sign.setLine(0, "");
                        String house = file.getString(s + ".house");
                        sign.setLine(2, points.getInt(house) + "");
                        switch(house){
                            case "Slytherin":
                                house = ChatColor.GREEN + house;
                                break;
                            case "Gryffindor":
                                house = ChatColor.RED + house;
                                break;
                            case "Ravenclaw":
                                house = ChatColor.BLUE + house;
                                break;
                            case "Hufflepuff":
                                house = ChatColor.GOLD + house;
                                break;
                        }
                        sign.setLine(1, house);
                        sign.update(true);
                        delete = false;
                    }
                    if(delete)
                        file.set(s, null);
                    delete = true;
                }
                return true;
            }catch(Exception e){
                Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "ERROR while updating House point signs!");
                e.printStackTrace();
                return false;
            }
        }
       
        @EventHandler
        public void signPlace(SignChangeEvent event){
            if(!event.getPlayer().hasPermission(permission))
                return;
            Player player = event.getPlayer();
            String line1 = event.getLine(0);
            String line2 = event.getLine(1);
            if(line1 == null)
                return;
            if(line1.equalsIgnoreCase("{{House Points}}")){
                if(line2 == null)
                    return;
                line2 = line2.toUpperCase().substring(0, 1) + line2.toLowerCase().substring(1);
                if(!houses.contains(line2)){
                    player.sendMessage(enterValidHouse);
                    return;
                }
                YamlFile file = new YamlFile(FileManager.getFile("housesigns.yml", false));
                Location loc = event.getBlock().getLocation();
                String path = String.format("%s%s%s%s", loc.getWorld().getUID().toString(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
                file.set(path + ".world_name", loc.getWorld().getName());
                file.set(path + ".sign_creator", player.getName());
                file.set(path + ".uuid", loc.getWorld().getUID().toString());
                file.set(path + ".x", loc.getBlockX());
                file.set(path + ".y", loc.getBlockY());
                file.set(path + ".z", loc.getBlockZ());
                file.set(path + ".house", line2);
                try {
                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, new Runnable() {
                        public void run(){
                            try {
                                updateSigns();
                            } catch(Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }, 2);
                } catch(Exception e) {
                    e.printStackTrace();
                }
                updateSigns();
                player.sendMessage(String.format(signCreated, line2));
            }
        }
       
        @EventHandler
        public void signBreak(BlockBreakEvent event){
            if(!(event.getBlock().getState() instanceof Sign))
                return;
            Sign sign = (Sign) event.getBlock().getState();
            Location loc = sign.getLocation();
            String path = String.format("%s%s%s%s", loc.getWorld().getUID().toString(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
            YamlFile file = new YamlFile(FileManager.getFile("housesigns.yml", false));
            if(!file.getKeys(false).contains(path))
                return;
            if(!event.getPlayer().hasPermission(permission)){
                event.setCancelled(true);
                event.getPlayer().sendMessage(noPermission);
                return;
            }
            file.set(path, null);
            event.getPlayer().sendMessage(signDestroyed);
        }
       
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if(!sender.hasPermission(permission))
                return true;
            if(args.length != 2)
                error(sender);
            if(args.length < 2) {
                return true;
            }
            String house = args[0].toUpperCase().substring(0, 1) + args[0].toLowerCase().substring(1); //Line 307
            int value = 0;
            try{
                value = Integer.parseInt(args[1]);
            }catch(Exception e){
                error(sender);
            }
            if(value == 0){
                sender.sendMessage(greaterThanZero);
                return true;
            }
            if(!houses.contains(house)){
                sender.sendMessage(enterValidHouse);
                return true;
            }
            modifyHousePoints(house, value);
            informServerOfPointsChange(value, house);
            return true;
        }
       
        private void informServerOfPointsChange(int amount, String house){
            for(Player p : Bukkit.getServer().getOnlinePlayers()){
                if(amount < 0)
                    p.sendMessage(String.format(removedFrom , amount * -1, house));
                else
                    p.sendMessage(String.format(addedTo , amount, house));
            }
        }
       
        private boolean error(CommandSender sender){
            sender.sendMessage(ChatColor.RED + "Please try again!");
            sender.sendMessage(ChatColor.ITALIC + "Usage: /points <house> <amount>");
            return true;
        }
    
    }
    
    here's the main class
     
    Last edited: Jun 11, 2016
  6. Offline

    Zombie_Striker

    @Fhbgsdhkfbl
    For your actual server, are you sure that file actually exists? Also, are you allowed to access and modify that file?
     
  7. Offline

    Fhbgsdhkfbl

    @Zombie_Striker
    As in do I have the source, Yes, I do.

    to your first question, it's supposed to create the file on enable, I changed it from signs.yml to housesigns.yml thinking that was the problem cause of another plugin that has a file named signs.yml,.
     
  8. Offline

    N00BHUN73R

    @Fhbgsdhkfbl
    I see your points.yml is also being created if it does not exist.
    Is that file being created?
     
  9. Offline

    pookeythekid

    @Fhbgsdhkfbl
    I've had some similar file issues before, where I would test it on my private server and it would work fine, but things went whack on publicly-hosted servers. It turned out to be an issue of operating systems--I know, Java not working across platforms. :mad:

    I presume you're using either Windows or MacOS <insert whatever version>; most server hosts use Linux. For Windows (not sure about Mac), the file separator "\\", or, as I saw in your code, "/", works perfectly well, but when you move that onto Linux, things kind of break. Java has a super simple solution to this: File.separator. It's a static property of File, and it gets the correct file separator for the current platform. If you replace your current separators with this, I think you should be good to go.

    This may or may not work, but it did for me so 'ey why not you too. ;)
     
  10. Offline

    Fhbgsdhkfbl

    @pookeythekid
    I'm not sure what you want me to do? What should I change in my FileManager for your fix you told me about?
     
  11. Offline

    mine-care

    Does the folder HousePoints exist when you try to create the file?
    Attempting to create a file in an Inexistant folder results in such an exception.
     
  12. Offline

    Fhbgsdhkfbl

    @mine-care
    No it doesn't create the file for some reason, it doesn't make it on my test server, but everything works, the signs etc, when I put it on my public server, I get that error.
     
  13. Offline

    mine-care

    @Fhbgsdhkfbl so does the folder "House Points" exist??
    Do you have write and read permit ions for the file?
     
  14. Offline

    Fhbgsdhkfbl

    Yes I do
     
  15. Offline

    mine-care

    That still doesn't answer my question..
     
  16. Offline

    Fhbgsdhkfbl

    @mine-care
    When the plugin loads up, no a folder named HousePoints does not go into the plugins folder.
     
  17. Offline

    mine-care

    @Fhbgsdhkfbl So the folder does not exist. That can explain the problem because as i said above:
    So you need to create the folder in it before trying to create the file within it.
     
  18. Offline

    Fhbgsdhkfbl

    @mine-care
    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("housesigns.yml")) {
                FileManager.getFile("housesigns.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");
            }
        }
    this is my onEnable, it's creating the files if they don't exist, why doesn't it create the folder also?
     
  19. Offline

    mine-care

    @Fhbgsdhkfbl
    Lets see it this way:
    Lets supose i want to create a file called "names.yml" in the directory "/desktop/dir/plugins/name/"
    Also lets supose that the directory "/name/" in the folder "/plugins/" does not exist.

    So i tell Java to create the file "names.yml" in the path shown above, but one folder of them doesnt exist. Java does not know where to put it in so thats why it errors.

    The solution would be to manually create the folder like so:

    Code:
    File FOLDER = File /desktop/dir/plugins/name/ 
    
    if !folder.exist() then:
        folder#mkdirs();
    end if    
    //Here goes the creation of the rest of the files.
    
     
  20. @Fhbgsdhkfbl Did you create the FileManager or was that someone else?

    Can you put these lines in onEnable and see what happens

    Code:java
    1. File dir = new File(getDataFolder() + File.separator + "data");
    2. if(!dir.exists()){
    3. dir.mkdir();
    4. }
    5. File f = new File(dir + File.separator + "points.yml");
    6. if(!f.exists()){
    7. f.createNewFile();
    8. }
    9.  


    (Note I just quickly wrote this up and I haven't done Bukkit in a long time, but it should work)
     
  21. Offline

    Fhbgsdhkfbl

    @bwfcwalshy
    Someone else made the FileManager class

    Code:
    [14:32:45 WARN]: java.io.IOException: The system cannot find the path specified
    [14:32:45 WARN]:        at java.io.WinNTFileSystem.createFileExclusively(Native Method)
    [14:32:45 WARN]:        at java.io.File.createNewFile(File.java:1012)
    [14:32:45 WARN]:        at me.Fhbgsdhkfbll.Points.HousePoints.onEnable(HousePoints.java:66)
    [14:32:45 WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321)
    [14:32:45 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:335)
    [14:32:45 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405)
    [14:32:45 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:356)
    [14:32:45 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:316)
    [14:32:45 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(CraftServer.java:746)
    [14:32:45 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:534)
    [14:32:45 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25)
    [14:32:45 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141)
    [14:32:45 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:646)
    [14:32:45 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchServerCommand(CraftServer.java:632)
    [14:32:45 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.aM(DedicatedServer.java:353)
    [14:32:45 WARN]:        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:317)
    [14:32:45 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634)
    [14:32:45 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537)
    [14:32:45 WARN]:        at java.lang.Thread.run(Thread.java:745)
    Code:
    I marked line 66
    Code:
    public void onEnable(){
            instance = this;
            houses = new ArrayList<String>();
            houses.add("Slytherin");
            houses.add("Gryffindor");
            houses.add("Ravenclaw");
            houses.add("Hufflepuff");
            File dir = new File(getDataFolder() + File.separator + "data");
            if(!dir.exists()){
                dir.mkdir();
            }
            File f = new File(dir + File.separator + "points.yml");
            if(!f.exists()){
                try {
                    f.createNewFile(); //line 66
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            FileManager.init(this);
            // Initialize the file if it doesn't exist
            if(!FileManager.fileExists("housesigns.yml")) {
                FileManager.getFile("housesigns.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");
            }
        }
     
  22. Offline

    Fhbgsdhkfbl

  23. Offline

    Zombie_Striker

    @Fhbgsdhkfbl
    You said you have a test server and an "actual server". Is this "actual server" hosted by some other company? If so, the problem may be that the company is not allowing you to create these files due to some reason.
     
  24. Offline

    Fhbgsdhkfbl

    @Zombie_Striker
    yes it's hosted by another company, but why would that be an issue? should i change the name of the files to see if that'll fix it or?
     
  25. Offline

    Zombie_Striker

    @Fhbgsdhkfbl
    Not at all. This may be an issue where you will have to manually (through the company) add the files and directories.
     
  26. Offline

    timtower Administrator Administrator Moderator

    @Zombie_Striker @Fhbgsdhkfbl Might be an issue of permissions though, server side.
    Normally you run the server with the run file next to the server file. I am not sure if hosting companies also do this. Might change the path in a way so you cant wroite there.
    But that should throw exceptions.
     
  27. Offline

    I Al Istannen

    @Fhbgsdhkfbl
    What happens if you put an empty config.yml right next to your plugin.yml and call "saveDefaultConfig()" in the onEnable? Is the file and the directory generated?
     
  28. Offline

    Fhbgsdhkfbl

    @I Al Istannen
    Yes, when I do that it creates the file and directory. That's on my test server, I can't test it on my other server cause to many players are on
     
  29. Offline

    Fhbgsdhkfbl

    @I Al Istannen @timtower @Zombie_Striker
    I think I found the issue, I tested it on my test server with all the same plugins and files on my public server and it worked completely fine, so it might be an issue with the host we use, is there a way I can recode it for it to work correctly?

    I seem to be getting errors on these methods:

    Code:
     public void set(String path, Object item){
            configuration.set(path, item);
            if(count == saveQue) {
                save();
                reload(); //Line 119
                count = 0;
            } else {
                count++;
            }
        }
    public void reload(){
            try {
                configuration.load(file); //Line 90
            } catch(FileNotFoundException e) {
                e.printStackTrace();
            } catch(IOException e) {
                e.printStackTrace();
            } catch(InvalidConfigurationException e) {
                e.printStackTrace();
            }
        }
    
     
    Last edited: Jun 13, 2016
Thread Status:
Not open for further replies.

Share This Page