Fix HelpCommand not working without static CommandsExecutor

This commit is contained in:
P0nk
2023-03-31 07:57:31 +02:00
parent 699da37f06
commit 785f74ed21
7 changed files with 33 additions and 13 deletions

View File

@@ -6,5 +6,9 @@ import server.shop.ShopFactory;
/**
* @author Ponk
*/
public record CommandContext(DropProvider dropProvider, ShopFactory shopFactory) {
public record CommandContext(CommandsExecutor commandsExecutor, DropProvider dropProvider, ShopFactory shopFactory) {
public CommandContext with(CommandsExecutor ce) {
return new CommandContext(ce, this.dropProvider, this.shopFactory);
}
}

View File

@@ -52,7 +52,7 @@ public class CommandsExecutor {
private Pair<List<String>, List<String>> levelCommandsCursor;
public CommandsExecutor(CommandContext commandContext) {
this.commandContext = commandContext;
this.commandContext = commandContext.with(this);
registerCommands();
}

View File

@@ -28,6 +28,8 @@ import client.command.Command;
import client.command.CommandContext;
import constants.id.NpcId;
import java.util.Map;
public class HelpCommand extends Command {
{
setDescription("Show available commands.");
@@ -35,6 +37,7 @@ public class HelpCommand extends Command {
@Override
public void execute(Client client, String[] params, CommandContext ctx) {
client.getAbstractPlayerInteraction().openNpc(NpcId.STEWARD, "commands");
Map<String, Object> bindings = Map.of("ce", ctx.commandsExecutor());
client.getAbstractPlayerInteraction().openNpc(NpcId.STEWARD, "commands", bindings);
}
}