RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
TradeLogEvent.java
1package com.osroyale.game.event.impl.log;
2
3import com.jcabi.jdbc.JdbcSession;
4import com.jcabi.jdbc.SingleOutcome;
5import com.osroyale.game.service.PostgreService;
6import com.osroyale.game.world.entity.mob.player.Player;
7import com.osroyale.game.world.items.Item;
8
33
34public class TradeLogEvent extends LogEvent {
35
36 private final Player player;
37 private final Item[] items;
38 private final Player other;
39 private final Item[] otherItems;
40
41 public TradeLogEvent(Player player, Item[] items, Player other, Item[] otherItems) {
42 this.player = player;
43 this.items = items;
44 this.other = other;
45 this.otherItems = otherItems;
46 }
47
48 @Override
49 public void onLog() throws Exception {
50 final JdbcSession session = new JdbcSession(PostgreService.getConnectionPool());
51
52 long logId = session.autocommit(false)
53 .sql("INSERT INTO log.log(log_time) VALUES (?::timestamp) RETURNING id")
54 .set(dateTime)
55 .insert(new SingleOutcome<>(Long.class));
56
57 for (Item item : items) {
58
59 if (item == null) {
60 continue;
61 }
62
63 session.sql("INSERT INTO log.trade_log(log_id, item_id, amount, sender_id, receiver_id) VALUES (?, ?, ?, ?, ?)")
64 .set(logId)
65 .set(item.getId())
66 .set(item.getAmount())
67 .set(player.getMemberId())
68 .set(other.getMemberId())
69 .execute();
70 }
71
72 for (Item item : otherItems) {
73 if (item == null) {
74 continue;
75 }
76 session.sql("INSERT INTO log.trade_log(log_id, item_id, amount, sender_id, receiver_id) VALUES (?, ?, ?, ?, ?)")
77 .set(logId)
78 .set(item.getId())
79 .set(item.getAmount())
80 .set(other.getMemberId())
81 .set(player.getMemberId())
82 .execute();
83
84 }
85
86 session.commit();
87
88 }
89
90}