auto reconnect to MySQL and added gm ability to translate messages send to player
This commit is contained in:
parent
e2fabea733
commit
200490c1b4
@ -5,3 +5,6 @@ mysql:
|
||||
password: "password"
|
||||
database: "minecraft"
|
||||
table: "playerLevel"
|
||||
message:
|
||||
syncError: "Couln't sync your experience"
|
||||
dbError: "An error occured while trying to save your experience to database"
|
@ -14,16 +14,20 @@ import fr.topeka.levelSync.sql.Sql;
|
||||
*/
|
||||
public class Main extends JavaPlugin{
|
||||
|
||||
Sql sql;
|
||||
private Sql _sql;
|
||||
public String msg_syncError, msg_dbError;
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
try {
|
||||
this.saveDefaultConfig();
|
||||
sql = new Sql(this);
|
||||
_sql = new Sql(this);
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvents(new EventsListener(this, sql), this);
|
||||
pm.registerEvents(new EventsListener(this, _sql), this);
|
||||
this.getLogger().info("[levelSync] Plugin enabled");
|
||||
msg_syncError = getConfig().getString("message.syncError");
|
||||
msg_dbError = getConfig().getString("message.dbError");
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
this.getLogger().warning("An error occured during loading, disabling plugin...");
|
||||
@ -33,7 +37,7 @@ public class Main extends JavaPlugin{
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
sql.closeConnection();
|
||||
_sql.closeConnection();
|
||||
this.getLogger().info("Plugin disabled");
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class EventsListener implements Listener {
|
||||
p.setLevel((int) values[0]);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage("Couln't sync your experience");
|
||||
p.sendMessage("[LevelSync] " + plugin.msg_syncError);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -46,7 +46,7 @@ public class EventsListener implements Listener {
|
||||
}
|
||||
}, 20L);
|
||||
}else {
|
||||
p.sendMessage("Couln't sync your experience");
|
||||
p.sendMessage("[LevelSync] " + plugin.msg_syncError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,11 +61,11 @@ public class EventsListener implements Listener {
|
||||
try {
|
||||
sql.setPlayerLevel(p);
|
||||
}catch(SQLException e) {
|
||||
p.sendMessage("An error occured while trying to save your experience to database");
|
||||
p.sendMessage("[LevelSync] " + plugin.msg_dbError);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else {
|
||||
p.sendMessage("An error occured while trying to save your experience to database");
|
||||
p.sendMessage("[LevelSync] " + plugin.msg_dbError);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,15 +16,19 @@ public class Sql {
|
||||
private Main plugin;
|
||||
|
||||
private String host, database, table, username, password;
|
||||
private int port = 3306;
|
||||
private int port;
|
||||
|
||||
public Sql(Main plugin) throws ClassNotFoundException, SQLException{
|
||||
this.plugin = plugin;
|
||||
this.loadConfig();
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
connection = DriverManager.getConnection("jdbc:mysql://"+ host + ":" + port + "/" + database, username, password);
|
||||
statement = connection.createStatement();
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + this.table + "`("
|
||||
this.connect();
|
||||
}
|
||||
|
||||
private void connect() throws SQLException{
|
||||
this.connection = DriverManager.getConnection("jdbc:mysql://"+ host + ":" + port + "/" + database + "?autoReconnect=true", username, password);
|
||||
this.statement = connection.createStatement();
|
||||
this.statement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + this.table + "`("
|
||||
+ "`uuid` VARCHAR(36) NOT NULL,"
|
||||
+ "`experience` FLOAT(2,1),"
|
||||
+ "`level` INT(6)"
|
||||
@ -84,8 +88,7 @@ public class Sql {
|
||||
|
||||
public boolean reConnect() {
|
||||
try {
|
||||
connection = DriverManager.getConnection("jdbc:mysql://"+ host + ":" + port + "/" + database, username, password);
|
||||
statement = connection.createStatement();
|
||||
this.connect();
|
||||
return true;
|
||||
}catch(SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
Loading…
Reference in New Issue
Block a user