stuff
This commit is contained in:
parent
48547a2c66
commit
dc1e189d38
25 changed files with 259 additions and 157 deletions
|
@ -29,6 +29,7 @@ public class CommandManager
|
|||
add(new Help());
|
||||
add(new Toggle());
|
||||
add(new Teleport());
|
||||
add(new SettingCommand());
|
||||
commands.sort(Comparator.comparing(Command::getName));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
package me.kawaiizenbo.moonlight.command;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
|
||||
import me.kawaiizenbo.moonlight.module.Module_;
|
||||
import me.kawaiizenbo.moonlight.module.ModuleManager;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class ModuleArgumentType implements ArgumentType<Module_>
|
||||
{
|
||||
private static final Collection<String> EXAMPLES = ModuleManager.INSTANCE.modules
|
||||
.stream()
|
||||
.limit(3)
|
||||
.map(module -> module.name)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
private static final DynamicCommandExceptionType NO_SUCH_MODULE = new DynamicCommandExceptionType(o ->
|
||||
Text.literal("Module with name " + o + " doesn't exist."));
|
||||
|
||||
public static ModuleArgumentType module()
|
||||
{
|
||||
return new ModuleArgumentType();
|
||||
}
|
||||
|
||||
public static Module_ getModule(final CommandContext<?> context, final String name)
|
||||
{
|
||||
return context.getArgument(name, Module_.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module_ parse(StringReader reader) throws CommandSyntaxException
|
||||
{
|
||||
String argument = reader.readString();
|
||||
Module_ module = ModuleManager.INSTANCE.getModuleByName(argument);
|
||||
|
||||
if (module == null) throw NO_SUCH_MODULE.create(argument);
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder)
|
||||
{
|
||||
return CommandSource.suggestMatching(ModuleManager.INSTANCE.modules.stream().map(module -> module.name), builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getExamples()
|
||||
{
|
||||
return EXAMPLES;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package me.kawaiizenbo.moonlight.command.commands;
|
||||
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
|
||||
import me.kawaiizenbo.moonlight.command.Command;
|
||||
import me.kawaiizenbo.moonlight.module.ModuleManager;
|
||||
import me.kawaiizenbo.moonlight.module.settings.BooleanSetting;
|
||||
import me.kawaiizenbo.moonlight.module.settings.DoubleSetting;
|
||||
import me.kawaiizenbo.moonlight.module.settings.KeycodeSetting;
|
||||
import me.kawaiizenbo.moonlight.module.settings.Setting;
|
||||
import me.kawaiizenbo.moonlight.module.settings.StringSetting;
|
||||
import me.kawaiizenbo.moonlight.util.ChatUtils;
|
||||
import me.kawaiizenbo.moonlight.util.ColorUtils;
|
||||
import me.kawaiizenbo.moonlight.module.Module;
|
||||
import net.minecraft.command.CommandSource;
|
||||
|
||||
public class SettingCommand extends Command
|
||||
{
|
||||
public SettingCommand()
|
||||
{
|
||||
super("setting", "Change a setting of a module.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<CommandSource> builder)
|
||||
{
|
||||
builder
|
||||
.then(argument("module", StringArgumentType.string())
|
||||
.then(argument("setting", StringArgumentType.string())
|
||||
.then(argument("value", StringArgumentType.string())
|
||||
.executes(context ->
|
||||
{
|
||||
String m = context.getArgument("module", String.class);
|
||||
String s = context.getArgument("setting", String.class);
|
||||
String v = context.getArgument("value", String.class);
|
||||
|
||||
Module module = ModuleManager.INSTANCE.getModuleByName(m);
|
||||
if (module == null)
|
||||
{
|
||||
ChatUtils.sendMsg(ColorUtils.red + "Invalid Module Name");
|
||||
return 0;
|
||||
}
|
||||
Setting setting = module.getSettingByName(s);
|
||||
if (setting == null)
|
||||
{
|
||||
ChatUtils.sendMsg(ColorUtils.red + "Invalid Setting Name");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// you can break this really easily and i dont feel like fixing it :3 have fun
|
||||
if (setting instanceof BooleanSetting)
|
||||
{
|
||||
((BooleanSetting)setting).value = Boolean.parseBoolean(v);
|
||||
}
|
||||
else if (setting instanceof DoubleSetting)
|
||||
{
|
||||
((DoubleSetting)setting).value = Double.parseDouble(v);
|
||||
}
|
||||
if (setting instanceof StringSetting)
|
||||
{
|
||||
((StringSetting)setting).value = v;
|
||||
}
|
||||
else if (setting instanceof KeycodeSetting)
|
||||
{
|
||||
((KeycodeSetting)setting).value = Integer.parseInt(v);
|
||||
}
|
||||
|
||||
return SINGLE_SUCCESS;
|
||||
}))));
|
||||
}
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package me.kawaiizenbo.moonlight.command.commands;
|
||||
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
|
||||
import me.kawaiizenbo.moonlight.command.Command;
|
||||
import me.kawaiizenbo.moonlight.command.ModuleArgumentType;
|
||||
import me.kawaiizenbo.moonlight.module.Module_;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import me.kawaiizenbo.moonlight.module.ModuleManager;
|
||||
import me.kawaiizenbo.moonlight.module.Module;
|
||||
import net.minecraft.command.CommandSource;
|
||||
|
||||
public class Toggle extends Command
|
||||
|
@ -19,13 +19,12 @@ public class Toggle extends Command
|
|||
@Override
|
||||
public void build(LiteralArgumentBuilder<CommandSource> builder)
|
||||
{
|
||||
builder.then(argument("module", new ModuleArgumentType()).executes(context ->
|
||||
builder.then(argument("module", StringArgumentType.string())
|
||||
.executes(context ->
|
||||
{
|
||||
ClientPlayerEntity player = mc.player;
|
||||
assert player != null;
|
||||
|
||||
Module_ m = context.getArgument("module", Module_.class);
|
||||
m.toggle();
|
||||
String m = context.getArgument("module", String.class);
|
||||
Module module = ModuleManager.INSTANCE.getModuleByName(m);
|
||||
module.toggle();
|
||||
|
||||
return SINGLE_SUCCESS;
|
||||
}));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue