RuneHive-Game
Loading...
Searching...
No Matches
DropItemLogEvent.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 DropItemLogEvent extends LogEvent {
10 private final Player player;
11 private final GroundItem groundItem;
12
14 this.player = player;
15 this.groundItem = groundItem;
16 }
17
18 @Override
19 public void onLog() throws Exception {
20 if ((groundItem.item.getValue() * groundItem.item.getAmount()) < 250_000) {
21 return;
22 }
23
24 final JdbcSession session = new JdbcSession(PostgreService.getConnectionPool());
25 long logId = session.autocommit(false)
26 .sql("INSERT INTO log.log(log_time) VALUES (?::timestamp) RETURNING id")
27 .set(dateTime)
28 .insert(new SingleOutcome<>(Long.class));
29
30 session.sql("INSERT INTO log.drop_item_log(player_id, item_id, item_amount, log_id) VALUES (?, ?, ?, ?)")
31 .set(player.getMemberId())
32 .set(groundItem.item.getId())
33 .set(groundItem.item.getAmount())
34 .set(logId)
35 .execute()
36 .commit();
37 }
38
39}
DropItemLogEvent(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.