Skip to content

Commit

Permalink
Fix a few command issues (#151)
Browse files Browse the repository at this point in the history
Signed-off-by: Lyfts <127234178+Lyfts@users.noreply.github.com>
  • Loading branch information
Lyfts authored Dec 10, 2024
1 parent 8c6e21b commit 3780a4a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/main/java/serverutils/lib/command/CmdTreeHelp.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package serverutils.lib.command;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import net.minecraft.command.CommandHelp;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.StatCollector;

public class CmdTreeHelp extends CommandHelp {

Expand All @@ -32,10 +32,15 @@ protected List<ICommand> getSortedPossibleCommands(ICommandSender sender) {
}
}

Collections.sort(list);
list.sort(null);
return list;
}

@Override
public String getCommandUsage(ICommandSender sender) {
return StatCollector.translateToLocal(parent.getCommandUsage(sender)) + " help";
}

@Override
protected Map<String, ICommand> getCommands() {
return parent.getCommandMap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package serverutils.mixins.early.minecraft;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandHandler;
import net.minecraft.command.ICommand;
Expand Down Expand Up @@ -31,6 +34,9 @@
@Mixin(CommandHandler.class)
public abstract class MixinCommandHandler {

@Unique
private static final Matcher PERMISSION_REPLACE_MATCHER = Pattern.compile("[^a-zA-Z0-9._]").matcher("");

@ModifyExpressionValue(
method = { "getPossibleCommands(Lnet/minecraft/command/ICommandSender;)Ljava/util/List;",
"executeCommand" },
Expand Down Expand Up @@ -58,7 +64,7 @@ public abstract class MixinCommandHandler {
String node = (container == null ? Rank.NODE_COMMAND : (Rank.NODE_COMMAND + '.' + container.getModId())) + "."
+ command.getCommandName();
ICommandWithPermission cmd = (ICommandWithPermission) command;
cmd.serverutilities$setPermissionNode(node.toLowerCase());
cmd.serverutilities$setPermissionNode(PERMISSION_REPLACE_MATCHER.reset(node.toLowerCase()).replaceAll("_"));
cmd.serverutilities$setModName(container == null ? "Minecraft" : container.getName());
serverUtilities$registerPermissions(cmd);
}
Expand Down

0 comments on commit 3780a4a

Please sign in to comment.