Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MySQL {
- private static Connection connection;
- public MySQL(String ip, String userName, String password, String db) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection("jdbc:mysql://" + ip + "/" + db + "?user=" + userName + "&password=" + password);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * Bans Start
- */
- public static String getBannedReason(UUID p) {
- try {
- PreparedStatement statement = connection.prepareStatement("select reason from Ban where uuid='" + p + "'");
- ResultSet result = statement.executeQuery();
- if (result.next()) {
- return result.getString("reason");
- } else {
- return null;
- }
- } catch (Exception e) {
- e.printStackTrace();
- return "\n"+"§4§l(X): §cCan't connect to our Datebase, Please inform: \n §a§o@NotSoSmartCoder";
- }
- }
- public static void banPlayer(OfflinePlayer p, String reason) {
- try {
- PreparedStatement statement = connection.prepareStatement("insert into Ban (uuid, reason)\nvalues ('" + p.getUniqueId() + "', '" + reason + "');");
- statement.executeUpdate();
- statement.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void pardonPlayer(OfflinePlayer p) {
- try {
- PreparedStatement statement = connection.prepareStatement("DELETE FROM Ban WHERE uuid='"+p.getUniqueId()+"'");
- statement.executeUpdate();
- statement.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * Bans Start
- */
- /**
- * Gems Start
- */
- public static int getPlayerGems(UUID p) {
- try {
- PreparedStatement statement = connection.prepareStatement("SELECT gems FROM xGems WHERE uuid='" + p + "'");
- ResultSet result = statement.executeQuery();
- if (result.next()) {
- return result.getInt("gems");
- } else {
- return 0;
- }
- } catch (Exception e) {
- e.printStackTrace();
- return 0;
- }
- }
- public static void setPlayersGems(Player p, int amount) {
- try {
- PreparedStatement statement = connection.prepareStatement("insert into xGems (uuid, gems)\nvalues ('" + p.getUniqueId() + "', '" + amount + "');");
- statement.executeUpdate();
- statement.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void addGems(Player p, int amounttoadd) {
- try {
- int oldamount = getPlayerGems(p.getUniqueId());
- int newamount = oldamount+amounttoadd;
- PreparedStatement statement = connection.prepareStatement("insert into xGems (uuid, gems)\nvalues ('" + p.getUniqueId() + "', '" + newamount + "');");
- statement.executeUpdate();
- statement.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void removeGems(Player p, int amount) {
- try {
- int oldamount = getPlayerGems(p.getUniqueId());
- int newamount = oldamount-amount;
- PreparedStatement statement = connection.prepareStatement("insert into xGems (uuid, gems)\nvalues ('" + p.getUniqueId() + "', '" + newamount + "');");
- statement.executeUpdate();
- statement.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement