Skip to content

Commit 7a641dd

Browse files
committed
Merge branch 'sylviameows-main'
2 parents 69141e0 + cc4f790 commit 7a641dd

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

src/main/java/dev/dfonline/codeclient/Commands.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.mojang.brigadier.context.CommandContext;
55
import com.mojang.brigadier.suggestion.Suggestions;
66
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
7+
import com.mojang.brigadier.tree.LiteralCommandNode;
78
import dev.dfonline.codeclient.action.Action;
89
import dev.dfonline.codeclient.action.None;
910
import dev.dfonline.codeclient.action.impl.*;
@@ -13,6 +14,7 @@
1314
import dev.dfonline.codeclient.location.Plot;
1415
import dev.dfonline.codeclient.websocket.SocketHandler;
1516
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
17+
import net.minecraft.block.entity.SignText;
1618
import net.minecraft.client.font.TextRenderer;
1719
import net.minecraft.item.ItemStack;
1820
import net.minecraft.text.ClickEvent;
@@ -22,6 +24,7 @@
2224
import net.minecraft.util.Formatting;
2325
import net.minecraft.util.math.BlockPos;
2426
import org.apache.commons.io.FileUtils;
27+
import org.jetbrains.annotations.Nullable;
2528

2629
import java.io.IOException;
2730
import java.nio.file.Files;
@@ -286,7 +289,7 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
286289
return -1;
287290
})));
288291

289-
dispatcher.register(literal("jump")
292+
LiteralCommandNode<FabricClientCommandSource> jumpCommand = dispatcher.register(literal("jump")
290293
.then(literal("player").then(argument("name", greedyString()).suggests((context, builder) -> suggestJump(JumpType.PLAYER_EVENT, context, builder)).executes(context -> {
291294
var name = context.getArgument("name", String.class);
292295
jump(JumpType.PLAYER_EVENT,name);
@@ -308,6 +311,9 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
308311
return 0;
309312
})))
310313
);
314+
315+
dispatcher.register(literal("goto").redirect(jumpCommand));
316+
311317
// dispatcher.register(literal("swapininv").executes(context -> {
312318
// if(CodeClient.location instanceof Dev) {
313319
// PlaceTemplates action = Utility.createSwapper(Utility.templatesInInventory(), () -> {
@@ -551,10 +557,25 @@ private static CompletableFuture<Suggestions> suggestJump(JumpType type, Command
551557
}
552558
private static void jump(JumpType type, String name) {
553559
if(CodeClient.location instanceof Dev dev && CodeClient.currentAction instanceof None) {
554-
var results = dev.scanForSigns(type.pattern,Pattern.compile("^" + Pattern.quote(name) + "$"));
560+
@Nullable HashMap<BlockPos, SignText> results = null;
561+
// functions/processes in diamondfire are case-sensitive, and you can have two functions with the same name if they have different cases.
562+
if (type == JumpType.FUNCTION || type == JumpType.PROCESS) {
563+
results = dev.scanForSigns(type.pattern,Pattern.compile("^" + Pattern.quote(name) + "$"));
564+
} else {
565+
// however, events do not have this problem and the case of what you type shouldn't matter.
566+
results = dev.scanForSigns(type.pattern,Pattern.compile("^" + Pattern.quote(name) + "$", Pattern.CASE_INSENSITIVE));
567+
}
568+
555569
if(results == null) return;
556570
var first = results.keySet().stream().findFirst();
557-
if(first.isEmpty()) return;
571+
572+
// no exact match exists in the plot, so we can run a less restrictive search.
573+
if(first.isEmpty()) {
574+
results = dev.scanForSigns(type.pattern,Pattern.compile("^.*"+Pattern.quote(name)+".*$", Pattern.CASE_INSENSITIVE));
575+
if(results == null) return;
576+
first = results.keySet().stream().findFirst();
577+
if(first.isEmpty()) return; // there is no partial match, so the player doesn't get sent
578+
}
558579
CodeClient.currentAction = new GoTo(first.get().toCenterPos(), () -> CodeClient.currentAction = new None());
559580
CodeClient.currentAction.init();
560581
}

0 commit comments

Comments
 (0)