@Override public boolean updateQuitLoc(final PlayerAuth auth) { if (!cache.containsKey(auth.getNickname())) { return false; } final PlayerAuth cachedAuth = cache.get(auth.getNickname()); final double oldX = cachedAuth.getQuitLocX(); final double oldY = cachedAuth.getQuitLocY(); final double oldZ = cachedAuth.getQuitLocZ(); final String oldWorld = cachedAuth.getWorld(); cachedAuth.setQuitLocX(auth.getQuitLocX()); cachedAuth.setQuitLocY(auth.getQuitLocY()); cachedAuth.setQuitLocZ(auth.getQuitLocZ()); cachedAuth.setWorld(auth.getWorld()); exec.execute( new Runnable() { @Override public void run() { if (!source.updateQuitLoc(auth)) { if (cache.containsKey(auth.getNickname())) { PlayerAuth cachedAuth = cache.get(auth.getNickname()); cachedAuth.setQuitLocX(oldX); cachedAuth.setQuitLocY(oldY); cachedAuth.setQuitLocZ(oldZ); cachedAuth.setWorld(oldWorld); } } } }); return true; }
/** * Method set. * * @param auth PlayerAuth */ public void set(PlayerAuth auth) { this.setEmail(auth.getEmail()); this.setPassword(auth.getPassword()); this.setIp(auth.getIp()); this.setLastLogin(auth.getLastLogin()); this.setNickname(auth.getNickname()); this.setQuitLocX(auth.getQuitLocX()); this.setQuitLocY(auth.getQuitLocY()); this.setQuitLocZ(auth.getQuitLocZ()); this.setWorld(auth.getWorld()); this.setRealName(auth.getRealName()); }
@Override public boolean updateQuitLoc(PlayerAuth auth) { if (!isAuthAvailable(auth.getNickname())) { return false; } PlayerAuth newAuth = null; BufferedReader br = null; try { br = new BufferedReader(new FileReader(source)); String line; while ((line = br.readLine()) != null) { String[] args = line.split(":"); if (args[0].equalsIgnoreCase(auth.getNickname())) { newAuth = new PlayerAuth( args[0], args[1], args[2], Long.parseLong(args[3]), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), auth.getEmail(), args[0]); break; } } } catch (FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return false; } catch (IOException ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { if (br != null) { try { br.close(); } catch (IOException ex) { } } } if (newAuth != null) { removeAuth(auth.getNickname()); saveAuth(newAuth); } return true; }
@Override public synchronized boolean saveAuth(PlayerAuth auth) { if (isAuthAvailable(auth.getNickname())) { return false; } BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(source, true)); bw.write( auth.getNickname() + ":" + auth.getHash() + ":" + auth.getIp() + ":" + auth.getLastLogin() + ":" + auth.getQuitLocX() + ":" + auth.getQuitLocY() + ":" + auth.getQuitLocZ() + ":" + auth.getWorld() + ":" + auth.getEmail() + "\n"); } catch (IOException ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { if (bw != null) { try { bw.close(); } catch (IOException ex) { } } } return true; }