close db then plugin is disabled

This commit is contained in:
Chris 2020-12-28 09:10:40 +01:00
parent 78e65372d9
commit 752da189c2
5 changed files with 36 additions and 1 deletions

View File

@ -35,4 +35,9 @@ public class DB
{
return m_DBClass.getPlayerTime(_playerUUID);
}
public void close()
{
m_DBClass.close();
}
}

View File

@ -32,4 +32,5 @@ public interface IDB
public void update(UUID _playerUUID, int _newTime);
public List<String[]> getTopPlayers(int _count);
public int getPlayerTime(UUID _playerUUID);
public void close();
}

View File

@ -111,4 +111,13 @@ public class MySQL implements IDB
return 0;
}
public void close()
{
try {
m_MySqlTools.getConnection().close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}

View File

@ -133,4 +133,13 @@ public class SQLLite implements IDB
return 0;
}
public void close()
{
try {
m_connection.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}

View File

@ -52,7 +52,7 @@ public class Playtime extends JavaPlugin implements Listener
//Load the text from the lang config.
if(m_db == null)
m_db = new DB(this, m_config);
m_db = new DB(this, m_config);
getServer().getPluginManager().registerEvents(this, this);
@ -62,6 +62,17 @@ public class Playtime extends JavaPlugin implements Listener
}}, 0, 1200);
}
@Override
public void onDisable()
{
//Load the text from the lang config.
if(m_db != null)
{
m_db.close();
m_db = null;
}
}
public static boolean isInteger(String s) {
try {
Integer.parseInt(s);