diff --git a/src/main/java/li/inc/PlaytimeReloaded/DataStore/Config.java b/src/main/java/li/inc/PlaytimeReloaded/DataStore/Config.java
index 6f73556..3b1a8e6 100644
--- a/src/main/java/li/inc/PlaytimeReloaded/DataStore/Config.java
+++ b/src/main/java/li/inc/PlaytimeReloaded/DataStore/Config.java
@@ -1,22 +1,22 @@
/*
-* Copyright (c) 2016
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
-*
-* PlaytimeReloaded 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 3 of the License, or
-* (at your option) any later version.
-*
-* PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
-*/
+ * Copyright (c) 2016
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
+ *
+ * PlaytimeReloaded 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
+ */
package li.inc.PlaytimeReloaded.DataStore;
@@ -26,121 +26,111 @@ import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
import java.util.List;
-public class Config
-{
+public class Config {
//DBType
private String m_DBType = "SQLLite";
- public String getDBType()
- {
+ //MySQL
+ private String m_MySqlHost = "127.0.0.1";
+ private int m_MySqlPort = 3306;
+ private String m_MySqlDB = "";
+ private String m_mySqlUserName = "USER";
+ private String m_mySqlPassword = "PASSWORD";
+ //Texte
+ private String m_textPrefix = "&6[&aPlayTime&6] &a";
+ private String m_textYourCurrentPlaytime = "Your current playtime is &6%t";
+ private String m_textPlayerPlaytimeIs = "The playtime from player &6%s&a is &6%t";
+ private String m_textPlayerNotFound = "&cThis player dont have play on this server.";
+ private String m_textTopPlayerListHead = "This is the Top %r player list.";
+ private String m_textPlayerEntry = "%r : %s - %t";
+ private String m_textNoPermission = "&cYou dont have permission to do this!";
+ private String m_textDateDays = "&aDays&6";
+ private String m_textDateHours = "&aHours&6";
+ private String m_textDateMinutes = "&aMinutes&a";
+ private List m_timeCommands = new ArrayList();
+ private Plugin m_plugin;
+
+ public Config(Plugin _plugin) {
+ m_plugin = _plugin;
+ setDefaultConfigValues(m_plugin.getConfig());
+ getConfigValues(m_plugin.getConfig());
+ saveConfigValues(m_plugin.getConfig());
+ }
+
+ public String getDBType() {
return m_DBType;
}
- //MySQL
- private String m_MySqlHost = "127.0.0.1";
- public String getMysqlHost()
- {
- return m_MySqlHost;
- }
+ public String getMysqlHost() {
+ return m_MySqlHost;
+ }
- private int m_MySqlPort = 3306;
- public int getMysqlPort()
- {
- return m_MySqlPort;
- }
+ public int getMysqlPort() {
+ return m_MySqlPort;
+ }
- private String m_MySqlDB = "";
- public String getMysqlDB()
- {
- return m_MySqlDB;
- }
+ public String getMysqlDB() {
+ return m_MySqlDB;
+ }
- private String m_mySqlUserName = "USER";
- public String getMysqlUsername()
- {
- return m_mySqlUserName;
- }
+ public String getMysqlUsername() {
+ return m_mySqlUserName;
+ }
- private String m_mySqlPassword = "PASSWORD";
- public String getMysqlPassword()
- {
- return m_mySqlPassword;
- }
+ public String getMysqlPassword() {
+ return m_mySqlPassword;
+ }
- //Texte
- private String m_textPrefix = "&6[&aPlayTime&6] &a";
- public String getTextPrefix()
- {
+ public String getTextPrefix() {
return m_textPrefix;
}
- private String m_textYourCurrentPlaytime = "Your current playtime is &6%t";
- public String getTextYourCurrentPlaytime()
- {
- return m_textYourCurrentPlaytime;
- }
+ public String getTextYourCurrentPlaytime() {
+ return m_textYourCurrentPlaytime;
+ }
- private String m_textPlayerPlaytimeIs = "The playtime from player &6%s&a is &6%t";
- public String getTextPlayerPlaytimeIs()
- {
+ public String getTextPlayerPlaytimeIs() {
return m_textPlayerPlaytimeIs;
}
- private String m_textPlayerNotFound = "&cThis player dont have play on this server.";
- public String getTextPlayerNotFound()
- {
+ public String getTextPlayerNotFound() {
return m_textPlayerNotFound;
}
- private String m_textTopPlayerListHead = "This is the Top %r player list.";
- public String getTextTopPlayerListHead()
- {
- return m_textTopPlayerListHead;
- }
+ public String getTextTopPlayerListHead() {
+ return m_textTopPlayerListHead;
+ }
- private String m_textPlayerEntry = "%r : %s - %t";
- public String getTextPlayerEntry()
- {
- return m_textPlayerEntry;
- }
+ public String getTextPlayerEntry() {
+ return m_textPlayerEntry;
+ }
- private String m_textNoPermission = "&cYou dont have permission to do this!";
- public String getTextNoPermission()
- {
+ public String getTextNoPermission() {
return m_textNoPermission;
}
- private String m_textDateDays = "&aDays&6";
- public String getTextDateDays()
- {
+ public String getTextDateDays() {
return m_textDateDays;
}
- private String m_textDateHours = "&aHours&6";
- public String getTextDateHours()
- {
+ public String getTextDateHours() {
return m_textDateHours;
}
- private String m_textDateMinutes = "&aMinutes&a";
- public String getTextDateMinutes()
- {
+ public String getTextDateMinutes() {
return m_textDateMinutes;
}
- private List m_timeCommands = new ArrayList();
- public List getTimeCommandList()
- {
+ public List getTimeCommandList() {
return m_timeCommands;
}
- private void setDefaultConfigValues(FileConfiguration _config)
- {
+ private void setDefaultConfigValues(FileConfiguration _config) {
_config.addDefault("DB.Type", m_DBType);
- _config.addDefault("mysql.host", m_MySqlHost);
- _config.addDefault("mysql.port", m_MySqlPort);
- _config.addDefault("mysql.db", m_MySqlDB);
- _config.addDefault("mysql.user", m_mySqlUserName);
+ _config.addDefault("mysql.host", m_MySqlHost);
+ _config.addDefault("mysql.port", m_MySqlPort);
+ _config.addDefault("mysql.db", m_MySqlDB);
+ _config.addDefault("mysql.user", m_mySqlUserName);
_config.addDefault("mysql.pass", m_mySqlPassword);
_config.addDefault("text.Prefix", m_textPrefix);
@@ -158,17 +148,16 @@ public class Config
_config.addDefault("text.TopPlayerEntry", m_textPlayerEntry);
_config.addDefault("timeCommand", m_timeCommands);
- }
-
- private void getConfigValues(FileConfiguration _config)
- {
+ }
+
+ private void getConfigValues(FileConfiguration _config) {
m_DBType = _config.getString("DB.Type");
- m_MySqlHost = _config.getString("mysql.host");
- m_MySqlPort = _config.getInt("mysql.port");
- m_MySqlDB = _config.getString("mysql.db");
- m_mySqlUserName = _config.getString("mysql.user");
- m_mySqlPassword = _config.getString("mysql.pass");
+ m_MySqlHost = _config.getString("mysql.host");
+ m_MySqlPort = _config.getInt("mysql.port");
+ m_MySqlDB = _config.getString("mysql.db");
+ m_mySqlUserName = _config.getString("mysql.user");
+ m_mySqlPassword = _config.getString("mysql.pass");
m_textPrefix = _config.getString("text.Prefix");
@@ -184,25 +173,22 @@ public class Config
m_textTopPlayerListHead = _config.getString("text.TopPlayerTitel");
m_textPlayerEntry = _config.getString("text.TopPlayerEntry");
- for (String _l: _config.getStringList("timeCommand"))
- {
+ for (String _l : _config.getStringList("timeCommand")) {
String[] _ld = _l.split(";");
- if(_ld.length == 2)
- {
+ if (_ld.length == 2) {
m_timeCommands.add(new TimeCommand(Integer.parseInt(_ld[0]), _ld[1]));
}
}
- }
-
- private void saveConfigValues(FileConfiguration _config)
- {
+ }
+
+ private void saveConfigValues(FileConfiguration _config) {
_config.set("DB.Type", m_DBType);
- _config.set("mysql.host", m_MySqlHost);
- _config.set("mysql.port", m_MySqlPort);
- _config.set("mysql.db", m_MySqlDB);
- _config.set("mysql.user", m_mySqlUserName);
+ _config.set("mysql.host", m_MySqlHost);
+ _config.set("mysql.port", m_MySqlPort);
+ _config.set("mysql.db", m_MySqlDB);
+ _config.set("mysql.user", m_mySqlUserName);
_config.set("mysql.pass", m_mySqlPassword);
_config.set("text.Prefix", m_textPrefix);
@@ -220,28 +206,17 @@ public class Config
_config.set("text.TopPlayerEntry", m_textPlayerEntry);
List _timeCommands = new ArrayList();
- for (TimeCommand _tc: m_timeCommands)
- {
+ for (TimeCommand _tc : m_timeCommands) {
_timeCommands.add(_tc.getTime() + ";" + _tc.getCommand());
}
_config.set("timeCommand", _timeCommands);
- m_plugin.saveConfig();
- }
+ m_plugin.saveConfig();
+ }
- private Plugin m_plugin;
- public Config(Plugin _plugin)
- {
- m_plugin = _plugin;
- setDefaultConfigValues(m_plugin.getConfig());
- getConfigValues(m_plugin.getConfig());
- saveConfigValues(m_plugin.getConfig());
- }
-
- public void reload()
- {
- m_plugin.reloadConfig();
- getConfigValues(m_plugin.getConfig());
- }
+ public void reload() {
+ m_plugin.reloadConfig();
+ getConfigValues(m_plugin.getConfig());
+ }
}
diff --git a/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/DB.java b/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/DB.java
index d02c7bf..3e2067f 100644
--- a/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/DB.java
+++ b/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/DB.java
@@ -6,38 +6,35 @@ import org.bukkit.plugin.Plugin;
import java.util.List;
import java.util.UUID;
-public class DB
-{
+public class DB {
private IDB m_DBClass = null;
- public DB(Plugin _plugin, Config _config)
- {
- if(_config.getDBType().trim().equalsIgnoreCase("mysql"))
+ public DB(Plugin _plugin, Config _config) {
+ if (_config.getDBType().trim().equalsIgnoreCase("mysql"))
m_DBClass = new MySQL();
- if(_config.getDBType().trim().equalsIgnoreCase("sqllite"))
+ if (_config.getDBType().trim().equalsIgnoreCase("sqllite"))
m_DBClass = new SQLLite();
- if(m_DBClass == null)
+ if (m_DBClass == null)
m_DBClass = new SQLLite();
m_DBClass.init(_plugin, _config);
}
- public void update(UUID _playerUUID, int _newTime)
- {
+ public void update(UUID _playerUUID, int _newTime) {
m_DBClass.update(_playerUUID, _newTime);
}
- public List getTopPlayers(int _count){ return m_DBClass.getTopPlayers(_count); }
+ public List getTopPlayers(int _count) {
+ return m_DBClass.getTopPlayers(_count);
+ }
- public int getPlayerTime(UUID _playerUUID)
- {
+ public int getPlayerTime(UUID _playerUUID) {
return m_DBClass.getPlayerTime(_playerUUID);
}
- public void close()
- {
+ public void close() {
m_DBClass.close();
}
}
diff --git a/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/IDB.java b/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/IDB.java
index 9082e86..e2a4c85 100644
--- a/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/IDB.java
+++ b/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/IDB.java
@@ -1,22 +1,22 @@
/*
-* Copyright (c) 2016
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
-*
-* PlaytimeReloaded 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 3 of the License, or
-* (at your option) any later version.
-*
-* PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
-*/
+ * Copyright (c) 2016
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
+ *
+ * PlaytimeReloaded 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
+ */
package li.inc.PlaytimeReloaded.DataStore.DB;
@@ -26,11 +26,14 @@ import org.bukkit.plugin.Plugin;
import java.util.List;
import java.util.UUID;
-public interface IDB
-{
+public interface IDB {
public void init(Plugin _plugin, Config _config);
+
public void update(UUID _playerUUID, int _newTime);
+
public List getTopPlayers(int _count);
+
public int getPlayerTime(UUID _playerUUID);
+
public void close();
}
diff --git a/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/MySQL.java b/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/MySQL.java
index 7fc3490..70e1242 100644
--- a/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/MySQL.java
+++ b/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/MySQL.java
@@ -1,22 +1,22 @@
/*
-* Copyright (c) 2016
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
-*
-* PlaytimeReloaded 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 3 of the License, or
-* (at your option) any later version.
-*
-* PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
-*/
+ * Copyright (c) 2016
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
+ *
+ * PlaytimeReloaded 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
+ */
package li.inc.PlaytimeReloaded.DataStore.DB;
@@ -30,49 +30,38 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
-public class MySQL implements IDB
-{
+public class MySQL implements IDB {
private Plugin m_plugin;
private Config m_config;
private MySQLTools m_MySqlTools;
- public void init(Plugin _plugin, Config _config)
- {
+ public void init(Plugin _plugin, Config _config) {
m_plugin = _plugin;
m_config = _config;
- try
- {
+ try {
m_MySqlTools = new MySQLTools(m_config.getMysqlHost(), m_config.getMysqlPort(), m_config.getMysqlDB(), m_config.getMysqlUsername(), m_config.getMysqlPassword());
m_MySqlTools.saveMySQLUpdate("CREATE TABLE IF NOT EXISTS playtime(playeruuid varchar(36), playtime int(6), PRIMARY KEY (playeruuid))", new String[]{});
- }catch(Exception _e)
- {
+ } catch (Exception _e) {
_plugin.getLogger().info("!!!!!!!!!!!! ERROR: CANT CONNECT TO MySQL Server !!!!!!!!!!!!");
}
}
- public void update(UUID _playerUUID, int _newTime)
- {
+ public void update(UUID _playerUUID, int _newTime) {
m_MySqlTools.saveMySQLUpdate("REPLACE INTO playtime (`playeruuid`, `playtime`) VALUES ('" + _playerUUID.toString() + "', '" + _newTime + "')", new String[]{});
}
- public List getTopPlayers(int _count)
- {
+ public List getTopPlayers(int _count) {
ResultSet _rs = m_MySqlTools.saveMySQLQuarry("SELECT * FROM playtime ORDER BY playtime DESC LIMIT " + _count, new String[]{});
List _returnList = new ArrayList();
- if(_rs != null)
- {
- try
- {
- while(_rs.next())
- {
- try
- {
+ if (_rs != null) {
+ try {
+ while (_rs.next()) {
+ try {
_returnList.add(new String[]{UUIDCache.get(UUID.fromString(_rs.getString("playeruuid"))), _rs.getString("playtime")});
- }catch(Exception _e)
- {
+ } catch (Exception _e) {
return new ArrayList();
}
}
@@ -84,36 +73,29 @@ public class MySQL implements IDB
return _returnList;
}
- public int getPlayerTime(UUID _playerUUID)
- {
+ public int getPlayerTime(UUID _playerUUID) {
ResultSet _rs = m_MySqlTools.saveMySQLQuarry("SELECT * FROM playtime WHERE `playeruuid` = '" + _playerUUID.toString() + "';", new String[]{});
- if(_rs != null)
- {
- try
- {
- while(_rs.next())
- {
- try
- {
+ if (_rs != null) {
+ try {
+ while (_rs.next()) {
+ try {
return _rs.getInt("playtime");
- }catch(Exception _e)
- {
+ } catch (Exception _e) {
return 0;
}
}
} catch (SQLException e) {
return 0;
}
- }else{
+ } else {
return 0;
}
return 0;
}
- public void close()
- {
+ public void close() {
try {
m_MySqlTools.getConnection().close();
} catch (SQLException throwables) {
diff --git a/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/MySQLTools.java b/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/MySQLTools.java
index de7e45b..9f488d6 100644
--- a/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/MySQLTools.java
+++ b/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/MySQLTools.java
@@ -1,128 +1,114 @@
/*
-* Copyright (c) 2016
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
-*
-* PlaytimeReloaded 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 3 of the License, or
-* (at your option) any later version.
-*
-* PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
-*/
+ * Copyright (c) 2016
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
+ *
+ * PlaytimeReloaded 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
+ */
package li.inc.PlaytimeReloaded.DataStore.DB;
import java.sql.*;
-public class MySQLTools
-{
- Connection m_MySQLConnection;
-
- String m_host;
- int m_port;
- String m_dbname;
- String m_username;
- String m_passwort;
-
- //Public Funktionen
-
- public MySQLTools(String _host, int _port, String _dbname, String _username, String _passwort)
- {
- m_host = _host;
- m_port = _port;
- m_dbname = _dbname;
- m_username = _username;
- m_passwort = _passwort;
+public class MySQLTools {
+ Connection m_MySQLConnection;
- m_MySQLConnection = createSQLConnection(m_host, m_port, m_dbname, m_username, m_passwort);
- }
-
- public Connection getConnection()
- {
- return m_MySQLConnection;
- }
-
-
- //Private Funktionen
-
- private Connection createSQLConnection(String _host, int _port, String _dbname, String _username, String _passwort)
- {
- Connection _MySQLConnection;
- try {
- _MySQLConnection = DriverManager.getConnection("jdbc:mysql://" + _host + ":" + _port + "/" + _dbname, _username, _passwort);
- _MySQLConnection.setAutoCommit(true);
+ String m_host;
+ int m_port;
+ String m_dbname;
+ String m_username;
+ String m_passwort;
- return _MySQLConnection;
- } catch (SQLException e) {
- e.printStackTrace();
- return null;
- }
- }
-
- private void pingConnection()
- {
- try {
- if(m_MySQLConnection.isClosed() || !m_MySQLConnection.isValid(3))
- {
- m_MySQLConnection.close();
- m_MySQLConnection = createSQLConnection(m_host, m_port, m_dbname, m_username, m_passwort);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- public void saveMySQLUpdate(String _quarry, String[] _values)
- {
- pingConnection();
+ //Public Funktionen
- try
- {
- PreparedStatement _ps = m_MySQLConnection.prepareStatement(_quarry);
-
- int index = 0;
- for( String _s: _values )
- {
- String thisValue = (String)_s;
- _ps.setString(++index, thisValue);
- }
+ public MySQLTools(String _host, int _port, String _dbname, String _username, String _passwort) {
+ m_host = _host;
+ m_port = _port;
+ m_dbname = _dbname;
+ m_username = _username;
+ m_passwort = _passwort;
- _ps.executeUpdate();
- }catch(Exception e)
- {
- e.printStackTrace();
- }
- }
-
- public ResultSet saveMySQLQuarry(String _quarry, String[] _values)
- {
- pingConnection();
+ m_MySQLConnection = createSQLConnection(m_host, m_port, m_dbname, m_username, m_passwort);
+ }
- try
- {
- PreparedStatement _ps = m_MySQLConnection.prepareStatement(_quarry);
+ public Connection getConnection() {
+ return m_MySQLConnection;
+ }
- int index = 0;
- for( String _s: _values )
- {
- String thisValue = (String)_s;
- _ps.setString(++index, thisValue);
- }
-
- return _ps.executeQuery();
- }catch(Exception e)
- {
- e.printStackTrace();
- return null;
- }
- }
+
+ //Private Funktionen
+
+ private Connection createSQLConnection(String _host, int _port, String _dbname, String _username, String _passwort) {
+ Connection _MySQLConnection;
+ try {
+ _MySQLConnection = DriverManager.getConnection("jdbc:mysql://" + _host + ":" + _port + "/" + _dbname, _username, _passwort);
+ _MySQLConnection.setAutoCommit(true);
+
+ return _MySQLConnection;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ private void pingConnection() {
+ try {
+ if (m_MySQLConnection.isClosed() || !m_MySQLConnection.isValid(3)) {
+ m_MySQLConnection.close();
+ m_MySQLConnection = createSQLConnection(m_host, m_port, m_dbname, m_username, m_passwort);
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void saveMySQLUpdate(String _quarry, String[] _values) {
+ pingConnection();
+
+ try {
+ PreparedStatement _ps = m_MySQLConnection.prepareStatement(_quarry);
+
+ int index = 0;
+ for (String _s : _values) {
+ String thisValue = (String) _s;
+ _ps.setString(++index, thisValue);
+ }
+
+ _ps.executeUpdate();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public ResultSet saveMySQLQuarry(String _quarry, String[] _values) {
+ pingConnection();
+
+ try {
+ PreparedStatement _ps = m_MySQLConnection.prepareStatement(_quarry);
+
+ int index = 0;
+ for (String _s : _values) {
+ String thisValue = (String) _s;
+ _ps.setString(++index, thisValue);
+ }
+
+ return _ps.executeQuery();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
}
diff --git a/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/SQLLite.java b/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/SQLLite.java
index eb2e112..405a691 100644
--- a/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/SQLLite.java
+++ b/src/main/java/li/inc/PlaytimeReloaded/DataStore/DB/SQLLite.java
@@ -1,22 +1,22 @@
/*
-* Copyright (c) 2016
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
-*
-* PlaytimeReloaded 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 3 of the License, or
-* (at your option) any later version.
-*
-* PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
-*/
+ * Copyright (c) 2016
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
+ *
+ * PlaytimeReloaded 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
+ */
package li.inc.PlaytimeReloaded.DataStore.DB;
@@ -29,20 +29,16 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
-public class SQLLite implements IDB
-{
+public class SQLLite implements IDB {
+ Connection m_connection = null;
private Plugin m_plugin;
private Config m_config;
- Connection m_connection = null;
-
- public void init(Plugin _plugin, Config _config)
- {
+ public void init(Plugin _plugin, Config _config) {
m_plugin = _plugin;
m_config = _config;
- try
- {
+ try {
m_connection = DriverManager.getConnection("jdbc:sqlite:" + m_plugin.getDataFolder().getAbsolutePath() + "/playtime.db");
Statement _statement = m_connection.createStatement();
@@ -50,46 +46,37 @@ public class SQLLite implements IDB
_statement.executeUpdate("CREATE TABLE IF NOT EXISTS playtime(playeruuid varchar(36), playtime int(6))");
_statement.close();
- }catch (SQLException _ex) {
- _ex.printStackTrace();
+ } catch (SQLException _ex) {
+ _ex.printStackTrace();
}
}
- public void update(UUID _playerUUID, int _newTime)
- {
- try
- {
- if(m_connection != null)
- {
+ public void update(UUID _playerUUID, int _newTime) {
+ try {
+ if (m_connection != null) {
Statement _statement = m_connection.createStatement();
_statement.executeUpdate("DELETE FROM playtime WHERE playeruuid = '" + _playerUUID.toString() + "'");
_statement.executeUpdate("INSERT INTO playtime (`playeruuid`, `playtime`) VALUES ('" + _playerUUID.toString() + "', '" + _newTime + "')");
_statement.close();
}
- }catch (SQLException _ex) {
+ } catch (SQLException _ex) {
_ex.printStackTrace();
}
}
- public List getTopPlayers(int _count)
- {
+ public List getTopPlayers(int _count) {
List _returnList = new ArrayList();
- try
- {
- if(m_connection != null)
- {
+ try {
+ if (m_connection != null) {
Statement _statement = m_connection.createStatement();
ResultSet _results = _statement.executeQuery("SELECT * FROM playtime ORDER BY playtime DESC LIMIT " + _count);
- while (_results.next())
- {
- try
- {
+ while (_results.next()) {
+ try {
_returnList.add(new String[]{UUIDCache.get(UUID.fromString(_results.getString("playeruuid"))), _results.getString("playtime")});
- }catch(Exception _e)
- {
+ } catch (Exception _e) {
return new ArrayList();
}
}
@@ -97,29 +84,23 @@ public class SQLLite implements IDB
_results.close();
_statement.close();
}
- }catch (SQLException _ex) {
+ } catch (SQLException _ex) {
_ex.printStackTrace();
}
return _returnList;
}
- public int getPlayerTime(UUID _playerUUID)
- {
- try
- {
- if(m_connection != null)
- {
+ public int getPlayerTime(UUID _playerUUID) {
+ try {
+ if (m_connection != null) {
Statement _statement = m_connection.createStatement();
ResultSet _results = _statement.executeQuery("SELECT * FROM playtime WHERE `playeruuid` = '" + _playerUUID.toString() + "'");
- while (_results.next())
- {
- try
- {
+ while (_results.next()) {
+ try {
return _results.getInt("playtime");
- }catch(Exception _e)
- {
+ } catch (Exception _e) {
return 0;
}
}
@@ -127,15 +108,14 @@ public class SQLLite implements IDB
_results.close();
_statement.close();
}
- }catch (SQLException _ex) {
+ } catch (SQLException _ex) {
_ex.printStackTrace();
}
return 0;
}
- public void close()
- {
+ public void close() {
try {
m_connection.close();
} catch (SQLException throwables) {
diff --git a/src/main/java/li/inc/PlaytimeReloaded/DataStore/PlayerObject.java b/src/main/java/li/inc/PlaytimeReloaded/DataStore/PlayerObject.java
index 92208fd..2527e34 100644
--- a/src/main/java/li/inc/PlaytimeReloaded/DataStore/PlayerObject.java
+++ b/src/main/java/li/inc/PlaytimeReloaded/DataStore/PlayerObject.java
@@ -1,45 +1,41 @@
/*
-* Copyright (c) 2016
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
-*
-* PlaytimeReloaded 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 3 of the License, or
-* (at your option) any later version.
-*
-* PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
-*/
+ * Copyright (c) 2016
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
+ *
+ * PlaytimeReloaded 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
+ */
package li.inc.PlaytimeReloaded.DataStore;
import java.util.UUID;
-public class PlayerObject
-{
+public class PlayerObject {
private UUID m_playerUUID;
private String m_playerName = "";
- public PlayerObject(UUID _playerUUID, String _playerName)
- {
+ public PlayerObject(UUID _playerUUID, String _playerName) {
m_playerUUID = _playerUUID;
m_playerName = _playerName;
}
- public UUID getUUID()
- {
+ public UUID getUUID() {
return m_playerUUID;
}
- public String getName()
- {
+ public String getName() {
return m_playerName;
}
}
diff --git a/src/main/java/li/inc/PlaytimeReloaded/DataStore/TimeCommand.java b/src/main/java/li/inc/PlaytimeReloaded/DataStore/TimeCommand.java
index d4a9270..2045040 100644
--- a/src/main/java/li/inc/PlaytimeReloaded/DataStore/TimeCommand.java
+++ b/src/main/java/li/inc/PlaytimeReloaded/DataStore/TimeCommand.java
@@ -1,42 +1,39 @@
/*
-* Copyright (c) 2016
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
-*
-* PlaytimeReloaded 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 3 of the License, or
-* (at your option) any later version.
-*
-* PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
-*/
+ * Copyright (c) 2016
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
+ *
+ * PlaytimeReloaded 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
+ */
package li.inc.PlaytimeReloaded.DataStore;
-public class TimeCommand
-{
+public class TimeCommand {
private int m_timeInMin = 0;
private String m_command = "";
- public int getTime()
- {
- return m_timeInMin;
- }
- public String getCommand()
- {
- return m_command;
- }
-
- public TimeCommand(int _time, String _command)
- {
+ public TimeCommand(int _time, String _command) {
m_timeInMin = _time;
m_command = _command;
}
+
+ public int getTime() {
+ return m_timeInMin;
+ }
+
+ public String getCommand() {
+ return m_command;
+ }
}
diff --git a/src/main/java/li/inc/PlaytimeReloaded/DataStore/UUIDCache.java b/src/main/java/li/inc/PlaytimeReloaded/DataStore/UUIDCache.java
index 0fb5e3c..7e2e59d 100644
--- a/src/main/java/li/inc/PlaytimeReloaded/DataStore/UUIDCache.java
+++ b/src/main/java/li/inc/PlaytimeReloaded/DataStore/UUIDCache.java
@@ -1,22 +1,22 @@
/*
-* Copyright (c) 2016
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
-*
-* PlaytimeReloaded 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 3 of the License, or
-* (at your option) any later version.
-*
-* PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
-*/
+ * Copyright (c) 2016
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
+ *
+ * PlaytimeReloaded 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
+ */
package li.inc.PlaytimeReloaded.DataStore;
@@ -25,16 +25,12 @@ import org.bukkit.Bukkit;
import java.util.*;
-public class UUIDCache
-{
+public class UUIDCache {
private static List m_players = new ArrayList();
- public static void update(String _playerName, UUID _playerUUID)
- {
- for (PlayerObject _dieserPlayer : m_players)
- {
- if(_dieserPlayer.getUUID() == _playerUUID)
- {
+ public static void update(String _playerName, UUID _playerUUID) {
+ for (PlayerObject _dieserPlayer : m_players) {
+ if (_dieserPlayer.getUUID() == _playerUUID) {
return;
}
}
@@ -42,18 +38,14 @@ public class UUIDCache
m_players.add(new PlayerObject(_playerUUID, _playerName));
}
- public static UUID get(String _playerName)
- {
- for (PlayerObject _dieserPlayer : m_players)
- {
- if(_dieserPlayer.getName() == _playerName)
- {
+ public static UUID get(String _playerName) {
+ for (PlayerObject _dieserPlayer : m_players) {
+ if (_dieserPlayer.getName() == _playerName) {
return _dieserPlayer.getUUID();
}
}
- try
- {
+ try {
UUIDFetcher _uuidFetcher = new UUIDFetcher(Arrays.asList(_playerName));
Map _fetcherResponse = _uuidFetcher.call();
UUID _playerUUID = _fetcherResponse.get(_playerName);
@@ -61,19 +53,15 @@ public class UUIDCache
update(_playerName, _playerUUID);
return _playerUUID;
- }catch(Exception _e)
- {
+ } catch (Exception _e) {
update(_playerName, null);
return null;
}
}
- public static String get(UUID _playerUUID)
- {
- for (PlayerObject _dieserPlayer : m_players)
- {
- if(_dieserPlayer.getUUID() == _playerUUID)
- {
+ public static String get(UUID _playerUUID) {
+ for (PlayerObject _dieserPlayer : m_players) {
+ if (_dieserPlayer.getUUID() == _playerUUID) {
return _dieserPlayer.getName();
}
}
diff --git a/src/main/java/li/inc/PlaytimeReloaded/DataStore/UUIDFetcher.java b/src/main/java/li/inc/PlaytimeReloaded/DataStore/UUIDFetcher.java
index f738b3f..63476ef 100644
--- a/src/main/java/li/inc/PlaytimeReloaded/DataStore/UUIDFetcher.java
+++ b/src/main/java/li/inc/PlaytimeReloaded/DataStore/UUIDFetcher.java
@@ -1,22 +1,22 @@
/*
-* Copyright (c) 2016
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
-*
-* PlaytimeReloaded 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 3 of the License, or
-* (at your option) any later version.
-*
-* PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
-*/
+ * Copyright (c) 2016
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * This file is part of the spigot Minecraft server plugin 'PlaytimeReloaded'.
+ *
+ * PlaytimeReloaded 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PlaytimeReloaded 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 PlaytimeReloaded. If not, see .
+ */
package li.inc.PlaytimeReloaded.DataStore;
@@ -49,28 +49,6 @@ public class UUIDFetcher implements Callable