9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-21 07:49:35 +00:00
Files
LeavesMC/patches/server/0008-Add-Leaves-Command.patch
2022-04-21 18:23:23 +08:00

83 lines
4.0 KiB
Diff

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 705797683bea7b29a873f01ddb99496f1a17eb40..dddbbdf2a5b3f7e28253c88b307ad42ca7f6b36b 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -237,6 +237,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 b932ea565a8381817dc159b938757666d8e167c7..e1b15532a60152d058ed0e1c68c0cff5ef481895 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
com.destroystokyo.paper.PaperConfig.registerCommands(); // 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<String, Command> 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<String, Command> 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);