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> { this(names, true); } - public Map call() throws Exception { - Map uuidMap = new HashMap(); - int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); - for (int i = 0; i < requests; i++) { - HttpURLConnection connection = createConnection(); - String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); - writeBody(connection, body); - JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); - for (Object profile : array) { - JSONObject jsonProfile = (JSONObject) profile; - String id = (String) jsonProfile.get("id"); - String name = (String) jsonProfile.get("name"); - UUID uuid = UUIDFetcher.getUUID(id); - uuidMap.put(name, uuid); - } - if (rateLimiting && i != requests - 1) { - Thread.sleep(100L); - } - } - return uuidMap; - } - private static void writeBody(HttpURLConnection connection, String body) throws Exception { OutputStream stream = connection.getOutputStream(); stream.write(body.getBytes()); @@ -90,7 +68,7 @@ public class UUIDFetcher implements Callable> { } private static UUID getUUID(String id) { - return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" +id.substring(20, 32)); + return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32)); } public static byte[] toBytes(UUID uuid) { @@ -113,4 +91,26 @@ public class UUIDFetcher implements Callable> { public static UUID getUUIDOf(String name) throws Exception { return new UUIDFetcher(Arrays.asList(name)).call().get(name); } + + public Map call() throws Exception { + Map uuidMap = new HashMap(); + int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); + for (int i = 0; i < requests; i++) { + HttpURLConnection connection = createConnection(); + String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); + writeBody(connection, body); + JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); + for (Object profile : array) { + JSONObject jsonProfile = (JSONObject) profile; + String id = (String) jsonProfile.get("id"); + String name = (String) jsonProfile.get("name"); + UUID uuid = UUIDFetcher.getUUID(id); + uuidMap.put(name, uuid); + } + if (rateLimiting && i != requests - 1) { + Thread.sleep(100L); + } + } + return uuidMap; + } } \ No newline at end of file diff --git a/src/main/java/li/inc/PlaytimeReloaded/Playtime.java b/src/main/java/li/inc/PlaytimeReloaded/Playtime.java index 1cb15a5..3666e3c 100644 --- a/src/main/java/li/inc/PlaytimeReloaded/Playtime.java +++ b/src/main/java/li/inc/PlaytimeReloaded/Playtime.java @@ -1,31 +1,29 @@ /* -* 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; import li.inc.PlaytimeReloaded.DataStore.Config; import li.inc.PlaytimeReloaded.DataStore.DB.DB; -import li.inc.PlaytimeReloaded.DataStore.DB.MySQL; import li.inc.PlaytimeReloaded.DataStore.TimeCommand; import li.inc.PlaytimeReloaded.DataStore.UUIDCache; -import li.inc.PlaytimeReloaded.DataStore.UUIDFetcher; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; @@ -36,22 +34,34 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.plugin.java.JavaPlugin; -import java.util.*; + +import java.util.List; +import java.util.UUID; -public class Playtime extends JavaPlugin implements Listener -{ +public class Playtime extends JavaPlugin implements Listener { private Config m_config = null; private DB m_db = null; + public static boolean isInteger(String s) { + try { + Integer.parseInt(s); + } catch (NumberFormatException e) { + return false; + } catch (NullPointerException e) { + return false; + } + // only got here if we didn't return false + return true; + } + @Override - public void onEnable() - { + public void onEnable() { //Load config from file into Config class. m_config = new Config(this); //Load the text from the lang config. - if(m_db == null) + if (m_db == null) m_db = new DB(this, m_config); getServer().getPluginManager().registerEvents(this, this); @@ -59,125 +69,94 @@ public class Playtime extends JavaPlugin implements Listener int id = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { public void run() { refreshPlaytime(); - }}, 0, 1200); + } + }, 0, 1200); } @Override - public void onDisable() - { + public void onDisable() { //Load the text from the lang config. - if(m_db != null) - { + if (m_db != null) { m_db.close(); m_db = null; } } - public static boolean isInteger(String s) { - try { - Integer.parseInt(s); - } catch(NumberFormatException e) { - return false; - } catch(NullPointerException e) { - return false; - } - // only got here if we didn't return false - return true; - } - - public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) - { - if (cmd.getName().equalsIgnoreCase("toptime")) - { + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + if (cmd.getName().equalsIgnoreCase("toptime")) { int _count = 5; - if(args.length == 1) - { - if(isInteger(args[0])) - { + if (args.length == 1) { + if (isInteger(args[0])) { _count = Integer.parseInt(args[0]); } } - if (sender instanceof Player) - { - Player _player = (Player)sender; + if (sender instanceof Player) { + Player _player = (Player) sender; - if(_player.hasPermission("playtime.top")) - { + if (_player.hasPermission("playtime.top")) { _player.sendMessage(getChatMessage(m_config.getTextTopPlayerListHead(), _player.getName(), 0, _count, true)); List _topPlayers = m_db.getTopPlayers(_count); int _rang = 1; - for (String[] _playerData: _topPlayers) - { - if(_playerData.length >= 2) - { + for (String[] _playerData : _topPlayers) { + if (_playerData.length >= 2) { _player.sendMessage(getChatMessage(m_config.getTextPlayerEntry(), _playerData[0], Integer.parseInt(_playerData[1]), _rang++, true)); } } - }else{ + } else { _player.sendMessage(getChatMessage(m_config.getTextNoPermission(), _player.getName(), 0, 0, true)); } - }else{ + } else { this.getLogger().info(getChatMessage(m_config.getTextTopPlayerListHead(), "", 0, _count, false)); List _topPlayers = m_db.getTopPlayers(_count); int _rang = 1; - for (String[] _playerData: _topPlayers) - { - if(_playerData.length >= 2) - { + for (String[] _playerData : _topPlayers) { + if (_playerData.length >= 2) { this.getLogger().info(getChatMessage(m_config.getTextPlayerEntry(), _playerData[0], Integer.parseInt(_playerData[1]), _rang++, false)); } } } } - if (cmd.getName().equalsIgnoreCase("playtime")) - { - if(args.length == 0) - { + if (cmd.getName().equalsIgnoreCase("playtime")) { + if (args.length == 0) { //Player will seine eigene Playtime wissen. - if (sender instanceof Player) - { - Player _player = (Player)sender; + if (sender instanceof Player) { + Player _player = (Player) sender; - if(_player.hasPermission("playtime.use")) - { + if (_player.hasPermission("playtime.use")) { _player.sendMessage(getChatMessage(m_config.getTextYourCurrentPlaytime(), _player.getName(), m_db.getPlayerTime(_player.getUniqueId()), 0, true)); - }else{ + } else { _player.sendMessage(getChatMessage(m_config.getTextNoPermission(), _player.getName(), 0, 0, true)); } - }else{ + } else { this.getLogger().info("Ey you bread! You cant display the playtime from the console!"); } - }else{ + } else { //Player will andere Spielzeit wissen. UUID _searchPlayer = getPlayerUUID(args[0]); - if(_searchPlayer != null) - { + if (_searchPlayer != null) { //Spieler wurde gefunden. - if (sender instanceof Player) - { - Player _player = (Player)sender; - if(_player.hasPermission("playtime.use.others")) - { + if (sender instanceof Player) { + Player _player = (Player) sender; + if (_player.hasPermission("playtime.use.others")) { _player.sendMessage(getChatMessage(m_config.getTextPlayerPlaytimeIs(), args[0], m_db.getPlayerTime(_searchPlayer), 0, true)); - }else{ + } else { _player.sendMessage(getChatMessage(m_config.getTextNoPermission(), args[0], 0, 0, true)); } - }else{ + } else { this.getLogger().info(getChatMessage(m_config.getTextPlayerPlaytimeIs(), args[0], m_db.getPlayerTime(_searchPlayer), 0, false)); } - }else{ + } else { //Spieler wurde nicht gefunden / Hat noch nicht auf dem Server gespielt. - if (sender instanceof Player) - { - Player _player = (Player)sender; + if (sender instanceof Player) { + Player _player = (Player) sender; _player.sendMessage(getChatMessage(m_config.getTextPlayerNotFound(), "", 0, 0, true)); - }else{ + } else { this.getLogger().info(getChatMessage(m_config.getTextPlayerNotFound(), "", 0, 0, false)); } } @@ -188,10 +167,8 @@ public class Playtime extends JavaPlugin implements Listener } @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - if(event.getPlayer().hasPermission("playtime.use") && event.getPlayer().hasPermission("playtime.login")) - { + public void onPlayerJoin(PlayerJoinEvent event) { + if (event.getPlayer().hasPermission("playtime.use") && event.getPlayer().hasPermission("playtime.login")) { event.getPlayer().sendMessage(getChatMessage(m_config.getTextYourCurrentPlaytime(), event.getPlayer().getName(), m_db.getPlayerTime(event.getPlayer().getUniqueId()), 0, true)); } @@ -199,16 +176,13 @@ public class Playtime extends JavaPlugin implements Listener addPlayTime(event.getPlayer().getUniqueId(), 0); } - private void refreshPlaytime() - { - for(Player _dieserSpieler : getServer().getOnlinePlayers()) - { + private void refreshPlaytime() { + for (Player _dieserSpieler : getServer().getOnlinePlayers()) { addPlayTime(_dieserSpieler.getUniqueId(), 1); } } - private void addPlayTime(UUID _playerUUID, int _time) - { + private void addPlayTime(UUID _playerUUID, int _time) { int _spielerPlaytime = m_db.getPlayerTime(_playerUUID); _spielerPlaytime = _spielerPlaytime + _time; @@ -218,40 +192,35 @@ public class Playtime extends JavaPlugin implements Listener checkPlaytimeCommand(_playerUUID, _spielerPlaytime); } - private UUID getPlayerUUID(String _playerName) - { + private UUID getPlayerUUID(String _playerName) { Player _returnPlayer = Bukkit.getPlayerExact(_playerName); - if(_returnPlayer != null) + if (_returnPlayer != null) return _returnPlayer.getUniqueId(); - for(Player _dieserSpieler : getServer().getOnlinePlayers()) - { - if(_dieserSpieler.getName() == _playerName) - { + for (Player _dieserSpieler : getServer().getOnlinePlayers()) { + if (_dieserSpieler.getName() == _playerName) { return _dieserSpieler.getUniqueId(); } } UUID _playerUUID = UUIDCache.get(_playerName); - if(_playerUUID == null) + if (_playerUUID == null) return null; OfflinePlayer _offlinePlayer = Bukkit.getOfflinePlayer(_playerUUID); - if(_offlinePlayer != null) - { - if(!_offlinePlayer.hasPlayedBefore()) + if (_offlinePlayer != null) { + if (!_offlinePlayer.hasPlayedBefore()) return null; return _offlinePlayer.getUniqueId(); - }else{ - return null; + } else { + return null; } } - private long[] calculateTime(long seconds) - { + private long[] calculateTime(long seconds) { long sec = seconds % 60; long minutes = seconds % 3600 / 60; long hours = seconds % 86400 / 3600; @@ -260,33 +229,30 @@ public class Playtime extends JavaPlugin implements Listener return new long[]{days, hours, minutes, sec}; } - private String getTimeString(int _timeInMin) - { + private String getTimeString(int _timeInMin) { String _ausgabe = ""; long seconds = _timeInMin * 60; - if(seconds != 0) - { + if (seconds != 0) { long[] _time = calculateTime(seconds); - if(_time[0] > 0) + if (_time[0] > 0) _ausgabe += _time[0] + " " + m_config.getTextDateDays() + " "; - if(_time[1] > 0) + if (_time[1] > 0) _ausgabe += _time[1] + " " + m_config.getTextDateHours() + " "; - if(_time[2] > 0) + if (_time[2] > 0) _ausgabe += _time[2] + " " + m_config.getTextDateMinutes(); - }else{ + } else { _ausgabe += "0 " + m_config.getTextDateMinutes(); } return _ausgabe; } - private String getChatMessage(String _plainText, String _player, int _time, int _rang, boolean _color) - { + private String getChatMessage(String _plainText, String _player, int _time, int _rang, boolean _color) { String returnText = m_config.getTextPrefix() + _plainText; returnText = returnText.replace("%s", _player); @@ -296,20 +262,17 @@ public class Playtime extends JavaPlugin implements Listener returnText = ChatColor.translateAlternateColorCodes('&', returnText); - if(_color == false) + if (_color == false) returnText = ChatColor.stripColor(returnText); return returnText; } - private void checkPlaytimeCommand(UUID _player, int _time) - { + private void checkPlaytimeCommand(UUID _player, int _time) { List _timeCommands = m_config.getTimeCommandList(); - for (TimeCommand _tc: _timeCommands) - { - if(_tc.getTime() == _time) - { + for (TimeCommand _tc : _timeCommands) { + if (_tc.getTime() == _time) { String _commandWithParas = _tc.getCommand(); _commandWithParas = _commandWithParas.replace("%%player%%", UUIDCache.get(_player));