Skip to content

Commit 663ea55

Browse files
committed
i think virtual threads will better
1 parent b904775 commit 663ea55

2 files changed

Lines changed: 34 additions & 45 deletions

File tree

patches/minecraft/net/minecraft/tileentity/TileEntitySkull.java.patch

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- before/net/minecraft/tileentity/TileEntitySkull.java
22
+++ after/net/minecraft/tileentity/TileEntitySkull.java
3-
@@ -1,14 +1,32 @@
3+
@@ -1,14 +1,34 @@
44
package net.minecraft.tileentity;
55

66
+import catserver.server.CatServer;
@@ -16,6 +16,8 @@
1616
+import com.mojang.authlib.ProfileLookupCallback;
1717
import com.mojang.authlib.minecraft.MinecraftSessionService;
1818
import com.mojang.authlib.properties.Property;
19+
+
20+
+import java.util.Locale;
1921
+import java.util.UUID;
2022
+import java.util.concurrent.Callable;
2123
+import java.util.concurrent.ExecutorService;
@@ -33,7 +35,7 @@
3335
import net.minecraft.server.management.PlayerProfileCache;
3436
import net.minecraft.util.EnumFacing;
3537
import net.minecraft.util.ITickable;
36-
@@ -21,12 +39,65 @@
38+
@@ -21,12 +41,61 @@
3739
public class TileEntitySkull extends TileEntity implements ITickable
3840
{
3941
private int skullType;
@@ -45,15 +47,11 @@
4547
private static PlayerProfileCache profileCache;
4648
private static MinecraftSessionService sessionService;
4749
+ // Spigot start
48-
+ public static final ExecutorService executor = Executors.newFixedThreadPool(3,
49-
+ new ThreadFactoryBuilder()
50-
+ .setNameFormat("Head Conversion Thread - %1$d")
51-
+ .build()
52-
+ );
50+
+ public static final ExecutorService executor = Executors.newThreadPerTaskExecutor(Thread.ofVirtual().name("Head Conversion Thread - %1$d").factory());
5351
+ public static final LoadingCache<String, GameProfile> skinCache = CacheBuilder.newBuilder()
5452
+ .maximumSize( 5000 )
5553
+ .expireAfterAccess( 60, TimeUnit.MINUTES )
56-
+ .build( new CacheLoader<String, GameProfile>()
54+
+ .build( new CacheLoader<>()
5755
+ {
5856
+ @Override
5957
+ public GameProfile load(String key) throws Exception
@@ -100,7 +98,7 @@
10098

10199
public static void setProfileCache(PlayerProfileCache profileCacheIn)
102100
{
103-
@@ -89,7 +160,7 @@
101+
@@ -89,7 +158,7 @@
104102
if (this.world.isBlockPowered(this.pos))
105103
{
106104
this.dragonAnimated = true;
@@ -109,7 +107,7 @@
109107
}
110108
else
111109
{
112-
@@ -138,47 +209,88 @@
110+
@@ -138,47 +207,76 @@
113111

114112
private void updatePlayerProfile()
115113
{
@@ -118,19 +116,15 @@
118116
+ // Spigot start
119117
+ GameProfile profile = this.playerProfile;
120118
+ setType( 0 ); // Work around client bug
121-
+ updateGameprofile(profile, new Predicate<GameProfile>() {
122-
+
123-
+ @Override
124-
+ public boolean apply(GameProfile input) {
125-
+ setType(3); // Work around client bug
126-
+ playerProfile = input;
127-
+ markDirty();
128-
+ if (world != null) {
129-
+ world.notifyLightSet(pos); // PAIL: notify
130-
+ }
131-
+ return false;
119+
+ updateGameprofile(profile, input -> {
120+
+ setType(3); // Work around client bug
121+
+ playerProfile = input;
122+
+ markDirty();
123+
+ if (world != null) {
124+
+ world.notifyLightSet(pos); // PAIL: notify
132125
+ }
133-
+ }, false);
126+
+ return false;
127+
+ }, false);
134128
+ // Spigot end
135129
+
136130
}
@@ -140,19 +134,20 @@
140134
+ public static Future<GameProfile> updateGameprofile(final GameProfile input, final Predicate<GameProfile> callback, boolean sync)
141135
{
142136
if (input != null && !StringUtils.isNullOrEmpty(input.getName()))
143-
{
144-
if (input.isComplete() && input.getProperties().containsKey("textures"))
145-
{
137+
- {
138+
- if (input.isComplete() && input.getProperties().containsKey("textures"))
139+
- {
146140
- return input;
147141
- }
148142
- else if (profileCache != null && sessionService != null)
149143
- {
150144
- GameProfile gameprofile = profileCache.getGameProfileForUsername(input.getName());
151-
+ callback.apply(input);
152-
+ } else if (MinecraftServer.getServerInst() == null) {
145+
+ { // TODO: can server instance be null?
146+
+ if ((input.isComplete() && input.getProperties().containsKey("textures")) || MinecraftServer.getServerInst() == null)
147+
+ {
153148
+ callback.apply(input);
154149
+ } else {
155-
+ GameProfile profile = skinCache.getIfPresent(input.getName().toLowerCase(java.util.Locale.ROOT));
150+
+ GameProfile profile = skinCache.getIfPresent(input.getName().toLowerCase(Locale.ROOT));
156151
+ if (profile != null && Iterables.getFirst(profile.getProperties().get("textures"), (Object) null) != null) {
157152
+ callback.apply(profile);
158153

@@ -168,22 +163,16 @@
168163
- if (property == null)
169164
- {
170165
- gameprofile = sessionService.fillProfileProperties(gameprofile, true);
171-
+ Callable<GameProfile> callable = new Callable<GameProfile>() {
172-
+ @Override
173-
+ public GameProfile call() {
174-
+ final GameProfile profile = skinCache.getUnchecked(input.getName().toLowerCase(java.util.Locale.ROOT));
175-
+ MinecraftServer.getServerInst().processQueue.add(new Runnable() {
176-
+ @Override
177-
+ public void run() {
178-
+ if (profile == null) {
179-
+ callback.apply(input);
180-
+ } else {
181-
+ callback.apply(profile);
182-
+ }
183-
+ }
184-
+ });
185-
+ return profile;
186-
+ }
166+
+ Callable<GameProfile> callable = () -> {
167+
+ final GameProfile profile1 = skinCache.getUnchecked(input.getName().toLowerCase(Locale.ROOT));
168+
+ MinecraftServer.getServerInst().processQueue.add(() -> {
169+
+ if (profile1 == null) {
170+
+ callback.apply(input);
171+
+ } else {
172+
+ callback.apply(profile1);
173+
+ }
174+
+ });
175+
+ return profile1;
187176
+ };
188177
+ if (sync) {
189178
+ try {

src/main/java/catserver/server/threads/AsyncTaskThread.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.util.concurrent.TimeUnit;
88

99
public class AsyncTaskThread {
10-
private static final ExecutorService asyncExecutor = Executors.newFixedThreadPool(2, new ThreadFactoryBuilder().setNameFormat("CatServer Async Task Handler Thread - %1$d").build()); // CatRoom - Sync Paper changes
10+
private static final ExecutorService asyncExecutor = Executors.newThreadPerTaskExecutor(Thread.ofVirtual().name("CatServer Async Task Handler Thread - %1$d").factory()); // CatRoom - Sync Paper changes
1111

1212
public static void shutdown() {
1313
try {

0 commit comments

Comments
 (0)