ReadFile

Discussion in 'Plugin Development' started by wouter0100, Jul 13, 2011.

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

    wouter0100

    Don't work, no log ore something :(.
     
  2. Offline

    Hretsam

    Nothing at all, then it works right? can you print the outcome?
     
  3. Offline

    wouter0100

    Nothing outcome, don't work good :(!
     
  4. Offline

    Hretsam

    Thats not possible, It would return true/false or give an exception (those are all caught and send to the console)
     
  5. Offline

    wouter0100


    Log: Return1 false.
    Code:
     if (inputDate.getTime() <= currentDate.getTime()) {
                                    log("Return true");
                                    return true;
                                } else {
                                    log("Return1 false");
                                    return false;
                                }
                            }
    //edit with 1 player.
    When the 2e joins, and 1 of the 2 players rejoin.
    the server say:
    Return2 false.
    code (open)

    Code:
                boolean ReadFile(Player player, String checkdate) {
                    String strLine;
                    String[] split;
                    String p = player.getName();
    
                    DateFormat format = new SimpleDateFormat("yyyy/MM/dd/kk");
                    Date currentDate = new Date(), inputDate;
    
                    try {
                        FileInputStream fstream = new FileInputStream(playersListFile);
                        DataInputStream in = new DataInputStream(fstream);
                        BufferedReader bw = new BufferedReader(new InputStreamReader(in));
    
                        while ((strLine = bw.readLine()) != null) {
    
                            split = strLine.split(" ");
    
                            //log("ReadFile out: ."+p+". ."+split[0]+".");
    
                            if (p.compareTo(split[0]) == 0) {
    
                                split = split[1].split("/");
    
                                try {
                                    inputDate = format.parse(split[0]
                                            + "/" + (split[1].length() == 2 ? split[1] : "0" + split[1])
                                            + "/" + (split[2].length() == 2 ? split[2] : "0" + split[2])
                                            + "/" + (split[3].length() == 2 ? split[3] : "0" + split[3]) );
                                } catch (ParseException pe) {
                                    log("ParseException " + pe);
                                    inputDate = new Date();
                                }
    
                                if (inputDate.getTime() >= currentDate.getTime()) {
                                    log("Return true");
                                    return true;
                                } else {
                                    log("Return1 false");
                                    return false;
                                }
                            }
                            log("Return2 false");
                            return false;
                        }
                        in.close();
                    } catch (Exception e) {
                        log("Error: " + e.getMessage());
                    }
                    log("Return3 false");
                    return false;
                }
     
  6. Offline

    Hretsam

    Then it works right?
     
  7. Offline

    wouter0100


    No, 2 players dont work, return2 false is that the
    if (p.compareTo(split[0]) == 0) {
    is failed...
    i'am bussy with more logs.

    i'am trying this:
    Code:
    log("Return2 false - "+ p.compareTo(split[0]) + " - " + checkdate +  " - " +  currentDate.getTime() + " - " + split);
    outcoming when the 2e player rejoin:
    outcoming when the 3e player rejoin:
    p.compareTo(split[0]) is something wrong..
     
  8. Offline

    Hretsam

    ok and what is p?
     
  9. Offline

    wouter0100

  10. Offline

    Hretsam

    You cant compare a player to a name, to compare the names use
    p.getName().equalsignorecase(split[0])
     
  11. Offline

    wouter0100

    String p = player.getName();
    and if i replace your script to it and replace p to player, it gives the following error:
     
  12. Offline

    Hretsam

    Hmm your using an "==" somewhere?
     
  13. Offline

    wouter0100

    if (player.getName().equalsIgnoreCase(split[0]) == 0) {
     
  14. Offline

    Hretsam

    just if (player.getName().equalsIgnoreCase(split[0]) ) {
     
  15. Offline

    wouter0100

    Same, its not 0, i see here 13 by the 3e player and -18 by the 2e player ;o
     
  16. Offline

    Hretsam

    The .equalsIgnoreCase() method returns a boolean, not an int value
     
  17. Offline

    wouter0100

    and how can i fix that?

    //edit:
    Code:
     if (player.getName().compareToIgnoreCase(split[0]) == 0) {
    ?
     
  18. Offline

    Hretsam

    Like my post #45, remove the == 0
     
  19. Offline

    wouter0100

    aa okay!
    but then it don't work very good (when 2 ore more players are registered its buggy.)
     
  20. Offline

    Hretsam

    What is it exactly what your trying to do?
     
  21. Offline

    wouter0100

    It need to check the time in the file with the current time.
    If the time in the file is same ore lower, it need to return true. if higher false.
    Time: yyyy/MM/dd/kk (time in file is +24 hours, but that works.)
    it need to check the time from the player that gives with the function (
    Code:
     public boolean ReadFile(Player player, String checkdate) {
    checkdate is current time in a string
    Script:
    Code:
     public boolean ReadFile(Player player, String checkdate) {
                    String strLine;
                    String[] split;
                    String p = player.getName();
    
                    DateFormat format = new SimpleDateFormat("yyyy/MM/dd/kk");
                    Date currentDate = new Date(), inputDate;
    
                    try {
                        FileInputStream fstream = new FileInputStream(playersListFile);
                        DataInputStream in = new DataInputStream(fstream);
                        BufferedReader bw = new BufferedReader(new InputStreamReader(in));
    
                        while ((strLine = bw.readLine()) != null) {
    
                            split = strLine.split(" ");
    
                            //log("ReadFile out: ."+p+". ."+split[0]+".");
    
                            if (player.getName().equalsIgnoreCase(split[0])) {
    
                                split = split[1].split("/");
    
                                try {
                                    inputDate = format.parse(split[0]
                                            + "/" + (split[1].length() == 2 ? split[1] : "0" + split[1])
                                            + "/" + (split[2].length() == 2 ? split[2] : "0" + split[2])
                                            + "/" + (split[3].length() == 2 ? split[3] : "0" + split[3]) );
                                } catch (ParseException pe) {
                                    log("ParseException " + pe);
                                    inputDate = new Date();
                                }
    
                                if (inputDate.getTime() >= currentDate.getTime()) {
                                    log("Return true - "+ p.compareTo(split[0]) + " - " + checkdate +  " - " +  currentDate.getTime() + " - " + split);
                                    return true;
                                } else {
                                    log("Return1 false");
                                    return false;
                                }
                            }
                            log("Return2 false - "+ p.compareTo(split[0]) + " - " + checkdate +  " - " +  currentDate.getTime() + " - " + split);
                            return false;
                        }
                        in.close();
                    } catch (Exception e) {
                        log("Error: " + e.getMessage());
                    }
                    log("Return3 false");
                    return false;
                }
    (with some logs)
     
Thread Status:
Not open for further replies.

Share This Page