Caffeine!
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -117,7 +117,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
<version>2.6.3-SNAPSHOT</version>
|
||||
<version>2.7.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.koloboke</groupId>
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package co.aikar.timings;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import net.minecraft.server.*;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.bukkit.craftbukkit.scheduler.CraftTask;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -39,7 +40,7 @@ public final class MinecraftTimings {
|
||||
public static final Timing antiXrayUpdateTimer = Timings.ofSafe("anti-xray - update");
|
||||
public static final Timing antiXrayObfuscateTimer = Timings.ofSafe("anti-xray - obfuscate");
|
||||
|
||||
private static final Map<Class<?>, String> taskNameCache = new MapMaker().weakKeys().makeMap();
|
||||
private static final Cache<Class<?>, String> taskNameCache = com.github.benmanes.caffeine.cache.Caffeine.newBuilder().weakKeys().build(); // Akarin - caffeine
|
||||
|
||||
private MinecraftTimings() {}
|
||||
|
||||
@@ -64,7 +65,7 @@ public final class MinecraftTimings {
|
||||
plugin = TimingsManager.getPluginByClassloader(taskClass);
|
||||
}
|
||||
|
||||
final String taskname = taskNameCache.computeIfAbsent(taskClass, clazz ->
|
||||
final String taskname = taskNameCache.get(taskClass, clazz -> // Akarin - caffeine
|
||||
clazz.isAnonymousClass() || clazz.isLocalClass()
|
||||
? clazz.getName()
|
||||
: clazz.getCanonicalName());
|
||||
|
||||
@@ -1,28 +1,30 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class BiomeCache {
|
||||
|
||||
private final WorldChunkManager a;
|
||||
private final LoadingCache<ChunkCoordIntPair, BiomeCache.a> b;
|
||||
private final com.github.benmanes.caffeine.cache.LoadingCache<ChunkCoordIntPair, net.minecraft.server.BiomeCache.a> b; // Akarin - caffeine
|
||||
|
||||
public BiomeCache(WorldChunkManager worldchunkmanager) {
|
||||
this.b = CacheBuilder.newBuilder().expireAfterAccess(30000L, TimeUnit.MILLISECONDS).build(new CacheLoader<ChunkCoordIntPair, BiomeCache.a>() {
|
||||
// Akarin start - caffeine
|
||||
this.b = com.github.benmanes.caffeine.cache.Caffeine.newBuilder().expireAfterAccess(30L, TimeUnit.SECONDS).build(new com.github.benmanes.caffeine.cache.CacheLoader<ChunkCoordIntPair, BiomeCache.a>() {
|
||||
@Override
|
||||
public BiomeCache.a load(ChunkCoordIntPair chunkcoordintpair) throws Exception {
|
||||
return BiomeCache.this.new a(chunkcoordintpair.x, chunkcoordintpair.z);
|
||||
}
|
||||
});
|
||||
// Akarin end
|
||||
this.a = worldchunkmanager;
|
||||
}
|
||||
|
||||
public BiomeCache.a a(int i, int j) {
|
||||
i >>= 4;
|
||||
j >>= 4;
|
||||
return (BiomeCache.a) this.b.getUnchecked(new ChunkCoordIntPair(i, j));
|
||||
return (BiomeCache.a) this.b.get(new ChunkCoordIntPair(i, j)); // Akarin - caffeine
|
||||
}
|
||||
|
||||
public BiomeBase a(int i, int j, BiomeBase biomebase) {
|
||||
|
||||
@@ -138,7 +138,7 @@ public class BlockPortal extends Block {
|
||||
public ShapeDetector.ShapeDetectorCollection c(GeneratorAccess generatoraccess, BlockPosition blockposition) {
|
||||
EnumDirection.EnumAxis enumdirection_enumaxis = EnumDirection.EnumAxis.Z;
|
||||
BlockPortal.Shape blockportal_shape = new BlockPortal.Shape(generatoraccess, blockposition, EnumDirection.EnumAxis.X);
|
||||
LoadingCache<BlockPosition, ShapeDetectorBlock> loadingcache = ShapeDetector.a(generatoraccess, true);
|
||||
com.github.benmanes.caffeine.cache.LoadingCache<BlockPosition, ShapeDetectorBlock> loadingcache = ShapeDetector.a(generatoraccess, true); // Akarin - caffeine
|
||||
|
||||
if (!blockportal_shape.d()) {
|
||||
enumdirection_enumaxis = EnumDirection.EnumAxis.X;
|
||||
|
||||
@@ -45,23 +45,23 @@ public class ShapeDetector {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ShapeDetector.ShapeDetectorCollection a(BlockPosition blockposition, EnumDirection enumdirection, EnumDirection enumdirection1, LoadingCache<BlockPosition, ShapeDetectorBlock> loadingcache) {
|
||||
private ShapeDetector.ShapeDetectorCollection a(BlockPosition blockposition, EnumDirection enumdirection, EnumDirection enumdirection1, com.github.benmanes.caffeine.cache.LoadingCache<BlockPosition, ShapeDetectorBlock> loadingcache) { // Akarin - caffeine
|
||||
for (int i = 0; i < this.d; ++i) {
|
||||
for (int j = 0; j < this.c; ++j) {
|
||||
for (int k = 0; k < this.b; ++k) {
|
||||
if (!this.a[k][j][i].test(loadingcache.getUnchecked(a(blockposition, enumdirection, enumdirection1, i, j, k)))) {
|
||||
if (!this.a[k][j][i].test(loadingcache.get(a(blockposition, enumdirection, enumdirection1, i, j, k)))) { // Akarin - caffeine
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ShapeDetector.ShapeDetectorCollection(blockposition, enumdirection, enumdirection1, loadingcache, this.d, this.c, this.b);
|
||||
return new ShapeDetector.ShapeDetectorCollection(blockposition, enumdirection, enumdirection1, loadingcache, this.d, this.c, this.b); // Akarin - caffeine
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ShapeDetector.ShapeDetectorCollection a(IWorldReader iworldreader, BlockPosition blockposition) {
|
||||
LoadingCache<BlockPosition, ShapeDetectorBlock> loadingcache = a(iworldreader, false);
|
||||
com.github.benmanes.caffeine.cache.LoadingCache<BlockPosition, ShapeDetectorBlock> loadingcache = a(iworldreader, false); // Akarin - caffeine
|
||||
int i = Math.max(Math.max(this.d, this.c), this.b);
|
||||
Iterator iterator = BlockPosition.a(blockposition, blockposition.a(i - 1, i - 1, i - 1)).iterator();
|
||||
|
||||
@@ -92,8 +92,8 @@ public class ShapeDetector {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static LoadingCache<BlockPosition, ShapeDetectorBlock> a(IWorldReader iworldreader, boolean flag) {
|
||||
return CacheBuilder.newBuilder().build(new ShapeDetector.BlockLoader(iworldreader, flag));
|
||||
public static com.github.benmanes.caffeine.cache.LoadingCache<BlockPosition, ShapeDetectorBlock> a(IWorldReader iworldreader, boolean flag) { // Akarin - caffeine
|
||||
return com.github.benmanes.caffeine.cache.Caffeine.newBuilder().build(new ShapeDetector.BlockLoader(iworldreader, flag)); // Akarin - caffeine
|
||||
}
|
||||
|
||||
protected static BlockPosition a(BlockPosition blockposition, EnumDirection enumdirection, EnumDirection enumdirection1, int i, int j, int k) {
|
||||
@@ -113,12 +113,12 @@ public class ShapeDetector {
|
||||
private final BlockPosition a;
|
||||
private final EnumDirection b;
|
||||
private final EnumDirection c;
|
||||
private final LoadingCache<BlockPosition, ShapeDetectorBlock> d;
|
||||
private final com.github.benmanes.caffeine.cache.LoadingCache<BlockPosition, ShapeDetectorBlock> d; // Akarin - caffeine
|
||||
private final int e;
|
||||
private final int f;
|
||||
private final int g;
|
||||
|
||||
public ShapeDetectorCollection(BlockPosition blockposition, EnumDirection enumdirection, EnumDirection enumdirection1, LoadingCache<BlockPosition, ShapeDetectorBlock> loadingcache, int i, int j, int k) {
|
||||
public ShapeDetectorCollection(BlockPosition blockposition, EnumDirection enumdirection, EnumDirection enumdirection1, com.github.benmanes.caffeine.cache.LoadingCache<BlockPosition, ShapeDetectorBlock> loadingcache, int i, int j, int k) { // Akarin - caffeine
|
||||
this.a = blockposition;
|
||||
this.b = enumdirection;
|
||||
this.c = enumdirection1;
|
||||
@@ -150,7 +150,7 @@ public class ShapeDetector {
|
||||
}
|
||||
|
||||
public ShapeDetectorBlock a(int i, int j, int k) {
|
||||
return (ShapeDetectorBlock) this.d.getUnchecked(ShapeDetector.a(this.a, this.getFacing(), this.c(), i, j, k));
|
||||
return (ShapeDetectorBlock) this.d.get(ShapeDetector.a(this.a, this.getFacing(), this.c(), i, j, k)); // Akarin - caffeine
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
@@ -158,7 +158,7 @@ public class ShapeDetector {
|
||||
}
|
||||
}
|
||||
|
||||
static class BlockLoader extends CacheLoader<BlockPosition, ShapeDetectorBlock> {
|
||||
static class BlockLoader implements com.github.benmanes.caffeine.cache.CacheLoader<BlockPosition, ShapeDetectorBlock> { // Akarin - caffeine
|
||||
|
||||
private final IWorldReader a;
|
||||
private final boolean b;
|
||||
|
||||
@@ -38,10 +38,10 @@ public class TileEntitySkull extends TileEntity /*implements ITickable*/ { // Pa
|
||||
.setNameFormat("Head Conversion Thread - %1$d")
|
||||
.build()
|
||||
);
|
||||
public static final LoadingCache<String, GameProfile> skinCache = CacheBuilder.newBuilder()
|
||||
public static final com.github.benmanes.caffeine.cache.LoadingCache<String, GameProfile> skinCache = com.github.benmanes.caffeine.cache.Caffeine.newBuilder() // Akarin - caffeine
|
||||
.maximumSize( 5000 )
|
||||
.expireAfterAccess( 60, TimeUnit.MINUTES )
|
||||
.build( new CacheLoader<String, GameProfile>()
|
||||
.build( new com.github.benmanes.caffeine.cache.CacheLoader<String, GameProfile>()
|
||||
{
|
||||
@Override
|
||||
public GameProfile load(String key) throws Exception
|
||||
@@ -216,7 +216,7 @@ public class TileEntitySkull extends TileEntity /*implements ITickable*/ { // Pa
|
||||
Callable<GameProfile> callable = new Callable<GameProfile>() {
|
||||
@Override
|
||||
public GameProfile call() {
|
||||
final GameProfile profile = skinCache.getUnchecked(gameprofile.getName().toLowerCase(java.util.Locale.ROOT));
|
||||
final GameProfile profile = skinCache.get(gameprofile.getName().toLowerCase(java.util.Locale.ROOT)); // Akarin - caffeine
|
||||
MinecraftServer.getServer().processQueue.add(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -7,6 +7,10 @@ import com.google.common.collect.ContiguousSet;
|
||||
import com.google.common.collect.DiscreteDomain;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Range;
|
||||
|
||||
import net.minecraft.server.BiomeCache.a;
|
||||
import net.minecraft.server.WorldGenEnder.Spike;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
@@ -14,7 +18,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class WorldGenDecoratorSpike extends WorldGenDecorator<WorldGenFeatureDecoratorEmptyConfiguration> {
|
||||
|
||||
private static final LoadingCache<Long, WorldGenEnder.Spike[]> a = CacheBuilder.newBuilder().expireAfterWrite(5L, TimeUnit.MINUTES).build(new WorldGenDecoratorSpike.a());
|
||||
private static final com.github.benmanes.caffeine.cache.LoadingCache<Long, Spike[]> a = com.github.benmanes.caffeine.cache.Caffeine.newBuilder().expireAfterAccess(5L, TimeUnit.MINUTES).build(new WorldGenDecoratorSpike.a()); // Akarin - caffeine
|
||||
|
||||
public WorldGenDecoratorSpike() {}
|
||||
|
||||
@@ -40,10 +44,10 @@ public class WorldGenDecoratorSpike extends WorldGenDecorator<WorldGenFeatureDec
|
||||
Random random = new Random(generatoraccess.getSeed());
|
||||
long i = random.nextLong() & 65535L;
|
||||
|
||||
return (WorldGenEnder.Spike[]) WorldGenDecoratorSpike.a.getUnchecked(i);
|
||||
return (WorldGenEnder.Spike[]) WorldGenDecoratorSpike.a.get(i); // Akarin - caffeine
|
||||
}
|
||||
|
||||
static class a extends CacheLoader<Long, WorldGenEnder.Spike[]> {
|
||||
static class a implements com.github.benmanes.caffeine.cache.CacheLoader<Long, WorldGenEnder.Spike[]> { // Akarin - caffeine
|
||||
|
||||
private a() {}
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ public final class CraftServer implements Server {
|
||||
private YamlConfiguration configuration;
|
||||
private YamlConfiguration commandsConfiguration;
|
||||
private final Yaml yaml = new Yaml(new SafeConstructor());
|
||||
private final Map<UUID, OfflinePlayer> offlinePlayers = new MapMaker().weakValues().makeMap();
|
||||
private final com.github.benmanes.caffeine.cache.Cache<UUID, OfflinePlayer> offlinePlayers = com.github.benmanes.caffeine.cache.Caffeine.newBuilder().weakValues().build(); // Akarin - caffeine
|
||||
private final EntityMetadataStore entityMetadata = new EntityMetadataStore();
|
||||
private final PlayerMetadataStore playerMetadata = new PlayerMetadataStore();
|
||||
private final WorldMetadataStore worldMetadata = new WorldMetadataStore();
|
||||
@@ -1468,7 +1468,7 @@ public final class CraftServer implements Server {
|
||||
result = getOfflinePlayer(profile);
|
||||
}
|
||||
} else {
|
||||
offlinePlayers.remove(result.getUniqueId());
|
||||
offlinePlayers.invalidate(result.getUniqueId()); // Akarin - caffeine
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -1480,13 +1480,13 @@ public final class CraftServer implements Server {
|
||||
|
||||
OfflinePlayer result = getPlayer(id);
|
||||
if (result == null) {
|
||||
result = offlinePlayers.get(id);
|
||||
result = offlinePlayers.getIfPresent(id);
|
||||
if (result == null) {
|
||||
result = new CraftOfflinePlayer(this, new GameProfile(id, null));
|
||||
offlinePlayers.put(id, result);
|
||||
}
|
||||
} else {
|
||||
offlinePlayers.remove(id);
|
||||
offlinePlayers.invalidate(id); // Akarin - caffeine
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user