Skip to content

Commit cbfdd81

Browse files
committed
isOverridden checking added.
Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
1 parent dfe9bc2 commit cbfdd81

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/main/kotlin/com/mairwunnx/projectessentials/core/impl/utils/NativeCommandUtils.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.mairwunnx.projectessentials.core.impl.utils
22

3+
import com.mairwunnx.projectessentials.core.api.v1.SETTING_NATIVE_COMMAND_REPLACE
34
import com.mairwunnx.projectessentials.core.api.v1.commands.CommandAPI
45
import com.mairwunnx.projectessentials.core.api.v1.commands.CommandAliases
56
import com.mairwunnx.projectessentials.core.api.v1.helpers.getFieldsOf
67
import com.mairwunnx.projectessentials.core.api.v1.permissions.hasPermission
8+
import com.mairwunnx.projectessentials.core.impl.generalConfiguration
79
import com.mairwunnx.projectessentials.core.impl.nativeMappingsConfiguration
810
import com.mojang.brigadier.tree.LiteralCommandNode
911
import com.mojang.brigadier.tree.RootCommandNode
@@ -17,11 +19,14 @@ import java.util.function.Predicate
1719
object 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

Comments
 (0)