aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/ymc/acron/cmd/CmdResConsumer.java
blob: d22b77e103288d40471d576fbbb24d92f6aa432a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package moe.ymc.acron.cmd;

import com.mojang.brigadier.ResultConsumer;
import com.mojang.brigadier.context.CommandContext;
import io.netty.channel.Channel;
import moe.ymc.acron.s2c.response.EventCmdRes;
import moe.ymc.acron.serialization.Serializer;
import net.minecraft.server.command.ServerCommandSource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;

public class CmdResConsumer implements ResultConsumer<ServerCommandSource> {
    private static final Logger LOGGER = LogManager.getLogger();

    private final @NotNull Channel channel;
    private final int id;

    public CmdResConsumer(@NotNull Channel channel,
                  int id) {
        this.channel = channel;
        this.id = id;
    }

    @Override
    public void onCommandComplete(CommandContext<ServerCommandSource> context, boolean success, int result) {
        LOGGER.debug("onCommandComplete[{}]: {} {}",
                id,
                success,
                result);
        channel.writeAndFlush(Serializer.serialize(new EventCmdRes(id, success, result)));
    }
}