Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.starfluxgames.playtime;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.UUID;
- import org.bukkit.entity.Player;
- import org.bukkit.event.Listener;
- public class mysqlSetterGetter implements Listener{
- static Main plugin = Main.getPlugin(Main.class);
- public static boolean isPlayerInDB(UUID uuid)
- {
- try {
- PreparedStatement statement = plugin.getConnection().prepareStatement("SELECT * FROM `stats` WHERE uuid='" + uuid.toString() + "'"); //Setting command
- ResultSet results = statement.executeQuery(); //Executing command
- if (results.next())
- {
- return true;
- }
- return false;
- }catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public static boolean isUsernameInDB(String username)
- {
- try {
- PreparedStatement statement = plugin.getConnection().prepareStatement("SELECT * FROM `stats` WHERE username='" + username + "'"); //Setting command
- ResultSet results = statement.executeQuery(); //Executing command
- if (results.next())
- {
- return true;
- }
- return false;
- }catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public static String getUUIDfromName(String username){
- try {
- PreparedStatement statement = plugin.getConnection().prepareStatement("SELECT * FROM `stats` WHERE username='" + username + "'");
- ResultSet results = statement.executeQuery(); //Executing command
- if (results.next())
- {
- return results.getString("uuid");
- }
- return null;
- }catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
- public static void setupPlayer(final UUID uuid, Player player)
- {
- try
- {
- if (!isPlayerInDB(uuid))
- {
- PreparedStatement insert = plugin.getConnection().prepareStatement("INSERT INTO `stats`(`uuid`, `username`, `firstJoin`, `lastSeen`, `global`, `lobby`, `creative`) VALUES ('" + uuid + "','" + player.getName() + "'," + System.currentTimeMillis() + ",0,0,0,0)");
- insert.executeUpdate();
- }
- }catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void addPlaytime(final UUID uuid, long time, String server)
- {
- try
- {
- PreparedStatement insert = plugin.getConnection().prepareStatement("UPDATE `stats` SET `global`=`global` + '" + time + "', `" + server + "` = `" + server + "`+'" + time + "' WHERE uuid = '" + uuid + "'");
- insert.executeUpdate();
- }catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void setLastSeen(UUID uuid, long time)
- {
- try
- {
- PreparedStatement insert = plugin.getConnection().prepareStatement("UPDATE `stats` SET `lastSeen`='" + time + "' WHERE uuid='" + uuid + "'");
- insert.executeUpdate();
- }catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static Long getplaytime(UUID uuid){
- try {
- PreparedStatement statement = plugin.getConnection().prepareStatement("SELECT * FROM `stats` WHERE uuid='" + uuid + "'");
- ResultSet results = statement.executeQuery(); //Executing command
- if (results.next())
- {
- return results.getLong("global");
- }
- return null;
- }catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
- public static Long getLastSeen(UUID uuid){
- try {
- PreparedStatement statement = plugin.getConnection().prepareStatement("SELECT * FROM `stats` WHERE uuid='" + uuid + "'");
- ResultSet results = statement.executeQuery(); //Executing command
- if (results.next())
- {
- return results.getLong("lastSeen");
- }
- return null;
- }catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
- public static Long getFirstJoin(UUID uuid)
- {
- try {
- PreparedStatement statement = plugin.getConnection().prepareStatement("SELECT * FROM `stats` WHERE uuid='" + uuid + "'");
- ResultSet results = statement.executeQuery(); //Executing command
- if (results.next())
- {
- return results.getLong("firstJoin");
- }
- return null;
- }catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
- public static int playerGlobalCoins(UUID uuid){
- try {
- PreparedStatement statement = plugin.getConnection().prepareStatement("SELECT globalCoins FROM `players` WHERE uuid='" + uuid.toString() + "'"); //Setting command
- ResultSet results = statement.executeQuery(); //Executing command
- if (results.next())
- {
- return results.getInt("globalCoins");
- }
- return -1;
- }catch (SQLException e) {
- e.printStackTrace();
- }
- return -1;
- }
- }
Add Comment
Please, Sign In to add comment