refactor: Deprecate IMP initializors in favor of builders

This commit is contained in:
NotMyFault
2021-12-22 20:58:23 +01:00
parent 34f971c729
commit 7da921e075
129 changed files with 750 additions and 677 deletions

View File

@ -510,10 +510,10 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
chunkPacket.setNativePacket(nmsPacket);
}
try {
FaweCache.IMP.CHUNK_FLAG.get().set(true);
FaweCache.INSTANCE.CHUNK_FLAG.get().set(true);
entityPlayer.connection.send(nmsPacket);
} finally {
FaweCache.IMP.CHUNK_FLAG.get().set(false);
FaweCache.INSTANCE.CHUNK_FLAG.get().set(false);
}
}
});

View File

@ -250,7 +250,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
}
}
};
TaskManager.IMP.async(() -> TaskManager.IMP.sync(runnableVal));
TaskManager.taskManager().async(() -> TaskManager.taskManager().sync(runnableVal));
}
@Override
@ -269,7 +269,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
if (Fawe.isMainThread()) {
runnableVal.run();
} else {
TaskManager.IMP.sync(runnableVal);
TaskManager.taskManager().sync(runnableVal);
}
cachedChanges.clear();
cachedChunksToSend.clear();

View File

@ -418,7 +418,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
try {
ServerLevel nmsWorld = serverLevel;
LevelChunk nmsChunk = ensureLoaded(nmsWorld, chunkX, chunkZ);
boolean fastmode = set.isFastMode() && Settings.IMP.QUEUE.NO_TICK_FASTMODE;
boolean fastmode = set.isFastMode() && Settings.settings().QUEUE.NO_TICK_FASTMODE;
// Remove existing tiles. Create a copy so that we can remove blocks
Map<BlockPos, BlockEntity> chunkTiles = new HashMap<>(nmsChunk.getBlockEntities());
@ -726,7 +726,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
nmsChunk.mustNotSave = false;
nmsChunk.markUnsaved();
// send to player
if (Settings.IMP.LIGHTING.MODE == 0 || !Settings.IMP.LIGHTING.DELAY_PACKET_SENDING) {
if (Settings.settings().LIGHTING.MODE == 0 || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING) {
this.send(finalMask, finalLightUpdate);
}
if (finalizer != null) {
@ -735,7 +735,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
};
}
if (syncTasks != null) {
QueueHandler queueHandler = Fawe.get().getQueueHandler();
QueueHandler queueHandler = Fawe.instance().getQueueHandler();
Runnable[] finalSyncTasks = syncTasks;
// Chain the sync tasks and the callback
@ -851,7 +851,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
data = new char[4096];
Arrays.fill(data, (char) 1);
}
if (data == null || data == FaweCache.IMP.EMPTY_CHAR_4096) {
if (data == null || data == FaweCache.INSTANCE.EMPTY_CHAR_4096) {
data = new char[4096];
Arrays.fill(data, (char) 1);
}
@ -884,7 +884,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
return data;
}
char[] paletteToOrdinal = FaweCache.IMP.PALETTE_TO_BLOCK_CHAR.get();
char[] paletteToOrdinal = FaweCache.INSTANCE.PALETTE_TO_BLOCK_CHAR.get();
try {
if (num_palette != 1) {
for (int i = 0; i < num_palette; i++) {

View File

@ -215,7 +215,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
e.printStackTrace();
}
}
return TaskManager.IMP.sync(() -> serverLevel.getChunk(chunkX, chunkZ));
return TaskManager.taskManager().sync(() -> serverLevel.getChunk(chunkX, chunkZ));
}
public static ChunkHolder getPlayerChunk(ServerLevel nmsWorld, final int chunkX, final int chunkZ) {
@ -247,7 +247,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
return;
}
LevelChunk levelChunk = optional.get();
TaskManager.IMP.task(() -> {
TaskManager.taskManager().task(() -> {
ClientboundLevelChunkPacket chunkPacket = new ClientboundLevelChunkPacket(levelChunk);
nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(chunkPacket));
if (lighting) {
@ -283,10 +283,10 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
if (set == null) {
return newChunkSection(layer);
}
final int[] blockToPalette = FaweCache.IMP.BLOCK_TO_PALETTE.get();
final int[] paletteToBlock = FaweCache.IMP.PALETTE_TO_BLOCK.get();
final long[] blockStates = FaweCache.IMP.BLOCK_STATES.get();
final int[] blocksCopy = FaweCache.IMP.SECTION_BLOCKS.get();
final int[] blockToPalette = FaweCache.INSTANCE.BLOCK_TO_PALETTE.get();
final int[] paletteToBlock = FaweCache.INSTANCE.PALETTE_TO_BLOCK.get();
final long[] blockStates = FaweCache.INSTANCE.BLOCK_STATES.get();
final int[] blocksCopy = FaweCache.INSTANCE.SECTION_BLOCKS.get();
try {
int[] num_palette_buffer = new int[1];
Map<BlockVector3, Integer> ticking_blocks = new HashMap<>();
@ -303,7 +303,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
int num_palette = num_palette_buffer[0];
// BlockStates
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
if (Settings.IMP.PROTOCOL_SUPPORT_FIX || num_palette != 1) {
if (Settings.settings().PROTOCOL_SUPPORT_FIX || num_palette != 1) {
bitsPerEntry = Math.max(bitsPerEntry, 4); // Protocol support breaks <4 bits per entry
} else {
bitsPerEntry = Math.max(bitsPerEntry, 1); // For some reason minecraft needs 4096 bits to store 0 entries

View File

@ -129,7 +129,7 @@ public class PaperweightStarlightRelighter implements Relighter {
while (iterator.hasNext()) {
coords.add(new ChunkPos(iterator.nextLong()));
}
TaskManager.IMP.task(() -> {
TaskManager.taskManager().task(() -> {
// trigger chunk load and apply ticket on main thread
List<CompletableFuture<?>> futures = new ArrayList<>();
for (ChunkPos pos : coords) {
@ -153,9 +153,9 @@ public class PaperweightStarlightRelighter implements Relighter {
LOGGER.warn("Processed {} chunks instead of {}", i, coords.size());
}
// post process chunks on main thread
TaskManager.IMP.task(() -> postProcessChunks(coords));
TaskManager.taskManager().task(() -> postProcessChunks(coords));
// call callback on our own threads
TaskManager.IMP.async(andThen);
TaskManager.taskManager().async(andThen);
}
)
);
@ -184,7 +184,7 @@ public class PaperweightStarlightRelighter implements Relighter {
* Also, if chunk packets are sent delayed, we need to do that here
*/
private void postProcessChunks(Set<ChunkPos> coords) {
boolean delay = Settings.IMP.LIGHTING.DELAY_PACKET_SENDING;
boolean delay = Settings.settings().LIGHTING.DELAY_PACKET_SENDING;
for (ChunkPos pos : coords) {
int x = pos.x;
int z = pos.z;

View File

@ -232,7 +232,7 @@ public class PaperweightRegen extends Regenerator<ChunkAccess, ProtoChunk, Level
PrimaryLevelData newWorldData = new PrimaryLevelData(newWorldSettings, newOpts, Lifecycle.stable());
//init world
freshWorld = Fawe.get().getQueueHandler().sync((Supplier<ServerLevel>) () -> new ServerLevel(
freshWorld = Fawe.instance().getQueueHandler().sync((Supplier<ServerLevel>) () -> new ServerLevel(
server,
server.executor,
session,
@ -336,7 +336,7 @@ public class PaperweightRegen extends Regenerator<ChunkAccess, ProtoChunk, Level
//shutdown chunk provider
try {
Fawe.get().getQueueHandler().sync(() -> {
Fawe.instance().getQueueHandler().sync(() -> {
try {
freshChunkProvider.close(false);
} catch (IOException e) {
@ -348,7 +348,7 @@ public class PaperweightRegen extends Regenerator<ChunkAccess, ProtoChunk, Level
//remove world from server
try {
Fawe.get().getQueueHandler().sync(this::removeWorldFromWorldsMap);
Fawe.instance().getQueueHandler().sync(this::removeWorldFromWorldsMap);
} catch (Exception ignored) {
}
@ -388,7 +388,7 @@ public class PaperweightRegen extends Regenerator<ChunkAccess, ProtoChunk, Level
@Override
protected void populate(LevelChunk levelChunk, Random random, BlockPopulator blockPopulator) {
// BlockPopulator#populate has to be called synchronously for TileEntity access
TaskManager.IMP.task(() -> blockPopulator.populate(freshWorld.getWorld(), random, levelChunk.getBukkitChunk()));
TaskManager.taskManager().task(() -> blockPopulator.populate(freshWorld.getWorld(), random, levelChunk.getBukkitChunk()));
}
@Override
@ -403,7 +403,7 @@ public class PaperweightRegen extends Regenerator<ChunkAccess, ProtoChunk, Level
//util
private void removeWorldFromWorldsMap() {
Fawe.get().getQueueHandler().sync(() -> {
Fawe.instance().getQueueHandler().sync(() -> {
try {
Map<String, org.bukkit.World> map = (Map<String, org.bukkit.World>) serverWorldsField.get(Bukkit.getServer());
map.remove("worldeditregentempworld");

View File

@ -504,10 +504,10 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
chunkPacket.setNativePacket(nmsPacket);
}
try {
FaweCache.IMP.CHUNK_FLAG.get().set(true);
FaweCache.INSTANCE.CHUNK_FLAG.get().set(true);
entityPlayer.connection.send(nmsPacket);
} finally {
FaweCache.IMP.CHUNK_FLAG.get().set(false);
FaweCache.INSTANCE.CHUNK_FLAG.get().set(false);
}
}
});

View File

@ -250,7 +250,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
}
}
};
TaskManager.IMP.async(() -> TaskManager.IMP.sync(runnableVal));
TaskManager.taskManager().async(() -> TaskManager.taskManager().sync(runnableVal));
}
@Override
@ -269,7 +269,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
if (Fawe.isMainThread()) {
runnableVal.run();
} else {
TaskManager.IMP.sync(runnableVal);
TaskManager.taskManager().sync(runnableVal);
}
cachedChanges.clear();
cachedChunksToSend.clear();

View File

@ -401,7 +401,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
try {
ServerLevel nmsWorld = serverLevel;
LevelChunk nmsChunk = ensureLoaded(nmsWorld, chunkX, chunkZ);
boolean fastmode = set.isFastMode() && Settings.IMP.QUEUE.NO_TICK_FASTMODE;
boolean fastmode = set.isFastMode() && Settings.settings().QUEUE.NO_TICK_FASTMODE;
// Remove existing tiles. Create a copy so that we can remove blocks
Map<BlockPos, BlockEntity> chunkTiles = new HashMap<>(nmsChunk.getBlockEntities());
@ -755,7 +755,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
nmsChunk.mustNotSave = false;
nmsChunk.setUnsaved(true);
// send to player
if (Settings.IMP.LIGHTING.MODE == 0 || !Settings.IMP.LIGHTING.DELAY_PACKET_SENDING) {
if (Settings.settings().LIGHTING.MODE == 0 || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING) {
this.send(finalMask, finalLightUpdate);
}
if (finalizer != null) {
@ -764,7 +764,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
};
}
if (syncTasks != null) {
QueueHandler queueHandler = Fawe.get().getQueueHandler();
QueueHandler queueHandler = Fawe.instance().getQueueHandler();
Runnable[] finalSyncTasks = syncTasks;
// Chain the sync tasks and the callback
@ -881,7 +881,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
data = new char[4096];
Arrays.fill(data, (char) 1);
}
if (data == null || data == FaweCache.IMP.EMPTY_CHAR_4096) {
if (data == null || data == FaweCache.INSTANCE.EMPTY_CHAR_4096) {
data = new char[4096];
Arrays.fill(data, (char) 1);
}
@ -921,7 +921,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
return data;
}
char[] paletteToOrdinal = FaweCache.IMP.PALETTE_TO_BLOCK_CHAR.get();
char[] paletteToOrdinal = FaweCache.INSTANCE.PALETTE_TO_BLOCK_CHAR.get();
try {
if (num_palette != 1) {
for (int i = 0; i < num_palette; i++) {

View File

@ -236,7 +236,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
e.printStackTrace();
}
}
return TaskManager.IMP.sync(() -> serverLevel.getChunk(chunkX, chunkZ));
return TaskManager.taskManager().sync(() -> serverLevel.getChunk(chunkX, chunkZ));
}
public static ChunkHolder getPlayerChunk(ServerLevel nmsWorld, final int chunkX, final int chunkZ) {
@ -268,7 +268,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
return;
}
LevelChunk levelChunk = optional.get();
TaskManager.IMP.task(() -> {
TaskManager.taskManager().task(() -> {
ClientboundLevelChunkWithLightPacket packet =
new ClientboundLevelChunkWithLightPacket(levelChunk, nmsWorld.getChunkSource().getLightEngine(), null, null
, true, false); // last false is to not bother with x-ray
@ -299,10 +299,10 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
if (set == null) {
return newChunkSection(layer, biomeRegistry, biomes);
}
final int[] blockToPalette = FaweCache.IMP.BLOCK_TO_PALETTE.get();
final int[] paletteToBlock = FaweCache.IMP.PALETTE_TO_BLOCK.get();
final long[] blockStates = FaweCache.IMP.BLOCK_STATES.get();
final int[] blocksCopy = FaweCache.IMP.SECTION_BLOCKS.get();
final int[] blockToPalette = FaweCache.INSTANCE.BLOCK_TO_PALETTE.get();
final int[] paletteToBlock = FaweCache.INSTANCE.PALETTE_TO_BLOCK.get();
final long[] blockStates = FaweCache.INSTANCE.BLOCK_STATES.get();
final int[] blocksCopy = FaweCache.INSTANCE.SECTION_BLOCKS.get();
try {
int[] num_palette_buffer = new int[1];
Map<BlockVector3, Integer> ticking_blocks = new HashMap<>();

View File

@ -130,7 +130,7 @@ public class PaperweightStarlightRelighter implements Relighter {
while (iterator.hasNext()) {
coords.add(new ChunkPos(iterator.nextLong()));
}
TaskManager.IMP.task(() -> {
TaskManager.taskManager().task(() -> {
// trigger chunk load and apply ticket on main thread
List<CompletableFuture<?>> futures = new ArrayList<>();
for (ChunkPos pos : coords) {
@ -154,9 +154,9 @@ public class PaperweightStarlightRelighter implements Relighter {
LOGGER.warn("Processed {} chunks instead of {}", i, coords.size());
}
// post process chunks on main thread
TaskManager.IMP.task(() -> postProcessChunks(coords));
TaskManager.taskManager().task(() -> postProcessChunks(coords));
// call callback on our own threads
TaskManager.IMP.async(andThen);
TaskManager.taskManager().async(andThen);
}
)
);
@ -185,7 +185,7 @@ public class PaperweightStarlightRelighter implements Relighter {
* Also, if chunk packets are sent delayed, we need to do that here
*/
private void postProcessChunks(Set<ChunkPos> coords) {
boolean delay = Settings.IMP.LIGHTING.DELAY_PACKET_SENDING;
boolean delay = Settings.settings().LIGHTING.DELAY_PACKET_SENDING;
for (ChunkPos pos : coords) {
int x = pos.x;
int z = pos.z;

View File

@ -238,7 +238,7 @@
// PrimaryLevelData newWorldData = new PrimaryLevelData(newWorldSettings, newOpts, Lifecycle.stable());
//
// //init world
// freshWorld = Fawe.get().getQueueHandler().sync((Supplier<ServerLevel>) () -> new ServerLevel(
// freshWorld = Fawe.instance().getQueueHandler().sync((Supplier<ServerLevel>) () -> new ServerLevel(
// server,
// server.executor,
// session,
@ -345,7 +345,7 @@
//
// //shutdown chunk provider
// try {
// Fawe.get().getQueueHandler().sync(() -> {
// Fawe.instance().getQueueHandler().sync(() -> {
// try {
// freshChunkProvider.close(false);
// } catch (IOException e) {
@ -357,7 +357,7 @@
//
// //remove world from server
// try {
// Fawe.get().getQueueHandler().sync(this::removeWorldFromWorldsMap);
// Fawe.instance().getQueueHandler().sync(this::removeWorldFromWorldsMap);
// } catch (Exception ignored) {
// }
//
@ -397,7 +397,7 @@
// @Override
// protected void populate(LevelChunk levelChunk, Random random, BlockPopulator blockPopulator) {
// // BlockPopulator#populate has to be called synchronously for TileEntity access
// TaskManager.IMP.task(() -> blockPopulator.populate(freshWorld.getWorld(), random, levelChunk.getBukkitChunk()));
// TaskManager.taskManager().task(() -> blockPopulator.populate(freshWorld.getWorld(), random, levelChunk.getBukkitChunk()));
// }
//
// @Override
@ -412,7 +412,7 @@
//
// //util
// private void removeWorldFromWorldsMap() {
// Fawe.get().getQueueHandler().sync(() -> {
// Fawe.instance().getQueueHandler().sync(() -> {
// try {
// Map<String, org.bukkit.World> map = (Map<String, org.bukkit.World>) serverWorldsField.get(Bukkit.getServer());
// map.remove("worldeditregentempworld");