Repackage patches

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2021-03-16 09:00:00 +11:00
parent 2777f7b780
commit 18496e998f
433 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,243 @@
--- a/net/minecraft/server/DedicatedServer.java
+++ b/net/minecraft/server/DedicatedServer.java
@@ -22,6 +22,14 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.io.IoBuilder;
+import org.bukkit.command.CommandSender;
+import org.bukkit.event.server.ServerCommandEvent;
+import org.bukkit.event.server.RemoteServerCommandEvent;
+// CraftBukkit end
+
public class DedicatedServer extends MinecraftServer implements IMinecraftServer {
private static final Logger LOGGER = LogManager.getLogger();
@@ -36,8 +44,10 @@
@Nullable
private final TextFilter r;
- public DedicatedServer(Thread thread, IRegistryCustom.Dimension iregistrycustom_dimension, Convertable.ConversionSession convertable_conversionsession, ResourcePackRepository resourcepackrepository, DataPackResources datapackresources, SaveData savedata, DedicatedServerSettings dedicatedserversettings, DataFixer datafixer, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache, WorldLoadListenerFactory worldloadlistenerfactory) {
- super(thread, iregistrycustom_dimension, convertable_conversionsession, savedata, resourcepackrepository, Proxy.NO_PROXY, datafixer, datapackresources, minecraftsessionservice, gameprofilerepository, usercache, worldloadlistenerfactory);
+ // CraftBukkit start - Signature changed
+ public DedicatedServer(joptsimple.OptionSet options, DataPackConfiguration datapackconfiguration, Thread thread, IRegistryCustom.Dimension iregistrycustom_dimension, Convertable.ConversionSession convertable_conversionsession, ResourcePackRepository resourcepackrepository, DataPackResources datapackresources, SaveData savedata, DedicatedServerSettings dedicatedserversettings, DataFixer datafixer, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache, WorldLoadListenerFactory worldloadlistenerfactory) {
+ super(options, datapackconfiguration, thread, iregistrycustom_dimension, convertable_conversionsession, savedata, resourcepackrepository, Proxy.NO_PROXY, datafixer, datapackresources, minecraftsessionservice, gameprofilerepository, usercache, worldloadlistenerfactory);
+ // CraftBukkit end
this.propertyManager = dedicatedserversettings;
this.remoteControlCommandListener = new RemoteControlCommandListener(this);
this.r = null;
@@ -47,13 +57,44 @@
public boolean init() 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.issueCommand(s, DedicatedServer.this.getServerCommandListener());
+ // 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.issueCommand(s, DedicatedServer.this.getServerCommandListener());
+ }
+ // CraftBukkit end
}
} catch (IOException ioexception) {
DedicatedServer.LOGGER.error("Exception handling console input", ioexception);
@@ -62,6 +103,27 @@
}
};
+ // 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);
+ }
+ }
+
+ new org.bukkit.craftbukkit.util.TerminalConsoleWriterThread(System.out, this.reader).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();
@@ -88,7 +150,7 @@
this.setForceGamemode(dedicatedserverproperties.forceGamemode);
super.setIdleTimeout((Integer) dedicatedserverproperties.playerIdleTimeout.get());
this.i(dedicatedserverproperties.enforceWhitelist);
- this.saveData.setGameType(dedicatedserverproperties.gamemode);
+ // this.saveData.setGameType(dedicatedserverproperties.gamemode); // CraftBukkit - moved to world loading
DedicatedServer.LOGGER.info("Default game type: {}", dedicatedserverproperties.gamemode);
InetAddress inetaddress = null;
@@ -112,6 +174,12 @@
return false;
}
+ // CraftBukkit start
+ this.a((PlayerList) (new DedicatedPlayerList(this, this.customRegistry, this.worldNBTStorage)));
+ server.loadPlugins();
+ server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.STARTUP);
+ // CraftBukkit end
+
if (!this.getOnlineMode()) {
DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware.");
@@ -126,7 +194,7 @@
if (!NameReferencingFileConverter.e(this)) {
return false;
} else {
- this.a((PlayerList) (new DedicatedPlayerList(this, this.customRegistry, this.worldNBTStorage)));
+ // this.a((PlayerList) (new DedicatedPlayerList(this, this.customRegistry, this.worldNBTStorage))); // CraftBukkit - moved up
long i = SystemUtils.getMonotonicNanos();
this.c(dedicatedserverproperties.maxBuildHeight);
@@ -134,7 +202,7 @@
TileEntitySkull.a(this.getMinecraftSessionService());
UserCache.a(this.getOnlineMode());
DedicatedServer.LOGGER.info("Preparing level \"{}\"", this.getWorld());
- this.loadWorld();
+ this.loadWorld(convertable.getLevelName()); // CraftBukkit
long j = SystemUtils.getMonotonicNanos() - i;
String s = String.format(Locale.ROOT, "%.3fs", (double) j / 1.0E9D);
@@ -151,6 +219,7 @@
if (dedicatedserverproperties.enableRcon) {
DedicatedServer.LOGGER.info("Starting remote control listener");
this.remoteControlListener = RemoteControlListener.a((IMinecraftServer) this);
+ this.remoteConsole = new org.bukkit.craftbukkit.command.CraftRemoteConsoleCommandSender(this.remoteControlCommandListener); // CraftBukkit
}
if (this.getMaxTickTime() > 0L) {
@@ -265,6 +334,7 @@
this.remoteStatusListener.b();
}
+ System.exit(0); // CraftBukkit
}
@Override
@@ -293,7 +363,15 @@
while (!this.serverCommandQueue.isEmpty()) {
ServerCommand servercommand = (ServerCommand) this.serverCommandQueue.remove(0);
- this.getCommandDispatcher().a(servercommand.source, servercommand.command);
+ // CraftBukkit start - ServerCommand for preprocessing
+ ServerCommandEvent event = new ServerCommandEvent(console, servercommand.command);
+ server.getPluginManager().callEvent(event);
+ if (event.isCancelled()) continue;
+ servercommand = new ServerCommand(event.getCommand(), servercommand.source);
+
+ // this.getCommandDispatcher().a(servercommand.source, servercommand.command); // Called in dispatchServerCommand
+ server.dispatchServerCommand(console, servercommand);
+ // CraftBukkit end
}
}
@@ -503,14 +581,45 @@
@Override
public String getPlugins() {
- 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 executeRemoteCommand(String s) {
this.remoteControlCommandListener.clearMessages();
this.executeSync(() -> {
- this.getCommandDispatcher().a(this.remoteControlCommandListener.getWrapper(), s);
+ // CraftBukkit start - fire RemoteServerCommandEvent
+ RemoteServerCommandEvent event = new RemoteServerCommandEvent(remoteConsole, s);
+ server.getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+ ServerCommand serverCommand = new ServerCommand(event.getCommand(), remoteControlCommandListener.getWrapper());
+ server.dispatchServerCommand(remoteConsole, serverCommand);
+ // CraftBukkit end
});
return this.remoteControlCommandListener.getMessages();
}
@@ -552,4 +661,15 @@
public ITextFilter a(EntityPlayer entityplayer) {
return this.r != null ? this.r.a(entityplayer.getProfile()) : null;
}
+
+ // CraftBukkit start
+ public boolean isDebugging() {
+ return this.getDedicatedServerProperties().debug;
+ }
+
+ @Override
+ public CommandSender getBukkitSender(CommandListenerWrapper wrapper) {
+ return console;
+ }
+ // CraftBukkit end
}

View File

@@ -0,0 +1,49 @@
--- a/net/minecraft/server/DedicatedServerProperties.java
+++ b/net/minecraft/server/DedicatedServerProperties.java
@@ -3,8 +3,14 @@
import java.util.Properties;
import java.util.concurrent.TimeUnit;
+// CraftBukkit start
+import joptsimple.OptionSet;
+import net.minecraft.server.PropertyManager.EditableProperty;
+// CraftBukkit end
+
public class DedicatedServerProperties extends PropertyManager<DedicatedServerProperties> {
+ public final boolean debug = this.getBoolean("debug", false); // CraftBukkit
public final boolean onlineMode = this.getBoolean("online-mode", true);
public final boolean preventProxyConnections = this.getBoolean("prevent-proxy-connections", false);
public final String serverIp = this.getString("server-ip", "");
@@ -55,8 +61,10 @@
public final PropertyManager<DedicatedServerProperties>.EditableProperty<Boolean> whiteList;
public final GeneratorSettings generatorSettings;
- public DedicatedServerProperties(Properties properties, IRegistryCustom iregistrycustom) {
- super(properties);
+ // CraftBukkit start
+ public DedicatedServerProperties(Properties properties, IRegistryCustom iregistrycustom, OptionSet optionset) {
+ super(properties, optionset);
+ // CraftBukkit end
this.difficulty = (EnumDifficulty) this.a("difficulty", a(EnumDifficulty::getById, EnumDifficulty::a), EnumDifficulty::c, EnumDifficulty.EASY);
this.gamemode = (EnumGamemode) this.a("gamemode", a(EnumGamemode::getById, EnumGamemode::a), EnumGamemode::b, EnumGamemode.SURVIVAL);
this.levelName = this.getString("level-name", "world");
@@ -107,12 +115,14 @@
this.generatorSettings = GeneratorSettings.a(iregistrycustom, properties);
}
- public static DedicatedServerProperties load(IRegistryCustom iregistrycustom, java.nio.file.Path java_nio_file_path) {
- return new DedicatedServerProperties(loadPropertiesFile(java_nio_file_path), iregistrycustom);
+ // CraftBukkit start
+ public static DedicatedServerProperties load(IRegistryCustom iregistrycustom, java.nio.file.Path java_nio_file_path, OptionSet optionset) {
+ return new DedicatedServerProperties(loadPropertiesFile(java_nio_file_path), iregistrycustom, optionset);
}
@Override
- protected DedicatedServerProperties reload(IRegistryCustom iregistrycustom, Properties properties) {
- return new DedicatedServerProperties(properties, iregistrycustom);
+ protected DedicatedServerProperties reload(IRegistryCustom iregistrycustom, Properties properties, OptionSet optionset) {
+ return new DedicatedServerProperties(properties, iregistrycustom, optionset);
+ // CraftBukkit end
}
}

View File

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

View File

@@ -0,0 +1,118 @@
--- a/net/minecraft/server/PropertyManager.java
+++ b/net/minecraft/server/PropertyManager.java
@@ -15,15 +15,30 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import joptsimple.OptionSet; // CraftBukkit
+
public abstract class PropertyManager<T extends PropertyManager<T>> {
private static final Logger LOGGER = LogManager.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 loadPropertiesFile(java.nio.file.Path java_nio_file_path) {
Properties properties = new Properties();
@@ -59,6 +74,11 @@
public void savePropertiesFile(java.nio.file.Path java_nio_file_path) {
try {
+ // CraftBukkit start - Don't attempt writing to file if it's read only
+ if (java_nio_file_path.toFile().exists() && !java_nio_file_path.toFile().canWrite()) {
+ return;
+ }
+ // CraftBukkit end
OutputStream outputstream = Files.newOutputStream(java_nio_file_path);
Throwable throwable = null;
@@ -90,7 +110,7 @@
private static <V extends Number> Function<String, V> a(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;
}
@@ -109,7 +129,7 @@
@Nullable
private String c(String s) {
- return (String) this.properties.get(s);
+ return (String) getOverride(s, this.properties.getProperty(s)); // CraftBukkit
}
@Nullable
@@ -137,7 +157,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 a(String s, Function<String, V> function, UnaryOperator<V> unaryoperator, Function<V, String> function1, V v0) {
@@ -166,7 +186,7 @@
}
protected int getInt(String s, int i) {
- return (Integer) this.a(s, a(Integer::parseInt), (Object) i);
+ return (Integer) this.a(s, a(Integer::parseInt), i); // CraftBukkit - decompile error
}
protected PropertyManager<T>.EditableProperty<Integer> b(String s, int i) {
@@ -178,7 +198,7 @@
}
protected long getLong(String s, long i) {
- return (Long) this.a(s, a(Long::parseLong), (Object) i);
+ return (Long) this.a(s, a(Long::parseLong), i); // CraftBukkit - decompile error
}
protected boolean getBoolean(String s, boolean flag) {
@@ -201,7 +221,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> {
@@ -209,7 +229,7 @@
private final V c;
private final Function<V, String> d;
- private EditableProperty(String s, Object object, Function function) {
+ private EditableProperty(String s, V object, Function function) { // CraftBukkit - decompile error
this.b = s;
this.c = object;
this.d = function;
@@ -223,7 +243,7 @@
Properties properties = PropertyManager.this.a();
properties.put(this.b, this.d.apply(v0));
- return PropertyManager.this.reload(iregistrycustom, properties);
+ return PropertyManager.this.reload(iregistrycustom, properties, PropertyManager.this.options); // CraftBukkit
}
}
}