11package com.mairwunnx.projectessentials.core.impl.utils
22
3+ import com.mairwunnx.projectessentials.core.api.v1.SETTING_NATIVE_COMMAND_REPLACE
34import com.mairwunnx.projectessentials.core.api.v1.commands.CommandAPI
45import com.mairwunnx.projectessentials.core.api.v1.commands.CommandAliases
56import com.mairwunnx.projectessentials.core.api.v1.helpers.getFieldsOf
67import com.mairwunnx.projectessentials.core.api.v1.permissions.hasPermission
8+ import com.mairwunnx.projectessentials.core.impl.generalConfiguration
79import com.mairwunnx.projectessentials.core.impl.nativeMappingsConfiguration
810import com.mojang.brigadier.tree.LiteralCommandNode
911import com.mojang.brigadier.tree.RootCommandNode
@@ -17,11 +19,14 @@ import java.util.function.Predicate
1719object NativeCommandUtils {
1820 private val logger = LogManager .getLogger()
1921
22+ private fun isOverridden (name : String ) =
23+ if (generalConfiguration.getBool(SETTING_NATIVE_COMMAND_REPLACE )) name !in overridden else false
24+
2025 internal fun replaceRequirementPredicates () {
2126 logger.debug(" Replacing native requirement predicates ..." )
2227
2328 CommandAPI .getDispatcher().root.children.asSequence().filter { node ->
24- node.name in natives
29+ node.name in natives && ! isOverridden(node.name)
2530 }.forEach { node ->
2631 logger.debug(" Replacing requirement predicate for ${node.name} " )
2732 try {
@@ -54,7 +59,7 @@ object NativeCommandUtils {
5459 internal fun insertNativeAliases () {
5560 logger.debug(" Replacing and inserting native aliases ..." )
5661 CommandAPI .getDispatcher().root.children.filter { node ->
57- node.name in natives
62+ node.name in natives && ! isOverridden(node.name)
5863 }.forEach { node ->
5964 node as LiteralCommandNode
6065 nativeMappingsConfiguration.aliases[node.literal]?.split(' ,' )?.let { aliases ->
@@ -84,4 +89,8 @@ object NativeCommandUtils {
8489 " tag" , " team" , " teammsg" , " teleport" , " tell" , " tellraw" , " time" , " title" , " tp" , " trigger" ,
8590 " w" , " weather" , " whitelist" , " worldborder" , " xp"
8691 )
92+
93+ val overridden = listOf (
94+ " weather" , " time" , " save-all" , " reload" , " gamemode" , " enchant" , " teleport"
95+ )
8796}
0 commit comments