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 7ad3569628fd6c6ac0038394e7d88979b29935a0..d27f115b74fe00623985255d1027656166c1c459 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 599ad9516e9642f774c4f8b1d60b453a775b172a..9e21aa4d6464b86923f4ccc4cdec9e3b663dd268 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -991,6 +991,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 b82efc14c0e7aa33260cffcfc20fa42d24e61192..393ced680a790cb6e6abf448a6c60f413ac97551 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; // Powered by 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);