-
Notifications
You must be signed in to change notification settings - Fork 5
/
MySQL.java
146 lines (128 loc) · 3.48 KB
/
MySQL.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* iConomy v1.x
* Copyright (C) 2010 Nijikokun <nijikokun@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* MySQL.java
* <br /><br />
* Controls MySQL Queries & Connections for the plugin, not data.
*
* @author Nijikokun <nijikokun@gmail.com>
*/
public class MySQL {
public MySQL() {
}
public static void Rank(String checking, Player viewing, boolean mine) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
int i = 1;
try {
conn = iData.MySQL();
ps = conn.prepareStatement("SELECT player,balance FROM iBalances ORDER BY balance DESC");
rs = ps.executeQuery();
while (rs.next()) {
if (mine) {
if (rs.getString("player").equalsIgnoreCase(checking)) {
Messaging.send(
viewing,
iConomy.MoneyTPL.color("tag") +
iConomy.MoneyTPL.parse(
"personal-rank",
new String[]{"+name,+n", "+rank,+r"},
new String[]{checking, Misc.string(i)}));
break;
}
} else {
if (rs.getString("player").equalsIgnoreCase(checking)) {
Messaging.send(
viewing,
iConomy.MoneyTPL.color("tag") +
iConomy.MoneyTPL.parse(
"player-rank",
new String[]{"+name,+n", "+rank,+r"},
new String[]{checking, Misc.string(i)}));
break;
}
}
i++;
}
} catch (SQLException ex) {
iConomy.log.severe(Messaging.bracketize(iConomy.name + " MySQL") + " Unable to grab the ranking from database!");
} finally {
try {
if (ps != null) {
ps.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException ex) {
}
}
return;
}
public static void Top(int amount) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
int i = 1;
try {
conn = iData.MySQL();
ps = conn.prepareStatement("SELECT player,balance FROM iBalances ORDER BY balance DESC LIMIT 0,?");
ps.setInt(1, amount);
rs = ps.executeQuery();
Messaging.send(
iConomy.MoneyTPL.parse(
"top-opening",
new String[]{"+amount,+a"},
new String[]{Misc.string(amount)}
)
);
if (rs != null) {
while (rs.next()) {
Messaging.send(
iConomy.MoneyTPL.parse(
"top-line",
new String[]{ "+i,+number", "+name,+n", "+balance,+b" },
new String[]{ Misc.string(i), rs.getString("player"), iConomy.Misc.formatCurrency(rs.getInt("balance"), iConomy.currency) }
)
);
i++;
}
} else {
Messaging.send(iConomy.MoneyTPL.color("top-empty"));
}
} catch (SQLException ex) {
iConomy.log.severe(Messaging.bracketize(iConomy.name + " MySQL") + " Unable to grab the top players from the database!");
} finally {
try {
if (ps != null) {
ps.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException ex) {
}
}
return;
}
}