Refactor CommandsExecutor - is no longer static singleton

Preparing for change in Command#handle,
which is going to take a CommandContext as an additional argument.
This way we can pass in command dependencies in a safe way
instead of requiring them to access static methods.
This commit is contained in:
P0nk
2023-03-15 22:56:40 +01:00
parent a6a7a26ebc
commit eed94ec34a
6 changed files with 35 additions and 19 deletions

View File

@@ -25,6 +25,7 @@ import client.Character;
import client.Client;
import client.Family;
import client.SkillFactory;
import client.command.CommandContext;
import client.command.CommandsExecutor;
import client.inventory.Item;
import client.inventory.ItemFactory;
@@ -930,7 +931,6 @@ public class Server {
log.info("Cosmic is now online after {} ms.", initDuration.toMillis());
OpcodeConstants.generateOpcodeNames();
CommandsExecutor.getInstance();
for (Channel ch : this.getAllChannels()) {
ch.reloadEventScriptManager();
@@ -977,8 +977,10 @@ public class Server {
MakerProcessor makerProcessor = new MakerProcessor(new MakerInfoProvider(new MakerDao(connection)));
FredrickProcessor fredrickProcessor = new FredrickProcessor(noteService);
DropProvider dropProvider = new DropProvider(new DropDao(connection));
CommandContext commandContext = new CommandContext(dropProvider);
CommandsExecutor commandsExecutor = new CommandsExecutor(commandContext);
ChannelDependencies channelDependencies = new ChannelDependencies(noteService, fredrickProcessor,
makerProcessor, dropProvider);
makerProcessor, dropProvider, commandsExecutor);
PacketProcessor.registerGameHandlerDependencies(channelDependencies);

View File

@@ -34,6 +34,11 @@ import tools.PacketCreator;
public final class GeneralChatHandler extends AbstractPacketHandler {
private static final Logger log = LoggerFactory.getLogger(GeneralChatHandler.class);
private final CommandsExecutor commandsExecutor;
public GeneralChatHandler(CommandsExecutor commandsExecutor) {
this.commandsExecutor = commandsExecutor;
}
@Override
public void handlePacket(InPacket p, Client c) {
@@ -51,7 +56,7 @@ public final class GeneralChatHandler extends AbstractPacketHandler {
}
char heading = s.charAt(0);
if (CommandsExecutor.isCommand(c, s)) {
CommandsExecutor.getInstance().handle(c, s);
commandsExecutor.handle(c, s);
} else if (heading != '/') {
int show = p.readByte();
if (chr.getMap().isMuted() && !chr.isGM()) {
@@ -70,4 +75,4 @@ public final class GeneralChatHandler extends AbstractPacketHandler {
chr.getAutobanManager().spam(7);
}
}
}
}