Skip to content

Commit

Permalink
alias command
Browse files Browse the repository at this point in the history
  • Loading branch information
AV306 committed Aug 3, 2023
1 parent 418cdab commit 8fcbbbd
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/main/java/me/av306/xenon/Xenon.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ private void initCommands()
{
new DebugCrashCommand();
new HelpCommand();
new BindCommand();
//new BindCommand();
new AliasCommand();
}

private void initFeatures()
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/me/av306/xenon/commands/AliasCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package me.av306.xenon.commands;

import me.av306.xenon.Xenon;
import me.av306.xenon.command.Command;
import me.av306.xenon.feature.IFeature;
import me.av306.xenon.util.KeybindUtil;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.input.Input;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;

public class AliasCommand extends Command
{
public AliasCommand()
{
super( "alias" );
}

@Override
public void execute( String[] args )
{
// args[0] is feature name, args[1] is new alias
try
{
IFeature feature = Xenon.INSTANCE.featureRegistry.get( args[0] );
String alias = args[1];

Xenon.INSTANCE.featureRegistry.put( alias, feature );

Xenon.INSTANCE.sendInfoMessage( "text.xenon.command.alias.success", args[0] );
}
catch ( NullPointerException npe )
{
// FIXME: We have a lot of repeated messages
Xenon.INSTANCE.sendErrorMessage( "text.xenon.command.unresolvable", this.name, args[0] );
}
catch ( ArrayIndexOutOfBoundsException oobe )
{
Xenon.INSTANCE.sendErrorMessage( "text.xenon.command.notenoughargs", this.name, args.length, 2 );
}
}
}
13 changes: 11 additions & 2 deletions src/main/java/me/av306/xenon/commands/BindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import me.av306.xenon.Xenon;
import me.av306.xenon.command.Command;
import me.av306.xenon.feature.IFeature;
import me.av306.xenon.util.KeybindUtil;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.input.Input;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;

public class BindCommand extends Command
Expand All @@ -22,8 +25,14 @@ public void execute( String[] args )
IFeature feature = Xenon.INSTANCE.featureRegistry.get( args[0] );
char key = args[1].charAt( 0 );

// Idk what the scancodes are :(
feature.getKeyBinding().setBoundKey( InputUtil.fromKeyCode( key, -1 ) );
feature.setKeyBinding( KeybindUtil.registerKeybind(
"key.xenon." + feature.getName()
.toLowerCase()
.replaceAll( " ", "" ),
key,
"category.xenon." + feature.getCategory()
)
);

Xenon.INSTANCE.sendInfoMessage( "text.xenon.command.bind.success", args[0], key );
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/me/av306/xenon/feature/IFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public abstract class IFeature
public void setName( String name ) { this.name = name; }

protected String category = "features";
public String getCategory() { return this.category; }

/**
* Whether the server wishes to force-disable the feature
Expand All @@ -51,6 +52,7 @@ public abstract class IFeature
*/
protected KeyBinding keyBinding;
public KeyBinding getKeyBinding() { return this.keyBinding; }
public void setKeyBinding( KeyBinding keybinding ) { this.keyBinding = keybinding; }

/**
* Sets whether this Feature should be hidden in FeatureList.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public final class FullKeyboardFeature extends IToggleableFeature

public FullKeyboardFeature()
{
super( "FullKeyboard", "fullkey", "fullkb" );
super( "FullKeyboard", "fullkey", "fullkb", "fkb" );

// Register extra keys
this.virtualLeftMouseKey = KeybindUtil.registerKeybind(
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/xenon/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@
"text.xenon.blackbox.ioexception.write": "An exception occurred while writing to the log file",
"text.xenon.blackbox.ioexception.disposal": "An exception occurred while cleaning up, you might want to restart your PC to clean up potential memory leaks",
"text.xenon.command.debugcrash.warning": "WARNING: This action will not save the world and may corrupt it. Pass the argument \"confirm\" to continue.",
"text.xenon.command.unresolvable": "[%s] Could not resolve feature: %s",
"text.xenon.command.notenoughargs": "[%s] Not enough arguments! %d provided, %d expected",
"text.xenon.command.bind.success": "[Bind] Successfully bound %s to %c",
"text.xenon.command.alias.success": "[%s] Successfully aliased %s to %s",
"text.xenon.command.bind.unresolvable": "[Bind] Could not resolve feature: %s",
"text.xenon.command.bind.notenoughargs": "[Bind] Not enough arguments! %d provided, 2 expected",
"text.xenon.commandprocessor.report": "> %s",
Expand Down

0 comments on commit 8fcbbbd

Please sign in to comment.