mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
Purpur config files
This commit is contained in:
committed by
granny
parent
e35e614ec8
commit
0813a32106
@@ -0,0 +1,33 @@
|
||||
--- a/net/minecraft/commands/CommandSourceStack.java
|
||||
+++ b/net/minecraft/commands/CommandSourceStack.java
|
||||
@@ -517,6 +_,30 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ // Purpur start - Purpur config files
|
||||
+ public void sendSuccess(@Nullable String message) {
|
||||
+ sendSuccess(message, false);
|
||||
+ }
|
||||
+
|
||||
+ public void sendSuccess(@Nullable String message, boolean broadcastToOps) {
|
||||
+ if (message == null) {
|
||||
+ return;
|
||||
+ }
|
||||
+ sendSuccess(net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(message), broadcastToOps);
|
||||
+ }
|
||||
+
|
||||
+ public void sendSuccess(@Nullable net.kyori.adventure.text.Component message) {
|
||||
+ sendSuccess(message, false);
|
||||
+ }
|
||||
+
|
||||
+ public void sendSuccess(@Nullable net.kyori.adventure.text.Component message, boolean broadcastToOps) {
|
||||
+ if (message == null) {
|
||||
+ return;
|
||||
+ }
|
||||
+ sendSuccess(() -> io.papermc.paper.adventure.PaperAdventure.asVanilla(message), broadcastToOps);
|
||||
+ }
|
||||
+ // Purpur end - Purpur config files
|
||||
+
|
||||
public void sendSuccess(Supplier<Component> messageSupplier, boolean allowLogging) {
|
||||
boolean flag = this.source.acceptsSuccess() && !this.silent;
|
||||
boolean flag1 = allowLogging && this.source.shouldInformAdmins() && !this.silent;
|
||||
@@ -0,0 +1,18 @@
|
||||
--- a/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
@@ -224,6 +_,15 @@
|
||||
io.papermc.paper.command.PaperCommands.registerCommands(this); // Paper - setup /paper command
|
||||
this.server.spark.registerCommandBeforePlugins(this.server); // Paper - spark
|
||||
com.destroystokyo.paper.Metrics.PaperMetrics.startMetrics(); // Paper - start metrics
|
||||
+ // Purpur start - Purpur config files
|
||||
+ try {
|
||||
+ org.purpurmc.purpur.PurpurConfig.init((java.io.File) options.valueOf("purpur-settings"));
|
||||
+ } catch (Exception e) {
|
||||
+ DedicatedServer.LOGGER.error("Unable to load server configuration", e);
|
||||
+ return false;
|
||||
+ }
|
||||
+ org.purpurmc.purpur.PurpurConfig.registerCommands();
|
||||
+ // Purpur end - Purpur config files
|
||||
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now
|
||||
|
||||
this.setPvpAllowed(properties.pvp);
|
||||
@@ -0,0 +1,18 @@
|
||||
--- a/net/minecraft/world/level/Level.java
|
||||
+++ b/net/minecraft/world/level/Level.java
|
||||
@@ -170,6 +_,7 @@
|
||||
// Paper end - add paper world config
|
||||
|
||||
public final io.papermc.paper.antixray.ChunkPacketBlockController chunkPacketBlockController; // Paper - Anti-Xray
|
||||
+ public final org.purpurmc.purpur.PurpurWorldConfig purpurConfig; // Purpur - Purpur config files
|
||||
public static BlockPos lastPhysicsProblem; // Spigot
|
||||
private org.spigotmc.TickLimiter entityLimiter;
|
||||
private org.spigotmc.TickLimiter tileLimiter;
|
||||
@@ -853,6 +_,7 @@
|
||||
// Paper end - getblock optimisations - cache world height/sections
|
||||
this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) levelData).getLevelName()); // Spigot
|
||||
this.paperConfig = paperWorldConfigCreator.apply(this.spigotConfig); // Paper - create paper world config
|
||||
+ this.purpurConfig = new org.purpurmc.purpur.PurpurWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) levelData).getLevelName(), env); // Purpur - Purpur config files
|
||||
this.generator = gen;
|
||||
this.world = new CraftWorld((ServerLevel) this, gen, biomeProvider, env);
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
--- a/src/main/java/com/destroystokyo/paper/Metrics.java
|
||||
+++ b/src/main/java/com/destroystokyo/paper/Metrics.java
|
||||
@@ -592,7 +_,7 @@
|
||||
boolean logFailedRequests = config.getBoolean("logFailedRequests", false);
|
||||
// Only start Metrics, if it's enabled in the config
|
||||
if (config.getBoolean("enabled", true)) {
|
||||
- Metrics metrics = new Metrics("Paper", serverUUID, logFailedRequests, Bukkit.getLogger());
|
||||
+ Metrics metrics = new Metrics("Purpur", serverUUID, logFailedRequests, Bukkit.getLogger()); // Pufferfish // Purpur - Purpur config files
|
||||
|
||||
metrics.addCustomChart(new Metrics.SimplePie("minecraft_version", () -> {
|
||||
String minecraftVersion = Bukkit.getVersion();
|
||||
@@ -601,16 +_,8 @@
|
||||
}));
|
||||
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("players", () -> Bukkit.getOnlinePlayers().size()));
|
||||
- metrics.addCustomChart(new Metrics.SimplePie("online_mode", () -> Bukkit.getOnlineMode() ? "online" : "offline"));
|
||||
- final String paperVersion;
|
||||
- final String implVersion = org.bukkit.craftbukkit.Main.class.getPackage().getImplementationVersion();
|
||||
- if (implVersion != null) {
|
||||
- final String buildOrHash = implVersion.substring(implVersion.lastIndexOf('-') + 1);
|
||||
- paperVersion = "git-Paper-%s-%s".formatted(Bukkit.getServer().getMinecraftVersion(), buildOrHash);
|
||||
- } else {
|
||||
- paperVersion = "unknown";
|
||||
- }
|
||||
- metrics.addCustomChart(new Metrics.SimplePie("paper_version", () -> paperVersion));
|
||||
+ metrics.addCustomChart(new Metrics.SimplePie("online_mode", () -> Bukkit.getOnlineMode() ? "online" : (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode() ? "bungee" : "offline"))); // Purpur - Purpur config files
|
||||
+ metrics.addCustomChart(new Metrics.SimplePie("purpur_version", () -> (org.bukkit.craftbukkit.Main.class.getPackage().getImplementationVersion() != null) ? org.bukkit.craftbukkit.Main.class.getPackage().getImplementationVersion() : "unknown")); // Purpur - Purpur config files
|
||||
|
||||
metrics.addCustomChart(new Metrics.DrilldownPie("java_version", () -> {
|
||||
Map<String, Map<String, Integer>> map = new HashMap<>();
|
||||
@@ -0,0 +1,45 @@
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -1086,6 +_,7 @@
|
||||
|
||||
org.spigotmc.SpigotConfig.init((File) this.console.options.valueOf("spigot-settings")); // Spigot
|
||||
this.console.paperConfigurations.reloadConfigs(this.console);
|
||||
+ org.purpurmc.purpur.PurpurConfig.init((File) console.options.valueOf("purpur-settings")); // Purpur - Purpur config files
|
||||
for (ServerLevel world : this.console.getAllLevels()) {
|
||||
// world.serverLevelData.setDifficulty(config.difficulty); // Paper - per level difficulty
|
||||
world.setSpawnSettings(world.serverLevelData.getDifficulty() != Difficulty.PEACEFUL && config.spawnMonsters); // Paper - per level difficulty (from MinecraftServer#setDifficulty(ServerLevel, Difficulty, boolean))
|
||||
@@ -1101,6 +_,7 @@
|
||||
}
|
||||
}
|
||||
world.spigotConfig.init(); // Spigot
|
||||
+ world.purpurConfig.init(); // Purpur - Purpur config files
|
||||
}
|
||||
|
||||
Plugin[] pluginClone = pluginManager.getPlugins().clone(); // Paper
|
||||
@@ -1118,6 +_,7 @@
|
||||
org.spigotmc.SpigotConfig.registerCommands(); // Spigot
|
||||
io.papermc.paper.command.PaperCommands.registerCommands(this.console); // Paper
|
||||
this.spark.registerCommandBeforePlugins(this); // Paper - spark
|
||||
+ org.purpurmc.purpur.PurpurConfig.registerCommands(); // Purpur - Purpur config files
|
||||
this.overrideAllCommandBlockCommands = this.commandsConfiguration.getStringList("command-block-overrides").contains("*");
|
||||
this.ignoreVanillaPermissions = this.commandsConfiguration.getBoolean("ignore-vanilla-permissions");
|
||||
|
||||
@@ -3048,6 +_,18 @@
|
||||
{
|
||||
return CraftServer.this.console.paperConfigurations.createLegacyObject(CraftServer.this.console);
|
||||
}
|
||||
+
|
||||
+ // Purpur start - Purpur config files
|
||||
+ @Override
|
||||
+ public YamlConfiguration getPurpurConfig() {
|
||||
+ return org.purpurmc.purpur.PurpurConfig.config;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public java.util.Properties getServerProperties() {
|
||||
+ return getProperties().properties;
|
||||
+ }
|
||||
+ // Purpur end - Purpur config files
|
||||
|
||||
@Override
|
||||
public void restart() {
|
||||
@@ -0,0 +1,16 @@
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
|
||||
@@ -176,6 +_,13 @@
|
||||
.describedAs("Jar file");
|
||||
// Paper end
|
||||
|
||||
+ // Purpur start - Purpur config files
|
||||
+ acceptsAll(asList("purpur", "purpur-settings"), "File for purpur settings")
|
||||
+ .withRequiredArg()
|
||||
+ .ofType(File.class)
|
||||
+ .defaultsTo(new File("purpur.yml"))
|
||||
+ .describedAs("Yml file");
|
||||
+ // Purpur end - Purpur config files
|
||||
// Paper start
|
||||
acceptsAll(asList("server-name"), "Name of the server")
|
||||
.withRequiredArg()
|
||||
@@ -0,0 +1,158 @@
|
||||
package org.purpurmc.purpur;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.purpurmc.purpur.command.PurpurCommand;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class PurpurConfig {
|
||||
private static final String HEADER = "This is the main configuration file for Purpur.\n"
|
||||
+ "As you can see, there's tons to configure. Some options may impact gameplay, so use\n"
|
||||
+ "with caution, and make sure you know what each option does before configuring.\n"
|
||||
+ "\n"
|
||||
+ "If you need help with the configuration or have any questions related to Purpur,\n"
|
||||
+ "join us in our Discord guild.\n"
|
||||
+ "\n"
|
||||
+ "Website: https://purpurmc.org \n"
|
||||
+ "Docs: https://purpurmc.org/docs \n";
|
||||
private static File CONFIG_FILE;
|
||||
public static YamlConfiguration config;
|
||||
|
||||
private static Map<String, Command> commands;
|
||||
|
||||
public static int version;
|
||||
static boolean verbose;
|
||||
|
||||
public static void init(File configFile) {
|
||||
CONFIG_FILE = configFile;
|
||||
config = new YamlConfiguration();
|
||||
try {
|
||||
config.load(CONFIG_FILE);
|
||||
} catch (IOException ignore) {
|
||||
} catch (InvalidConfigurationException ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Could not load purpur.yml, please correct your syntax errors", ex);
|
||||
throw Throwables.propagate(ex);
|
||||
}
|
||||
config.options().header(HEADER);
|
||||
config.options().copyDefaults(true);
|
||||
verbose = getBoolean("verbose", false);
|
||||
|
||||
commands = new HashMap<>();
|
||||
commands.put("purpur", new PurpurCommand("purpur"));
|
||||
|
||||
version = getInt("config-version", 38);
|
||||
set("config-version", 38);
|
||||
|
||||
readConfig(PurpurConfig.class, null);
|
||||
|
||||
Block.BLOCK_STATE_REGISTRY.forEach(BlockBehaviour.BlockStateBase::initCache);
|
||||
}
|
||||
|
||||
protected static void log(String s) {
|
||||
if (verbose) {
|
||||
log(Level.INFO, s);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void log(Level level, String s) {
|
||||
Bukkit.getLogger().log(level, s);
|
||||
}
|
||||
|
||||
public static void registerCommands() {
|
||||
for (Map.Entry<String, Command> entry : commands.entrySet()) {
|
||||
MinecraftServer.getServer().server.getCommandMap().register(entry.getKey(), "Purpur", entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
static void readConfig(Class<?> clazz, Object instance) {
|
||||
for (Method method : clazz.getDeclaredMethods()) {
|
||||
if (Modifier.isPrivate(method.getModifiers())) {
|
||||
if (method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE) {
|
||||
try {
|
||||
method.setAccessible(true);
|
||||
method.invoke(instance);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw Throwables.propagate(ex.getCause());
|
||||
} catch (Exception ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Error invoking " + method, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
config.save(CONFIG_FILE);
|
||||
} catch (IOException ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Could not save " + CONFIG_FILE, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static void set(String path, Object val) {
|
||||
config.addDefault(path, val);
|
||||
config.set(path, val);
|
||||
}
|
||||
|
||||
private static String getString(String path, String def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getString(path, config.getString(path));
|
||||
}
|
||||
|
||||
private static boolean getBoolean(String path, boolean def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getBoolean(path, config.getBoolean(path));
|
||||
}
|
||||
|
||||
private static double getDouble(String path, double def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getDouble(path, config.getDouble(path));
|
||||
}
|
||||
|
||||
private static int getInt(String path, int def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getInt(path, config.getInt(path));
|
||||
}
|
||||
|
||||
private static <T> List<?> getList(String path, T def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getList(path, config.getList(path));
|
||||
}
|
||||
|
||||
static Map<String, Object> getMap(String path, Map<String, Object> def) {
|
||||
if (def != null && config.getConfigurationSection(path) == null) {
|
||||
config.addDefault(path, def);
|
||||
return def;
|
||||
}
|
||||
return toMap(config.getConfigurationSection(path));
|
||||
}
|
||||
|
||||
private static Map<String, Object> toMap(ConfigurationSection section) {
|
||||
ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
|
||||
if (section != null) {
|
||||
for (String key : section.getKeys(false)) {
|
||||
Object obj = section.get(key);
|
||||
if (obj != null) {
|
||||
builder.put(key, obj instanceof ConfigurationSection val ? toMap(val) : obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package org.purpurmc.purpur;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import static org.purpurmc.purpur.PurpurConfig.log;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class PurpurWorldConfig {
|
||||
|
||||
private final String worldName;
|
||||
private final World.Environment environment;
|
||||
|
||||
public PurpurWorldConfig(String worldName, World.Environment environment) {
|
||||
this.worldName = worldName;
|
||||
this.environment = environment;
|
||||
init();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
log("-------- World Settings For [" + worldName + "] --------");
|
||||
PurpurConfig.readConfig(PurpurWorldConfig.class, this);
|
||||
}
|
||||
|
||||
private void set(String path, Object val) {
|
||||
PurpurConfig.config.addDefault("world-settings.default." + path, val);
|
||||
PurpurConfig.config.set("world-settings.default." + path, val);
|
||||
if (PurpurConfig.config.get("world-settings." + worldName + "." + path) != null) {
|
||||
PurpurConfig.config.addDefault("world-settings." + worldName + "." + path, val);
|
||||
PurpurConfig.config.set("world-settings." + worldName + "." + path, val);
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigurationSection getConfigurationSection(String path) {
|
||||
ConfigurationSection section = PurpurConfig.config.getConfigurationSection("world-settings." + worldName + "." + path);
|
||||
return section != null ? section : PurpurConfig.config.getConfigurationSection("world-settings.default." + path);
|
||||
}
|
||||
|
||||
private String getString(String path, String def) {
|
||||
PurpurConfig.config.addDefault("world-settings.default." + path, def);
|
||||
return PurpurConfig.config.getString("world-settings." + worldName + "." + path, PurpurConfig.config.getString("world-settings.default." + path));
|
||||
}
|
||||
|
||||
private boolean getBoolean(String path, boolean def) {
|
||||
PurpurConfig.config.addDefault("world-settings.default." + path, def);
|
||||
return PurpurConfig.config.getBoolean("world-settings." + worldName + "." + path, PurpurConfig.config.getBoolean("world-settings.default." + path));
|
||||
}
|
||||
|
||||
private double getDouble(String path, double def) {
|
||||
PurpurConfig.config.addDefault("world-settings.default." + path, def);
|
||||
return PurpurConfig.config.getDouble("world-settings." + worldName + "." + path, PurpurConfig.config.getDouble("world-settings.default." + path));
|
||||
}
|
||||
|
||||
private int getInt(String path, int def) {
|
||||
PurpurConfig.config.addDefault("world-settings.default." + path, def);
|
||||
return PurpurConfig.config.getInt("world-settings." + worldName + "." + path, PurpurConfig.config.getInt("world-settings.default." + path));
|
||||
}
|
||||
|
||||
private <T> List<?> getList(String path, T def) {
|
||||
PurpurConfig.config.addDefault("world-settings.default." + path, def);
|
||||
return PurpurConfig.config.getList("world-settings." + worldName + "." + path, PurpurConfig.config.getList("world-settings.default." + path));
|
||||
}
|
||||
|
||||
private Map<String, Object> getMap(String path, Map<String, Object> def) {
|
||||
final Map<String, Object> fallback = PurpurConfig.getMap("world-settings.default." + path, def);
|
||||
final Map<String, Object> value = PurpurConfig.getMap("world-settings." + worldName + "." + path, null);
|
||||
return value.isEmpty() ? fallback : value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package org.purpurmc.purpur.command;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import org.purpurmc.purpur.PurpurConfig;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class PurpurCommand extends Command {
|
||||
public PurpurCommand(String name) {
|
||||
super(name);
|
||||
this.description = "Purpur related commands";
|
||||
this.usageMessage = "/purpur [reload | version]";
|
||||
this.setPermission("bukkit.command.purpur");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException {
|
||||
if (args.length == 1) {
|
||||
return Stream.of("reload", "version")
|
||||
.filter(arg -> arg.startsWith(args[0].toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
if (!testPermission(sender)) return true;
|
||||
|
||||
if (args.length != 1) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
Command.broadcastCommandMessage(sender, ChatColor.RED + "Please note that this command is not supported and may cause issues.");
|
||||
Command.broadcastCommandMessage(sender, ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server.");
|
||||
|
||||
MinecraftServer console = MinecraftServer.getServer();
|
||||
PurpurConfig.init((File) console.options.valueOf("purpur-settings"));
|
||||
for (ServerLevel level : console.getAllLevels()) {
|
||||
level.purpurConfig.init();
|
||||
}
|
||||
console.server.reloadCount++;
|
||||
|
||||
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Purpur config reload complete.");
|
||||
} else if (args[0].equalsIgnoreCase("version")) {
|
||||
Command verCmd = org.bukkit.Bukkit.getServer().getCommandMap().getCommand("version");
|
||||
if (verCmd != null) {
|
||||
return verCmd.execute(sender, commandLabel, new String[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user