Little changes (look comments)

This commit is contained in:
Lukas
2015-01-08 21:32:38 +01:00
parent 5c70ba6926
commit a2d91f0bd2

View File

@@ -26,34 +26,30 @@ import org.bukkit.plugin.messaging.PluginMessageListener;
public class VotifierListener implements Listener, PluginMessageListener { public class VotifierListener implements Listener, PluginMessageListener {
private int timestampInt;
private int votesInRow;
private int playerId;
@EventHandler @EventHandler
public void onVotifierEvent(VotifierEvent event) { public void onVotifierEvent(VotifierEvent event) {
Vote vote = event.getVote(); Vote vote = event.getVote();
String timestamp = vote.getTimeStamp(); String timestamp = vote.getTimeStamp();
int timestampInt;
try { try {
timestampInt = Integer.parseInt(timestamp); timestampInt = Integer.parseInt(timestamp);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
timestampInt = (int) (System.currentTimeMillis() / 1000); timestampInt = (int) (System.currentTimeMillis() / 1000);
} }
System.out.println("Got vote from " + vote.getServiceName() + " Username: " + vote.getUsername() + " with Adress: " + vote.getAddress() + " @ " + vote.getTimeStamp());
try { try {
ResultSet rs1 = Core.getMySql().querySelect("SELECT id FROM `players` WHERE name = '" + vote.getUsername() + "'"); ResultSet rs1 = Core.getMySql().querySelect("SELECT id FROM `players` WHERE name = '" + vote.getUsername() + "'");
if (!rs1.next()) { if (!rs1.next()) {
System.out.println("Database doesn't contain player!");
return; return;
} }
System.out.println("Found Player in Database!");
addPlayerMoney(25, vote); addPlayerMoney(25, vote);
int playerId;
playerId = rs1.getInt("id"); playerId = rs1.getInt("id");
ResultSet rs2 = Core.getMySql().querySelect("SELECT * FROM `voteUsers` WHERE playerId = '" + playerId + "'"); ResultSet rs2 = Core.getMySql().querySelect("SELECT * FROM `voteUsers` WHERE playerId = '" + playerId + "'");
if (rs2.first()) { if (rs2.first()) {
int lastVoteDate = rs2.getInt("dateOfLastVote"); int lastVoteDate = rs2.getInt("dateOfLastVote");
int votesInRow;
votesInRow = rs2.getInt("votesInARow"); votesInRow = rs2.getInt("votesInARow");
if (lastVoteDate > ((System.currentTimeMillis() / 1000) - 86400)) { if (lastVoteDate > ((System.currentTimeMillis() / 1000) - (60*60*24))) {
votesInRow++; votesInRow++;
if (votesInRow == 10) { if (votesInRow == 10) {
addPlayerMoney(50, vote); addPlayerMoney(50, vote);