Skip to content

Commit

Permalink
Merge pull request #77 from sylviameows/main
Browse files Browse the repository at this point in the history
code search command
  • Loading branch information
GeorgeRNG committed Jun 12, 2024
2 parents f0b6890 + b60a10d commit 6c63feb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/main/java/dev/dfonline/codeclient/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,48 @@ else if(field.getType().isEnum()) {
return -1;
})));

dispatcher.register(literal("search")
.then(argument("query",greedyString()).suggests((context,builder) -> suggestJump(JumpType.ANY, context, builder)).executes(context -> {
if(CodeClient.location instanceof Dev dev) {
var query = context.getArgument("query", String.class);
var results = dev.scanForSigns(JumpType.ANY.pattern,Pattern.compile("^.*"+Pattern.quote(query)+".*$", Pattern.CASE_INSENSITIVE));

if (results == null || results.isEmpty()) {
Utility.sendMessage(Text.translatable("codeclient.search.no_results"), ChatType.INFO);
return 0;
}

var message = Text.translatable("codeclient.search.results");
results.forEach((pos,text) -> {
var type = text.getMessage(0, false).getString();
var name = text.getMessage(1, false).getString();

String sub = null;
if (JumpType.PLAYER_EVENT.pattern.matcher(type).matches()) sub = "player";
else if (JumpType.ENTITY_EVENT.pattern.matcher(type).matches()) sub = "entity";
else if (JumpType.FUNCTION.pattern.matcher(type).matches()) sub = "func";
else if (JumpType.PROCESS.pattern.matcher(type).matches()) sub = "proc";
else return;

var action = Text.empty().append(" [⏼]").setStyle(Style.EMPTY
.withColor(Formatting.GREEN)
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/jump %s %s", sub, name)))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("codeclient.search.hover.teleport", pos.getX(), pos.getY(), pos.getZ())))
);
var entry = Text.empty().append("\n • ").formatted(Formatting.GREEN)
.append(Text.empty().append(name).formatted(Formatting.WHITE))
.append(action);
message.append(entry);
});

Utility.sendMessage(message, ChatType.SUCCESS);
} else {
Utility.sendMessage(Text.translatable("codeclient.warning.dev_mode"), ChatType.FAIL);
}
return 0;
})
));

LiteralCommandNode<FabricClientCommandSource> jumpCommand = dispatcher.register(literal("jump")
.then(literal("player").then(argument("name", greedyString()).suggests((context, builder) -> suggestJump(JumpType.PLAYER_EVENT, context, builder)).executes(context -> {
var name = context.getArgument("name", String.class);
Expand Down Expand Up @@ -613,7 +655,8 @@ private static enum JumpType {
PLAYER_EVENT("PLAYER EVENT"),
ENTITY_EVENT("ENTITY EVENT"),
FUNCTION("FUNCTION"),
PROCESS("PROCESS");
PROCESS("PROCESS"),
ANY("(((PLAYER)|(ENTITY)) EVENT)|(FUNCTION)|(PROCESS)");

public final Pattern pattern;
JumpType(String scan) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/assets/codeclient/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"codeclient.warning.dev_mode": "You must be in dev mode!",
"codeclient.warning.creative_mode": "You must be in creative mode!",

"codeclient.search.results": "Search Results:",
"codeclient.search.no_results": "No results.",
"codeclient.search.hover.teleport": "Click to teleport\nx: %s, y: %s, z: %s",

"codeclient.files.template_fail": "Couldn't load templates.",
"codeclient.files.hold_template": "You need to hold a template to save.",
"codeclient.files.empty_dir": "Please use an empty folder to save into.",
Expand Down

0 comments on commit 6c63feb

Please sign in to comment.