add alias to chome ns bot suggestions
This commit is contained in:
parent
08c3773660
commit
63967e407d
3 changed files with 40 additions and 8 deletions
|
@ -1,8 +1,12 @@
|
|||
package land.chipmunk.chipmunkmod.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChomeNSBotCommand {
|
||||
public final String name;
|
||||
public final TrustLevel trustLevel;
|
||||
public final List<String> aliases = new ArrayList<>();
|
||||
|
||||
public ChomeNSBotCommand (
|
||||
String name,
|
||||
|
|
|
@ -23,6 +23,7 @@ import javax.net.ssl.HttpsURLConnection;
|
|||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(value = net.minecraft.client.gui.screen.ChatScreen.class)
|
||||
|
@ -104,9 +105,21 @@ public class ChatScreenMixin extends Screen {
|
|||
.map((command) -> command.name.toLowerCase())
|
||||
.toList();
|
||||
|
||||
if (moreOrTrustedCommands.contains(chatText.toLowerCase().split("\\s")[0])) {
|
||||
final List<String> aliases = new ArrayList<>();
|
||||
for (ChomeNSBotCommand command : commands) {
|
||||
aliases.addAll(command.aliases);
|
||||
}
|
||||
|
||||
final String chatCommand = chatText.toLowerCase().split("\\s")[0];
|
||||
|
||||
final int prefixLength = ChipmunkMod.CONFIG.bots.chomens.prefix.length();
|
||||
|
||||
if (
|
||||
moreOrTrustedCommands.contains(chatCommand) ||
|
||||
aliases.contains(chatCommand.substring(prefixLength))
|
||||
) {
|
||||
try {
|
||||
BotValidationUtilities.chomens(chatText.substring(ChipmunkMod.CONFIG.bots.chomens.prefix.length()));
|
||||
BotValidationUtilities.chomens(chatText.substring(prefixLength));
|
||||
|
||||
cir.setReturnValue(true);
|
||||
cir.cancel();
|
||||
|
@ -116,6 +129,8 @@ public class ChatScreenMixin extends Screen {
|
|||
}
|
||||
}
|
||||
|
||||
if (client == null) return;
|
||||
|
||||
if (chatText.startsWith("/")) {
|
||||
client.player.networkHandler.sendChatCommand(chatText.substring(1));
|
||||
} else {
|
||||
|
|
|
@ -13,7 +13,6 @@ import net.minecraft.client.network.ClientPlayerEntity;
|
|||
import net.minecraft.text.Text;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ChomeNSBotCommandSuggestions extends Listener {
|
||||
|
@ -59,7 +58,7 @@ public class ChomeNSBotCommandSuggestions extends Listener {
|
|||
|
||||
final List<Component> children = component.children();
|
||||
|
||||
if (children.size() == 0) return;
|
||||
if (children.isEmpty()) return;
|
||||
|
||||
final TextComponent textComponent = (TextComponent) children.get(0);
|
||||
|
||||
|
@ -68,10 +67,24 @@ public class ChomeNSBotCommandSuggestions extends Listener {
|
|||
commands = children.subList(1, children.size())
|
||||
.stream()
|
||||
.map(
|
||||
(eachCum) -> new ChomeNSBotCommand(
|
||||
ChipmunkMod.CONFIG.bots.chomens.prefix + ((TextComponent) eachCum).content(),
|
||||
ChomeNSBotCommand.TrustLevel.valueOf(((TextComponent) eachCum.children().get(0)).content())
|
||||
)
|
||||
(eachComponent) -> {
|
||||
final ChomeNSBotCommand command = new ChomeNSBotCommand(
|
||||
ChipmunkMod.CONFIG.bots.chomens.prefix + ((TextComponent) eachComponent).content(),
|
||||
ChomeNSBotCommand.TrustLevel.valueOf(((TextComponent) eachComponent.children().get(0)).content())
|
||||
);
|
||||
|
||||
if (!Boolean.parseBoolean(((TextComponent) eachComponent.children().get(1)).content())) return command;
|
||||
|
||||
final List<Component> subList = eachComponent.children().subList(2, eachComponent.children().size());
|
||||
|
||||
for (Component aliasComponent : subList) {
|
||||
final String alias = ((TextComponent) aliasComponent).content();
|
||||
|
||||
command.aliases.add(alias);
|
||||
}
|
||||
|
||||
return command;
|
||||
}
|
||||
)
|
||||
.toList();
|
||||
} catch (Exception ignored) {}
|
||||
|
|
Loading…
Reference in a new issue