RuneHive-Game
Loading...
Searching...
No Matches
TradeLogEvent.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.items.Item;
8
9public class TradeLogEvent extends LogEvent {
10
11 private final Player player;
12 private final Item[] items;
13 private final Player other;
14 private final Item[] otherItems;
15
17 this.player = player;
18 this.items = items;
19 this.other = other;
20 this.otherItems = otherItems;
21 }
22
23 @Override
24 public void onLog() throws Exception {
25 final JdbcSession session = new JdbcSession(PostgreService.getConnectionPool());
26
27 long logId = session.autocommit(false)
28 .sql("INSERT INTO log.log(log_time) VALUES (?::timestamp) RETURNING id")
29 .set(dateTime)
30 .insert(new SingleOutcome<>(Long.class));
31
32 for (Item item : items) {
33
34 if (item == null) {
35 continue;
36 }
37
38 session.sql("INSERT INTO log.trade_log(log_id, item_id, amount, sender_id, receiver_id) VALUES (?, ?, ?, ?, ?)")
39 .set(logId)
40 .set(item.getId())
41 .set(item.getAmount())
42 .set(player.getMemberId())
43 .set(other.getMemberId())
44 .execute();
45 }
46
47 for (Item item : otherItems) {
48 if (item == null) {
49 continue;
50 }
51 session.sql("INSERT INTO log.trade_log(log_id, item_id, amount, sender_id, receiver_id) VALUES (?, ?, ?, ?, ?)")
52 .set(logId)
53 .set(item.getId())
54 .set(item.getAmount())
55 .set(other.getMemberId())
56 .set(player.getMemberId())
57 .execute();
58
59 }
60
61 session.commit();
62
63 }
64
65}
TradeLogEvent(Player player, Item[] items, Player other, Item[] otherItems)
static HikariDataSource getConnectionPool()
This class represents a character controlled by a player.
Definition Player.java:125
The container class that represents an item that can be interacted with.
Definition Item.java:21