-
-
Notifications
You must be signed in to change notification settings - Fork 204
/
SlowExtent.java
41 lines (34 loc) · 1.18 KB
/
SlowExtent.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
package com.fastasyncworldedit.core.extent;
import com.fastasyncworldedit.core.Fawe;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.block.BlockStateHolder;
public final class SlowExtent extends AbstractDelegateExtent {
private final long THRESHOLD = 50 * 1000000; // 1 tick
private final long nanos;
private long increment;
public SlowExtent(Extent extent, long nanos) {
super(extent);
this.nanos = nanos;
}
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException {
delay();
return super.setBlock(x, y, z, block);
}
public void delay() {
increment += nanos;
if (increment >= THRESHOLD) {
long wait = increment / 1000000;
if (!Fawe.isMainThread()) {
try {
Thread.sleep(wait);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
increment -= wait * 1000000;
}
}
}