RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.game.service.VoteService Class Reference
Collaboration diagram for com.runehive.game.service.VoteService:

Static Public Member Functions

static void claimReward (Player player)

Static Private Attributes

static final String CONNECTION_STRING = "jdbc:mysql://173.82.152.23:3306/osroyjs_vote"
static final Logger logger = LogManager.getLogger(VoteService.class)
static final String PASS = "3AXbU=W7IfzX"
static final Item REWARD = new Item(7478, 1)
static final String USER = "osroyjs_exo1"

Detailed Description

Definition at line 14 of file VoteService.java.

Member Function Documentation

◆ claimReward()

void com.runehive.game.service.VoteService.claimReward ( Player player)
static

Definition at line 22 of file VoteService.java.

22 {
23 if (!player.databaseRequest.elapsed(1, TimeUnit.MINUTES)) {
24 player.dialogueFactory.sendStatement("You can only check our database once every 1 minute!").execute();
25 return;
26 }
27
28 if (!player.inventory.hasCapacityFor(REWARD)) {
29 player.dialogueFactory.sendStatement("Please clear up some inventory spaces before doing this!").execute();
30 return;
31 }
32
33 boolean found = false;
34 player.dialogueFactory.sendStatement("Checking request...").execute();
35 player.databaseRequest.reset();
36
37 try (Connection connection = DriverManager.getConnection(CONNECTION_STRING, USER, PASS);
38 PreparedStatement sta = connection.prepareStatement("SELECT * FROM fx_votes WHERE username = ? AND claimed=0 AND callback_date IS NOT NULL", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)) {
39
40 sta.setString(1, player.getName().replace(" ", "_"));
41
42 try (ResultSet rs = sta.executeQuery()) {
43 while (rs.next()) {
44 String timestamp = rs.getTimestamp("callback_date").toString();
45 String ipAddress = rs.getString("ip_address");
46 int siteId = rs.getInt("site_id");
47
48 found = true;
49 player.inventory.add(REWARD);
50 player.totalVotes += 1;
51 logger.info(String.format("[Vote] Vote claimed by %s. (sid: %d, ip: %s, time: %s)", player.getName(), siteId, ipAddress, timestamp));
52 rs.updateInt("claimed", 1); // do not delete otherwise they can reclaim!
53 rs.updateRow();
54 }
55 }
56
57 if (!found) {
58 player.dialogueFactory.sendStatement("There is no vote reward for you to claim!").execute();
59 } else {
60 AchievementHandler.activate(player, AchievementKey.VOTE);
61 player.dialogueFactory.sendStatement("Thank-you for your support, " + player.getName() + "!").execute();
62 World.sendMessage("<col=CF2192>osroyale: <col=" + player.right.getColor() + ">" + player.getName() + " </col>has just voted! They have voted a total of <col=CF2192>" + player.totalVotes + " </col>times.");
63 }
64 } catch (SQLException ex) {
65 logger.error(String.format("Error claiming vote for player=%s", player.getName()), ex);
66 }
67 }

References com.runehive.content.achievement.AchievementHandler.activate(), com.runehive.game.world.items.containers.ItemContainer.add(), CONNECTION_STRING, com.runehive.game.world.entity.mob.player.Player.databaseRequest, com.runehive.game.world.entity.mob.player.Player.dialogueFactory, com.runehive.util.Stopwatch.elapsed(), com.runehive.content.dialogue.DialogueFactory.execute(), com.runehive.game.world.entity.mob.player.PlayerRight.getColor(), com.runehive.game.world.entity.mob.player.Player.getName(), com.runehive.game.world.items.containers.ItemContainer.hasCapacityFor(), com.runehive.game.world.entity.mob.player.Player.inventory, logger, PASS, com.runehive.util.Stopwatch.reset(), REWARD, com.runehive.game.world.entity.mob.player.Player.right, com.runehive.game.world.World.sendMessage(), com.runehive.content.dialogue.DialogueFactory.sendStatement(), com.runehive.game.world.entity.mob.player.Player.totalVotes, USER, and com.runehive.content.achievement.AchievementKey.VOTE.

Here is the call graph for this function:

Member Data Documentation

◆ CONNECTION_STRING

final String com.runehive.game.service.VoteService.CONNECTION_STRING = "jdbc:mysql://173.82.152.23:3306/osroyjs_vote"
staticprivate

Definition at line 17 of file VoteService.java.

Referenced by claimReward().

◆ logger

final Logger com.runehive.game.service.VoteService.logger = LogManager.getLogger(VoteService.class)
staticprivate

Definition at line 16 of file VoteService.java.

Referenced by claimReward().

◆ PASS

final String com.runehive.game.service.VoteService.PASS = "3AXbU=W7IfzX"
staticprivate

Definition at line 19 of file VoteService.java.

Referenced by claimReward().

◆ REWARD

final Item com.runehive.game.service.VoteService.REWARD = new Item(7478, 1)
staticprivate

Definition at line 20 of file VoteService.java.

Referenced by claimReward().

◆ USER

final String com.runehive.game.service.VoteService.USER = "osroyjs_exo1"
staticprivate

Definition at line 18 of file VoteService.java.

Referenced by claimReward().


The documentation for this class was generated from the following file: