RuneHive-Game
Loading...
Searching...
No Matches
CommandLogEvent.java
Go to the documentation of this file.
1package com.runehive.game.event.impl.log;
2
3import com.jcabi.jdbc.JdbcSession;
4import com.jcabi.jdbc.SingleOutcome;
5import com.runehive.game.service.PostgreService;
6import com.runehive.game.world.entity.mob.player.Player;
7import com.runehive.game.world.entity.mob.player.command.CommandParser;
8
9import java.util.Arrays;
10
11public class CommandLogEvent extends LogEvent {
12
13 private final Player player;
14 private final CommandParser parser;
15
17 this.player = player;
18 this.parser = parser;
19 }
20
21 @Override
22 public void onLog() throws Exception {
23 JdbcSession session = new JdbcSession(PostgreService.getConnectionPool());
24 long logId = session.autocommit(false)
25 .sql("INSERT INTO log.log(log_time) VALUES (?::timestamp) RETURNING id")
26 .set(dateTime)
27 .insert(new SingleOutcome<>(Long.class));
28
29 session.sql("INSERT INTO log.command_log(player_id, name, argument, log_id) VALUES (?, ?, ?, ?)")
30 .set(player.getMemberId())
31 .set(parser.getCommand())
32 .set(Arrays.toString(parser.getArguments()).replace("[", "").replace("]", ""))
33 .set(logId)
34 .execute()
35 .commit();
36 }
37
38}
CommandLogEvent(Player player, CommandParser parser)
static HikariDataSource getConnectionPool()
This class represents a character controlled by a player.
Definition Player.java:125