9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-20 23:39:34 +00:00
Files
LeavesMC/patches/server/0008-Add-Leaves-Command.patch
2022-03-09 09:19:31 +00:00

83 lines
4.1 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 e92b98177189df1b162b648c0e259035c7ec2263..4f0d97c51db4313a73e46878546ca4c192b483d0 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 3fb3fc5b30d3cb171047cfb9caebf064a83f02bc..5b33ca9c6e97dfb8cd60e08272c6bc8022ede687 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -988,6 +988,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 34501df6372f40840208671953f7912ccc29e459..85a24dd51762b7590cc8116fb51b742174b85e7e 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;
@@ -53,6 +57,8 @@ public final class LeavesConfig {
LeavesConfig.set("config-version-please-do-not-modify-me", CURRENT_CONFIG_VERSION);
LeavesConfig.load(config);
+
+ commands = new HashMap<>();
}
public static void load(final YamlConfiguration config) {
@@ -93,6 +99,12 @@ public final class LeavesConfig {
snowballAndEggCanKnockback = getBoolean("settings.snowball-and-egg-can-knockback-player", snowballAndEggCanKnockback);
}
+ 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);