diff options
Diffstat (limited to 'src/main/java/moe/nea/firmament/mixins/CaseInsensitiveCommandMapPatch.java')
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/CaseInsensitiveCommandMapPatch.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/CaseInsensitiveCommandMapPatch.java b/src/main/java/moe/nea/firmament/mixins/CaseInsensitiveCommandMapPatch.java new file mode 100644 index 0000000..2696a6f --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/CaseInsensitiveCommandMapPatch.java @@ -0,0 +1,29 @@ +/* + * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.mixins; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.mojang.brigadier.tree.CommandNode; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import java.util.Locale; +import java.util.Map; + +@Mixin(value = CommandNode.class, remap = false) +public class CaseInsensitiveCommandMapPatch<S> { + @WrapOperation(method = "getRelevantNodes", at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;"), remap = false) + public Object modify(Map map, Object text, Operation<Object> op) { + var original = op.call(map, text); + if (original == null) { + return map.get(((String) text).toLowerCase(Locale.ROOT)); + } + return original; + } + +} |