forked from cybertiger/Bukkit-LibNBT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstanceChunkLoader.java
86 lines (76 loc) · 2.38 KB
/
InstanceChunkLoader.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.cyberiantiger.minecraft.unsafe.v1_12_R1_1;
import java.io.IOException;
import net.minecraft.server.v1_12_R1.*;
/**
* Version for Spigot 1.12.2
*/
public final class InstanceChunkLoader implements IChunkLoader, IAsyncChunkSaver {
private final ChunkRegionLoader loadLoader;
private final ChunkRegionLoader saveLoader;
public InstanceChunkLoader(ChunkRegionLoader loadLoader, ChunkRegionLoader saveLoader) {
this.loadLoader = loadLoader;
this.saveLoader = saveLoader;
}
/**
* Load chunk.
* @param world World
* @param i Chunk x coord.
* @param j Chunk y coord.
* @return The loaded chunk, or null if it does not exist.
* @throws IOException When an IOException occurs.
*/
@Override
public Chunk a(World world, int i, int j) throws IOException {
if (saveLoader.chunkExists(i, j)) {
return saveLoader.a(world, i, j);
}
return loadLoader.a(world, i, j);
}
/**
* Save chunk.
* @param world World
* @param chunk Chunk to save.
* @throws IOException If an error occurs saving the chunk.
* @throws ExceptionWorldConflict If more than one Minecraft has opened the world.
*/
@Override
public void saveChunk(World world, Chunk chunk, boolean unload) throws IOException, ExceptionWorldConflict {
saveLoader.saveChunk(world, chunk, unload);
}
/**
* This is a no-op in the server version of minecraft, it is assumed to do something useful in the client
* internal server version.
*/
@Override
public void b() {
}
/**
* Sync all in memory data to disk.
* @return true if all chunks saved successfully, false otherwise.
*/
@Override
public boolean a() {
return saveLoader.a();
}
/**
* Force sync to disk (keeps trying until all chunks are saved or an error occurs).
*/
@Override
public void c() {
saveLoader.c();
}
/**
* Test if a chunk exists in the save file.
* @param i Chunk x coordinate.
* @param j Chunk y coordinate.
* @return true if the chunk exists, false otherwise.
*/
@Override
public boolean chunkExists(int i, int j) {
return loadLoader.chunkExists(i, j) || saveLoader.chunkExists(i, j);
}
}