RuneHive-Game
Loading...
Searching...
No Matches
DonationService.java
Go to the documentation of this file.
1package com.runehive.game.service;
2
3import com.runehive.content.dialogue.Expression;
4import com.runehive.content.donators.DonatorBond;
5import com.runehive.game.world.entity.mob.player.Player;
6import com.runehive.game.world.items.Item;
7import org.apache.logging.log4j.LogManager;
8import org.apache.logging.log4j.Logger;
9
10import java.sql.*;
11import java.util.concurrent.TimeUnit;
12
13public final class DonationService {
14 private static final Logger logger = LogManager.getLogger(DonationService.class);
15 private static final String USER = "osroyjs_exo1";
16 private static final String PASS = "3AXbU=W7IfzX";
17 private static final String CONNECTION_STRING = "jdbc:mysql://173.82.152.23:3306/osroyjs_store_2";
18
19 private DonationService() {
20
21 }
22
23 public static void claimDonation(Player player) {
24 if (!player.databaseRequest.elapsed(1, TimeUnit.MINUTES)) {
25 player.dialogueFactory.sendNpcChat(5523,"You can only check our database once every 1 minute!").execute();
26 return;
27 }
28
29 if (!player.inventory.isEmpty()) {
30 player.dialogueFactory.sendNpcChat(5523, Expression.SAD, "You must have an empty inventory to do this!").execute();
31 return;
32 }
33
34 player.dialogueFactory.sendStatement("Checking request...").execute();
35 boolean claimed = false;
36 player.databaseRequest.reset();
37
38 try(Connection connection = DriverManager.getConnection(CONNECTION_STRING, USER, PASS);
39 PreparedStatement sta = connection.prepareStatement("SELECT * FROM payments WHERE player_name = ? AND status='Completed' AND claimed=0", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)) {
40 sta.setString(1, player.getName().replace("_", " "));
41
42 ResultSet rs = sta.executeQuery();
43
44
45 while(rs.next()) {
46 final int itemNumber = rs.getInt("item_number");
47 final int quantity = rs.getInt("quantity");
48
49 switch(itemNumber) {
50 //$10 DONATOR BOND
51 case 10:
52 if (player.inventory.add(new Item(DonatorBond.BOND_10.item, quantity))) {
53 claimed = true;
54 }
55 break;
56
57 //$50 DONATOR BOND
58 case 20:
59 if (player.inventory.add(new Item(DonatorBond.BOND_50.item, quantity))) {
60 claimed = true;
61 }
62 break;
63
64 //$100 DONATOR BOND
65 case 21:
66 if (player.inventory.add(new Item(DonatorBond.BOND_100.item, quantity))) {
67 claimed = true;
68 }
69 break;
70
71 //$200 DONATOR BOND
72 case 22:
73 if (player.inventory.add(new Item(DonatorBond.BOND_200.item, quantity))) {
74 claimed = true;
75 }
76 break;
77
78 //$500 DONATOR BOND
79 case 23:
80 if (player.inventory.add(new Item(DonatorBond.BOND_500.item, quantity))) {
81 claimed = true;
82 }
83 break;
84 }
85
86 if (claimed) {
87 rs.updateInt("claimed", 1);
88 rs.updateRow();
89 }
90
91 }
92
93 if (!claimed) {
94 player.dialogueFactory.sendNpcChat(5523,"There is no donation reward for you to claim!").execute();
95 } else {
96 player.dialogueFactory.sendNpcChat(5523,"Thank-you for your donation!").execute();
97 }
98
99 } catch (SQLException ex) {
100 logger.error(String.format("Failed to claim donation for player=%s", player.getName()), ex);
101 }
102 }
103}
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
final DialogueFactory sendNpcChat(int id, String... lines)
Appends an NpcDialogue to the current dialogue chain.
final DialogueFactory sendStatement(String... lines)
Appends a StatementDialogue to the current dialogue chain.
This class represents a character controlled by a player.
Definition Player.java:125
String getName()
Gets the name of this entity.
Definition Player.java:774
The container class that represents an item that can be interacted with.
Definition Item.java:21
boolean add(Item item)
Attempts to deposit item into this container.
boolean elapsed(long time, TimeUnit unit)
Represents the expressions of entities for dialogue.
Holds all the donator bond data.