Skip to content

Commit

Permalink
fix case commands + forge not checking for a / before running comma…
Browse files Browse the repository at this point in the history
…nds (#413)
  • Loading branch information
Alexdoru authored Aug 27, 2024
1 parent 9b76405 commit 28a6e1b
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,16 @@ public class FixesConfig {
@Config.RequiresMcRestart
public static boolean earlyChunkTileCoordinateCheckDestructive;

@Config.Comment("Fix forge command handler not checking for a / and also not running commands with any case")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean fixSlashCommands;

@Config.Comment("Fix the command handler not allowing you to run commands typed in any case")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean fixCaseCommands;

// affecting multiple mods

@Config.Comment("Remove old/stale/outdated update checks.")
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,16 @@ public enum Mixins {
.addMixinClasses("minecraft.MixinMinecraft_FixDuplicateSounds")
.setApplyIf(() -> FixesConfig.fixDuplicateSounds)),

FIX_SLASH_COMMAND(
new Builder("Fix forge command handler not checking for a / and also not running commands with any case")
.setPhase(Phase.EARLY).setSide(Side.CLIENT).addTargetedMod(TargetedMod.VANILLA)
.addMixinClasses("minecraft.MixinClientCommandHandler_CommandFix")
.setApplyIf(() -> FixesConfig.fixSlashCommands)),

FIX_CASE_COMMAND(new Builder("Fix the command handler not allowing you to run commands typed in any case")
.setPhase(Phase.EARLY).setSide(Side.BOTH).addTargetedMod(TargetedMod.VANILLA)
.addMixinClasses("minecraft.MixinCommandHandler_CommandFix").setApplyIf(() -> FixesConfig.fixCaseCommands)),

// Ic2 adjustments
IC2_UNPROTECTED_GET_BLOCK_FIX(new Builder("IC2 Kinetic Fix").setPhase(Phase.EARLY).setSide(Side.BOTH)
.addMixinClasses("ic2.MixinIc2WaterKinetic").setApplyIf(() -> FixesConfig.fixIc2UnprotectedGetBlock)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.mitchej123.hodgepodge.mixins.early.minecraft;

import java.util.Locale;

import net.minecraft.command.ICommandSender;
import net.minecraftforge.client.ClientCommandHandler;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;

@Mixin(ClientCommandHandler.class)
public class MixinClientCommandHandler_CommandFix {

@Inject(method = "executeCommand", at = @At("HEAD"), cancellable = true)
private void hodgepodge$checkSlash(ICommandSender sender, String message, CallbackInfoReturnable<Integer> cir) {
if (!message.trim().startsWith("/")) {
cir.setReturnValue(0);
}
}

@ModifyExpressionValue(
method = "executeCommand",
at = @At(value = "INVOKE", target = "Ljava/lang/String;split(Ljava/lang/String;)[Ljava/lang/String;"))
private String[] hodgepodge$caseCommand(String[] original) {
final String s = original[0];
if (s != null) {
original[0] = s.toLowerCase(Locale.ENGLISH);
}
return original;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.mitchej123.hodgepodge.mixins.early.minecraft;

import java.util.Locale;

import net.minecraft.command.CommandHandler;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;

@Mixin(CommandHandler.class)
public class MixinCommandHandler_CommandFix {

@ModifyExpressionValue(
method = "executeCommand",
at = @At(
value = "INVOKE",
target = "Ljava/lang/String;split(Ljava/lang/String;)[Ljava/lang/String;",
remap = false))
private String[] hodgepodge$caseCommand(String[] original) {
final String s = original[0];
if (s != null) {
original[0] = s.toLowerCase(Locale.ENGLISH);
}
return original;
}

@ModifyArg(
method = "registerCommand",
index = 0,
at = @At(
value = "INVOKE",
target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
remap = false))
private Object hodgepodge$caseCommand(Object s) {
if (s instanceof String) {
s = ((String) s).toLowerCase(Locale.ENGLISH);
}
return s;
}

@ModifyExpressionValue(
method = "getPossibleCommands(Lnet/minecraft/command/ICommandSender;Ljava/lang/String;)Ljava/util/List;",
at = @At(
value = "INVOKE",
target = "Ljava/lang/String;split(Ljava/lang/String;I)[Ljava/lang/String;",
remap = false))
private String[] hodgepodge$caseCommandTabComplete(String[] original) {
final String s = original[0];
if (s != null) {
original[0] = s.toLowerCase(Locale.ENGLISH);
}
return original;
}

}

0 comments on commit 28a6e1b

Please sign in to comment.