Move CraftBukkit per-file patches

By: Initial <noreply+automated@papermc.io>
This commit is contained in:
CraftBukkit/Spigot
2024-12-11 22:26:36 +01:00
parent a4de181b77
commit a265d64138
583 changed files with 71 additions and 857 deletions

View File

@@ -0,0 +1,269 @@
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -59,6 +59,18 @@
import net.minecraft.world.level.storage.Convertable;
import org.slf4j.Logger;
+// CraftBukkit start
+import net.minecraft.server.WorldLoader;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.io.IoBuilder;
+import org.bukkit.command.CommandSender;
+import org.bukkit.craftbukkit.util.TerminalCompletionHandler;
+import org.bukkit.craftbukkit.util.TerminalConsoleWriterThread;
+import org.bukkit.event.server.ServerCommandEvent;
+import org.bukkit.event.server.RemoteServerCommandEvent;
+// CraftBukkit end
+
public class DedicatedServer extends MinecraftServer implements IMinecraftServer {
static final Logger LOGGER = LogUtils.getLogger();
@@ -67,7 +79,7 @@
private final List<ServerCommand> consoleInput = Collections.synchronizedList(Lists.newArrayList());
@Nullable
private RemoteStatusListener queryThreadGs4;
- private final RemoteControlCommandListener rconConsoleSource;
+ // private final RemoteControlCommandListener rconConsoleSource; // CraftBukkit - remove field
@Nullable
private RemoteControlListener rconThread;
public DedicatedServerSettings settings;
@@ -81,10 +93,12 @@
private DebugSampleSubscriptionTracker debugSampleSubscriptionTracker;
public ServerLinks serverLinks;
- public DedicatedServer(Thread thread, Convertable.ConversionSession convertable_conversionsession, ResourcePackRepository resourcepackrepository, WorldStem worldstem, DedicatedServerSettings dedicatedserversettings, DataFixer datafixer, Services services, WorldLoadListenerFactory worldloadlistenerfactory) {
- super(thread, convertable_conversionsession, resourcepackrepository, worldstem, Proxy.NO_PROXY, datafixer, services, worldloadlistenerfactory);
+ // CraftBukkit start - Signature changed
+ public DedicatedServer(joptsimple.OptionSet options, WorldLoader.a worldLoader, Thread thread, Convertable.ConversionSession convertable_conversionsession, ResourcePackRepository resourcepackrepository, WorldStem worldstem, DedicatedServerSettings dedicatedserversettings, DataFixer datafixer, Services services, WorldLoadListenerFactory worldloadlistenerfactory) {
+ super(options, worldLoader, thread, convertable_conversionsession, resourcepackrepository, worldstem, Proxy.NO_PROXY, datafixer, services, worldloadlistenerfactory);
+ // CraftBukkit end
this.settings = dedicatedserversettings;
- this.rconConsoleSource = new RemoteControlCommandListener(this);
+ // this.rconConsoleSource = new RemoteControlCommandListener(this); // CraftBukkit - remove field
this.serverTextFilter = ServerTextFilter.createFromConfig(dedicatedserversettings.getProperties());
this.serverLinks = createServerLinks(dedicatedserversettings);
}
@@ -93,13 +107,44 @@
public boolean initServer() throws IOException {
Thread thread = new Thread("Server console handler") {
public void run() {
- BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
+ // CraftBukkit start
+ if (!org.bukkit.craftbukkit.Main.useConsole) {
+ return;
+ }
+ jline.console.ConsoleReader bufferedreader = reader;
+
+ // MC-33041, SPIGOT-5538: if System.in is not valid due to javaw, then return
+ try {
+ System.in.available();
+ } catch (IOException ex) {
+ return;
+ }
+ // CraftBukkit end
String s;
try {
- while (!DedicatedServer.this.isStopped() && DedicatedServer.this.isRunning() && (s = bufferedreader.readLine()) != null) {
- DedicatedServer.this.handleConsoleInput(s, DedicatedServer.this.createCommandSourceStack());
+ // CraftBukkit start - JLine disabling compatibility
+ while (!DedicatedServer.this.isStopped() && DedicatedServer.this.isRunning()) {
+ if (org.bukkit.craftbukkit.Main.useJline) {
+ s = bufferedreader.readLine(">", null);
+ } else {
+ s = bufferedreader.readLine();
+ }
+
+ // SPIGOT-5220: Throttle if EOF (ctrl^d) or stdin is /dev/null
+ if (s == null) {
+ try {
+ Thread.sleep(50L);
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ }
+ continue;
+ }
+ if (s.trim().length() > 0) { // Trim to filter lines which are just spaces
+ DedicatedServer.this.handleConsoleInput(s, DedicatedServer.this.createCommandSourceStack());
+ }
+ // CraftBukkit end
}
} catch (IOException ioexception) {
DedicatedServer.LOGGER.error("Exception handling console input", ioexception);
@@ -108,6 +153,29 @@
}
};
+ // CraftBukkit start - TODO: handle command-line logging arguments
+ java.util.logging.Logger global = java.util.logging.Logger.getLogger("");
+ global.setUseParentHandlers(false);
+ for (java.util.logging.Handler handler : global.getHandlers()) {
+ global.removeHandler(handler);
+ }
+ global.addHandler(new org.bukkit.craftbukkit.util.ForwardLogHandler());
+
+ final org.apache.logging.log4j.core.Logger logger = ((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger());
+ for (org.apache.logging.log4j.core.Appender appender : logger.getAppenders().values()) {
+ if (appender instanceof org.apache.logging.log4j.core.appender.ConsoleAppender) {
+ logger.removeAppender(appender);
+ }
+ }
+
+ TerminalConsoleWriterThread writerThread = new TerminalConsoleWriterThread(System.out, this.reader);
+ this.reader.setCompletionHandler(new TerminalCompletionHandler(writerThread, this.reader.getCompletionHandler()));
+ writerThread.start();
+
+ System.setOut(IoBuilder.forLogger(logger).setLevel(Level.INFO).buildPrintStream());
+ System.setErr(IoBuilder.forLogger(logger).setLevel(Level.WARN).buildPrintStream());
+ // CraftBukkit end
+
thread.setDaemon(true);
thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(DedicatedServer.LOGGER));
thread.start();
@@ -132,7 +200,7 @@
this.setMotd(dedicatedserverproperties.motd);
super.setPlayerIdleTimeout((Integer) dedicatedserverproperties.playerIdleTimeout.get());
this.setEnforceWhitelist(dedicatedserverproperties.enforceWhitelist);
- this.worldData.setGameType(dedicatedserverproperties.gamemode);
+ // this.worldData.setGameType(dedicatedserverproperties.gamemode); // CraftBukkit - moved to world loading
DedicatedServer.LOGGER.info("Default game type: {}", dedicatedserverproperties.gamemode);
InetAddress inetaddress = null;
@@ -156,6 +224,12 @@
return false;
}
+ // CraftBukkit start
+ this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage));
+ server.loadPlugins();
+ server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.STARTUP);
+ // CraftBukkit end
+
if (!this.usesAuthentication()) {
DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware.");
@@ -170,7 +244,7 @@
if (!NameReferencingFileConverter.serverReadyAfterUserconversion(this)) {
return false;
} else {
- this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage));
+ // this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage)); // CraftBukkit - moved up
this.debugSampleSubscriptionTracker = new DebugSampleSubscriptionTracker(this.getPlayerList());
this.tickTimeLogger = new RemoteSampleLogger(TpsDebugDimensions.values().length, this.debugSampleSubscriptionTracker, RemoteDebugSampleType.TICK_TIME);
long i = SystemUtils.getNanos();
@@ -178,13 +252,13 @@
TileEntitySkull.setup(this.services, this);
UserCache.setUsesAuthentication(this.usesAuthentication());
DedicatedServer.LOGGER.info("Preparing level \"{}\"", this.getLevelIdName());
- this.loadLevel();
+ this.loadLevel(storageSource.getLevelId()); // CraftBukkit
long j = SystemUtils.getNanos() - i;
String s = String.format(Locale.ROOT, "%.3fs", (double) j / 1.0E9D);
DedicatedServer.LOGGER.info("Done ({})! For help, type \"help\"", s);
if (dedicatedserverproperties.announcePlayerAchievements != null) {
- ((GameRules.GameRuleBoolean) this.getGameRules().getRule(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)).set(dedicatedserverproperties.announcePlayerAchievements, this);
+ ((GameRules.GameRuleBoolean) this.getGameRules().getRule(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)).set(dedicatedserverproperties.announcePlayerAchievements, this.overworld()); // CraftBukkit - per-world
}
if (dedicatedserverproperties.enableQuery) {
@@ -293,6 +367,7 @@
this.queryThreadGs4.stop();
}
+ System.exit(0); // CraftBukkit
}
@Override
@@ -314,7 +389,15 @@
while (!this.consoleInput.isEmpty()) {
ServerCommand servercommand = (ServerCommand) this.consoleInput.remove(0);
- this.getCommands().performPrefixedCommand(servercommand.source, servercommand.msg);
+ // CraftBukkit start - ServerCommand for preprocessing
+ ServerCommandEvent event = new ServerCommandEvent(console, servercommand.msg);
+ server.getPluginManager().callEvent(event);
+ if (event.isCancelled()) continue;
+ servercommand = new ServerCommand(event.getCommand(), servercommand.source);
+
+ // this.getCommands().performPrefixedCommand(servercommand.source, servercommand.msg); // Called in dispatchServerCommand
+ server.dispatchServerCommand(console, servercommand);
+ // CraftBukkit end
}
}
@@ -541,16 +624,52 @@
@Override
public String getPluginNames() {
- return "";
+ // CraftBukkit start - Whole method
+ StringBuilder result = new StringBuilder();
+ org.bukkit.plugin.Plugin[] plugins = server.getPluginManager().getPlugins();
+
+ result.append(server.getName());
+ result.append(" on Bukkit ");
+ result.append(server.getBukkitVersion());
+
+ if (plugins.length > 0 && server.getQueryPlugins()) {
+ result.append(": ");
+
+ for (int i = 0; i < plugins.length; i++) {
+ if (i > 0) {
+ result.append("; ");
+ }
+
+ result.append(plugins[i].getDescription().getName());
+ result.append(" ");
+ result.append(plugins[i].getDescription().getVersion().replaceAll(";", ","));
+ }
+ }
+
+ return result.toString();
+ // CraftBukkit end
}
@Override
public String runCommand(String s) {
- this.rconConsoleSource.prepareForCommand();
+ // CraftBukkit start - fire RemoteServerCommandEvent
+ throw new UnsupportedOperationException("Not supported - remote source required.");
+ }
+
+ public String runCommand(RemoteControlCommandListener rconConsoleSource, String s) {
+ rconConsoleSource.prepareForCommand();
this.executeBlocking(() -> {
- this.getCommands().performPrefixedCommand(this.rconConsoleSource.createCommandSourceStack(), s);
+ CommandListenerWrapper wrapper = rconConsoleSource.createCommandSourceStack();
+ RemoteServerCommandEvent event = new RemoteServerCommandEvent(rconConsoleSource.getBukkitSender(wrapper), s);
+ server.getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+ ServerCommand serverCommand = new ServerCommand(event.getCommand(), wrapper);
+ server.dispatchServerCommand(event.getSender(), serverCommand);
});
- return this.rconConsoleSource.getCommandResponse();
+ return rconConsoleSource.getCommandResponse();
+ // CraftBukkit end
}
public void storeUsingWhiteList(boolean flag) {
@@ -660,4 +779,15 @@
}
}
}
+
+ // CraftBukkit start
+ public boolean isDebugging() {
+ return this.getProperties().debug;
+ }
+
+ @Override
+ public CommandSender getBukkitSender(CommandListenerWrapper wrapper) {
+ return console;
+ }
+ // CraftBukkit end
}

View File

@@ -0,0 +1,80 @@
--- a/net/minecraft/server/dedicated/DedicatedServerProperties.java
+++ b/net/minecraft/server/dedicated/DedicatedServerProperties.java
@@ -43,11 +43,16 @@
import net.minecraft.world.level.levelgen.presets.WorldPresets;
import org.slf4j.Logger;
+// CraftBukkit start
+import joptsimple.OptionSet;
+// CraftBukkit end
+
public class DedicatedServerProperties extends PropertyManager<DedicatedServerProperties> {
static final Logger LOGGER = LogUtils.getLogger();
private static final Pattern SHA1 = Pattern.compile("^[a-fA-F0-9]{40}$");
private static final Splitter COMMA_SPLITTER = Splitter.on(',').trimResults();
+ public final boolean debug = this.get("debug", false); // CraftBukkit
public final boolean onlineMode = this.get("online-mode", true);
public final boolean preventProxyConnections = this.get("prevent-proxy-connections", false);
public final String serverIp = this.get("server-ip", "");
@@ -100,13 +105,15 @@
public final PropertyManager<DedicatedServerProperties>.EditableProperty<Boolean> whiteList;
public final boolean enforceSecureProfile;
public final boolean logIPs;
- public final int pauseWhenEmptySeconds;
+ public int pauseWhenEmptySeconds;
private final DedicatedServerProperties.WorldDimensionData worldDimensionData;
public final WorldOptions worldOptions;
public boolean acceptsTransfers;
- public DedicatedServerProperties(Properties properties) {
- super(properties);
+ // CraftBukkit start
+ public DedicatedServerProperties(Properties properties, OptionSet optionset) {
+ super(properties, optionset);
+ // CraftBukkit end
this.difficulty = (EnumDifficulty) this.get("difficulty", dispatchNumberOrString(EnumDifficulty::byId, EnumDifficulty::byName), EnumDifficulty::getKey, EnumDifficulty.EASY);
this.gamemode = (EnumGamemode) this.get("gamemode", dispatchNumberOrString(EnumGamemode::byId, EnumGamemode::byName), EnumGamemode::getName, EnumGamemode.SURVIVAL);
this.levelName = this.get("level-name", "world");
@@ -167,13 +174,15 @@
this.initialDataPackConfiguration = getDatapackConfig(this.get("initial-enabled-packs", String.join(",", WorldDataConfiguration.DEFAULT.dataPacks().getEnabled())), this.get("initial-disabled-packs", String.join(",", WorldDataConfiguration.DEFAULT.dataPacks().getDisabled())));
}
- public static DedicatedServerProperties fromFile(Path path) {
- return new DedicatedServerProperties(loadFromFile(path));
+ // CraftBukkit start
+ public static DedicatedServerProperties fromFile(Path path, OptionSet optionset) {
+ return new DedicatedServerProperties(loadFromFile(path), optionset);
}
@Override
- protected DedicatedServerProperties reload(IRegistryCustom iregistrycustom, Properties properties) {
- return new DedicatedServerProperties(properties);
+ protected DedicatedServerProperties reload(IRegistryCustom iregistrycustom, Properties properties, OptionSet optionset) {
+ return new DedicatedServerProperties(properties, optionset);
+ // CraftBukkit end
}
@Nullable
@@ -254,10 +263,10 @@
}).orElseThrow(() -> {
return new IllegalStateException("Invalid datapack contents: can't find default preset");
});
- Optional optional = Optional.ofNullable(MinecraftKey.tryParse(this.levelType)).map((minecraftkey) -> {
+ Optional<ResourceKey<WorldPreset>> optional = Optional.ofNullable(MinecraftKey.tryParse(this.levelType)).map((minecraftkey) -> { // CraftBukkit - decompile error
return ResourceKey.create(Registries.WORLD_PRESET, minecraftkey);
}).or(() -> {
- return Optional.ofNullable((ResourceKey) DedicatedServerProperties.WorldDimensionData.LEGACY_PRESET_NAMES.get(this.levelType));
+ return Optional.ofNullable(DedicatedServerProperties.WorldDimensionData.LEGACY_PRESET_NAMES.get(this.levelType)); // CraftBukkit - decompile error
});
Objects.requireNonNull(holderlookup);
@@ -269,7 +278,7 @@
if (holder.is(WorldPresets.FLAT)) {
RegistryOps<JsonElement> registryops = holderlookup_a.createSerializationContext(JsonOps.INSTANCE);
- DataResult dataresult = GeneratorSettingsFlat.CODEC.parse(new Dynamic(registryops, this.generatorSettings()));
+ DataResult<GeneratorSettingsFlat> dataresult = GeneratorSettingsFlat.CODEC.parse(new Dynamic(registryops, this.generatorSettings())); // CraftBukkit - decompile error
Logger logger = DedicatedServerProperties.LOGGER;
Objects.requireNonNull(logger);

View File

@@ -0,0 +1,27 @@
--- a/net/minecraft/server/dedicated/DedicatedServerSettings.java
+++ b/net/minecraft/server/dedicated/DedicatedServerSettings.java
@@ -3,14 +3,21 @@
import java.nio.file.Path;
import java.util.function.UnaryOperator;
+// CraftBukkit start
+import java.io.File;
+import joptsimple.OptionSet;
+// CraftBukkit end
+
public class DedicatedServerSettings {
private final Path source;
private DedicatedServerProperties properties;
- public DedicatedServerSettings(Path path) {
- this.source = path;
- this.properties = DedicatedServerProperties.fromFile(path);
+ // CraftBukkit start
+ public DedicatedServerSettings(OptionSet optionset) {
+ this.source = ((File) optionset.valueOf("config")).toPath();
+ this.properties = DedicatedServerProperties.fromFile(source, optionset);
+ // CraftBukkit end
}
public DedicatedServerProperties getProperties() {

View File

@@ -0,0 +1,124 @@
--- a/net/minecraft/server/dedicated/PropertyManager.java
+++ b/net/minecraft/server/dedicated/PropertyManager.java
@@ -23,17 +23,37 @@
import net.minecraft.core.IRegistryCustom;
import org.slf4j.Logger;
+import joptsimple.OptionSet; // CraftBukkit
+
public abstract class PropertyManager<T extends PropertyManager<T>> {
private static final Logger LOGGER = LogUtils.getLogger();
public final Properties properties;
+ // CraftBukkit start
+ private OptionSet options = null;
- public PropertyManager(Properties properties) {
+ public PropertyManager(Properties properties, final OptionSet options) {
this.properties = properties;
+
+ this.options = options;
+ }
+
+ private String getOverride(String name, String value) {
+ if ((this.options != null) && (this.options.has(name))) {
+ return String.valueOf(this.options.valueOf(name));
+ }
+
+ return value;
+ // CraftBukkit end
}
public static Properties loadFromFile(Path path) {
try {
+ // CraftBukkit start - SPIGOT-7465, MC-264979: Don't load if file doesn't exist
+ if (!path.toFile().exists()) {
+ return new Properties();
+ }
+ // CraftBukkit end
Properties properties;
Properties properties1;
@@ -97,6 +117,11 @@
public void store(Path path) {
try {
+ // CraftBukkit start - Don't attempt writing to file if it's read only
+ if (path.toFile().exists() && !path.toFile().canWrite()) {
+ return;
+ }
+ // CraftBukkit end
BufferedWriter bufferedwriter = Files.newBufferedWriter(path, StandardCharsets.UTF_8);
try {
@@ -125,7 +150,7 @@
private static <V extends Number> Function<String, V> wrapNumberDeserializer(Function<String, V> function) {
return (s) -> {
try {
- return (Number) function.apply(s);
+ return (V) function.apply(s); // CraftBukkit - decompile error
} catch (NumberFormatException numberformatexception) {
return null;
}
@@ -144,7 +169,7 @@
@Nullable
private String getStringRaw(String s) {
- return (String) this.properties.get(s);
+ return (String) getOverride(s, this.properties.getProperty(s)); // CraftBukkit
}
@Nullable
@@ -160,6 +185,16 @@
}
protected <V> V get(String s, Function<String, V> function, Function<V, String> function1, V v0) {
+ // CraftBukkit start
+ try {
+ return get0(s, function, function1, v0);
+ } catch (Exception ex) {
+ throw new RuntimeException("Could not load invalidly configured property '" + s + "'", ex);
+ }
+ }
+
+ private <V> V get0(String s, Function<String, V> function, Function<V, String> function1, V v0) {
+ // CraftBukkit end
String s1 = this.getStringRaw(s);
V v1 = MoreObjects.firstNonNull(s1 != null ? function.apply(s1) : null, v0);
@@ -172,7 +207,7 @@
V v1 = MoreObjects.firstNonNull(s1 != null ? function.apply(s1) : null, v0);
this.properties.put(s, function1.apply(v1));
- return new PropertyManager.EditableProperty<>(s, v1, function1);
+ return new PropertyManager.EditableProperty(s, v1, function1); // CraftBukkit - decompile error
}
protected <V> V get(String s, Function<String, V> function, UnaryOperator<V> unaryoperator, Function<V, String> function1, V v0) {
@@ -236,7 +271,7 @@
return properties;
}
- protected abstract T reload(IRegistryCustom iregistrycustom, Properties properties);
+ protected abstract T reload(IRegistryCustom iregistrycustom, Properties properties, OptionSet optionset); // CraftBukkit
public class EditableProperty<V> implements Supplier<V> {
@@ -244,7 +279,7 @@
private final V value;
private final Function<V, String> serializer;
- EditableProperty(final String s, final Object object, final Function function) {
+ EditableProperty(final String s, final V object, final Function function) { // CraftBukkit - decompile error
this.key = s;
this.value = object;
this.serializer = function;
@@ -258,7 +293,7 @@
Properties properties = PropertyManager.this.cloneProperties();
properties.put(this.key, this.serializer.apply(v0));
- return PropertyManager.this.reload(iregistrycustom, properties);
+ return PropertyManager.this.reload(iregistrycustom, properties, PropertyManager.this.options); // CraftBukkit
}
}
}