[help] issue with plugin

Discussion in 'Plugin Development' started by mason1370, May 17, 2012.

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

    mason1370

    so basicly im trying to write a plugin so when the player types/"Command" there name is added to a list

    i screwed up one of my newest ones so i went back to an older form and was able to fix that

    the issue with that is that it keeps rewriting the names everytime some one does it so it would say
    mason1370
    then someone else would type it and instead of
    mason1370
    joe123

    it would just show joe123
    here is my code

    publicboolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    {
    Player player = null;
    if (sender instanceof Player)
    {
    player = (Player) sender;
    }
    try{
    BufferedWriter out = new BufferedWriter(new FileWriter("test.txt"));
    out.write(sender.getName());
    out.newLine();
    }
    catch (IOException e)
    {
    log.info("There seems to be an issue");
    }

    log = this.getLogger();

    returnfalse;
     
  2. Offline

    r0306

    mason1370
    Try this instead.
    Code:
    publicboolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    {
    Player player = null;
    if (sender instanceof Player)
    {
    player = (Player) sender;
    }
    try{
    BufferedWriter out = new BufferedWriter(new FileWriter("test.txt"));
    out.write(sender.getName() + System.getProperty( "line.separator" ));
    out.close();
    }
    catch (IOException e)
    {
    log.info("There seems to be an issue");
    }
     
    log = this.getLogger();
     
    returnfalse;
     
  3. Offline

    Njol

    Change this line:
    BufferedWriter out = new BufferedWriter(new FileWriter("test.txt"));
    to:
    BufferedWriter out = new BufferedWriter(new FileWriter("test.txt", true));
    the 'true' lets the FileWriter append to the file instead of overwriting it.
     
  4. Offline

    mason1370

    Thank you guys very much it works great!!!! Hopefully this will finish up well and i will not need any more help.
     
Thread Status:
Not open for further replies.

Share This Page