Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hu.tucsok007.killsound;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import org.bukkit.entity.Player;
- import hu.tucsok007.mysql.MySQL;
- public class MySqlManager
- {
- private final KillSound main;
- private MySQL db;
- public MySqlManager(KillSound p)
- {
- this.main = p;
- }
- public void setupDB() throws SQLException, ClassNotFoundException
- {
- this.db = new MySQL(this.main, "localhost", "3306", "killpoints", "root", "tBgk8zzX7StnBRm");
- this.db.openConnection();
- Statement statement = this.db.getConnection().createStatement();
- statement.executeUpdate("CREATE TABLE IF NOT EXISTS `killpointsdata` (`Name` varchar(32),`Points` int)");
- statement.close();
- }
- public void closeDB() throws SQLException
- {
- this.db.closeConnection();
- }
- public int getPoints(Player player) throws SQLException, ClassNotFoundException
- {
- String p = player.getName();
- int playername = KillSound.pontok.get(p);
- if(!this.db.checkConnection())
- {
- this.db.openConnection();
- }
- Statement statement = this.db.getConnection().createStatement();
- ResultSet rs = statement.executeQuery("SELECT * FROM `killpointsdata` WHERE `Name`='"+playername+"';");
- if(!rs.next())
- {
- return 0;
- }
- return rs.getInt("Points");
- }
- public void updatePlayer(Player player) throws SQLException, ClassNotFoundException
- {
- String playername = player.getDisplayName().toLowerCase();
- if(!this.db.checkConnection())
- {
- this.db.openConnection();
- }
- Statement statement = this.db.getConnection().createStatement();
- int points = this.getPoints(player);
- if(points!=0)
- {
- statement.executeUpdate("UPDATE `killpointsdata` SET `Points`='"+KillSound.pontok.get(playername)+"' WHERE `Name`='" + playername + "';");
- }
- else
- {
- statement.executeUpdate("INSERT INTO `killpointsdata` (`Name`,`Points`) VALUES ('" + playername + "','"+KillSound.pontok.get(playername)+"');");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement