From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: violetc <58360096+s-yh-china@users.noreply.github.com> Date: Sat, 29 Jan 2022 18:04:46 +0800 Subject: [PATCH] Add Leaves Command diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java index 2294294bd192d380d99189a1884db7f2be885d04..026d79fb66cf96883a28e7a33707fb3116f80ab9 100644 --- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java +++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java @@ -228,6 +228,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface // Paper end top.leavesmc.leaves.LeavesConfig.init((java.io.File) options.valueOf("leaves-settings")); // Leaves - Server Config + top.leavesmc.leaves.LeavesConfig.registerCommands(); // Leaves - Server Command this.setPvpAllowed(dedicatedserverproperties.pvp); this.setFlightAllowed(dedicatedserverproperties.allowFlight); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 3d751aba4906b19eeefa1a8cde4a6305a7a0deea..298b8a38a83ec16bf2468ca2935883738d36feea 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -989,6 +989,7 @@ public final class CraftServer implements Server { this.reloadData(); org.spigotmc.SpigotConfig.registerCommands(); // Spigot io.papermc.paper.command.PaperCommands.registerCommands(this.console); // Paper + top.leavesmc.leaves.LeavesConfig.registerCommands(); // Leaves - Server Command this.overrideAllCommandBlockCommands = this.commandsConfiguration.getStringList("command-block-overrides").contains("*"); this.ignoreVanillaPermissions = this.commandsConfiguration.getBoolean("ignore-vanilla-permissions"); diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java index 8999a852440c5c15dec5adf892eb60674500f70e..a85a5de7d85cf6c5e19c0245c40e6106e6623007 100644 --- a/src/main/java/top/leavesmc/leaves/LeavesConfig.java +++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java @@ -4,6 +4,7 @@ import com.destroystokyo.paper.util.SneakyThrow; import com.google.common.base.Throwables; import net.minecraft.server.MinecraftServer; import org.bukkit.Bukkit; +import org.bukkit.command.Command; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -11,7 +12,9 @@ import java.io.File; 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; // Copy form Tuinity(https://github.com/Tuinity/Tuinity) @@ -27,6 +30,7 @@ public final class LeavesConfig { public static YamlConfiguration config; private static int configVersion; public static boolean createWorldSections = true; + static Map commands; public static void init(final File file) { LeavesConfig.configFile = file; @@ -57,6 +61,8 @@ public final class LeavesConfig { LeavesConfig.set("config-version", CURRENT_CONFIG_VERSION); LeavesConfig.load(config); + + commands = new HashMap<>(); } public static void load(final YamlConfiguration config) { @@ -87,6 +93,12 @@ public final class LeavesConfig { LeavesConfig.config.set(path, value); } + public static void registerCommands() { + for (Map.Entry entry : commands.entrySet()) { + MinecraftServer.getServer().server.getCommandMap().register(entry.getKey(), "Leaves", entry.getValue()); + } + } + static boolean getBoolean(final String path, final boolean dfl) { LeavesConfig.config.addDefault(path, Boolean.valueOf(dfl)); return LeavesConfig.config.getBoolean(path, dfl);