The System Can Not Find The Path Specified (Hashmaps ans Saving)

Discussion in 'Plugin Development' started by Tehepicford, Aug 22, 2012.

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

    Tehepicford

    Hello, Its me AGAIN. I've been having lots of troubles with Hashmaps and IO...
    Well here is the code and error.

    Code:
    package com.fordnatford.Commands;
     
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.FileWriter;
    import java.io.ObjectOutputStream;
    import java.util.HashMap;
    import java.util.logging.Logger;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin {
        public static HashMap<String, Boolean> FreezedPlayers = new HashMap<String, Boolean>();
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Main plugin;
        public final BukkitListner bl = new BukkitListner(this);
     
    public void onDisable() {
        PluginDescriptionFile pdfFile = this.getDescription();
        this.logger.info(pdfFile.getName() + " Has been disabled!");
       
    }
     
    public void onEnable() {
        PluginDescriptionFile pdfFile = this.getDescription();
        this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " Has been Enabled!");
        PluginManager pm = this.getServer().getPluginManager();
        pm.registerEvents(bl, this);
    }
     
    public void save(HashMap<String, Boolean> map, String path)
    {
        try
        {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(path));
            oos.writeObject(map);
            oos.flush();
            oos.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
     
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        Player player = (Player) sender;
        if(label.equalsIgnoreCase("freeze")) {
            if(args.length == 1) {
                if(FreezedPlayers.containsKey(args[0])) {
                FreezedPlayers.remove(args[0]);
                player.sendMessage(ChatColor.YELLOW + args[0] + ChatColor.WHITE + " has been " + ChatColor.GREEN + "Un-Frozen!");
                getServer().getPlayer(args[0]).sendMessage(ChatColor.YELLOW + "You " + ChatColor.WHITE + "have been " + ChatColor.YELLOW + "Frozen!");
                save(FreezedPlayers, getDataFolder() + File.separator + "Data.txt");
                } else {
            FreezedPlayers.put(args[0], true);
            player.sendMessage(ChatColor.YELLOW + args[0] + ChatColor.WHITE + " has been " + ChatColor.GREEN + "Frozen!");
            getServer().getPlayer(args[0]).sendMessage(ChatColor.YELLOW + "You " + ChatColor.WHITE + "have been frozen!");
            save(FreezedPlayers, getDataFolder() + File.separator + "Data.txt");
            }
        } else {
            if(args.length == 0) {
                if(FreezedPlayers.containsKey(player.getDisplayName())) {
                    player.sendMessage(ChatColor.YELLOW + "You " + ChatColor.WHITE + "have been " + ChatColor.GREEN + "Un-Frozen!");
                FreezedPlayers.remove(player.getDisplayName());
                save(FreezedPlayers, getDataFolder() + File.separator + "Data.txt");
            } else {
            player.sendMessage(ChatColor.YELLOW + "You " + ChatColor.WHITE + "have been " + ChatColor.GREEN + "Frozen!");
            FreezedPlayers.put(player.getDisplayName(), true);
            save(FreezedPlayers, getDataFolder() + File.separator + "Data.txt");
            }
            }
        }
        }
        return false;
       
    }
     
     
    public void onPlayerJoin(PlayerJoinEvent evt) {
        // Player player = evt.getPlayer(); // The player who joined
    }
     
    }
    The 'Data.txt' is named as said.
    Plugins > Commands > Data.txt

    Error:
    Code:
    2012-08-23 04:24:00 [INFO] Starting minecraft server version 1.3.1
    2012-08-23 04:24:00 [INFO] Loading properties
    2012-08-23 04:24:00 [INFO] Default game type: SURVIVAL
    2012-08-23 04:24:00 [INFO] Generating keypair
    2012-08-23 04:24:01 [INFO] Starting Minecraft server on *:4546
    2012-08-23 04:24:01 [INFO] This server is running CraftBukkit version git-Bukkit-1.3.1-R2.0-b2340jnks (MC: 1.3.1) (Implementing API version 1.3.1-R2.0)
    2012-08-23 04:24:01 [INFO] [Commands] Loading Commands v1.0
    2012-08-23 04:24:01 [INFO] Preparing level "Spawn"
    2012-08-23 04:24:02 [INFO] Preparing start region for level 0 (Seed: 473602228706924165)
    2012-08-23 04:24:03 [INFO] Preparing spawn area: 81%
    2012-08-23 04:24:03 [INFO] Preparing start region for level 1 (Seed: -7577936170730606454)
    2012-08-23 04:24:03 [INFO] [Commands] Enabling Commands v1.0
    2012-08-23 04:24:03 [INFO] Commands version 1.0 Has been Enabled!
    2012-08-23 04:24:03 [INFO] Server permissions file permissions.yml is empty, ignoring it
    2012-08-23 04:24:03 [INFO] Done (2.002s)! For help, type "help" or "?"
    2012-08-23 04:24:11 [INFO] Tehepicford[/86.21.20.243:56182] logged in with entity id 324 at ([Spawn] 43.898028906268095, 101.170014353305, 247.01437134194845)
    2012-08-23 04:24:13 [SEVERE] java.io.FileNotFoundException: plugins\Commands\Data.txt (The system cannot find the path specified)
    2012-08-23 04:24:13 [SEVERE]    at java.io.FileOutputStream.open(Native Method)
    2012-08-23 04:24:13 [SEVERE]    at java.io.FileOutputStream.<init>(Unknown Source)
    2012-08-23 04:24:13 [SEVERE]    at java.io.FileOutputStream.<init>(Unknown Source)
    2012-08-23 04:24:13 [SEVERE]    at com.fordnatford.Commands.Main.save(Main.java:41)
    2012-08-23 04:24:13 [SEVERE]    at com.fordnatford.Commands.Main.onCommand(Main.java:76)
    2012-08-23 04:24:13 [SEVERE]    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
    2012-08-23 04:24:13 [SEVERE]    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:168)
    2012-08-23 04:24:13 [SEVERE]    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:492)
    2012-08-23 04:24:13 [SEVERE]    at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:878)
    2012-08-23 04:24:13 [SEVERE]    at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:825)
    2012-08-23 04:24:13 [SEVERE]    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:807)
    2012-08-23 04:24:13 [SEVERE]    at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:44)
    2012-08-23 04:24:13 [SEVERE]    at net.minecraft.server.NetworkManager.b(NetworkManager.java:276)
    2012-08-23 04:24:13 [SEVERE]    at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:109)
    2012-08-23 04:24:13 [SEVERE]    at net.minecraft.server.ServerConnection.b(SourceFile:35)
    2012-08-23 04:24:13 [SEVERE]    at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
    2012-08-23 04:24:13 [SEVERE]    at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:581)
    2012-08-23 04:24:13 [SEVERE]    at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
    2012-08-23 04:24:13 [SEVERE]    at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:474)
    2012-08-23 04:24:13 [SEVERE]    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:406)
    2012-08-23 04:24:13 [SEVERE]    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    2012-08-23 04:24:16 [INFO] Tehepicford lost connection: disconnect.quitting
    2012-08-23 04:24:16 [INFO] Connection reset
    2012-08-23 04:24:18 [INFO] CONSOLE: Stopping the server..[m
    2012-08-23 04:24:18 [INFO] Stopping server
    2012-08-23 04:24:18 [INFO] [Commands] Disabling Commands v1.0
    2012-08-23 04:24:18 [INFO] Commands Has been disabled!
    2012-08-23 04:24:18 [WARNING] DSCT: socket closed
    2012-08-23 04:24:18 [INFO] Saving players
    2012-08-23 04:24:18 [INFO] Saving worlds
    2012-08-23 04:24:18 [INFO] Closing listening thread
    2012-08-23 04:24:18 [INFO] Saving chunks for level 'Spawn'/[email protected]
    2012-08-23 04:24:19 [INFO] Saving chunks for level 'Spawn_the_end'/[email protected]
    2012-08-23 04:24:19 [INFO] Stopping server
    2012-08-23 04:24:19 [INFO] Saving players
    2012-08-23 04:24:19 [INFO] Saving worlds
    


    HELP!!! :)
    Also! I dont want any nonsense saying 'Don't use a hashmap!' 'That is such a bad way to do it, Use this way' Just please, A FIX!

    Oh, And yes. I got this from the wiki, I know it is fairly outdated!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  2. Offline

    Jnorr44

    I would really like to know how to do this as well. One thing I have never been good at is saving objects to files. The wiki is outdated, but it still should work, because most of the section for this is Java, as is saving an object to a file, but there are a few bukkit things in the mix that may be causing your problem. I would suggest changing the Bukkit things around, and leaving the Java stuff alone.
     
  3. Offline

    Tehepicford

    Yes, Its something I wanted to know since I created my 2d game, And as of I desperately need it for Minecaft. HELP!
     
  4. Offline

    Jnorr44

    Don't worry, I never really get replies on my questions either. Its because were more advanced XD.
     
  5. Offline

    Tehepicford

    Lol.

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  6. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    Don't bump so quickly.

    You need to make sure the file exists before reading it.
     
  7. Offline

    Tehepicford

    Sorry, But it exists in Workspace > Commands > Data.txt
    plugins > Commands > Data.txt

    Are you any good at these?
    I hope this does not be considered as a bump :( I don't want a Infarction so soon.
     
Thread Status:
Not open for further replies.

Share This Page