net.minecraft.server

This commit is contained in:
Jake Potrebic 2024-12-13 19:12:33 -08:00
parent ce9d79a81b
commit 64500a201f
No known key found for this signature in database
GPG key ID: ECE0B3C133C016C5
16 changed files with 1083 additions and 1110 deletions

View file

@ -1,6 +1,6 @@
--- a/net/minecraft/server/Bootstrap.java
+++ b/net/minecraft/server/Bootstrap.java
@@ -17,6 +17,9 @@
@@ -17,6 +_,9 @@
import net.minecraft.core.dispenser.DispenseItemBehavior;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.locale.Language;
@ -10,45 +10,15 @@
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.ai.attributes.Attribute;
@@ -30,7 +33,8 @@
import net.minecraft.world.level.block.state.BlockBehaviour;
import org.slf4j.Logger;
-@SuppressForbidden(a = "System.out setup")
+@SuppressForbidden(reason = "System.out setup")
+// CraftBukkit end
public class Bootstrap {
public static final PrintStream STDOUT = System.out;
@@ -42,9 +46,27 @@
public static void bootStrap() {
if (!Bootstrap.isBootstrapped) {
+ // CraftBukkit start
+ /*String name = Bootstrap.class.getSimpleName(); // Paper
+ switch (name) {
+ case "DispenserRegistry":
+ break;
+ case "Bootstrap":
+ System.err.println("***************************************************************************");
+ System.err.println("*** WARNING: This server jar may only be used for development purposes. ***");
+ System.err.println("***************************************************************************");
+ break;
+ default:
+ System.err.println("**********************************************************************");
+ System.err.println("*** WARNING: This server jar is unsupported, use at your own risk. ***");
+ System.err.println("**********************************************************************");
+ break;
+ }*/ // Paper
+ // CraftBukkit end
Bootstrap.isBootstrapped = true;
@@ -43,6 +_,7 @@
if (!isBootstrapped) {
isBootstrapped = true;
Instant instant = Instant.now();
+ io.papermc.paper.plugin.entrypoint.LaunchEntryPointHandler.enterBootstrappers(); // Paper - Entrypoint for bootstrapping
if (BuiltInRegistries.REGISTRY.keySet().isEmpty()) {
throw new IllegalStateException("Unable to load registries");
} else {
@@ -56,11 +78,77 @@
@@ -54,11 +_,77 @@
EntitySelectorOptions.bootStrap();
DispenseItemBehavior.bootStrap();
CauldronInteraction.bootStrap();
@ -58,8 +28,8 @@
+ });
+ // Paper end
CreativeModeTabs.validate();
Bootstrap.wrapStreams();
Bootstrap.bootstrapDuration.set(Duration.between(instant, Instant.now()).toMillis());
wrapStreams();
bootstrapDuration.set(Duration.between(instant, Instant.now()).toMillis());
}
+ // CraftBukkit start - easier than fixing the decompile
+ BlockStateData.register(1008, "{Name:'minecraft:oak_sign',Properties:{rotation:'0'}}", "{Name:'minecraft:standing_sign',Properties:{rotation:'0'}}");

View file

@ -0,0 +1,254 @@
--- a/net/minecraft/server/Main.java
+++ b/net/minecraft/server/Main.java
@@ -37,6 +_,7 @@
import net.minecraft.server.dedicated.DedicatedServerProperties;
import net.minecraft.server.dedicated.DedicatedServerSettings;
import net.minecraft.server.level.progress.LoggerChunkProgressListener;
+import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.repository.PackRepository;
import net.minecraft.server.packs.repository.ServerPacksSource;
import net.minecraft.util.Mth;
@@ -67,8 +_,9 @@
reason = "System.out needed before bootstrap"
)
@DontObfuscate
- public static void main(String[] args) {
+ public static void main(final OptionSet optionSet) { // CraftBukkit - replaces main(String[] args)
SharedConstants.tryDetectVersion();
+ /* CraftBukkit start - Replace everything
OptionParser optionParser = new OptionParser();
OptionSpec<Void> optionSpec = optionParser.accepts("nogui");
OptionSpec<Void> optionSpec1 = optionParser.accepts("initSettings", "Initializes 'server.properties' and 'eula.txt', then quits");
@@ -93,41 +_,94 @@
optionParser.printHelpOn(System.err);
return;
}
+ */ // CraftBukkit end
+ try {
- Path path = optionSet.valueOf(optionSpec14);
+ Path path = (Path) optionSet.valueOf("pidFile"); // CraftBukkit
if (path != null) {
writePidFile(path);
}
CrashReport.preload();
- if (optionSet.has(optionSpec13)) {
+ if (optionSet.has("jfrProfile")) { // CraftBukkit
JvmProfiler.INSTANCE.start(Environment.SERVER);
}
+ io.papermc.paper.plugin.PluginInitializerManager.load(optionSet); // Paper
Bootstrap.bootStrap();
Bootstrap.validate();
Util.startTimerHackThread();
Path path1 = Paths.get("server.properties");
- DedicatedServerSettings dedicatedServerSettings = new DedicatedServerSettings(path1);
+ DedicatedServerSettings dedicatedServerSettings = new DedicatedServerSettings(optionSet); // CraftBukkit - CLI argument support
dedicatedServerSettings.forceSave();
RegionFileVersion.configure(dedicatedServerSettings.getProperties().regionFileComression);
Path path2 = Paths.get("eula.txt");
Eula eula = new Eula(path2);
- if (optionSet.has(optionSpec1)) {
+ // Paper start - load config files early for access below if needed
+ org.bukkit.configuration.file.YamlConfiguration bukkitConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) optionSet.valueOf("bukkit-settings"));
+ org.bukkit.configuration.file.YamlConfiguration spigotConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) optionSet.valueOf("spigot-settings"));
+ // Paper end - load config files early for access below if needed
+ if (optionSet.has("initSettings")) { // CraftBukkit
+ // CraftBukkit start - SPIGOT-5761: Create bukkit.yml and commands.yml if not present
+ File configFile = (File) optionSet.valueOf("bukkit-settings");
+ org.bukkit.configuration.file.YamlConfiguration configuration = org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(configFile);
+ configuration.options().copyDefaults(true);
+ configuration.setDefaults(org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(new java.io.InputStreamReader(Main.class.getClassLoader().getResourceAsStream("configurations/bukkit.yml"), com.google.common.base.Charsets.UTF_8)));
+ configuration.save(configFile);
+
+ File commandFile = (File) optionSet.valueOf("commands-settings");
+ org.bukkit.configuration.file.YamlConfiguration commandsConfiguration = org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(commandFile);
+ commandsConfiguration.options().copyDefaults(true);
+ commandsConfiguration.setDefaults(org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(new java.io.InputStreamReader(Main.class.getClassLoader().getResourceAsStream("configurations/commands.yml"), com.google.common.base.Charsets.UTF_8)));
+ commandsConfiguration.save(commandFile);
+ // CraftBukkit end
LOGGER.info("Initialized '{}' and '{}'", path1.toAbsolutePath(), path2.toAbsolutePath());
return;
}
- if (!eula.hasAgreedToEULA()) {
+ // Spigot Start
+ boolean eulaAgreed = Boolean.getBoolean("com.mojang.eula.agree");
+ if (eulaAgreed) {
+ System.err.println("You have used the Spigot command line EULA agreement flag.");
+ System.err.println("By using this setting you are indicating your agreement to Mojang's EULA (https://account.mojang.com/documents/minecraft_eula).");
+ System.err.println("If you do not agree to the above EULA please stop your server and remove this flag immediately.");
+ }
+ // Spigot End
+ if (!eula.hasAgreedToEULA() && !eulaAgreed) { // Spigot
LOGGER.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
return;
}
- File file = new File(optionSet.valueOf(optionSpec9));
- Services services = Services.create(new YggdrasilAuthenticationService(Proxy.NO_PROXY), file);
- String string = Optional.ofNullable(optionSet.valueOf(optionSpec10)).orElse(dedicatedServerSettings.getProperties().levelName);
+ // Paper start - Detect headless JRE
+ String awtException = io.papermc.paper.util.ServerEnvironment.awtDependencyCheck();
+ if (awtException != null) {
+ Main.LOGGER.error("You are using a headless JRE distribution.");
+ Main.LOGGER.error("This distribution is missing certain graphic libraries that the Minecraft server needs to function.");
+ Main.LOGGER.error("For instructions on how to install the non-headless JRE, see https://docs.papermc.io/misc/java-install");
+ Main.LOGGER.error("");
+ Main.LOGGER.error(awtException);
+ return;
+ }
+ // Paper end - Detect headless JRE
+
+ org.spigotmc.SpigotConfig.disabledAdvancements = spigotConfiguration.getStringList("advancements.disabled"); // Paper - fix SPIGOT-5885, must be set early in init
+
+ // Paper start - fix SPIGOT-5824
+ File file;
+ File userCacheFile = new File(Services.USERID_CACHE_FILE);
+ if (optionSet.has("universe")) {
+ file = (File) optionSet.valueOf("universe"); // CraftBukkit
+ userCacheFile = new File(file, Services.USERID_CACHE_FILE);
+ } else {
+ file = new File(bukkitConfiguration.getString("settings.world-container", "."));
+ }
+ // Paper end - fix SPIGOT-5824
+ Services services = Services.create(new com.destroystokyo.paper.profile.PaperAuthenticationService(Proxy.NO_PROXY), file, userCacheFile, optionSet); // Paper - pass OptionSet to load paper config files; override authentication service; fix world-container
+ // CraftBukkit start
+ String string = Optional.ofNullable((String) optionSet.valueOf("world")).orElse(dedicatedServerSettings.getProperties().levelName);
LevelStorageSource levelStorageSource = LevelStorageSource.createDefault(file.toPath());
- LevelStorageSource.LevelStorageAccess levelStorageAccess = levelStorageSource.validateAndCreateAccess(string);
+ LevelStorageSource.LevelStorageAccess levelStorageAccess = levelStorageSource.validateAndCreateAccess(string, LevelStem.OVERWORLD);
+ // CraftBukkit end
Dynamic<?> dataTag;
if (levelStorageAccess.hasWorldData()) {
LevelSummary summary;
@@ -169,12 +_,30 @@
}
Dynamic<?> dynamic = dataTag;
- boolean hasOptionSpec = optionSet.has(optionSpec7);
+ boolean hasOptionSpec = optionSet.has("safeMode"); // CraftBukkit
if (hasOptionSpec) {
LOGGER.warn("Safe mode active, only vanilla datapack will be loaded");
}
PackRepository packRepository = ServerPacksSource.createPackRepository(levelStorageAccess);
+ // CraftBukkit start
+ File bukkitDataPackFolder = new File(levelStorageAccess.getLevelPath(net.minecraft.world.level.storage.LevelResource.DATAPACK_DIR).toFile(), "bukkit");
+ if (!bukkitDataPackFolder.exists()) {
+ bukkitDataPackFolder.mkdirs();
+ }
+ File mcMeta = new File(bukkitDataPackFolder, "pack.mcmeta");
+ try {
+ com.google.common.io.Files.write("{\n"
+ + " \"pack\": {\n"
+ + " \"description\": \"Data pack for resources provided by Bukkit plugins\",\n"
+ + " \"pack_format\": " + SharedConstants.getCurrentVersion().getPackVersion(PackType.SERVER_DATA) + "\n"
+ + " }\n"
+ + "}\n", mcMeta, com.google.common.base.Charsets.UTF_8);
+ } catch (java.io.IOException ex) {
+ throw new RuntimeException("Could not initialize Bukkit datapack", ex);
+ }
+ java.util.concurrent.atomic.AtomicReference<WorldLoader.DataLoadContext> worldLoader = new java.util.concurrent.atomic.AtomicReference<>();
+ // CraftBukkit end
WorldStem worldStem;
try {
@@ -183,6 +_,7 @@
executor -> WorldLoader.load(
initConfig,
context -> {
+ worldLoader.set(context); // CraftBukkit
Registry<LevelStem> registry = context.datapackDimensions().lookupOrThrow(Registries.LEVEL_STEM);
if (dynamic != null) {
LevelDataAndDimensions levelDataAndDimensions = LevelStorageSource.getLevelDataAndDimensions(
@@ -196,7 +_,7 @@
LevelSettings levelSettings;
WorldOptions worldOptions;
WorldDimensions worldDimensions;
- if (optionSet.has(optionSpec2)) {
+ if (optionSet.has("demo")) { // CraftBukkit
levelSettings = MinecraftServer.DEMO_SETTINGS;
worldOptions = WorldOptions.DEMO_OPTIONS;
worldDimensions = WorldPresets.createNormalWorldDimensions(context.datapackWorldgen());
@@ -211,7 +_,7 @@
new GameRules(context.dataConfiguration().enabledFeatures()),
context.dataConfiguration()
);
- worldOptions = optionSet.has(optionSpec3) ? properties.worldOptions.withBonusChest(true) : properties.worldOptions;
+ worldOptions = optionSet.has("bonusChest") ? properties.worldOptions.withBonusChest(true) : properties.worldOptions; // CraftBukkit
worldDimensions = properties.createDimensions(context.datapackWorldgen());
}
@@ -237,6 +_,7 @@
return;
}
+ /*
RegistryAccess.Frozen frozen = worldStem.registries().compositeAccess();
boolean hasOptionSpec1 = optionSet.has(optionSpec6);
if (optionSet.has(optionSpec4) || hasOptionSpec1) {
@@ -245,9 +_,13 @@
WorldData worldData = worldStem.worldData();
levelStorageAccess.saveDataTag(frozen, worldData);
+ */
final DedicatedServer dedicatedServer = MinecraftServer.spin(
thread1 -> {
DedicatedServer dedicatedServer1 = new DedicatedServer(
+ // CraftBukkit start
+ optionSet,
+ worldLoader.get(),
thread1,
levelStorageAccess,
packRepository,
@@ -257,17 +_,29 @@
services,
LoggerChunkProgressListener::createFromGameruleRadius
);
+ /*
dedicatedServer1.setPort(optionSet.valueOf(optionSpec11));
- dedicatedServer1.setDemo(optionSet.has(optionSpec2));
+ */
+ dedicatedServer1.setDemo(optionSet.has("demo")); // Paper
+ /*
dedicatedServer1.setId(optionSet.valueOf(optionSpec12));
- boolean flag = !optionSet.has(optionSpec) && !optionSet.valuesOf(optionSpec15).contains("nogui");
+ */
+ boolean flag = !optionSet.has("nogui") && !optionSet.nonOptionArguments().contains("nogui");
if (flag && !GraphicsEnvironment.isHeadless()) {
dedicatedServer1.showGui();
}
+ if (optionSet.has("port")) {
+ int port = (Integer) optionSet.valueOf("port");
+ if (port > 0) {
+ dedicatedServer1.setPort(port);
+ }
+ }
+
return dedicatedServer1;
}
);
+ /* CraftBukkit start
Thread thread = new Thread("Server Shutdown Thread") {
@Override
public void run() {
@@ -276,6 +_,7 @@
};
thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER));
Runtime.getRuntime().addShutdownHook(thread);
+ */ // CraftBukkit end
} catch (Exception var42) {
LOGGER.error(LogUtils.FATAL_MARKER, "Failed to start the minecraft server", (Throwable)var42);
}
@@ -316,7 +_,7 @@
RegistryAccess registryAccess,
boolean recreateRegionFiles
) {
- LOGGER.info("Forcing world upgrade!");
+ LOGGER.info("Forcing world upgrade! {}", levelStorage.getLevelId()); // CraftBukkit
try (WorldUpgrader worldUpgrader = new WorldUpgrader(levelStorage, dataFixer, registryAccess, eraseCache, recreateRegionFiles)) {
Component component = null;

View file

@ -1,52 +1,52 @@
--- a/net/minecraft/server/PlayerAdvancements.java
+++ b/net/minecraft/server/PlayerAdvancements.java
@@ -50,7 +50,7 @@
public class PlayerAdvancements {
@@ -47,7 +_,7 @@
public class PlayerAdvancements {
private static final Logger LOGGER = LogUtils.getLogger();
- private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().create();
+ private static final Gson GSON = (new GsonBuilder()).create(); // Paper - Remove pretty printing from advancements
- private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
+ private static final Gson GSON = new GsonBuilder().create(); // Paper - Remove pretty printing from advancements
private final PlayerList playerList;
private final Path playerSavePath;
private AdvancementTree tree;
@@ -63,6 +63,7 @@
@@ -60,6 +_,7 @@
private AdvancementHolder lastSelectedTab;
private boolean isFirstPacket = true;
private final Codec<PlayerAdvancements.Data> codec;
+ public final Map<net.minecraft.advancements.critereon.SimpleCriterionTrigger<?>, Set<CriterionTrigger.Listener<?>>> criterionData = new java.util.IdentityHashMap<>(); // Paper - fix advancement data player leakage
public PlayerAdvancements(DataFixer dataFixer, PlayerList playerManager, ServerAdvancementManager advancementLoader, Path filePath, ServerPlayer owner) {
this.playerList = playerManager;
@@ -162,6 +163,7 @@
public PlayerAdvancements(DataFixer dataFixer, PlayerList playerList, ServerAdvancementManager manager, Path playerSavePath, ServerPlayer player) {
this.playerList = playerList;
@@ -128,6 +_,7 @@
}
public void save() {
+ if (org.spigotmc.SpigotConfig.disableAdvancementSaving) return; // Spigot
JsonElement jsonelement = (JsonElement) this.codec.encodeStart(JsonOps.INSTANCE, this.asData()).getOrThrow();
JsonElement jsonElement = this.codec.encodeStart(JsonOps.INSTANCE, this.asData()).getOrThrow();
try {
@@ -196,6 +198,7 @@
AdvancementHolder advancementholder = loader.get(minecraftkey);
if (advancementholder == null) {
+ if (!minecraftkey.getNamespace().equals("minecraft")) return; // CraftBukkit
PlayerAdvancements.LOGGER.warn("Ignored advancement '{}' in progress file {} - it doesn't exist anymore?", minecraftkey, this.playerSavePath);
@@ -145,6 +_,7 @@
data.forEach((path, progress) -> {
AdvancementHolder advancementHolder = advancementManager.get(path);
if (advancementHolder == null) {
+ if (!path.getNamespace().equals(ResourceLocation.DEFAULT_NAMESPACE)) return; // CraftBukkit
LOGGER.warn("Ignored advancement '{}' in progress file {} - it doesn't exist anymore?", path, this.playerSavePath);
} else {
this.startProgress(advancementholder, advancementprogress);
@@ -223,14 +226,31 @@
boolean flag1 = advancementprogress.isDone();
if (advancementprogress.grantProgress(criterionName)) {
this.startProgress(advancementHolder, progress);
@@ -169,14 +_,31 @@
AdvancementProgress orStartProgress = this.getOrStartProgress(advancement);
boolean isDone = orStartProgress.isDone();
if (orStartProgress.grantProgress(criterionKey)) {
+ // Paper start - Add PlayerAdvancementCriterionGrantEvent
+ if (!new com.destroystokyo.paper.event.player.PlayerAdvancementCriterionGrantEvent(this.player.getBukkitEntity(), advancement.toBukkit(), criterionName).callEvent()) {
+ advancementprogress.revokeProgress(criterionName);
+ if (!new com.destroystokyo.paper.event.player.PlayerAdvancementCriterionGrantEvent(this.player.getBukkitEntity(), advancement.toBukkit(), criterionKey).callEvent()) {
+ orStartProgress.revokeProgress(criterionKey);
+ return false;
+ }
+ // Paper end - Add PlayerAdvancementCriterionGrantEvent
this.unregisterListeners(advancement);
this.progressChanged.add(advancement);
flag = true;
if (!flag1 && advancementprogress.isDone()) {
if (!isDone && orStartProgress.isDone()) {
+ // Paper start - Add Adventure message to PlayerAdvancementDoneEvent
+ final net.kyori.adventure.text.Component message = advancement.value().display().flatMap(info -> {
+ return java.util.Optional.ofNullable(
@ -57,13 +57,13 @@
+ this.player.level().getCraftServer().getPluginManager().callEvent(event); // CraftBukkit
+ // Paper end
advancement.value().rewards().grant(this.player);
advancement.value().display().ifPresent((advancementdisplay) -> {
- if (advancementdisplay.shouldAnnounceChat() && this.player.serverLevel().getGameRules().getBoolean(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)) {
- this.playerList.broadcastSystemMessage(advancementdisplay.getType().createAnnouncement(advancement, this.player), false);
advancement.value().display().ifPresent(displayInfo -> {
- if (displayInfo.shouldAnnounceChat() && this.player.serverLevel().getGameRules().getBoolean(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)) {
- this.playerList.broadcastSystemMessage(displayInfo.getType().createAnnouncement(advancement, this.player), false);
+ // Paper start - Add Adventure message to PlayerAdvancementDoneEvent
+ if (event.message() != null && this.player.serverLevel().getGameRules().getBoolean(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)) {
+ this.playerList.broadcastSystemMessage(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.message()), false);
+ // Paper end
}
});
}

View file

@ -0,0 +1,38 @@
--- a/net/minecraft/server/ReloadableServerRegistries.java
+++ b/net/minecraft/server/ReloadableServerRegistries.java
@@ -48,8 +_,9 @@
List<HolderLookup.RegistryLookup<?>> list = TagLoader.buildUpdatedLookups(registryAccess.getAccessForLoading(RegistryLayer.RELOADABLE), postponedTags);
HolderLookup.Provider provider = HolderLookup.Provider.create(list.stream());
RegistryOps<JsonElement> registryOps = provider.createSerializationContext(JsonOps.INSTANCE);
+ final io.papermc.paper.registry.data.util.Conversions conversions = new io.papermc.paper.registry.data.util.Conversions(registryOps.lookupProvider); // Paper
List<CompletableFuture<WritableRegistry<?>>> list1 = LootDataType.values()
- .map(lootDataType -> scheduleRegistryLoad((LootDataType<?>)lootDataType, registryOps, resourceManager, backgroundExecutor))
+ .map(lootDataType -> scheduleRegistryLoad((LootDataType<?>)lootDataType, registryOps, resourceManager, backgroundExecutor, conversions)) // Paper
.toList();
CompletableFuture<List<WritableRegistry<?>>> completableFuture = Util.sequence(list1);
return completableFuture.thenApplyAsync(
@@ -58,19 +_,20 @@
}
private static <T> CompletableFuture<WritableRegistry<?>> scheduleRegistryLoad(
- LootDataType<T> lootDataType, RegistryOps<JsonElement> ops, ResourceManager resourceManager, Executor backgroundExecutor
+ LootDataType<T> lootDataType, RegistryOps<JsonElement> ops, ResourceManager resourceManager, Executor backgroundExecutor, io.papermc.paper.registry.data.util.Conversions conversions // Paper
) {
return CompletableFuture.supplyAsync(
() -> {
WritableRegistry<T> writableRegistry = new MappedRegistry<>(lootDataType.registryKey(), Lifecycle.experimental());
+ io.papermc.paper.registry.PaperRegistryAccess.instance().registerReloadableRegistry(lootDataType.registryKey(), writableRegistry); // Paper - register reloadable registry
Map<ResourceLocation, T> map = new HashMap<>();
SimpleJsonResourceReloadListener.scanDirectory(resourceManager, lootDataType.registryKey(), ops, lootDataType.codec(), map);
map.forEach(
- (resourceLocation, object) -> writableRegistry.register(
- ResourceKey.create(lootDataType.registryKey(), resourceLocation), (T)object, DEFAULT_REGISTRATION_INFO
+ (resourceLocation, object) -> io.papermc.paper.registry.PaperRegistryListenerManager.INSTANCE.registerWithListeners(writableRegistry, // Paper - register with listeners
+ ResourceKey.create(lootDataType.registryKey(), resourceLocation), (T)object, DEFAULT_REGISTRATION_INFO, conversions // Paper - register with listeners
)
);
- TagLoader.loadTagsForRegistry(resourceManager, writableRegistry);
+ TagLoader.loadTagsForRegistry(resourceManager, writableRegistry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.RELOAD); // Paper - tag life cycle - reload
return writableRegistry;
},
backgroundExecutor

View file

@ -1,16 +1,16 @@
--- a/net/minecraft/server/ReloadableServerResources.java
+++ b/net/minecraft/server/ReloadableServerResources.java
@@ -39,6 +39,7 @@
this.postponedTags = pendingTagLoads;
@@ -39,6 +_,7 @@
this.postponedTags = postponedTags;
this.recipes = new RecipeManager(registries);
this.commands = new Commands(environment, CommandBuildContext.simple(registries, enabledFeatures));
this.commands = new Commands(commandSelection, CommandBuildContext.simple(registries, enabledFeatures));
+ io.papermc.paper.command.brigadier.PaperCommands.INSTANCE.setDispatcher(this.commands, CommandBuildContext.simple(registries, enabledFeatures)); // Paper - Brigadier Command API
this.advancements = new ServerAdvancementManager(registries);
this.functionLibrary = new ServerFunctionLibrary(functionPermissionLevel, this.commands.getDispatcher());
this.functionLibrary = new ServerFunctionLibrary(functionCompilationLevel, this.commands.getDispatcher());
}
@@ -83,6 +84,14 @@
@@ -83,6 +_,14 @@
ReloadableServerResources reloadableServerResources = new ReloadableServerResources(
reloadResult.layers(), reloadResult.lookupWithUpdatedTags(), enabledFeatures, environment, pendingTagLoads, functionPermissionLevel
loadResult.layers(), loadResult.lookupWithUpdatedTags(), enabledFeatures, commandSelection, postponedTags, functionCompilationLevel
);
+ // Paper start - call commands event for bootstraps
+ //noinspection ConstantValue

View file

@ -1,39 +1,31 @@
--- a/net/minecraft/server/ServerAdvancementManager.java
+++ b/net/minecraft/server/ServerAdvancementManager.java
@@ -21,10 +21,14 @@
import net.minecraft.util.profiling.ProfilerFiller;
import org.slf4j.Logger;
@@ -22,7 +_,7 @@
+// CraftBukkit start
+import java.util.HashMap;
+// CraftBukkit end
+
public class ServerAdvancementManager extends SimpleJsonResourceReloadListener<Advancement> {
private static final Logger LOGGER = LogUtils.getLogger();
- public Map<ResourceLocation, AdvancementHolder> advancements = Map.of();
+ public Map<ResourceLocation, AdvancementHolder> advancements = new HashMap<>(); // CraftBukkit - SPIGOT-7734: mutable
+ public Map<ResourceLocation, AdvancementHolder> advancements = new java.util.HashMap<>(); // CraftBukkit - SPIGOT-7734: mutable
private AdvancementTree tree = new AdvancementTree();
private final HolderLookup.Provider registries;
@@ -37,13 +41,19 @@
@@ -35,12 +_,18 @@
protected void apply(Map<ResourceLocation, Advancement> object, ResourceManager resourceManager, ProfilerFiller profiler) {
Builder<ResourceLocation, AdvancementHolder> builder = ImmutableMap.builder();
prepared.forEach((minecraftkey, advancement) -> {
object.forEach((resourceLocation, advancement) -> {
+ // Spigot start
+ if (org.spigotmc.SpigotConfig.disabledAdvancements != null && (org.spigotmc.SpigotConfig.disabledAdvancements.contains("*") || org.spigotmc.SpigotConfig.disabledAdvancements.contains(minecraftkey.toString()) || org.spigotmc.SpigotConfig.disabledAdvancements.contains(minecraftkey.getNamespace()))) {
+ if (org.spigotmc.SpigotConfig.disabledAdvancements != null && (org.spigotmc.SpigotConfig.disabledAdvancements.contains("*") || org.spigotmc.SpigotConfig.disabledAdvancements.contains(resourceLocation.toString()) || org.spigotmc.SpigotConfig.disabledAdvancements.contains(resourceLocation.getNamespace()))) {
+ return;
+ }
+ // Spigot end
this.validate(minecraftkey, advancement);
builder.put(minecraftkey, new AdvancementHolder(minecraftkey, advancement));
this.validate(resourceLocation, advancement);
builder.put(resourceLocation, new AdvancementHolder(resourceLocation, advancement));
});
- this.advancements = builder.buildOrThrow();
+ this.advancements = new HashMap<>(builder.buildOrThrow()); // CraftBukkit - SPIGOT-7734: mutable
AdvancementTree advancementtree = new AdvancementTree();
+ this.advancements = new java.util.HashMap<>(builder.buildOrThrow()); // CraftBukkit - SPIGOT-7734: mutable
AdvancementTree advancementTree = new AdvancementTree();
advancementTree.addAll(this.advancements.values());
+ LOGGER.info("Loaded {} advancements", advancementTree.nodes().size()); // Paper - Improve logging and errors; moved from AdvancementTree#addAll
advancementtree.addAll(this.advancements.values());
+ LOGGER.info("Loaded {} advancements", advancementtree.nodes().size()); // Paper - Improve logging and errors; moved from AdvancementTree#addAll
Iterator iterator = advancementtree.roots().iterator();
while (iterator.hasNext()) {
for (AdvancementNode advancementNode : advancementTree.roots()) {
if (advancementNode.holder().value().display().isPresent()) {

View file

@ -0,0 +1,11 @@
--- a/net/minecraft/server/ServerFunctionLibrary.java
+++ b/net/minecraft/server/ServerFunctionLibrary.java
@@ -113,7 +_,7 @@
return null;
}).join());
this.functions = builder.build();
- this.tags = this.tagsLoader.build((Map<ResourceLocation, List<TagLoader.EntryWithSource>>)pair.getFirst());
+ this.tags = this.tagsLoader.build((Map<ResourceLocation, List<TagLoader.EntryWithSource>>)pair.getFirst(), null); // Paper - command function tags are not implemented yet
},
gameExecutor
);

View file

@ -1,6 +1,6 @@
--- a/net/minecraft/server/ServerFunctionManager.java
+++ b/net/minecraft/server/ServerFunctionManager.java
@@ -37,7 +37,7 @@
@@ -34,7 +_,7 @@
}
public CommandDispatcher<CommandSourceStack> getDispatcher() {

View file

@ -1,24 +1,26 @@
--- a/net/minecraft/server/ServerScoreboard.java
+++ b/net/minecraft/server/ServerScoreboard.java
@@ -42,7 +42,7 @@
@@ -39,9 +_,7 @@
protected void onScoreChanged(ScoreHolder scoreHolder, Objective objective, Score score) {
super.onScoreChanged(scoreHolder, objective, score);
if (this.trackedObjectives.contains(objective)) {
- this.server.getPlayerList().broadcastAll(new ClientboundSetScorePacket(scoreHolder.getScoreboardName(), objective.getName(), score.value(), Optional.ofNullable(score.display()), Optional.ofNullable(score.numberFormat())));
+ this.broadcastAll(new ClientboundSetScorePacket(scoreHolder.getScoreboardName(), objective.getName(), score.value(), Optional.ofNullable(score.display()), Optional.ofNullable(score.numberFormat()))); // CraftBukkit
}
this.setDirty();
@@ -57,7 +57,7 @@
- this.server
- .getPlayerList()
- .broadcastAll(
+ this.broadcastAll( // CraftBukkit
new ClientboundSetScorePacket(
scoreHolder.getScoreboardName(),
objective.getName(),
@@ -64,7 +_,7 @@
@Override
public void onPlayerRemoved(ScoreHolder scoreHolder) {
super.onPlayerRemoved(scoreHolder);
- this.server.getPlayerList().broadcastAll(new ClientboundResetScorePacket(scoreHolder.getScoreboardName(), (String) null));
+ this.broadcastAll(new ClientboundResetScorePacket(scoreHolder.getScoreboardName(), (String) null)); // CraftBukkit
- this.server.getPlayerList().broadcastAll(new ClientboundResetScorePacket(scoreHolder.getScoreboardName(), null));
+ this.broadcastAll(new ClientboundResetScorePacket(scoreHolder.getScoreboardName(), null)); // CraftBukkit
this.setDirty();
}
@@ -65,7 +65,7 @@
@@ -72,7 +_,7 @@
public void onPlayerScoreRemoved(ScoreHolder scoreHolder, Objective objective) {
super.onPlayerScoreRemoved(scoreHolder, objective);
if (this.trackedObjectives.contains(objective)) {
@ -27,16 +29,16 @@
}
this.setDirty();
@@ -78,7 +78,7 @@
@@ -84,7 +_,7 @@
super.setDisplayObjective(slot, objective);
if (scoreboardobjective1 != objective && scoreboardobjective1 != null) {
if (this.getObjectiveDisplaySlotCount(scoreboardobjective1) > 0) {
if (displayObjective != objective && displayObjective != null) {
if (this.getObjectiveDisplaySlotCount(displayObjective) > 0) {
- this.server.getPlayerList().broadcastAll(new ClientboundSetDisplayObjectivePacket(slot, objective));
+ this.broadcastAll(new ClientboundSetDisplayObjectivePacket(slot, objective)); // CraftBukkit
} else {
this.stopTrackingObjective(scoreboardobjective1);
this.stopTrackingObjective(displayObjective);
}
@@ -86,7 +86,7 @@
@@ -92,7 +_,7 @@
if (objective != null) {
if (this.trackedObjectives.contains(objective)) {
@ -45,16 +47,7 @@
} else {
this.startTrackingObjective(objective);
}
@@ -98,7 +98,7 @@
@Override
public boolean addPlayerToTeam(String scoreHolderName, PlayerTeam team) {
if (super.addPlayerToTeam(scoreHolderName, team)) {
- this.server.getPlayerList().broadcastAll(ClientboundSetPlayerTeamPacket.createPlayerPacket(team, scoreHolderName, ClientboundSetPlayerTeamPacket.Action.ADD));
+ this.broadcastAll(ClientboundSetPlayerTeamPacket.createPlayerPacket(team, scoreHolderName, ClientboundSetPlayerTeamPacket.Action.ADD)); // CraftBukkit
this.setDirty();
return true;
} else {
@@ -106,13 +106,43 @@
@@ -114,14 +_,42 @@
}
}
@ -78,13 +71,17 @@
+ // Paper end - Multiple Entries with Scoreboards
+
@Override
public void removePlayerFromTeam(String scoreHolderName, PlayerTeam team) {
super.removePlayerFromTeam(scoreHolderName, team);
- this.server.getPlayerList().broadcastAll(ClientboundSetPlayerTeamPacket.createPlayerPacket(team, scoreHolderName, ClientboundSetPlayerTeamPacket.Action.REMOVE));
+ this.broadcastAll(ClientboundSetPlayerTeamPacket.createPlayerPacket(team, scoreHolderName, ClientboundSetPlayerTeamPacket.Action.REMOVE)); // CraftBukkit
this.setDirty();
}
public void removePlayerFromTeam(String username, PlayerTeam playerTeam) {
super.removePlayerFromTeam(username, playerTeam);
- this.server
- .getPlayerList()
- .broadcastAll(ClientboundSetPlayerTeamPacket.createPlayerPacket(playerTeam, username, ClientboundSetPlayerTeamPacket.Action.REMOVE));
- this.setDirty();
- }
+ this.broadcastAll(ClientboundSetPlayerTeamPacket.createPlayerPacket(playerTeam, username, ClientboundSetPlayerTeamPacket.Action.REMOVE)); // CraftBukkit
+ this.setDirty();
+ }
+
+ // Paper start - Multiple Entries with Scoreboards
+ public void removePlayersFromTeam(java.util.Collection<String> players, PlayerTeam team) {
+ for (String playerName : players) {
@ -95,11 +92,10 @@
+ this.setDirty();
+ }
+ // Paper end - Multiple Entries with Scoreboards
+
@Override
public void onObjectiveAdded(Objective objective) {
super.onObjectiveAdded(objective);
@@ -123,7 +153,7 @@
@@ -133,7 +_,7 @@
public void onObjectiveChanged(Objective objective) {
super.onObjectiveChanged(objective);
if (this.trackedObjectives.contains(objective)) {
@ -108,61 +104,61 @@
}
this.setDirty();
@@ -142,21 +172,21 @@
@@ -152,21 +_,21 @@
@Override
public void onTeamAdded(PlayerTeam team) {
super.onTeamAdded(team);
- this.server.getPlayerList().broadcastAll(ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, true));
+ this.broadcastAll(ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, true)); // CraftBukkit
public void onTeamAdded(PlayerTeam playerTeam) {
super.onTeamAdded(playerTeam);
- this.server.getPlayerList().broadcastAll(ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(playerTeam, true));
+ this.broadcastAll(ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(playerTeam, true)); // CraftBukkit
this.setDirty();
}
@Override
public void onTeamChanged(PlayerTeam team) {
super.onTeamChanged(team);
- this.server.getPlayerList().broadcastAll(ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, false));
+ this.broadcastAll(ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, false)); // CraftBukkit
public void onTeamChanged(PlayerTeam playerTeam) {
super.onTeamChanged(playerTeam);
- this.server.getPlayerList().broadcastAll(ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(playerTeam, false));
+ this.broadcastAll(ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(playerTeam, false)); // CraftBukkit
this.setDirty();
}
@Override
public void onTeamRemoved(PlayerTeam team) {
super.onTeamRemoved(team);
- this.server.getPlayerList().broadcastAll(ClientboundSetPlayerTeamPacket.createRemovePacket(team));
+ this.broadcastAll(ClientboundSetPlayerTeamPacket.createRemovePacket(team)); // CraftBukkit
public void onTeamRemoved(PlayerTeam playerTeam) {
super.onTeamRemoved(playerTeam);
- this.server.getPlayerList().broadcastAll(ClientboundSetPlayerTeamPacket.createRemovePacket(playerTeam));
+ this.broadcastAll(ClientboundSetPlayerTeamPacket.createRemovePacket(playerTeam)); // CraftBukkit
this.setDirty();
}
@@ -207,6 +237,7 @@
@@ -209,6 +_,7 @@
List<Packet<?>> startTrackingPackets = this.getStartTrackingPackets(objective);
while (iterator.hasNext()) {
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
+ if (entityplayer.getBukkitEntity().getScoreboard().getHandle() != this) continue; // CraftBukkit - Only players on this board
Iterator iterator1 = list.iterator();
for (ServerPlayer serverPlayer : this.server.getPlayerList().getPlayers()) {
+ if (serverPlayer.getBukkitEntity().getScoreboard().getHandle() != this) continue; // CraftBukkit - Only players on this board
for (Packet<?> packet : startTrackingPackets) {
serverPlayer.connection.send(packet);
}
@@ -234,6 +_,7 @@
List<Packet<?>> stopTrackingPackets = this.getStopTrackingPackets(objective);
while (iterator1.hasNext()) {
@@ -243,6 +274,7 @@
while (iterator.hasNext()) {
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
+ if (entityplayer.getBukkitEntity().getScoreboard().getHandle() != this) continue; // CraftBukkit - Only players on this board
Iterator iterator1 = list.iterator();
while (iterator1.hasNext()) {
@@ -287,6 +319,16 @@
return this.createData().load(nbt, registries);
for (ServerPlayer serverPlayer : this.server.getPlayerList().getPlayers()) {
+ if (serverPlayer.getBukkitEntity().getScoreboard().getHandle() != this) continue; // CraftBukkit - Only players on this board
for (Packet<?> packet : stopTrackingPackets) {
serverPlayer.connection.send(packet);
}
@@ -267,6 +_,16 @@
private ScoreboardSaveData createData(CompoundTag tag, HolderLookup.Provider registries) {
return this.createData().load(tag, registries);
}
+
+ // CraftBukkit start - Send to players
+ private void broadcastAll(Packet packet) {
+ for (ServerPlayer entityplayer : (List<ServerPlayer>) this.server.getPlayerList().players) {
+ if (entityplayer.getBukkitEntity().getScoreboard().getHandle() == this) {
+ entityplayer.connection.send(packet);
+ private void broadcastAll(Packet<?> packet) {
+ for (ServerPlayer serverPlayer : this.server.getPlayerList().players) {
+ if (serverPlayer.getBukkitEntity().getScoreboard().getHandle() == this) {
+ serverPlayer.connection.send(packet);
+ }
+ }
+ }
+ // CraftBukkit end
+
public static enum Method {
CHANGE, REMOVE;
public static enum Method {
CHANGE,

View file

@ -1,6 +1,6 @@
--- a/net/minecraft/server/ServerTickRateManager.java
+++ b/net/minecraft/server/ServerTickRateManager.java
@@ -59,8 +59,14 @@
@@ -58,8 +_,14 @@
}
public boolean stopSprinting() {
@ -16,34 +16,31 @@
return true;
} else {
return false;
@@ -78,7 +84,7 @@
@@ -76,14 +_,20 @@
return flag;
}
- private void finishTickSprint() {
+ private void finishTickSprint(boolean sendLog) { // CraftBukkit - add sendLog parameter
long i = this.scheduledCurrentSprintTicks - this.remainingSprintTicks;
double d0 = Math.max(1.0D, (double) this.sprintTimeSpend) / (double) TimeUtil.NANOSECONDS_PER_MILLISECOND;
int j = (int) ((double) (TimeUtil.MILLISECONDS_PER_SECOND * i) / d0);
@@ -86,9 +92,13 @@
long l = this.scheduledCurrentSprintTicks - this.remainingSprintTicks;
double d = Math.max(1.0, (double)this.sprintTimeSpend) / TimeUtil.NANOSECONDS_PER_MILLISECOND;
int i = (int)(TimeUtil.MILLISECONDS_PER_SECOND * l / d);
String string = String.format("%.2f", l == 0L ? this.millisecondsPerTick() : d / l);
this.scheduledCurrentSprintTicks = 0L;
this.sprintTimeSpend = 0L;
- this.server.createCommandSourceStack().sendSuccess(() -> {
- return Component.translatable("commands.tick.sprint.report", j, s);
- }, true);
- this.server.createCommandSourceStack().sendSuccess(() -> Component.translatable("commands.tick.sprint.report", i, string), true);
+ // CraftBukkit start - add sendLog parameter
+ if (sendLog) {
+ this.server.createCommandSourceStack().sendSuccess(() -> {
+ return Component.translatable("commands.tick.sprint.report", j, s);
+ return Component.translatable("commands.tick.sprint.report", i, string);
+ }, true);
+ }
+ // CraftBukkit end
this.remainingSprintTicks = 0L;
this.setFrozen(this.previousIsFrozen);
this.server.onTickRateChanged();
@@ -102,7 +112,7 @@
--this.remainingSprintTicks;
@@ -97,7 +_,7 @@
this.remainingSprintTicks--;
return true;
} else {
- this.finishTickSprint();

View file

@ -1,38 +1,38 @@
--- a/net/minecraft/server/Services.java
+++ b/net/minecraft/server/Services.java
@@ -10,16 +10,32 @@
import net.minecraft.server.players.GameProfileCache;
@@ -11,15 +_,31 @@
import net.minecraft.util.SignatureValidator;
+
public record Services(
- MinecraftSessionService sessionService, ServicesKeySet servicesKeySet, GameProfileRepository profileRepository, GameProfileCache profileCache
+ MinecraftSessionService sessionService, ServicesKeySet servicesKeySet, GameProfileRepository profileRepository, GameProfileCache profileCache, @javax.annotation.Nullable io.papermc.paper.configuration.PaperConfigurations paperConfigurations // Paper - add paper configuration files
) {
- private static final String USERID_CACHE_FILE = "usercache.json";
-
- public static Services create(YggdrasilAuthenticationService authenticationService, File profileRepository) {
+ public static final String USERID_CACHE_FILE = "usercache.json"; // Paper - private -> public
+
+ // Paper start - add paper configuration files
+ public Services(MinecraftSessionService sessionService, ServicesKeySet servicesKeySet, GameProfileRepository profileRepository, GameProfileCache profileCache) {
+ this(sessionService, servicesKeySet, profileRepository, profileCache, null);
+ }
- public static Services create(YggdrasilAuthenticationService authenticationService, File rootDirectory) {
+
+ @Override
+ public io.papermc.paper.configuration.PaperConfigurations paperConfigurations() {
+ return java.util.Objects.requireNonNull(this.paperConfigurations);
+ }
+ // Paper end - add paper configuration files
+ public static final String USERID_CACHE_FILE = "usercache.json"; // Paper - private -> public
+
+ public static Services create(YggdrasilAuthenticationService authenticationService, File rootDirectory, File userCacheFile, joptsimple.OptionSet optionSet) throws Exception { // Paper - add optionset to load paper config files; add userCacheFile parameter
+ public static Services create(YggdrasilAuthenticationService authenticationService, File profileRepository, File userCacheFile, joptsimple.OptionSet optionSet) throws Exception { // Paper - add optionset to load paper config files; add userCacheFile parameter
MinecraftSessionService minecraftSessionService = authenticationService.createMinecraftSessionService();
GameProfileRepository gameProfileRepository = authenticationService.createProfileRepository();
- GameProfileCache gameProfileCache = new GameProfileCache(gameProfileRepository, new File(rootDirectory, "usercache.json"));
- GameProfileCache gameProfileCache = new GameProfileCache(gameProfileRepository, new File(profileRepository, "usercache.json"));
- return new Services(minecraftSessionService, authenticationService.getServicesKeySet(), gameProfileRepository, gameProfileCache);
+ GameProfileCache gameProfileCache = new GameProfileCache(gameProfileRepository, userCacheFile); // Paper - use specified user cache file
+ // Paper start - load paper config files from cli options
+ final java.nio.file.Path legacyConfigPath = ((File) optionSet.valueOf("paper-settings")).toPath();
+ final java.nio.file.Path configDirPath = ((File) optionSet.valueOf("paper-settings-directory")).toPath();
+ io.papermc.paper.configuration.PaperConfigurations paperConfigurations = io.papermc.paper.configuration.PaperConfigurations.setup(legacyConfigPath, configDirPath, rootDirectory.toPath(), (File) optionSet.valueOf("spigot-settings"));
+ io.papermc.paper.configuration.PaperConfigurations paperConfigurations = io.papermc.paper.configuration.PaperConfigurations.setup(legacyConfigPath, configDirPath, profileRepository.toPath(), (File) optionSet.valueOf("spigot-settings"));
+ return new Services(minecraftSessionService, authenticationService.getServicesKeySet(), gameProfileRepository, gameProfileCache, paperConfigurations);
+ // Paper end - load paper config files from cli options
}

View file

@ -1,11 +1,11 @@
--- a/net/minecraft/server/WorldLoader.java
+++ b/net/minecraft/server/WorldLoader.java
@@ -37,7 +37,7 @@
@@ -37,7 +_,7 @@
CloseableResourceManager closeableResourceManager = pair.getSecond();
LayeredRegistryAccess<RegistryLayer> layeredRegistryAccess = RegistryLayer.createRegistryAccess();
List<Registry.PendingTags<?>> list = TagLoader.loadTagsForExistingRegistries(
- closeableResourceManager, layeredRegistryAccess.getLayer(RegistryLayer.STATIC)
+ closeableResourceManager, layeredRegistryAccess.getLayer(RegistryLayer.STATIC), io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL // Paper - tag lifecycle - add cause
);
RegistryAccess.Frozen frozen = layeredRegistryAccess.getAccessForLoading(RegistryLayer.WORLDGEN);
List<HolderLookup.RegistryLookup<?>> list2 = TagLoader.buildUpdatedLookups(frozen, list);
RegistryAccess.Frozen accessForLoading = layeredRegistryAccess.getAccessForLoading(RegistryLayer.WORLDGEN);
List<HolderLookup.RegistryLookup<?>> list1 = TagLoader.buildUpdatedLookups(accessForLoading, list);

View file

@ -1,290 +0,0 @@
--- a/net/minecraft/server/Main.java
+++ b/net/minecraft/server/Main.java
@@ -38,6 +38,7 @@
import net.minecraft.server.dedicated.DedicatedServerProperties;
import net.minecraft.server.dedicated.DedicatedServerSettings;
import net.minecraft.server.level.progress.LoggerChunkProgressListener;
+import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.repository.PackRepository;
import net.minecraft.server.packs.repository.ServerPacksSource;
import net.minecraft.util.Mth;
@@ -55,22 +56,31 @@
import net.minecraft.world.level.levelgen.WorldOptions;
import net.minecraft.world.level.levelgen.presets.WorldPresets;
import net.minecraft.world.level.storage.LevelDataAndDimensions;
+import net.minecraft.world.level.storage.LevelResource;
import net.minecraft.world.level.storage.LevelStorageSource;
import net.minecraft.world.level.storage.LevelSummary;
import net.minecraft.world.level.storage.PrimaryLevelData;
-import net.minecraft.world.level.storage.WorldData;
import org.slf4j.Logger;
+// CraftBukkit start
+import com.google.common.base.Charsets;
+import java.io.InputStreamReader;
+import java.util.concurrent.atomic.AtomicReference;
+import net.minecraft.SharedConstants;
+import org.bukkit.configuration.file.YamlConfiguration;
+// CraftBukkit end
+
public class Main {
private static final Logger LOGGER = LogUtils.getLogger();
public Main() {}
- @SuppressForbidden(a = "System.out needed before bootstrap")
+ @SuppressForbidden(reason = "System.out needed before bootstrap") // CraftBukkit - decompile error
@DontObfuscate
- public static void main(String[] args) {
+ public static void main(final OptionSet optionset) { // CraftBukkit - replaces main(String[] astring)
SharedConstants.tryDetectVersion();
+ /* CraftBukkit start - Replace everything
OptionParser optionparser = new OptionParser();
OptionSpec<Void> optionspec = optionparser.accepts("nogui");
OptionSpec<Void> optionspec1 = optionparser.accepts("initSettings", "Initializes 'server.properties' and 'eula.txt', then quits");
@@ -90,50 +100,104 @@
OptionSpec<String> optionspec15 = optionparser.nonOptions();
try {
- OptionSet optionset = optionparser.parse(args);
+ OptionSet optionset = optionparser.parse(astring);
if (optionset.has(optionspec8)) {
optionparser.printHelpOn(System.err);
return;
}
+ */ // CraftBukkit end
- Path path = (Path) optionset.valueOf(optionspec14);
+ try {
+ Path path = (Path) optionset.valueOf("pidFile"); // CraftBukkit
+
if (path != null) {
Main.writePidFile(path);
}
CrashReport.preload();
- if (optionset.has(optionspec13)) {
+ if (optionset.has("jfrProfile")) { // CraftBukkit
JvmProfiler.INSTANCE.start(Environment.SERVER);
}
+ io.papermc.paper.plugin.PluginInitializerManager.load(optionset); // Paper
Bootstrap.bootStrap();
Bootstrap.validate();
Util.startTimerHackThread();
Path path1 = Paths.get("server.properties");
- DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(path1);
+ DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(optionset); // CraftBukkit - CLI argument support
dedicatedserversettings.forceSave();
RegionFileVersion.configure(dedicatedserversettings.getProperties().regionFileComression);
Path path2 = Paths.get("eula.txt");
Eula eula = new Eula(path2);
+ // Paper start - load config files early for access below if needed
+ org.bukkit.configuration.file.YamlConfiguration bukkitConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) optionset.valueOf("bukkit-settings"));
+ org.bukkit.configuration.file.YamlConfiguration spigotConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) optionset.valueOf("spigot-settings"));
+ // Paper end - load config files early for access below if needed
- if (optionset.has(optionspec1)) {
+ if (optionset.has("initSettings")) { // CraftBukkit
+ // CraftBukkit start - SPIGOT-5761: Create bukkit.yml and commands.yml if not present
+ File configFile = (File) optionset.valueOf("bukkit-settings");
+ YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile);
+ configuration.options().copyDefaults(true);
+ configuration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(Main.class.getClassLoader().getResourceAsStream("configurations/bukkit.yml"), Charsets.UTF_8)));
+ configuration.save(configFile);
+
+ File commandFile = (File) optionset.valueOf("commands-settings");
+ YamlConfiguration commandsConfiguration = YamlConfiguration.loadConfiguration(commandFile);
+ commandsConfiguration.options().copyDefaults(true);
+ commandsConfiguration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(Main.class.getClassLoader().getResourceAsStream("configurations/commands.yml"), Charsets.UTF_8)));
+ commandsConfiguration.save(commandFile);
+ // CraftBukkit end
Main.LOGGER.info("Initialized '{}' and '{}'", path1.toAbsolutePath(), path2.toAbsolutePath());
return;
}
- if (!eula.hasAgreedToEULA()) {
+ // Spigot Start
+ boolean eulaAgreed = Boolean.getBoolean( "com.mojang.eula.agree" );
+ if ( eulaAgreed )
+ {
+ System.err.println( "You have used the Spigot command line EULA agreement flag." );
+ System.err.println( "By using this setting you are indicating your agreement to Mojang's EULA (https://account.mojang.com/documents/minecraft_eula)." );
+ System.err.println( "If you do not agree to the above EULA please stop your server and remove this flag immediately." );
+ }
+ // Spigot End
+ if (!eula.hasAgreedToEULA() && !eulaAgreed) { // Spigot
Main.LOGGER.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
return;
}
- File file = new File((String) optionset.valueOf(optionspec9));
- Services services = Services.create(new YggdrasilAuthenticationService(Proxy.NO_PROXY), file);
- String s = (String) Optional.ofNullable((String) optionset.valueOf(optionspec10)).orElse(dedicatedserversettings.getProperties().levelName);
+ // Paper start - Detect headless JRE
+ String awtException = io.papermc.paper.util.ServerEnvironment.awtDependencyCheck();
+ if (awtException != null) {
+ Main.LOGGER.error("You are using a headless JRE distribution.");
+ Main.LOGGER.error("This distribution is missing certain graphic libraries that the Minecraft server needs to function.");
+ Main.LOGGER.error("For instructions on how to install the non-headless JRE, see https://docs.papermc.io/misc/java-install");
+ Main.LOGGER.error("");
+ Main.LOGGER.error(awtException);
+ return;
+ }
+ // Paper end - Detect headless JRE
+
+ org.spigotmc.SpigotConfig.disabledAdvancements = spigotConfiguration.getStringList("advancements.disabled"); // Paper - fix SPIGOT-5885, must be set early in init
+ // Paper start - fix SPIGOT-5824
+ File file;
+ File userCacheFile = new File(Services.USERID_CACHE_FILE);
+ if (optionset.has("universe")) {
+ file = (File) optionset.valueOf("universe"); // CraftBukkit
+ userCacheFile = new File(file, Services.USERID_CACHE_FILE);
+ } else {
+ file = new File(bukkitConfiguration.getString("settings.world-container", "."));
+ }
+ // Paper end - fix SPIGOT-5824
+ Services services = Services.create(new com.destroystokyo.paper.profile.PaperAuthenticationService(Proxy.NO_PROXY), file, userCacheFile, optionset); // Paper - pass OptionSet to load paper config files; override authentication service; fix world-container
+ // CraftBukkit start
+ String s = (String) Optional.ofNullable((String) optionset.valueOf("world")).orElse(dedicatedserversettings.getProperties().levelName);
LevelStorageSource convertable = LevelStorageSource.createDefault(file.toPath());
- LevelStorageSource.LevelStorageAccess convertable_conversionsession = convertable.validateAndCreateAccess(s);
+ LevelStorageSource.LevelStorageAccess convertable_conversionsession = convertable.validateAndCreateAccess(s, LevelStem.OVERWORLD);
+ // CraftBukkit end
Dynamic dynamic;
if (convertable_conversionsession.hasWorldData()) {
@@ -174,13 +238,31 @@
}
Dynamic<?> dynamic1 = dynamic;
- boolean flag = optionset.has(optionspec7);
+ boolean flag = optionset.has("safeMode"); // CraftBukkit
if (flag) {
Main.LOGGER.warn("Safe mode active, only vanilla datapack will be loaded");
}
PackRepository resourcepackrepository = ServerPacksSource.createPackRepository(convertable_conversionsession);
+ // CraftBukkit start
+ File bukkitDataPackFolder = new File(convertable_conversionsession.getLevelPath(LevelResource.DATAPACK_DIR).toFile(), "bukkit");
+ if (!bukkitDataPackFolder.exists()) {
+ bukkitDataPackFolder.mkdirs();
+ }
+ File mcMeta = new File(bukkitDataPackFolder, "pack.mcmeta");
+ try {
+ com.google.common.io.Files.write("{\n"
+ + " \"pack\": {\n"
+ + " \"description\": \"Data pack for resources provided by Bukkit plugins\",\n"
+ + " \"pack_format\": " + SharedConstants.getCurrentVersion().getPackVersion(PackType.SERVER_DATA) + "\n"
+ + " }\n"
+ + "}\n", mcMeta, com.google.common.base.Charsets.UTF_8);
+ } catch (java.io.IOException ex) {
+ throw new RuntimeException("Could not initialize Bukkit datapack", ex);
+ }
+ AtomicReference<WorldLoader.DataLoadContext> worldLoader = new AtomicReference<>();
+ // CraftBukkit end
WorldStem worldstem;
@@ -189,6 +271,7 @@
worldstem = (WorldStem) Util.blockUntilDone((executor) -> {
return WorldLoader.load(worldloader_c, (worldloader_a) -> {
+ worldLoader.set(worldloader_a); // CraftBukkit
Registry<LevelStem> iregistry = worldloader_a.datapackDimensions().lookupOrThrow(Registries.LEVEL_STEM);
if (dynamic1 != null) {
@@ -201,7 +284,7 @@
WorldOptions worldoptions;
WorldDimensions worlddimensions;
- if (optionset.has(optionspec2)) {
+ if (optionset.has("demo")) { // CraftBukkit
worldsettings = MinecraftServer.DEMO_SETTINGS;
worldoptions = WorldOptions.DEMO_OPTIONS;
worlddimensions = WorldPresets.createNormalWorldDimensions(worldloader_a.datapackWorldgen());
@@ -209,7 +292,7 @@
DedicatedServerProperties dedicatedserverproperties = dedicatedserversettings.getProperties();
worldsettings = new LevelSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(worldloader_a.dataConfiguration().enabledFeatures()), worldloader_a.dataConfiguration());
- worldoptions = optionset.has(optionspec3) ? dedicatedserverproperties.worldOptions.withBonusChest(true) : dedicatedserverproperties.worldOptions;
+ worldoptions = optionset.has("bonusChest") ? dedicatedserverproperties.worldOptions.withBonusChest(true) : dedicatedserverproperties.worldOptions; // CraftBukkit
worlddimensions = dedicatedserverproperties.createDimensions(worldloader_a.datapackWorldgen());
}
@@ -225,32 +308,47 @@
return;
}
- RegistryAccess.Frozen iregistrycustom_dimension = worldstem.registries().compositeAccess();
+ /*
+ IRegistryCustom.Dimension iregistrycustom_dimension = worldstem.registries().compositeAccess();
boolean flag1 = optionset.has(optionspec6);
if (optionset.has(optionspec4) || flag1) {
- Main.forceUpgrade(convertable_conversionsession, DataFixers.getDataFixer(), optionset.has(optionspec5), () -> {
+ forceUpgrade(convertable_conversionsession, DataConverterRegistry.getDataFixer(), optionset.has(optionspec5), () -> {
return true;
}, iregistrycustom_dimension, flag1);
}
- WorldData savedata = worldstem.worldData();
+ SaveData savedata = worldstem.worldData();
convertable_conversionsession.saveDataTag(iregistrycustom_dimension, savedata);
+ */
final DedicatedServer dedicatedserver = (DedicatedServer) MinecraftServer.spin((thread) -> {
- DedicatedServer dedicatedserver1 = new DedicatedServer(thread, convertable_conversionsession, resourcepackrepository, worldstem, dedicatedserversettings, DataFixers.getDataFixer(), services, LoggerChunkProgressListener::createFromGameruleRadius);
+ DedicatedServer dedicatedserver1 = new DedicatedServer(optionset, worldLoader.get(), thread, convertable_conversionsession, resourcepackrepository, worldstem, dedicatedserversettings, DataFixers.getDataFixer(), services, LoggerChunkProgressListener::createFromGameruleRadius);
+ /*
dedicatedserver1.setPort((Integer) optionset.valueOf(optionspec11));
- dedicatedserver1.setDemo(optionset.has(optionspec2));
+ */
+ dedicatedserver1.setDemo(optionset.has("demo")); // Paper
+ /*
dedicatedserver1.setId((String) optionset.valueOf(optionspec12));
- boolean flag2 = !optionset.has(optionspec) && !optionset.valuesOf(optionspec15).contains("nogui");
+ */
+ boolean flag2 = !optionset.has("nogui") && !optionset.nonOptionArguments().contains("nogui");
+ if(!Boolean.parseBoolean(System.getenv().getOrDefault("PAPER_DISABLE_SERVER_GUI", String.valueOf(false)))) // Paper - Add environment variable to disable server gui
if (flag2 && !GraphicsEnvironment.isHeadless()) {
dedicatedserver1.showGui();
}
+ if (optionset.has("port")) {
+ int port = (Integer) optionset.valueOf("port");
+ if (port > 0) {
+ dedicatedserver1.setPort(port);
+ }
+ }
+
return dedicatedserver1;
});
+ /* CraftBukkit start
Thread thread = new Thread("Server Shutdown Thread") {
public void run() {
dedicatedserver.halt(true);
@@ -259,6 +357,7 @@
thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(Main.LOGGER));
Runtime.getRuntime().addShutdownHook(thread);
+ */ // CraftBukkit end
} catch (Exception exception1) {
Main.LOGGER.error(LogUtils.FATAL_MARKER, "Failed to start the minecraft server", exception1);
}
@@ -295,7 +394,7 @@
}
public static void forceUpgrade(LevelStorageSource.LevelStorageAccess session, DataFixer dataFixer, boolean eraseCache, BooleanSupplier continueCheck, RegistryAccess dynamicRegistryManager, boolean recreateRegionFiles) {
- Main.LOGGER.info("Forcing world upgrade!");
+ Main.LOGGER.info("Forcing world upgrade! {}", session.getLevelId()); // CraftBukkit
WorldUpgrader worldupgrader = new WorldUpgrader(session, dataFixer, dynamicRegistryManager, eraseCache, recreateRegionFiles);
try {

View file

@ -1,32 +0,0 @@
--- a/net/minecraft/server/ReloadableServerRegistries.java
+++ b/net/minecraft/server/ReloadableServerRegistries.java
@@ -50,8 +50,9 @@
);
HolderLookup.Provider provider = HolderLookup.Provider.create(list.stream());
RegistryOps<JsonElement> registryOps = provider.createSerializationContext(JsonOps.INSTANCE);
+ final io.papermc.paper.registry.data.util.Conversions conversions = new io.papermc.paper.registry.data.util.Conversions(registryOps.lookupProvider); // Paper
List<CompletableFuture<WritableRegistry<?>>> list2 = LootDataType.values()
- .map(type -> scheduleRegistryLoad((LootDataType<?>)type, registryOps, resourceManager, prepareExecutor))
+ .map(type -> scheduleRegistryLoad((LootDataType<?>)type, registryOps, resourceManager, prepareExecutor, conversions)) // Paper
.toList();
CompletableFuture<List<WritableRegistry<?>>> completableFuture = Util.sequence(list2);
return completableFuture.thenApplyAsync(
@@ -60,14 +61,15 @@
}
private static <T> CompletableFuture<WritableRegistry<?>> scheduleRegistryLoad(
- LootDataType<T> type, RegistryOps<JsonElement> ops, ResourceManager resourceManager, Executor prepareExecutor
+ LootDataType<T> type, RegistryOps<JsonElement> ops, ResourceManager resourceManager, Executor prepareExecutor, io.papermc.paper.registry.data.util.Conversions conversions // Paper
) {
return CompletableFuture.supplyAsync(() -> {
WritableRegistry<T> writableRegistry = new MappedRegistry<>(type.registryKey(), Lifecycle.experimental());
+ io.papermc.paper.registry.PaperRegistryAccess.instance().registerReloadableRegistry(type.registryKey(), writableRegistry); // Paper - register reloadable registry
Map<ResourceLocation, T> map = new HashMap<>();
SimpleJsonResourceReloadListener.scanDirectory(resourceManager, type.registryKey(), ops, type.codec(), map);
- map.forEach((id, value) -> writableRegistry.register(ResourceKey.create(type.registryKey(), id), (T)value, DEFAULT_REGISTRATION_INFO));
- TagLoader.loadTagsForRegistry(resourceManager, writableRegistry);
+ map.forEach((id, value) -> io.papermc.paper.registry.PaperRegistryListenerManager.INSTANCE.registerWithListeners(writableRegistry, ResourceKey.create(type.registryKey(), id), value, DEFAULT_REGISTRATION_INFO, conversions)); // Paper - register with listeners
+ TagLoader.loadTagsForRegistry(resourceManager, writableRegistry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.RELOAD); // Paper - tag life cycle - reload
return writableRegistry;
}, prepareExecutor);
}

View file

@ -1,11 +0,0 @@
--- a/net/minecraft/server/ServerFunctionLibrary.java
+++ b/net/minecraft/server/ServerFunctionLibrary.java
@@ -113,7 +113,7 @@
return null;
}).join());
this.functions = builder.build();
- this.tags = this.tagsLoader.build((Map<ResourceLocation, List<TagLoader.EntryWithSource>>)intermediate.getFirst());
+ this.tags = this.tagsLoader.build((Map<ResourceLocation, List<TagLoader.EntryWithSource>>)intermediate.getFirst(), null); // Paper - command function tags are not implemented yet
},
applyExecutor
);