Skip to content

Commit 0c7d909

Browse files
committed
Merge branch '1.21.11' into feature/antispam
2 parents 0ae3bcd + edb15e2 commit 0c7d909

File tree

11 files changed

+84
-912
lines changed

11 files changed

+84
-912
lines changed

src/main/java/com/lambda/mixin/render/ChatInputSuggestorMixin.java

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,23 @@
1717

1818
package com.lambda.mixin.render;
1919

20-
import com.google.common.base.Strings;
2120
import com.lambda.command.CommandManager;
22-
import com.lambda.graphics.renderer.gui.font.core.LambdaAtlas;
23-
import com.lambda.module.modules.client.LambdaMoji;
24-
import com.lambda.module.modules.client.StyleEditor;
2521
import com.mojang.brigadier.CommandDispatcher;
26-
import com.mojang.brigadier.suggestion.Suggestions;
27-
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
2822
import net.minecraft.client.gui.screen.ChatInputSuggestor;
2923
import net.minecraft.client.gui.widget.TextFieldWidget;
3024
import net.minecraft.client.network.ClientPlayNetworkHandler;
3125
import net.minecraft.command.CommandSource;
32-
import org.jetbrains.annotations.Nullable;
3326
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
3427
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
3528
import org.spongepowered.asm.mixin.Final;
3629
import org.spongepowered.asm.mixin.Mixin;
3730
import org.spongepowered.asm.mixin.Shadow;
38-
import org.spongepowered.asm.mixin.Unique;
3931
import org.spongepowered.asm.mixin.injection.At;
40-
import org.spongepowered.asm.mixin.injection.Inject;
4132
import org.spongepowered.asm.mixin.injection.ModifyVariable;
42-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
43-
44-
import java.util.Map;
45-
import java.util.concurrent.CompletableFuture;
46-
import java.util.regex.Matcher;
47-
import java.util.regex.Pattern;
48-
import java.util.stream.Stream;
4933

5034
@Mixin(ChatInputSuggestor.class)
5135
public abstract class ChatInputSuggestorMixin {
52-
@Unique private static final Pattern COLON_PATTERN = Pattern.compile("(:[a-zA-Z0-9_]+)");
53-
@Unique private static final Pattern EMOJI_PATTERN = Pattern.compile("(:)([a-zA-Z0-9_]+)(:)");
5436
@Shadow @Final TextFieldWidget textField;
55-
@Shadow private @Nullable CompletableFuture<Suggestions> pendingSuggestions;
5637

5738
@Shadow
5839
public abstract void show(boolean narrateFirstSuggestion);
@@ -67,64 +48,4 @@ private boolean refreshModify(boolean showCompletions) {
6748
private CommandDispatcher<CommandSource> wrapRefresh(ClientPlayNetworkHandler instance, Operation<CommandDispatcher<CommandSource>> original) {
6849
return (CommandDispatcher<CommandSource>) CommandManager.INSTANCE.currentDispatcher(textField.getText());
6950
}
70-
71-
@Inject(method = "refresh", at = @At("TAIL"))
72-
private void refreshEmojiSuggestion(CallbackInfo ci) {
73-
if (!LambdaMoji.INSTANCE.isEnabled() ||
74-
!LambdaMoji.INSTANCE.getSuggestions()) return;
75-
76-
String typing = textField.getText();
77-
78-
// Don't suggest emojis in commands
79-
if (CommandManager.INSTANCE.isCommand(typing) ||
80-
CommandManager.INSTANCE.isLambdaCommand(typing)) return;
81-
82-
int cursor = textField.getCursor();
83-
String textToCursor = typing.substring(0, cursor);
84-
if (textToCursor.isEmpty()) return;
85-
86-
// Most right index at the left of the regex expression
87-
int start = neoLambda$getLastColon(textToCursor);
88-
if (start == -1) return;
89-
90-
Matcher emojiMatcher = EMOJI_PATTERN.matcher(textToCursor);
91-
Map<String, ?> emojiKeys = LambdaAtlas.INSTANCE.getKeys(StyleEditor.INSTANCE.getEmojiFont());
92-
while (emojiMatcher.find()) {
93-
int openingColon = emojiMatcher.start(1);
94-
String key = emojiMatcher.group(2);
95-
int closingColon = emojiMatcher.end(3);
96-
97-
if (emojiKeys.containsKey(key) && start >= openingColon && start < closingColon) {
98-
// If the colon is part of a previous valid emoji, return
99-
return;
100-
}
101-
}
102-
103-
String emojiString = textToCursor.substring(start + 1);
104-
105-
Stream<String> results = emojiKeys.keySet().stream()
106-
.filter(s -> s.startsWith(emojiString))
107-
.map(s -> s + ":");
108-
109-
pendingSuggestions = CommandSource.suggestMatching(results, new SuggestionsBuilder(textToCursor, start + 1));
110-
pendingSuggestions.thenRun(() -> {
111-
if (!pendingSuggestions.isDone()) return;
112-
113-
show(false);
114-
});
115-
}
116-
117-
@Unique
118-
private int neoLambda$getLastColon(String input) {
119-
if (Strings.isNullOrEmpty(input)) return -1;
120-
121-
int i = -1;
122-
Matcher matcher = COLON_PATTERN.matcher(input);
123-
124-
while (matcher.find()) {
125-
i = matcher.start();
126-
}
127-
128-
return i;
129-
}
13051
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.command.commands
19+
20+
import com.lambda.brigadier.CommandResult.Companion.failure
21+
import com.lambda.brigadier.CommandResult.Companion.success
22+
import com.lambda.brigadier.argument.greedyString
23+
import com.lambda.brigadier.argument.string
24+
import com.lambda.brigadier.argument.value
25+
import com.lambda.brigadier.execute
26+
import com.lambda.brigadier.executeWithResult
27+
import com.lambda.brigadier.required
28+
import com.lambda.command.CommandRegistry
29+
import com.lambda.command.LambdaCommand
30+
import com.lambda.config.Configuration
31+
import com.lambda.config.Setting
32+
import com.lambda.util.Communication.info
33+
import com.lambda.util.extension.CommandBuilder
34+
import com.lambda.util.text.buildText
35+
import com.lambda.util.text.literal
36+
37+
object PrefixCommand : LambdaCommand(
38+
"prefix",
39+
usage = "prefix <prefix>",
40+
description = "Sets the prefix for Lambda commands. If the prefix does not seem to work, try putting it in double quotes."
41+
) {
42+
// i have no idea why someone would want to use some of these as a prefix
43+
// but ig the people who run 20 clients at once could benefit from this
44+
val ptrn = Regex("^[!\"#$%&'()*+,\\-./:;<=>?@\\[\\\\\\]^_`{|}~]$")
45+
46+
override fun CommandBuilder.create() {
47+
required(greedyString("prefix")) { prefixStr ->
48+
executeWithResult {
49+
val prefix = prefixStr().value()
50+
if (!ptrn.matches(prefix)) {
51+
return@executeWithResult failure("Prefix must be a single non-alphanumeric ASCII character, excluding spaces.")
52+
}
53+
val prefixChar = prefix.first()
54+
val configurable = Configuration.configurableByName("command") ?: return@executeWithResult failure("No command configurable found.")
55+
val setting = configurable.settings.find { it.name == "prefix" } as? Setting<*, Char>
56+
?: return@executeWithResult failure("Prefix setting is not a Char or can not be found.")
57+
setting.trySetValue(prefixChar)
58+
return@executeWithResult success()
59+
}
60+
}
61+
62+
execute {
63+
info(
64+
buildText {
65+
literal("The prefix is currently: ${CommandRegistry.prefix}")
66+
}
67+
)
68+
}
69+
}
70+
}

src/main/kotlin/com/lambda/graphics/renderer/gui/AbstractGUIRenderer.kt

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)