RuneHive-Game
Loading...
Searching...
No Matches
TradeLogEvent.java
Go to the documentation of this file.
1
package
com.runehive.game.event.impl.log;
2
3
import
com.jcabi.jdbc.JdbcSession;
4
import
com.jcabi.jdbc.SingleOutcome;
5
import
com.runehive.game.service.PostgreService;
6
import
com.runehive.game.world.entity.mob.player.Player;
7
import
com.runehive.game.world.items.Item;
8
9
public
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
16
public
TradeLogEvent
(
Player
player
,
Item
[]
items
,
Player
other
,
Item
[]
otherItems
) {
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
}
com.runehive.game.event.impl.log.LogEvent
Definition
LogEvent.java:10
com.runehive.game.event.impl.log.LogEvent.dateTime
final LocalDateTime dateTime
Definition
LogEvent.java:13
com.runehive.game.event.impl.log.TradeLogEvent.player
final Player player
Definition
TradeLogEvent.java:11
com.runehive.game.event.impl.log.TradeLogEvent.TradeLogEvent
TradeLogEvent(Player player, Item[] items, Player other, Item[] otherItems)
Definition
TradeLogEvent.java:16
com.runehive.game.event.impl.log.TradeLogEvent.items
final Item[] items
Definition
TradeLogEvent.java:12
com.runehive.game.event.impl.log.TradeLogEvent.other
final Player other
Definition
TradeLogEvent.java:13
com.runehive.game.event.impl.log.TradeLogEvent.onLog
void onLog()
Definition
TradeLogEvent.java:24
com.runehive.game.event.impl.log.TradeLogEvent.otherItems
final Item[] otherItems
Definition
TradeLogEvent.java:14
com.runehive.game.service.PostgreService
Definition
PostgreService.java:14
com.runehive.game.service.PostgreService.getConnectionPool
static HikariDataSource getConnectionPool()
Definition
PostgreService.java:35
com.runehive.game.world.entity.mob.player.Player
This class represents a character controlled by a player.
Definition
Player.java:125
com.runehive.game.world.items.Item
The container class that represents an item that can be interacted with.
Definition
Item.java:21