-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
PatchPlayerManagerForge.java
61 lines (51 loc) · 1.78 KB
/
PatchPlayerManagerForge.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package me.nallar.tickthreading.minecraft.patched;
import java.util.List;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import me.nallar.tickthreading.Log;
import me.nallar.tickthreading.patcher.Declare;
import net.minecraft.server.management.PlayerInstance;
import net.minecraft.server.management.PlayerManager;
import net.minecraft.world.WorldServer;
public abstract class PatchPlayerManagerForge extends PlayerManager {
@Declare
public java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock playerUpdateLock_;
@Declare
public java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock playersUpdateLock_;
public void construct() {
ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock();
playersUpdateLock = reentrantReadWriteLock.writeLock();
playerUpdateLock = reentrantReadWriteLock.readLock();
}
public PatchPlayerManagerForge(WorldServer par1WorldServer, int par2) {
super(par1WorldServer, par2);
}
@Override
@Declare
public net.minecraft.util.LongHashMap getChunkWatchers() {
return this.playerInstances;
}
@Override
@Declare
public List getChunkWatcherWithPlayers() {
return this.chunkWatcherWithPlayers;
}
@Override
public void updatePlayerInstances() {
playersUpdateLock.lock();
try {
for (Object chunkWatcherWithPlayer : this.chunkWatcherWithPlayers) {
if (chunkWatcherWithPlayer instanceof PlayerInstance) {
((PlayerInstance) chunkWatcherWithPlayer).sendChunkUpdate();
}
}
} catch (Exception e) {
Log.severe("Failed to send some chunks", e);
} finally {
playersUpdateLock.unlock();
}
this.chunkWatcherWithPlayers.clear();
if (this.players.isEmpty()) {
this.theWorldServer.theChunkProviderServer.unloadAllChunks();
}
}
}