Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
200490c1b4 | ||
|
|
e2fabea733 | ||
|
|
6f9297c484 |
11
README.md
11
README.md
@@ -2,7 +2,9 @@
|
||||
|
||||
levelSync is a spigot plugin which help you to synchronize minecraft vanilla experience between yours servers using MySQL.
|
||||
|
||||
# Installation
|
||||
__IMPORTANT:__ This plugin do no support player in offline mode, please enable online-mode on bungeecord
|
||||
|
||||
## Installation
|
||||
|
||||
- Put the .jar file in your spigot (not bungeecord) plugin folder
|
||||
|
||||
@@ -10,7 +12,7 @@ levelSync is a spigot plugin which help you to synchronize minecraft vanilla exp
|
||||
|
||||
- restart server, enjoy !
|
||||
|
||||
# Configuration
|
||||
## Configuration
|
||||
|
||||
|
||||
|
||||
@@ -27,3 +29,8 @@ mysql:
|
||||
# table name, automatically created by the plugin
|
||||
table: "playerLevel"
|
||||
```
|
||||
|
||||
## Need help ?
|
||||
|
||||
you can discuss my plugin and ask for help here:
|
||||
https://www.spigotmc.org/threads/levelsync.434249/
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user