RuneHive-Game
Loading...
Searching...
No Matches
PickupItemLogEvent.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.ground.GroundItem;
8
9public class PickupItemLogEvent extends LogEvent {
10
11 private final Player player;
12 private final GroundItem groundItem;
13
15 this.player = player;
16 this.groundItem = groundItem;
17 }
18
19 @Override
20 public void onLog() throws Exception {
21 if ((groundItem.item.getValue() * groundItem.item.getAmount()) < 250_000) {
22 return;
23 }
24
25 JdbcSession session = new JdbcSession(PostgreService.getConnectionPool());
26 long logId = session.autocommit(false)
27 .sql("INSERT INTO log.log(log_time) VALUES (?::timestamp) RETURNING id")
28 .set(dateTime)
29 .insert(new SingleOutcome<>(Long.class));
30
31 session.sql("INSERT INTO log.pickup_item_log(player_id, log_id, item_id, item_amount) VALUES (?, ?, ?, ?)")
32 .set(player.getMemberId())
33 .set(logId)
34 .set(groundItem.item.getId())
35 .set(groundItem.item.getAmount())
36 .execute()
37 .commit();
38 }
39
40}
PickupItemLogEvent(Player player, GroundItem groundItem)
static HikariDataSource getConnectionPool()
This class represents a character controlled by a player.
Definition Player.java:125
Represents a single Ground item on the world map.