MigrationModule class
Пакет: com.hypixel.hytale.server.core.modules.migrations
Файл: com/hypixel/hytale/server/core/modules/migrations/MigrationModule.java
extends: JavaPlugin
Поля (20)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
PluginManifest |
MANIFEST |
|
|
instance |
|
OptionSet |
var1 |
|
IChunkSaver |
var10 |
|
List |
var10 |
|
IChunkLoader |
var11 |
|
LongListIterator |
var11 |
|
long |
var12 |
|
int |
var14 |
|
int |
var15 |
|
List |
var2 |
|
Map |
var3 |
|
List |
var4 |
|
Function |
var4 |
|
AtomicInteger |
var5 |
|
WorldChunk |
var5 |
|
String |
var8 |
|
ChunkSavingSystems.Data |
var8 |
|
ChunkStore |
var9 |
|
LongList |
var9 |
Методы (8)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
static |
MigrationModule |
getMigrationModule get() |
public |
SystemType<ChunkStore, ChunkColumnMigrationSystem> |
getChunkColumnMigrationSystemSystemType<ChunkStore, ChunkColumnMigrationSystem> getChunkColumnMigrationSystem() |
public |
SystemType<ChunkStore, ChunkSectionMigrationSystem> |
getChunkSectionMigrationSystemSystemType<ChunkStore, ChunkSectionMigrationSystem> getChunkSectionMigrationSystem() |
|
|
if if(var4 != null) |
|
|
if if(var4x == null) |
public |
void |
registervoid register(String var1, Function<Path, Migration> var2) |
public |
void |
runMigrationsvoid runMigrations() |
abstract |
|
super super(var1) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.modules.migrations;
class="kw">import com.hypixel.hytale.common.plugin.PluginManifest;
class="kw">import com.hypixel.hytale.common.util.CompletableFutureUtil;
class="kw">import com.hypixel.hytale.component.Holder;
class="kw">import com.hypixel.hytale.component.SystemType;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.math.util.ChunkUtil;
class="kw">import com.hypixel.hytale.server.core.HytaleServer;
class="kw">import com.hypixel.hytale.server.core.Options;
class="kw">import com.hypixel.hytale.server.core.event.events.BootEvent;
class="kw">import com.hypixel.hytale.server.core.plugin.JavaPlugin;
class="kw">import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
class="kw">import com.hypixel.hytale.server.core.universe.Universe;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.IChunkLoader;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.IChunkSaver;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.component.ChunkSavingSystems;
class="kw">import it.unimi.dsi.fastutil.longs.LongList;
class="kw">import it.unimi.dsi.fastutil.longs.LongListIterator;
class="kw">import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
class="kw">import it.unimi.dsi.fastutil.objects.ObjectArrayList;
class="kw">import java.nio.file.Path;
class="kw">import java.util.List;
class="kw">import java.util.Map;
class="kw">import java.util.concurrent.CompletableFuture;
class="kw">import java.util.concurrent.atomic.AtomicInteger;
class="kw">import java.util.function.Function;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import joptsimple.OptionSet;
class="kw">public class MigrationModule class="kw">extends JavaPlugin {
class="kw">public class="kw">static class="kw">final PluginManifest MANIFEST = PluginManifest.corePlugin(MigrationModule.class).build();
class="kw">protected class="kw">static MigrationModule instance;
@Nonnull
class="kw">private class="kw">final Map<String, Function<Path, Migration>> migrationCtors = new Object2ObjectOpenHashMap();
class="kw">private SystemType<ChunkStore, ChunkColumnMigrationSystem> chunkColumnMigrationSystem;
class="kw">private SystemType<ChunkStore, ChunkSectionMigrationSystem> chunkSectionMigrationSystem;
class="kw">public MigrationModule(@Nonnull JavaPluginInit var1) {
super(var1);
instance = this;
}
class="kw">public class="kw">static MigrationModule get() {
class="kw">return instance;
}
@Override
class="kw">protected void setup() {
this.getEventRegistry().register(BootEvent.class, var1 -> {
if (Options.getOptionSet().has(Options.MIGRATIONS)) {
this.runMigrations();
HytaleServer.get().shutdownServer();
}
});
this.chunkColumnMigrationSystem = this.getChunkStoreRegistry().registerSystemType(ChunkColumnMigrationSystem.class);
this.chunkSectionMigrationSystem = this.getChunkStoreRegistry().registerSystemType(ChunkSectionMigrationSystem.class);
}
class="kw">public SystemType<ChunkStore, ChunkColumnMigrationSystem> getChunkColumnMigrationSystem() {
class="kw">return this.chunkColumnMigrationSystem;
}
class="kw">public SystemType<ChunkStore, ChunkSectionMigrationSystem> getChunkSectionMigrationSystem() {
class="kw">return this.chunkSectionMigrationSystem;
}
class="kw">public void register(String var1, Function<Path, Migration> var2) {
this.migrationCtors.put(var1, var2);
}
class="kw">public void runMigrations() {
OptionSet var1 = Options.getOptionSet();
List var2 = var1.has(Options.MIGRATE_WORLDS) ? var1.valuesOf(Options.MIGRATE_WORLDS) : null;
Map var3 = (Map<String, Path>)Options.getOptionSet().valueOf(Options.MIGRATIONS);
List var4 = new ObjectArrayList();
var3.forEach((var2x, var3x) -> {
Function var4 = this.migrationCtors.get(var2x);
if (var4 != null) {
var4.add(var4.apply(var3x));
}
});
if (!var4.isEmpty()) {
AtomicInteger var5 = new AtomicInteger();
for (World var7 : Universe.get().getWorlds().values()) {
String var8 = var7.getName();
if (var2 == null || var2.contains(var8)) {
var5.incrementAndGet();
this.getLogger().at(Level.INFO).log("Starting to migrate world '%s'...", var8);
ChunkStore var9 = var7.getChunkStore();
IChunkSaver var10 = var9.getSaver();
IChunkLoader var11 = var9.getLoader();
var7.execute(
() -> {
var7.lockSaving();
ChunkSavingSystems.Data var8 = var9.getStore().getResource(ChunkStore.SAVE_RESOURCE);
var8.waitForSavingChunks()
.whenComplete(
(var7x, var8x) -> {
try {
LongList var9 = var11.getIndexes();
this.getLogger().at(Level.INFO).log("Found %d chunks in world '%s'. Starting iteration...", var9.size(), var8);
List var10 = new ObjectArrayList(var9.size());
LongListIterator var11 = var9.iterator();
while (var11.hasNext()) {
long var12 = var11.nextLong();
int var14 = ChunkUtil.xOfChunkIndex(var12);
int var15 = ChunkUtil.zOfChunkIndex(var12);
var10.add(
var11.loadHolder(var14, var15)
.thenCompose(
var4x -> {
if (var4x == null) {
class="kw">return CompletableFuture.completedFuture(null);
}
WorldChunk var5 = var4x.getComponent(WorldChunk.getComponentType());
var4.forEach(var1x -> var1x.run(var5));
class="kw">return var5.getNeedsSaving()
? var10.saveHolder(var14, var15, (Holder<ChunkStore>)var4x)
: CompletableFuture.completedFuture(null);
}
)
);
}
try {
CompletableFutureUtil.joinWithProgress(
var10,
(var2x, var4x, var5x) -> this.getLogger()
.at(Level.INFO)
.log("Scanning + Migrating world '%s': %.2f%% (%d of %d)", var8, var2x * 100.0, var4x, var5x),
250,
750
);
} catch (InterruptedException var20) {
((HytaleLogger.Api)this.getLogger().at(Level.SEVERE).withCause(var20)).log("Interrupted while loading chunks:");
Thread.currentThread().interrupt();
}
} catch (Throwable var21) {
((HytaleLogger.Api)this.getLogger().at(Level.SEVERE).withCause(var21)).log("Failed to migrate chunks!");
} class="kw">finally {
var7.unlockSaving();
this.getLogger().at(Level.INFO).log("%d world(s) left to migrate.", var5.decrementAndGet());
}
}
);
}
);
}
}
}
}
}