Plugin remapping

Co-authored-by: Nassim Jahnke <nassim@njahnke.dev>
This commit is contained in:
Jason Penilla 2022-10-29 15:22:32 -07:00
commit 13e0a1a71e
22 changed files with 1691 additions and 70 deletions

View file

@ -268,7 +268,7 @@
if (profiledduration != null) {
profiledduration.finish(true);
}
@@ -387,23 +459,217 @@
@@ -387,23 +459,218 @@
protected void forceDifficulty() {}
@ -484,6 +484,7 @@
+ }
+
+ this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.POSTWORLD);
+ if (io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper != null) io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper.pluginsEnabled(); // Paper - Remap plugins
+ this.server.getPluginManager().callEvent(new ServerLoadEvent(ServerLoadEvent.LoadType.STARTUP));
+ this.connection.acceptConnections();
+ }
@ -500,7 +501,7 @@
if (!iworlddataserver.isInitialized()) {
try {
@@ -427,30 +693,8 @@
@@ -427,30 +694,8 @@
iworlddataserver.setInitialized(true);
}
@ -532,7 +533,7 @@
private static void setInitialSpawn(ServerLevel world, ServerLevelData worldProperties, boolean bonusChest, boolean debugWorld) {
if (debugWorld) {
@@ -458,6 +702,21 @@
@@ -458,6 +703,21 @@
} else {
ServerChunkCache chunkproviderserver = world.getChunkSource();
ChunkPos chunkcoordintpair = new ChunkPos(chunkproviderserver.randomState().sampler().findSpawnPosition());
@ -554,7 +555,7 @@
int i = chunkproviderserver.getGenerator().getSpawnHeight(world);
if (i < world.getMinY()) {
@@ -516,31 +775,36 @@
@@ -516,31 +776,36 @@
iworlddataserver.setGameType(GameType.SPECTATOR);
}
@ -602,7 +603,7 @@
ForcedChunksSavedData forcedchunk = (ForcedChunksSavedData) worldserver1.getDataStorage().get(ForcedChunksSavedData.factory(), "chunks");
if (forcedchunk != null) {
@@ -555,10 +819,17 @@
@@ -555,10 +820,17 @@
}
}
@ -624,7 +625,7 @@
}
public GameType getDefaultGameType() {
@@ -588,12 +859,16 @@
@@ -588,12 +860,16 @@
worldserver.save((ProgressListener) null, flush, worldserver.noSave && !force);
}
@ -643,7 +644,7 @@
if (flush) {
Iterator iterator1 = this.getAllLevels().iterator();
@@ -628,18 +903,40 @@
@@ -628,18 +904,41 @@
this.stopServer();
}
@ -674,6 +675,7 @@
+ this.server.disablePlugins();
+ }
+ // CraftBukkit end
+ if (io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper != null) io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper.shutdown(); // Paper - Plugin remapping
this.getConnection().stop();
this.isSaving = true;
if (this.playerList != null) {
@ -684,7 +686,7 @@
}
MinecraftServer.LOGGER.info("Saving worlds");
@@ -693,6 +990,15 @@
@@ -693,6 +992,15 @@
} catch (IOException ioexception1) {
MinecraftServer.LOGGER.error("Failed to unlock level {}", this.storageSource.getLevelId(), ioexception1);
}
@ -700,23 +702,21 @@
}
@@ -717,8 +1023,15 @@
MinecraftServer.LOGGER.error("Error while shutting down", interruptedexception);
}
}
+
+ }
@@ -720,6 +1028,13 @@
}
+ // Spigot Start
+ private static double calcTps(double avg, double exp, double tps)
+ {
+ return ( avg * exp ) + ( tps * ( 1 - exp ) );
}
+ }
+ // Spigot End
+
protected void runServer() {
try {
@@ -727,9 +1040,12 @@
if (!this.initServer()) {
@@ -727,9 +1042,12 @@
}
this.nextTickTimeNanos = Util.getNanos();
@ -730,7 +730,7 @@
while (this.running) {
long i;
@@ -744,11 +1060,23 @@
@@ -744,11 +1062,23 @@
if (j > MinecraftServer.OVERLOADED_THRESHOLD_NANOS + 20L * i && this.nextTickTimeNanos - this.lastOverloadWarningNanos >= MinecraftServer.OVERLOADED_WARNING_INTERVAL_NANOS + 100L * i) {
long k = j / i;
@ -754,7 +754,7 @@
boolean flag = i == 0L;
@@ -757,6 +1085,7 @@
@@ -757,6 +1087,7 @@
this.debugCommandProfiler = new MinecraftServer.TimeProfiler(Util.getNanos(), this.tickCount);
}
@ -762,7 +762,7 @@
this.nextTickTimeNanos += i;
try {
@@ -830,6 +1159,13 @@
@@ -830,6 +1161,13 @@
this.services.profileCache().clearExecutor();
}
@ -776,7 +776,7 @@
this.onServerExit();
}
@@ -889,9 +1225,16 @@
@@ -889,9 +1227,16 @@
}
private boolean haveTime() {
@ -794,7 +794,7 @@
public static boolean throwIfFatalException() {
RuntimeException runtimeexception = (RuntimeException) MinecraftServer.fatalException.get();
@@ -903,7 +1246,7 @@
@@ -903,7 +1248,7 @@
}
public static void setFatalException(RuntimeException exception) {
@ -803,7 +803,7 @@
}
@Override
@@ -977,7 +1320,7 @@
@@ -977,7 +1322,7 @@
}
}
@ -812,7 +812,7 @@
Profiler.get().incrementCounter("runTask");
super.doRunTask(ticktask);
}
@@ -1025,6 +1368,7 @@
@@ -1025,6 +1370,7 @@
}
public void tickServer(BooleanSupplier shouldKeepTicking) {
@ -820,7 +820,7 @@
long i = Util.getNanos();
int j = this.pauseWhileEmptySeconds() * 20;
@@ -1041,11 +1385,13 @@
@@ -1041,11 +1387,13 @@
this.autoSave();
}
@ -834,7 +834,7 @@
++this.tickCount;
this.tickRateManager.tick();
this.tickChildren(shouldKeepTicking);
@@ -1055,7 +1401,7 @@
@@ -1055,7 +1403,7 @@
}
--this.ticksUntilAutosave;
@ -843,7 +843,7 @@
this.autoSave();
}
@@ -1071,10 +1417,13 @@
@@ -1071,10 +1419,13 @@
this.smoothedTickTimeMillis = this.smoothedTickTimeMillis * 0.8F + (float) k / (float) TimeUtil.NANOSECONDS_PER_MILLISECOND * 0.19999999F;
this.logTickMethodTime(i);
gameprofilerfiller.pop();
@ -858,7 +858,7 @@
MinecraftServer.LOGGER.debug("Autosave started");
ProfilerFiller gameprofilerfiller = Profiler.get();
@@ -1082,6 +1431,7 @@
@@ -1082,6 +1433,7 @@
this.saveEverything(true, false, false);
gameprofilerfiller.pop();
MinecraftServer.LOGGER.debug("Autosave finished");
@ -866,7 +866,7 @@
}
private void logTickMethodTime(long tickStartTime) {
@@ -1123,7 +1473,7 @@
@@ -1123,7 +1475,7 @@
private ServerStatus buildServerStatus() {
ServerStatus.Players serverping_serverpingplayersample = this.buildPlayerStatus();
@ -875,7 +875,7 @@
}
private ServerStatus.Players buildPlayerStatus() {
@@ -1154,11 +1504,35 @@
@@ -1154,11 +1506,35 @@
this.getPlayerList().getPlayers().forEach((entityplayer) -> {
entityplayer.connection.suspendFlushing();
});
@ -911,7 +911,7 @@
while (iterator.hasNext()) {
ServerLevel worldserver = (ServerLevel) iterator.next();
@@ -1167,16 +1541,20 @@
@@ -1167,16 +1543,20 @@
return s + " " + String.valueOf(worldserver.dimension().location());
});
@ -932,7 +932,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Exception ticking world");
@@ -1189,18 +1567,24 @@
@@ -1189,18 +1569,24 @@
}
gameprofilerfiller.popPush("connection");
@ -957,10 +957,12 @@
gameprofilerfiller.popPush("send chunks");
iterator = this.playerList.getPlayers().iterator();
@@ -1267,6 +1651,22 @@
@@ -1265,7 +1651,23 @@
@Nullable
public ServerLevel getLevel(ResourceKey<Level> key) {
return (ServerLevel) this.levels.get(key);
}
+ }
+
+ // CraftBukkit start
+ public void addLevel(ServerLevel level) {
+ Map<ResourceKey<Level>, ServerLevel> oldLevels = this.levels;
@ -974,13 +976,12 @@
+ Map<ResourceKey<Level>, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels);
+ newLevels.remove(level.dimension());
+ this.levels = Collections.unmodifiableMap(newLevels);
+ }
}
+ // CraftBukkit end
+
public Set<ResourceKey<Level>> levelKeys() {
return this.levels.keySet();
}
@@ -1296,7 +1696,7 @@
@@ -1296,7 +1698,7 @@
@DontObfuscate
public String getServerModName() {
@ -989,7 +990,7 @@
}
public SystemReport fillSystemReport(SystemReport details) {
@@ -1347,7 +1747,7 @@
@@ -1347,7 +1749,7 @@
@Override
public void sendSystemMessage(Component message) {
@ -998,7 +999,7 @@
}
public KeyPair getKeyPair() {
@@ -1481,10 +1881,20 @@
@@ -1481,10 +1883,20 @@
@Override
public String getMotd() {
@ -1020,7 +1021,7 @@
this.motd = motd;
}
@@ -1507,7 +1917,7 @@
@@ -1507,7 +1919,7 @@
}
public ServerConnectionListener getConnection() {
@ -1029,7 +1030,7 @@
}
public boolean isReady() {
@@ -1634,11 +2044,11 @@
@@ -1634,11 +2046,11 @@
public CompletableFuture<Void> reloadResources(Collection<String> dataPacks) {
CompletableFuture<Void> completablefuture = CompletableFuture.supplyAsync(() -> {
@ -1043,7 +1044,7 @@
}, this).thenCompose((immutablelist) -> {
MultiPackResourceManager resourcemanager = new MultiPackResourceManager(PackType.SERVER_DATA, immutablelist);
List<Registry.PendingTags<?>> list = TagLoader.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess());
@@ -1654,6 +2064,7 @@
@@ -1654,6 +2066,7 @@
}).thenAcceptAsync((minecraftserver_reloadableresources) -> {
this.resources.close();
this.resources = minecraftserver_reloadableresources;
@ -1051,7 +1052,7 @@
this.packRepository.setSelected(dataPacks);
WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(MinecraftServer.getSelectedPacks(this.packRepository, true), this.worldData.enabledFeatures());
@@ -1952,7 +2363,7 @@
@@ -1952,7 +2365,7 @@
final List<String> list = Lists.newArrayList();
final GameRules gamerules = this.getGameRules();
@ -1060,7 +1061,7 @@
@Override
public <T extends GameRules.Value<T>> void visit(GameRules.Key<T> key, GameRules.Type<T> type) {
list.add(String.format(Locale.ROOT, "%s=%s\n", key.getId(), gamerules.getRule(key)));
@@ -2058,7 +2469,7 @@
@@ -2058,7 +2471,7 @@
try {
label51:
{
@ -1069,7 +1070,7 @@
try {
arraylist = Lists.newArrayList(NativeModuleLister.listModules());
@@ -2105,9 +2516,25 @@
@@ -2105,9 +2518,25 @@
if (bufferedwriter != null) {
bufferedwriter.close();
}
@ -1095,7 +1096,7 @@
private ProfilerFiller createProfiler() {
if (this.willStartRecordingMetrics) {
this.metricsRecorder = ActiveMetricsRecorder.createStarted(new ServerMetricsSamplersProvider(Util.timeSource, this.isDedicatedServer()), Util.timeSource, Util.ioPool(), new MetricsPersister("server"), this.onMetricsRecordingStopped, (path) -> {
@@ -2225,18 +2652,24 @@
@@ -2225,18 +2654,24 @@
}
public void logChatMessage(Component message, ChatType.Bound params, @Nullable String prefix) {