This repository has been archived on 2026-03-18. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
little-minecraft-vanilla-ex.../src/ml/codenoodles/lmve/modules/PlayerList.java
2020-11-20 11:31:10 +01:00

46 lines
1.1 KiB
Java

package ml.codenoodles.lmve.modules;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.bukkit.event.Listener;
import ml.codenoodles.lmve.Main;
public class PlayerList implements Listener{
private Main main;
public PlayerList(Main main) {
this.main = main;
}
public int getAmount() {
int totalPlayers;
Connection conn;
String path = "jdbc:sqlite:" + main.getDataFolder().getAbsolutePath() + "/" + "Players.db";
try { //Try Connection
conn = DriverManager.getConnection(path);
}catch(SQLException sqlEx) {
System.out.println("[LMVE]" + sqlEx.getMessage());
return 0;
}
try { //Count Players
String query = "SELECT COUNT(Name) AS totalPlayers FROM tblPlayers;";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
rs.next();
totalPlayers = rs.getInt("totalPlayers");
rs.close();
}catch(SQLException sqlEx) {
System.out.println("[LMVE]" + sqlEx.getMessage());
return 0;
}
return totalPlayers;
}
}