Skip to content

Commit

Permalink
added keybinding for command prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
SpigotRCE committed Oct 20, 2024
1 parent bc85570 commit a28ed98
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 37 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.21
yarn_mappings=1.21+build.9
loader_version=0.16.5
# Mod Properties
mod_version=1.21-3-5
mod_version=1.21-3-6
maven_group=io.github.spigotrce
archives_base_name=ParadiseClient-Fabric
# Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Constants {
/**
* The version of the mod.
*/
public static final String VERSION = "1.21-3-5";
public static final String VERSION = "1.21-3-6";

/**
* The ID of the mod.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
import io.github.spigotrce.paradiseclientfabric.listener.PacketListener;
import io.github.spigotrce.paradiseclientfabric.mod.*;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import org.lwjgl.glfw.GLFW;

/**
* The main class for the ParadiseClient Fabric mod.
Expand Down Expand Up @@ -170,5 +176,18 @@ public void onInitialize() {
getCommandManager().init();
getEventManager().registerListener(new PacketListener());
getEventManager().registerListener(getCommandManager());

KeyBinding paradiseCommandOpener = KeyBindingHelper.registerKeyBinding(
new KeyBinding(
"Open paradise command",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_COMMA,
Constants.MOD_NAME
)
);
ClientTickEvents.END_CLIENT_TICK.register(client -> {
while (paradiseCommandOpener.wasPressed())
MinecraftClient.getInstance().setScreen(new ChatScreen(getCommandManager().prefix));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class CommandManager implements Listener {

/**
* Constructs a new CommandManager instance and registers all commands.
*
*/
public CommandManager(MinecraftClient minecraftClient) {
this.minecraftClient = minecraftClient;
Expand All @@ -62,10 +61,6 @@ public void init() {
register(new ToggleTABCommand(minecraftClient));
register(new PurpurExploitCommand(minecraftClient));
register(new AuthMeVelocityBypassCommand(minecraftClient));

DISPATCHER.register(
new ParadiseCommand(minecraftClient).build()
);
}

/**
Expand All @@ -76,6 +71,7 @@ public void init() {
public void register(Command command) {
this.commands.add(command);
DISPATCHER.register(command.build());
Constants.LOGGER.info("Registered command: {}", command.getName());
}

/**
Expand Down Expand Up @@ -122,34 +118,4 @@ public void onClientCommand(ChatPreEvent event) {

minecraftClient.inGameHud.getChatHud().addToMessageHistory(event.getMessage());
}

/**
* This class represents a command the root command to execute all sub commands.
* It extends the {@link Command} class and overrides the {@link #build()} method to define the command structure.
*
* @author SpigotRCE
* @since 2.28
*/
private static class ParadiseCommand extends Command {
public ParadiseCommand(MinecraftClient minecraftClient) {
super("paradise", "The paradise command!", minecraftClient);
}

@Override
public LiteralArgumentBuilder<CommandSource> build() {
LiteralArgumentBuilder<CommandSource> node = literal(getName());
node.executes(context -> {
Helper.printChatMessage("Version information " + Constants.VERSION);
for (Command command : ParadiseClient_Fabric.getCommandManager().getCommands())
Helper.printChatMessage(command.getName() + " " +command.getDescription());
return SINGLE_SUCCESS;
});

ParadiseClient_Fabric.getCommandManager().getCommands().forEach(c -> {
if (c != this) node.then(c.build());
});

return node;
}
}
}

0 comments on commit a28ed98

Please sign in to comment.