Skip to content

Commit 657f791

Browse files
committed
Small improvement
1 parent efbd45e commit 657f791

3 files changed

Lines changed: 154 additions & 167 deletions

File tree

Lines changed: 154 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package fr.dgiproject;
2-
2+
33
import java.io.File;
44
import java.sql.Connection;
55
import java.sql.DriverManager;
@@ -9,172 +9,159 @@
99

1010
import org.bukkit.command.Command;
1111
import org.bukkit.command.CommandSender;
12-
import org.bukkit.entity.Player;
1312
import org.bukkit.plugin.PluginManager;
1413
import org.bukkit.plugin.java.JavaPlugin;
15-
16-
public final class UUIDSql extends JavaPlugin {
17-
18-
String[] dbInformation = new String[3];
19-
private final PlayerListener playerListener = new PlayerListener(this,dbInformation);
20-
@Override
21-
public void onEnable() {
22-
23-
24-
PluginManager pm = getServer().getPluginManager();
25-
26-
File config = new File(getDataFolder() + File.separator + "config.yml");
27-
28-
if (!config.exists())
29-
{
30-
getLogger().info("Creating configs file !");
31-
this.getConfig().addDefault("dbName", "userUUID");
32-
this.getConfig().addDefault("Username", "root");
33-
this.getConfig().addDefault("Password", "root");
34-
this.getConfig().addDefault("host", "jdbc:mysql://localhost:3306/");
35-
this.getConfig().options().copyDefaults(true);
36-
this.saveConfig();
37-
38-
}
39-
else
40-
{
41-
String dbURL = this.getConfig().getString("host")+this.getConfig().getString("dbName");
42-
String username = this.getConfig().getString("Username");
43-
String password = this.getConfig().getString("Password");
44-
45-
dbInformation[0] = dbURL;
46-
dbInformation[1] = username;
47-
dbInformation[2] = password;
48-
49-
}
50-
51-
52-
pm.registerEvents(playerListener, this);
53-
getLogger().info("Loaded !");
54-
55-
}
56-
57-
58-
@Override
59-
public void onDisable() {
60-
getLogger().info("Unloaded");
61-
}
62-
63-
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
64-
{
65-
if (commandLabel.equalsIgnoreCase("uuidSql"))
66-
{
67-
if (args.length != 0)
68-
{
69-
if (args[0].equalsIgnoreCase("name"))
70-
{
71-
if (args.length == 2)
72-
{
73-
sender.sendMessage("[UUIDSql]The name of "+args[1].toString()+" is Ringotter");
74-
75-
Connection dbCon = null;
76-
Statement stmt = null;
77-
ResultSet rs = null;
78-
79-
try {
80-
81-
String query = "SELECT COUNT(*) AS exist, username FROM userUUID WHERE uuid = '"+args[1].toString()+"' ";
82-
dbCon = DriverManager.getConnection(dbInformation[0], dbInformation[1], dbInformation[2]);
83-
84-
stmt = dbCon.prepareStatement(query);
85-
rs = stmt.executeQuery(query);
86-
while(rs.next()){
87-
int count = rs.getInt(1);
88-
if (count != 0)
89-
{
90-
sender.sendMessage("[UUIDSql]The username of uuid "+args[1].toString()+" is "+rs.getString(2)+"");
91-
}
92-
else
93-
{
94-
sender.sendMessage("This uuid was not found in the database");
95-
}
96-
}
97-
dbCon.close();
98-
} catch (SQLException e) {
99-
// TODO Auto-generated catch block
100-
this.getLogger().warning("an error occured while connecting to the db, please change the config file."+e.getMessage());
101-
}
102-
103-
}
104-
else
105-
{
106-
sender.sendMessage("[UUIDSql]You must specify a uuid");
107-
}
108-
}
109-
else if (args[0].equalsIgnoreCase("uuid"))
110-
{
111-
if (args.length == 2)
112-
{
113-
Connection dbCon = null;
114-
Statement stmt = null;
115-
ResultSet rs = null;
116-
117-
try {
118-
119-
String query = "SELECT COUNT(*) AS exist, uuid FROM userUUID WHERE username = '"+args[1].toString()+"' ";
120-
dbCon = DriverManager.getConnection(dbInformation[0], dbInformation[1], dbInformation[2]);
121-
122-
stmt = dbCon.prepareStatement(query);
123-
rs = stmt.executeQuery(query);
124-
while(rs.next()){
125-
int count = rs.getInt(1);
126-
if (count != 0)
127-
{
128-
sender.sendMessage("[UUIDSql]The UUID of "+args[1].toString()+" is "+rs.getString(2)+"");
129-
}
130-
else
131-
{
132-
sender.sendMessage("This player was not found in the database");
133-
}
134-
}
135-
dbCon.close();
136-
} catch (SQLException e) {
137-
// TODO Auto-generated catch block
138-
this.getLogger().warning("an error occured while connecting to the db, please change the config file."+e.getMessage());
139-
}
140-
}
141-
else
142-
{
143-
sender.sendMessage("[UUIDSql]You must specify a name");
144-
}
14+
15+
public final class UUIDSql extends JavaPlugin {
16+
17+
String[] dbInformation = new String[3];
18+
private final PlayerListener playerListener = new PlayerListener(this,
19+
dbInformation);
20+
21+
@Override
22+
public void onEnable() {
23+
24+
PluginManager pm = getServer().getPluginManager();
25+
26+
File config = new File(getDataFolder() + File.separator + "config.yml");
27+
28+
if (!config.exists()) {
29+
getLogger().info("Creating configs file !");
30+
this.getConfig().addDefault("dbName", "userUUID");
31+
this.getConfig().addDefault("Username", "root");
32+
this.getConfig().addDefault("Password", "root");
33+
this.getConfig().addDefault("host", "jdbc:mysql://localhost:3306/");
34+
this.getConfig().options().copyDefaults(true);
35+
this.saveConfig();
36+
37+
} else {
38+
String dbURL = this.getConfig().getString("host")
39+
+ this.getConfig().getString("dbName");
40+
String username = this.getConfig().getString("Username");
41+
String password = this.getConfig().getString("Password");
42+
43+
dbInformation[0] = dbURL;
44+
dbInformation[1] = username;
45+
dbInformation[2] = password;
46+
47+
}
48+
49+
pm.registerEvents(playerListener, this);
50+
getLogger().info("Loaded !");
51+
52+
}
53+
54+
@Override
55+
public void onDisable() {
56+
getLogger().info("Unloaded");
57+
}
58+
59+
public boolean onCommand(CommandSender sender, Command cmd,
60+
String commandLabel, String[] args) {
61+
if (commandLabel.equalsIgnoreCase("uuidSql")) {
62+
if (args.length != 0) {
63+
if (args[0].equalsIgnoreCase("getname")) {
64+
if (args.length == 2) {
65+
Connection dbCon = null;
66+
Statement stmt = null;
67+
ResultSet rs = null;
68+
69+
try {
70+
71+
String query = "SELECT COUNT(*) AS exist, username FROM userUUID WHERE uuid = '"
72+
+ args[1].toString() + "' ";
73+
dbCon = DriverManager.getConnection(
74+
dbInformation[0], dbInformation[1],
75+
dbInformation[2]);
76+
77+
stmt = dbCon.prepareStatement(query);
78+
rs = stmt.executeQuery(query);
79+
while (rs.next()) {
80+
int count = rs.getInt(1);
81+
if (count != 0) {
82+
sender.sendMessage("[UUIDSql]The username of uuid "
83+
+ args[1].toString()
84+
+ " is "
85+
+ rs.getString(2) + "");
86+
} else {
87+
sender.sendMessage("[UUIDSql]This uuid was not found in the database");
88+
}
89+
}
90+
dbCon.close();
91+
} catch (SQLException e) {
92+
// TODO Auto-generated catch block
93+
this.getLogger()
94+
.warning(
95+
"[UUIDSql]An error occured while connecting to the db, please change the config file."
96+
+ e.getMessage());
97+
}
98+
99+
} else {
100+
sender.sendMessage("[UUIDSql]You must specify a uuid");
101+
}
102+
} else if (args[0].equalsIgnoreCase("getuuid")) {
103+
if (args.length == 2) {
104+
Connection dbCon = null;
105+
Statement stmt = null;
106+
ResultSet rs = null;
107+
108+
try {
109+
110+
String query = "SELECT COUNT(*) AS exist, uuid FROM userUUID WHERE username = '"
111+
+ args[1].toString() + "' ";
112+
dbCon = DriverManager.getConnection(
113+
dbInformation[0], dbInformation[1],
114+
dbInformation[2]);
115+
116+
stmt = dbCon.prepareStatement(query);
117+
rs = stmt.executeQuery(query);
118+
while (rs.next()) {
119+
int count = rs.getInt(1);
120+
if (count != 0) {
121+
sender.sendMessage("[UUIDSql]The UUID of "
122+
+ args[1].toString() + " is "
123+
+ rs.getString(2) + "");
124+
} else {
125+
sender.sendMessage("[UUIDSql]This player was not found in the database");
126+
}
127+
}
128+
dbCon.close();
129+
} catch (SQLException e) {
130+
// TODO Auto-generated catch block
131+
this.getLogger()
132+
.warning(
133+
"[UUIDSql]An error occured while connecting to the db, please change the config file."
134+
+ e.getMessage());
135+
}
136+
} else {
137+
sender.sendMessage("[UUIDSql]You must specify a name");
145138
}
146-
else if (args[0].equalsIgnoreCase("reload"))
147-
{
148-
sender.sendMessage("[UUIDSql]Reloading UUIDSql");
149-
150-
String dbURL = this.getConfig().getString("host")+this.getConfig().getString("dbName");
151-
String username = this.getConfig().getString("Username");
152-
String password = this.getConfig().getString("Password");
153-
154-
dbInformation[0] = dbURL;
155-
dbInformation[1] = username;
156-
dbInformation[2] = password;
157-
158-
sender.sendMessage("[UUIDSql]Reload Ended !");
159-
160-
161-
}
162-
else
163-
{
164-
sender.sendMessage("[UUIDSql]There is a problem, this command doen't exist !");
165-
}
166-
}
167-
else
168-
{
169-
sender.sendMessage("Availbale commands");
170-
sender.sendMessage("1. uuidsql reload");
171-
sender.sendMessage("2. uuidsql name <uuid>");
172-
sender.sendMessage("3. uuidsql uuid <name>");
173-
}
174-
175-
}
176-
return false;
177-
178-
}
179-
180-
}
139+
} else if (args[0].equalsIgnoreCase("reload")) {
140+
141+
String dbURL = this.getConfig().getString("host")
142+
+ this.getConfig().getString("dbName");
143+
String username = this.getConfig().getString("Username");
144+
String password = this.getConfig().getString("Password");
145+
146+
dbInformation[0] = dbURL;
147+
dbInformation[1] = username;
148+
dbInformation[2] = password;
149+
150+
sender.sendMessage("[UUIDSql]Reloaded");
151+
152+
} else {
153+
sender.sendMessage("[UUIDSql]There is a problem, this command doen't exist !");
154+
}
155+
} else {
156+
sender.sendMessage("Availbale commands");
157+
sender.sendMessage("1. uuidsql reload");
158+
sender.sendMessage("2. uuidsql getName <uuid>");
159+
sender.sendMessage("3. uuidsql getUuid <name>");
160+
}
161+
162+
}
163+
return false;
164+
165+
}
166+
167+
}

target/UUIDtoSQL-0.2.jar

33 Bytes
Binary file not shown.
14 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)