Update Upstream

ed28089 Don't crash if fields are null in ChunkDeleter (1874)
f049d56 Revert "Use a Guava Cache instead of a ThreadLocal (1859)"
c5a4450 Internally use a negated mask class to prevent russian doll wrapping (1877)
1397ec7 Add Snow Smooth Tools (1580)

Fixes #955
Fixes #858
This commit is contained in:
NotMyFault
2021-08-22 11:56:39 +02:00
parent df8b2802b2
commit cf671ad7ff
11 changed files with 540 additions and 63 deletions

View File

@ -19,9 +19,6 @@
package com.sk89q.worldedit.session.request;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.extension.platform.Actor;
@ -30,15 +27,19 @@ import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Describes the current request
* Describes the current request using a {@link ThreadLocal}.
*/
public final class Request {
private static final LoadingCache<Thread, Request> THREAD_TO_REQUEST = CacheBuilder.newBuilder()
.weakKeys()
.build(CacheLoader.from(Request::new));
private static final ThreadLocal<Request> threadLocal = ThreadLocal.withInitial(Request::new);
//FAWE start
// TODO any better way to deal with this?
private static final Map<Thread, Request> requests = new ConcurrentHashMap<>();
//FAWE end
@Nullable
private World world;
@ -55,11 +56,14 @@ public final class Request {
//FAWE end
private Request() {
//FAWE start
requests.put(Thread.currentThread(), this);
//FAWE end
}
//FAWE start
public static Collection<Request> getAll() {
return THREAD_TO_REQUEST.asMap().values();
return requests.values();
}
//FAWE end
@ -158,7 +162,7 @@ public final class Request {
* @return the current request
*/
public static Request request() {
return THREAD_TO_REQUEST.getUnchecked(Thread.currentThread());
return threadLocal.get();
}
/**
@ -166,7 +170,10 @@ public final class Request {
*/
public static void reset() {
request().invalidate();
THREAD_TO_REQUEST.invalidate(Thread.currentThread());
threadLocal.remove();
//FAWE start
requests.remove(Thread.currentThread());
//FAWE end
}
/**