Solved Creating custom .yml problem.

Discussion in 'Plugin Development' started by sohardhun15, Jul 25, 2014.

Thread Status:
Not open for further replies.
  1. Code:java
    1. File f = new File("plugins/FallOut/", "arena.yml");
    2. try {
    3. f.createNewFile();
    4. } catch (IOException e) {
    5. Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Cannot create arena.yml!");
    6. }


    It cannot create the yml file.

    StackTrace:
    Code:
    [11:59:03 WARN]: java.io.IOException: A rendszer nem talßlja a megadott elÚrÚsi utat
    [11:59:03 WARN]:        at java.io.WinNTFileSystem.createFileExclusively(Native Method)
    [11:59:03 WARN]:        at java.io.File.createNewFile(Unknown Source)
    [11:59:03 WARN]:        at me.SoHardHUN.FallOut.Main.onEnable(Main.java:18)
    [11:59:03 WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316)
    [11:59:03 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.jav
    a:324)
    [11:59:03 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.ja
    va:404)
    [11:59:03 WARN]:        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.loadPlugin(CraftServer.java:44
    6)
    [11:59:03 WARN]:        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.enablePlugins(CraftServer.java
    :380)
    [11:59:03 WARN]:        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.reload(CraftServer.java:799)
    [11:59:03 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:288)
    [11:59:03 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23)
    [11:59:03 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180)
    [11:59:03 WARN]:        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServer.ja
    va:701)
    [11:59:03 WARN]:        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchServerCommand(CraftSer
    ver.java:688)
    [11:59:03 WARN]:        at net.minecraft.server.v1_7_R3.DedicatedServer.aB(DedicatedServer.java:296)
     
    [11:59:03 WARN]:        at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:261)
    [11:59:03 WARN]:        at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558)
    [11:59:03 WARN]:        at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469
    )
    [11:59:03 WARN]:        at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628)
     
  2. Offline

    ZodiacTheories

  3. ZodiacTheories
    Code:java
    1. package me.SoHardHUN.FallOut;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Main extends JavaPlugin {
    11.  
    12. @Override
    13. public void onEnable() {
    14. Bukkit.getConsoleSender().sendMessage(
    15. ChatColor.GREEN + "Fallout sikeresen elindult!");
    16. File f = new File("plugins/FallOut/", "arena.yml");
    17. try {
    18. f.createNewFile();
    19. } catch (IOException e) {
    20. e.printStackTrace();
    21. }
    22. }
    23.  
    24. @Override
    25. public void onDisable() {
    26. Bukkit.getConsoleSender().sendMessage(
    27. ChatColor.RED + "Fallout sikeresen leállt!");
    28. }
    29.  
    30. }
    31.  
     
  4. Offline

    AoH_Ruthless

    sohardhun15
    Use new File(plugin.getDataFolder(), "arena.yml"); if Fallout is your plugin.
     
  5. Offline

    fireblast709

    AoH_Ruthless likes this.
  6. AoH_Ruthless
    Yeah it's my plugin and i've got the same error.
     
  7. Offline

    AoH_Ruthless

    sohardhun15
    Can I see your updated onEnable()? The exception is being triggered because the new file cannot be created.
     
  8. AoH_Ruthless
    main:
    Code:java
    1. package me.SoHardHUN.FallOut;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.plugin.Plugin;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class Main extends JavaPlugin {
    12. public static Plugin plugin;
    13. @Override
    14. public void onEnable() {
    15. plugin = this;
    16. Bukkit.getConsoleSender().sendMessage(
    17. ChatColor.GREEN + "Fallout sikeresen elindult!");
    18. File f = new File(plugin.getDataFolder(), "arena.yml");
    19. try {
    20. f.createNewFile();
    21. } catch (IOException e) {
    22. e.printStackTrace();
    23. }
    24. }
    25.  
    26. @Override
    27. public void onDisable() {
    28. plugin = null;
    29. Bukkit.getConsoleSender().sendMessage(
    30. ChatColor.RED + "Fallout sikeresen leállt!");
    31. }
    32.  
    33. }
     
  9. Offline

    AoH_Ruthless

    sohardhun15
    You didn't need to make a new instance of your main class. Remove line 12 and line 15 (if you remove line 12 first, you have to remove line 14 instead of 15). Replace plugin with 'this' keyword.
     
  10. f.getParentFile().mkdirs();

    i put this above create new file and it works fine.
     
  11. Offline

    AoH_Ruthless

    sohardhun15
    I don't understand how that possibly resolved the issue, but whatever, it is fixed.
     
  12. Offline

    Dragonphase

    AoH_Ruthless
    Strange.

    sohardhun15
    Regardless; if you want, you can use this resource to manage YAML Configuration easily. Instantiating a new Config object will create a new file for you if one doesn't exist, so you don't have to go through the long process of doing it yourself every time.
     
  13. Offline

    AoH_Ruthless

    Dragonphase
    Strange that I don't know how the issue is resolved, or are you agreeing with me? I actually think it had to do with the static plugin instance, not creating the parent directory (which does nothing, as the parent directory will already exist).
     
  14. Offline

    Dragonphase

  15. Offline

    DusRonald

    @sohardhun15
    Code:java
    1.  
    2. File file = new File(this.getDataFolder(), "custom.yml");
    3. try {
    4. file.creatNewFile();
    5. } catch (IOException e){
    6. e.printStackTrace();
    7. }
    8.  
     
Thread Status:
Not open for further replies.

Share This Page