mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-12 08:18:35 +00:00
More deprecation removal
This commit is contained in:
@ -64,7 +64,7 @@ public class SessionManager {
|
||||
private static final Logger log = Logger.getLogger(SessionManager.class.getCanonicalName());
|
||||
private final Timer timer = new Timer();
|
||||
private final WorldEdit worldEdit;
|
||||
private final Map<UUID, SessionHolder> sessions = new HashMap<UUID, SessionHolder>();
|
||||
private final Map<UUID, SessionHolder> sessions = new HashMap<>();
|
||||
private SessionStore store = new VoidStore();
|
||||
|
||||
/**
|
||||
@ -204,30 +204,27 @@ public class SessionManager {
|
||||
return Futures.immediateFuture(sessions);
|
||||
}
|
||||
|
||||
return executorService.submit(new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
Exception exception = null;
|
||||
return executorService.submit((Callable<Object>) () -> {
|
||||
Exception exception = null;
|
||||
|
||||
for (Map.Entry<SessionKey, LocalSession> entry : sessions.entrySet()) {
|
||||
SessionKey key = entry.getKey();
|
||||
for (Map.Entry<SessionKey, LocalSession> entry : sessions.entrySet()) {
|
||||
SessionKey key = entry.getKey();
|
||||
|
||||
if (key.isPersistent()) {
|
||||
try {
|
||||
store.save(getKey(key), entry.getValue());
|
||||
} catch (IOException e) {
|
||||
log.log(Level.WARNING, "Failed to write session for UUID " + getKey(key), e);
|
||||
exception = e;
|
||||
}
|
||||
if (key.isPersistent()) {
|
||||
try {
|
||||
store.save(getKey(key), entry.getValue());
|
||||
} catch (IOException e) {
|
||||
log.log(Level.WARNING, "Failed to write session for UUID " + getKey(key), e);
|
||||
exception = e;
|
||||
}
|
||||
}
|
||||
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
}
|
||||
|
||||
return sessions;
|
||||
}
|
||||
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
}
|
||||
|
||||
return sessions;
|
||||
});
|
||||
}
|
||||
|
||||
@ -305,7 +302,7 @@ public class SessionManager {
|
||||
synchronized (SessionManager.this) {
|
||||
long now = System.currentTimeMillis();
|
||||
Iterator<SessionHolder> it = sessions.values().iterator();
|
||||
Map<SessionKey, LocalSession> saveQueue = new HashMap<SessionKey, LocalSession>();
|
||||
Map<SessionKey, LocalSession> saveQueue = new HashMap<>();
|
||||
|
||||
while (it.hasNext()) {
|
||||
SessionHolder stored = it.next();
|
||||
|
@ -30,12 +30,7 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public final class Request {
|
||||
|
||||
private static final ThreadLocal<Request> threadLocal =
|
||||
new ThreadLocal<Request>() {
|
||||
@Override protected Request initialValue() {
|
||||
return new Request();
|
||||
}
|
||||
};
|
||||
private static final ThreadLocal<Request> threadLocal = ThreadLocal.withInitial(Request::new);
|
||||
|
||||
private @Nullable World world;
|
||||
private @Nullable LocalSession session;
|
||||
|
@ -85,8 +85,7 @@ public class JsonFileSessionStore implements SessionStore {
|
||||
@Override
|
||||
public LocalSession load(UUID id) throws IOException {
|
||||
File file = getPath(id);
|
||||
Closer closer = Closer.create();
|
||||
try {
|
||||
try (Closer closer = Closer.create()) {
|
||||
FileReader fr = closer.register(new FileReader(file));
|
||||
BufferedReader br = closer.register(new BufferedReader(fr));
|
||||
return gson.fromJson(br, LocalSession.class);
|
||||
@ -94,11 +93,6 @@ public class JsonFileSessionStore implements SessionStore {
|
||||
throw new IOException(e);
|
||||
} catch (FileNotFoundException e) {
|
||||
return new LocalSession();
|
||||
} finally {
|
||||
try {
|
||||
closer.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,19 +100,13 @@ public class JsonFileSessionStore implements SessionStore {
|
||||
public void save(UUID id, LocalSession session) throws IOException {
|
||||
File finalFile = getPath(id);
|
||||
File tempFile = new File(finalFile.getParentFile(), finalFile.getName() + ".tmp");
|
||||
Closer closer = Closer.create();
|
||||
|
||||
try {
|
||||
try (Closer closer = Closer.create()) {
|
||||
FileWriter fr = closer.register(new FileWriter(tempFile));
|
||||
BufferedWriter bw = closer.register(new BufferedWriter(fr));
|
||||
gson.toJson(session, bw);
|
||||
} catch (JsonIOException e) {
|
||||
throw new IOException(e);
|
||||
} finally {
|
||||
try {
|
||||
closer.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if (finalFile.exists()) {
|
||||
|
Reference in New Issue
Block a user