mirror of
https://github.com/Zrips/Jobs.git
synced 2025-03-02 11:21:14 +01:00
Configurable encoding for mysql database
This commit is contained in:
parent
b2d88fc3d2
commit
ab38a64fb4
src/main/java/com/gamingmesh/jobs
@ -144,8 +144,7 @@ public class PlayerManager {
|
||||
if (player == null)
|
||||
return null;
|
||||
|
||||
if (players.containsKey(player.getName()))
|
||||
players.remove(player.getName().toLowerCase());
|
||||
players.remove(player.getName().toLowerCase());
|
||||
|
||||
return playersUUID.remove(player.getUniqueId());
|
||||
}
|
||||
@ -957,7 +956,6 @@ public class PlayerManager {
|
||||
if (c == null) {
|
||||
c = new ItemBonusCache(getInventoryBoost(player, prog));
|
||||
cj.put(prog, c);
|
||||
return c.getBoostMultiplier();
|
||||
}
|
||||
|
||||
return c.getBoostMultiplier();
|
||||
|
@ -32,17 +32,6 @@ public class JobsDAOData {
|
||||
private int level;
|
||||
private double experience;
|
||||
|
||||
/**
|
||||
* Constructor class for the DAO side of things.
|
||||
* @param job - the name of the job
|
||||
* @param level - the level of the job
|
||||
* @param experience - the experience of the job
|
||||
*/
|
||||
@Deprecated
|
||||
public JobsDAOData(String job, int level, int experience) {
|
||||
this(job, level, (double) experience);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor class for the DAO side of things.
|
||||
* @param job - the name of the job
|
||||
|
@ -62,20 +62,15 @@ public class JobsManager {
|
||||
Jobs.setDAO(dao);
|
||||
}
|
||||
|
||||
String username = "root";
|
||||
String password = "";
|
||||
String hostname = "localhost:3306";
|
||||
String database = "minecraft";
|
||||
String prefix = "jobs_";
|
||||
boolean certificate = false;
|
||||
boolean ssl = false;
|
||||
boolean autoReconnect = false;
|
||||
private String username = "root", password = "", hostname = "localhost:3306", database = "minecraft", prefix = "jobs_",
|
||||
characterEncoding = "utf8", encoding = "UTF-8";
|
||||
private boolean certificate = false, ssl = false, autoReconnect = false;
|
||||
|
||||
public void start() {
|
||||
ConfigReader c = Jobs.getGCManager().getConfig();
|
||||
c.addComment("storage.method", "storage method, can be MySQL or sqlite");
|
||||
String storageMethod = c.get("storage.method", "sqlite");
|
||||
c.addComment("mysql", "Requires Mysql.");
|
||||
c.addComment("mysql", "Requires Mysql");
|
||||
|
||||
username = c.get("mysql.username", c.getC().getString("mysql-username", "root"));
|
||||
password = c.get("mysql.password", c.getC().getString("mysql-password", ""));
|
||||
@ -85,6 +80,8 @@ public class JobsManager {
|
||||
certificate = c.get("mysql.verify-server-certificate", c.getC().getBoolean("verify-server-certificate", false));
|
||||
ssl = c.get("mysql.use-ssl", c.getC().getBoolean("use-ssl", false));
|
||||
autoReconnect = c.get("mysql.auto-reconnect", c.getC().getBoolean("auto-reconnect", true));
|
||||
characterEncoding = c.get("mysql.characterEncoding", "utf8");
|
||||
encoding = c.get("mysql.encoding", "UTF-8");
|
||||
|
||||
if (storageMethod.equalsIgnoreCase("mysql")) {
|
||||
DbType = DataBaseType.MySQL;
|
||||
@ -121,7 +118,8 @@ public class JobsManager {
|
||||
}
|
||||
|
||||
if (plugin.isEnabled()) {
|
||||
JobsMySQL data = new JobsMySQL(plugin, hostname, database, username, password, prefix, certificate, ssl, autoReconnect);
|
||||
JobsMySQL data = new JobsMySQL(plugin, hostname, database, username, password, prefix, certificate, ssl, autoReconnect,
|
||||
characterEncoding, encoding);
|
||||
data.initialize();
|
||||
return data;
|
||||
}
|
||||
|
@ -10,9 +10,11 @@ import com.gamingmesh.jobs.dao.JobsManager.DataBaseType;
|
||||
|
||||
public class JobsMySQL extends JobsDAO {
|
||||
|
||||
JobsMySQL(Jobs plugin, String hostname, String database, String username, String password, String prefix, boolean certificate, boolean ssl, boolean autoReconnect) {
|
||||
JobsMySQL(Jobs plugin, String hostname, String database, String username, String password, String prefix, boolean certificate, boolean ssl, boolean autoReconnect,
|
||||
String characterEncoding, String encoding) {
|
||||
super(plugin, "com.mysql.jdbc.Driver", "jdbc:mysql://" + hostname + "/" + database
|
||||
+ "?maxReconnects=1&useUnicode=true&characterEncoding=utf8&autoReconnect=" + autoReconnect + "&useSSL=" + ssl
|
||||
+ "?maxReconnects=1&characterEncoding=" + characterEncoding + "&encoding="
|
||||
+ encoding + "&useUnicode=true&autoReconnect=" + autoReconnect + "&useSSL=" + ssl
|
||||
+ "&verifyServerCertificate=" + certificate, username, password, prefix);
|
||||
setDbType(DataBaseType.MySQL);
|
||||
}
|
||||
@ -21,8 +23,10 @@ public class JobsMySQL extends JobsDAO {
|
||||
setUp();
|
||||
}
|
||||
|
||||
public JobsMySQL initialize(Jobs plugin, String hostname, String database, String username, String password, String prefix, boolean certificate, boolean ssl, boolean autoReconnect) {
|
||||
JobsMySQL dao = new JobsMySQL(plugin, hostname, database, username, password, prefix, certificate, ssl, autoReconnect);
|
||||
public JobsMySQL initialize(Jobs plugin, String hostname, String database, String username, String password, String prefix, boolean certificate, boolean ssl, boolean autoReconnect,
|
||||
String characterEncoding, String encoding) {
|
||||
JobsMySQL dao = new JobsMySQL(plugin, hostname, database, username, password, prefix, certificate, ssl, autoReconnect,
|
||||
characterEncoding, encoding);
|
||||
dao.setUp();
|
||||
return dao;
|
||||
}
|
||||
@ -44,18 +48,17 @@ public class JobsMySQL extends JobsDAO {
|
||||
JobsConnection conn = getConnection();
|
||||
if (conn == null)
|
||||
return null;
|
||||
PreparedStatement prest = null;
|
||||
|
||||
try {
|
||||
prest = conn.prepareStatement(query);
|
||||
return conn.prepareStatement(query);
|
||||
} catch (SQLException | NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return prest;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createTable(String query) {
|
||||
Statement statement = null;
|
||||
if (query == null || query.isEmpty()) {
|
||||
Jobs.consoleMsg("&cCould not create table: query is empty or null.");
|
||||
return false;
|
||||
@ -63,6 +66,7 @@ public class JobsMySQL extends JobsDAO {
|
||||
JobsConnection conn = getConnection();
|
||||
if (conn == null)
|
||||
return false;
|
||||
Statement statement = null;
|
||||
try {
|
||||
statement = conn.createStatement();
|
||||
statement.execute(query);
|
||||
|
@ -1,8 +1,6 @@
|
||||
package com.gamingmesh.jobs.dao;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
@ -48,13 +46,13 @@ public class JobsSQLite extends JobsDAO {
|
||||
JobsConnection conn = getConnection();
|
||||
if (conn == null)
|
||||
return null;
|
||||
PreparedStatement prest = null;
|
||||
|
||||
try {
|
||||
prest = conn.prepareStatement(query);
|
||||
return conn.prepareStatement(query);
|
||||
} catch (SQLException | NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return prest;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -79,10 +77,8 @@ public class JobsSQLite extends JobsDAO {
|
||||
|
||||
@Override
|
||||
public boolean isTable(String table) {
|
||||
DatabaseMetaData md = null;
|
||||
try {
|
||||
md = getConnection().getMetaData();
|
||||
ResultSet tables = md.getTables(null, null, table, null);
|
||||
ResultSet tables = getConnection().getMetaData().getTables(null, null, table, null);
|
||||
if (tables.next()) {
|
||||
tables.close();
|
||||
return true;
|
||||
@ -97,10 +93,8 @@ public class JobsSQLite extends JobsDAO {
|
||||
|
||||
@Override
|
||||
public boolean isCollumn(String table, String collumn) {
|
||||
DatabaseMetaData md = null;
|
||||
try {
|
||||
md = getConnection().getMetaData();
|
||||
ResultSet tables = md.getColumns(null, null, table, collumn);
|
||||
ResultSet tables = getConnection().getMetaData().getColumns(null, null, table, collumn);
|
||||
if (tables.next()) {
|
||||
tables.close();
|
||||
return true;
|
||||
|
@ -6,8 +6,6 @@ public interface JobsTableInterface {
|
||||
|
||||
String getType();
|
||||
|
||||
// TablesFieldsType getFieldType();
|
||||
|
||||
boolean isUnique();
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user