Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
259 additions
and
0 deletions.
There are no files selected for viewing
259 changes: 259 additions & 0 deletions
259
patches/server/0002-Pufferfish-Config-and-Command.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,259 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Kevin Raneri <kevin.raneri@gmail.com> | ||
Date: Tue, 9 Nov 2021 13:53:53 -0500 | ||
Subject: [PATCH] Pufferfish Config and Command | ||
|
||
|
||
diff --git a/src/main/java/co/aikar/timings/TimingsExport.java b/src/main/java/co/aikar/timings/TimingsExport.java | ||
index 6e8001c7ff6497c9e5c274a5fe85cc204f3ba4c5..052910be0bdd5e3eda1d062c729b01e5a4021d5c 100644 | ||
--- a/src/main/java/co/aikar/timings/TimingsExport.java | ||
+++ b/src/main/java/co/aikar/timings/TimingsExport.java | ||
@@ -229,7 +229,8 @@ public class TimingsExport extends Thread { | ||
pair("spigot", mapAsJSON(Bukkit.spigot().getSpigotConfig(), null)), | ||
pair("bukkit", mapAsJSON(Bukkit.spigot().getBukkitConfig(), null)), | ||
pair("paper", mapAsJSON(Bukkit.spigot().getPaperConfig(), null)), // Airplane | ||
- pair("airplane", mapAsJSON(gg.airplane.AirplaneConfig.getConfigCopy(), null)) // Airplane | ||
+ pair("airplane", mapAsJSON(gg.airplane.AirplaneConfig.getConfigCopy(), null)), // Airplane // Pufferfish | ||
+ pair("pufferfish", mapAsJSON(gg.pufferfish.pufferfish.PufferfishConfig.getConfigCopy(), null)) | ||
)); | ||
|
||
new TimingsExport(listeners, parent, history).start(); | ||
diff --git a/src/main/java/gg/pufferfish/pufferfish/PufferfishCommand.java b/src/main/java/gg/pufferfish/pufferfish/PufferfishCommand.java | ||
new file mode 100644 | ||
index 0000000000000000000000000000000000000000..020368da69b9a492155f6de6297f74732f4ab6ea | ||
--- /dev/null | ||
+++ b/src/main/java/gg/pufferfish/pufferfish/PufferfishCommand.java | ||
@@ -0,0 +1,68 @@ | ||
+package gg.pufferfish.pufferfish; | ||
+ | ||
+import java.io.IOException; | ||
+import java.util.Collections; | ||
+import java.util.List; | ||
+import java.util.stream.Collectors; | ||
+import java.util.stream.Stream; | ||
+import net.kyori.adventure.text.Component; | ||
+import net.kyori.adventure.text.format.NamedTextColor; | ||
+import net.md_5.bungee.api.ChatColor; | ||
+import net.minecraft.server.MinecraftServer; | ||
+import org.bukkit.Bukkit; | ||
+import org.bukkit.Location; | ||
+import org.bukkit.command.Command; | ||
+import org.bukkit.command.CommandSender; | ||
+ | ||
+public class PufferfishCommand extends Command { | ||
+ | ||
+ public PufferfishCommand() { | ||
+ super("pufferfish"); | ||
+ this.description = "Pufferfish related commands"; | ||
+ this.usageMessage = "/pufferfish [reload | version]"; | ||
+ this.setPermission("bukkit.command.pufferfish"); | ||
+ } | ||
+ | ||
+ public static void init() { | ||
+ MinecraftServer.getServer().server.getCommandMap().register("pufferfish", "Pufferfish", new PufferfishCommand()); | ||
+ } | ||
+ | ||
+ @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; | ||
+ String prefix = ChatColor.of("#12fff6") + "" + ChatColor.BOLD + "Pufferfish » " + ChatColor.of("#e8f9f9"); | ||
+ | ||
+ if (args.length != 1) { | ||
+ sender.sendMessage(prefix + "Usage: " + usageMessage); | ||
+ args = new String[]{"version"}; | ||
+ } | ||
+ | ||
+ if (args[0].equalsIgnoreCase("reload")) { | ||
+ MinecraftServer console = MinecraftServer.getServer(); | ||
+ try { | ||
+ PufferfishConfig.load(); | ||
+ } catch (IOException e) { | ||
+ sender.sendMessage(Component.text("Failed to reload.", NamedTextColor.RED)); | ||
+ e.printStackTrace(); | ||
+ return true; | ||
+ } | ||
+ console.server.reloadCount++; | ||
+ | ||
+ Command.broadcastCommandMessage(sender, prefix + "Pufferfish configuration has been reloaded."); | ||
+ } else if (args[0].equalsIgnoreCase("version")) { | ||
+ Command.broadcastCommandMessage(sender, prefix + "This server is running " + Bukkit.getName() + " version " + Bukkit.getVersion() + " (Implementing API version " + Bukkit.getBukkitVersion() + ")"); | ||
+ } | ||
+ | ||
+ return true; | ||
+ } | ||
+} | ||
diff --git a/src/main/java/gg/pufferfish/pufferfish/PufferfishConfig.java b/src/main/java/gg/pufferfish/pufferfish/PufferfishConfig.java | ||
new file mode 100644 | ||
index 0000000000000000000000000000000000000000..5e69763e07da98520f7bdd7d9eab1102ce9191be | ||
--- /dev/null | ||
+++ b/src/main/java/gg/pufferfish/pufferfish/PufferfishConfig.java | ||
@@ -0,0 +1,146 @@ | ||
+package gg.pufferfish.pufferfish; | ||
+ | ||
+import java.io.File; | ||
+import java.io.IOException; | ||
+import java.lang.reflect.Method; | ||
+import java.lang.reflect.Modifier; | ||
+import java.util.List; | ||
+import net.minecraft.server.MinecraftServer; | ||
+import org.apache.logging.log4j.Level; | ||
+import org.bukkit.configuration.ConfigurationSection; | ||
+import org.bukkit.configuration.MemoryConfiguration; | ||
+import org.jetbrains.annotations.Nullable; | ||
+import org.simpleyaml.configuration.comments.CommentType; | ||
+import org.simpleyaml.configuration.file.YamlFile; | ||
+import org.simpleyaml.exceptions.InvalidConfigurationException; | ||
+ | ||
+public class PufferfishConfig { | ||
+ | ||
+ private static final YamlFile config = new YamlFile(); | ||
+ private static int updates = 0; | ||
+ | ||
+ private static ConfigurationSection convertToBukkit(org.simpleyaml.configuration.ConfigurationSection section) { | ||
+ ConfigurationSection newSection = new MemoryConfiguration(); | ||
+ for (String key : section.getKeys(false)) { | ||
+ if (section.isConfigurationSection(key)) { | ||
+ newSection.set(key, convertToBukkit(section.getConfigurationSection(key))); | ||
+ } else { | ||
+ newSection.set(key, section.get(key)); | ||
+ } | ||
+ } | ||
+ return newSection; | ||
+ } | ||
+ | ||
+ public static ConfigurationSection getConfigCopy() { | ||
+ return convertToBukkit(config); | ||
+ } | ||
+ | ||
+ public static int getUpdates() { | ||
+ return updates; | ||
+ } | ||
+ | ||
+ public static void load() throws IOException { | ||
+ File configFile = new File("pufferfish.yml"); | ||
+ | ||
+ if (configFile.exists()) { | ||
+ try { | ||
+ config.load(configFile); | ||
+ } catch (InvalidConfigurationException e) { | ||
+ throw new IOException(e); | ||
+ } | ||
+ } | ||
+ | ||
+ getString("info.version", "1.0"); | ||
+ setComment("info", | ||
+ "Pufferfish Configuration", | ||
+ "Check out Pufferfish Host for maximum performance server hosting: https://pufferfish.host", | ||
+ "Join our Discord for support: https://discord.gg/reZw4vQV9H", | ||
+ "Download new builds at https://ci.pufferfish.host/job/Pufferfish"); | ||
+ | ||
+ for (Method method : PufferfishConfig.class.getDeclaredMethods()) { | ||
+ if (Modifier.isStatic(method.getModifiers()) && Modifier.isPrivate(method.getModifiers()) && method.getParameterCount() == 0 && | ||
+ method.getReturnType() == Void.TYPE && !method.getName().startsWith("lambda")) { | ||
+ method.setAccessible(true); | ||
+ try { | ||
+ method.invoke(null); | ||
+ } catch (Throwable t) { | ||
+ MinecraftServer.LOGGER.log(Level.WARN, "Failed to load configuration option from " + method.getName(), t); | ||
+ } | ||
+ } | ||
+ } | ||
+ | ||
+ updates++; | ||
+ | ||
+ config.save(configFile); | ||
+ } | ||
+ | ||
+ private static void setComment(String key, String... comment) { | ||
+ if (config.contains(key)) { | ||
+ config.setComment(key, String.join("\n", comment), CommentType.BLOCK); | ||
+ } | ||
+ } | ||
+ | ||
+ private static void ensureDefault(String key, Object defaultValue, String... comment) { | ||
+ if (!config.contains(key)) { | ||
+ config.set(key, defaultValue); | ||
+ config.setComment(key, String.join("\n", comment), CommentType.BLOCK); | ||
+ } | ||
+ } | ||
+ | ||
+ private static boolean getBoolean(String key, boolean defaultValue, String... comment) { | ||
+ return getBoolean(key, null, defaultValue, comment); | ||
+ } | ||
+ | ||
+ private static boolean getBoolean(String key, @Nullable String oldKey, boolean defaultValue, String... comment) { | ||
+ ensureDefault(key, defaultValue, comment); | ||
+ return config.getBoolean(key, defaultValue); | ||
+ } | ||
+ | ||
+ private static int getInt(String key, int defaultValue, String... comment) { | ||
+ return getInt(key, null, defaultValue, comment); | ||
+ } | ||
+ | ||
+ private static int getInt(String key, @Nullable String oldKey, int defaultValue, String... comment) { | ||
+ ensureDefault(key, defaultValue, comment); | ||
+ return config.getInt(key, defaultValue); | ||
+ } | ||
+ | ||
+ private static double getDouble(String key, double defaultValue, String... comment) { | ||
+ return getDouble(key, null, defaultValue, comment); | ||
+ } | ||
+ | ||
+ private static double getDouble(String key, @Nullable String oldKey, double defaultValue, String... comment) { | ||
+ ensureDefault(key, defaultValue, comment); | ||
+ return config.getDouble(key, defaultValue); | ||
+ } | ||
+ | ||
+ private static String getString(String key, String defaultValue, String... comment) { | ||
+ return getOldString(key, null, defaultValue, comment); | ||
+ } | ||
+ | ||
+ private static String getOldString(String key, @Nullable String oldKey, String defaultValue, String... comment) { | ||
+ ensureDefault(key, defaultValue, comment); | ||
+ return config.getString(key, defaultValue); | ||
+ } | ||
+ | ||
+ private static List<String> getStringList(String key, List<String> defaultValue, String... comment) { | ||
+ return getStringList(key, null, defaultValue, comment); | ||
+ } | ||
+ | ||
+ private static List<String> getStringList(String key, @Nullable String oldKey, List<String> defaultValue, String... comment) { | ||
+ ensureDefault(key, defaultValue, comment); | ||
+ return config.getStringList(key); | ||
+ } | ||
+ | ||
+ public static int maxProjectileLoadsPerTick; | ||
+ public static int maxProjectileLoadsPerProjectile; | ||
+ | ||
+ | ||
+ private static void projectileLoading() { | ||
+ maxProjectileLoadsPerTick = getInt("projectile.max-loads-per-tick", 10, "Controls how many chunks are allowed", "to be sync loaded by projectiles in a tick."); | ||
+ maxProjectileLoadsPerProjectile = getInt("projectile.max-loads-per-projectile", 10, "Controls how many chunks a projectile", "can load in its lifetime before it gets", "automatically removed."); | ||
+ | ||
+ setComment("projectile", "Optimizes projectile settings"); | ||
+ } | ||
+ | ||
+} | ||
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java | ||
index e2901132b78126c0a4eb04363dfe6a0dccd1313f..ab6e496d6d2aa11caca82b52c7e92715988455db 100644 | ||
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java | ||
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java | ||
@@ -236,6 +236,8 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface | ||
// Paper end | ||
gg.airplane.AirplaneConfig.load(); // Airplane - config | ||
gg.airplane.commands.AirplaneCommands.init(); // Airplane - command | ||
+ gg.pufferfish.pufferfish.PufferfishConfig.load(); // Pufferfish | ||
+ gg.pufferfish.pufferfish.PufferfishCommand.init(); // Pufferfish | ||
|
||
this.setPvpAllowed(dedicatedserverproperties.pvp); | ||
this.setFlightAllowed(dedicatedserverproperties.allowFlight); |