Update database to Hikari

This commit is contained in:
JaTiTV 2022-01-16 03:03:04 +01:00
parent b3934e22cc
commit fe7ae61242
5 changed files with 117 additions and 31 deletions

View File

@ -6,7 +6,7 @@
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>
<artifactId>CommandGUI_V2</artifactId> <artifactId>CommandGUI_V2</artifactId>
<version>2.5.21</version> <version>2.5.22_DEV</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>CommandGUI</name> <name>CommandGUI</name>
@ -173,5 +173,10 @@
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.8r1</version> <version>1.8r1</version>
</dependency> </dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.5</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,8 +1,10 @@
package de.jatitv.commandguiv2.Spigot; package de.jatitv.commandguiv2.Spigot;
//s<ds //s<ds
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
import de.jatitv.commandguiv2.Spigot.system.Load; import de.jatitv.commandguiv2.Spigot.system.Load;
import de.jatitv.commandguiv2.Spigot.Objekte.Object; import de.jatitv.commandguiv2.Spigot.Objekte.Object;
import de.jatitv.commandguiv2.Spigot.system.database.MySQL;
import de.jatitv.commandguiv2.Util; import de.jatitv.commandguiv2.Util;
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate; import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate;
import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.messages.send;
@ -113,5 +115,6 @@ public final class Main extends JavaPlugin {
public void onDisable() { public void onDisable() {
// Plugin shutdown logic // Plugin shutdown logic
if (enable) T2CodeTemplate.onDisable(prefix, autor, version, Util.getSpigot(), Util.getDiscord()); if (enable) T2CodeTemplate.onDisable(prefix, autor, version, Util.getSpigot(), Util.getDiscord());
MySQL.close();
} }
} }

View File

@ -1,5 +1,7 @@
package de.jatitv.commandguiv2.Spigot.system.database; package de.jatitv.commandguiv2.Spigot.system.database;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import de.jatitv.commandguiv2.Spigot.Main; import de.jatitv.commandguiv2.Spigot.Main;
import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.messages.send;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -8,57 +10,84 @@ import java.sql.*;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.HashMap;
public class MySQL { public class MySQL {
private static Plugin plugin = Main.plugin;
public static String ip = "localhost"; public static String ip = "localhost";
public static Integer port = 3306; public static Integer port = 3306;
public static String database; public static String database;
public static String user = "root"; public static String user = "root";
public static String password = ""; public static String password = "";
public static String url; protected static String url;
public static Boolean SSL; public static Boolean SSL;
private static final HikariConfig config = new HikariConfig();
private static HikariDataSource ds;
public static void main() { public static void main() {
Long long_ = Long.valueOf(System.currentTimeMillis()); long long_ = System.currentTimeMillis();
Calendar now = Calendar.getInstance(); Calendar now = Calendar.getInstance();
ZoneId timeZone = now.getTimeZone().toZoneId(); ZoneId timeZone = now.getTimeZone().toZoneId();
send.debug(plugin, "Server TimeZone is : " + timeZone); send.debug(Main.plugin, "Server TimeZone is : " + timeZone);
url = "jdbc:mysql://" + ip + ":" + port + "/" + database + "?useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=" + timeZone; try {
// Europe/Berlin config.setJdbcUrl("jdbc:mysql://" + ip + ":" + port + "/" + database + "?useJDBCCompliantTimezoneShift=true&allowMultiQueries=true&useLegacyDatetimeCode=false&autoReconnect=true&serverTimezone=" + timeZone + "&useSSL=" + SSL);
if (SSL) { config.setUsername(user);
url = url + "&useSSL=true"; config.setPassword(password);
} else url = url + "&useSSL=false"; config.addDataSourceProperty("cachePrepStmts", "true");
send.debug(plugin, url); config.addDataSourceProperty("prepStmtCacheSize", "250");
try (Connection con = DriverManager.getConnection(url, user, password)) { config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
Statement stmt = con.createStatement(); ds = new HikariDataSource(config);
stmt.close(); send.console(Main.prefix + " §2MySQL successfully connected." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
send.console(Main.prefix + " §2MySQL successfully connected." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms"); } catch (Exception ex) {
} catch (SQLException ex) { send.console(Main.prefix + " §4MySQL not connected." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
send.console(Main.prefix + " §4MySQL not connected." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms"); send.error(Main.plugin, ex.getMessage() + " --- " + (System.currentTimeMillis() - long_) + "ms");
send.error(plugin, ex.getMessage() + " --- " + (System.currentTimeMillis() - long_.longValue()) + "ms");
} }
//Bukkit.getConsoleSender().sendMessage((System.currentTimeMillis() - long_) + "ms");
} }
public static void query(String query) { public static void query(String query) {
try (Connection con = DriverManager.getConnection(url, user, password)) {
if (ds == null){
return;
}
send.debug(Main.plugin, query);
try (Connection con = ds.getConnection()) {
Statement stmt = con.createStatement(); Statement stmt = con.createStatement();
stmt.execute(query); stmt.execute(query);
stmt.close(); stmt.close();
} catch (SQLException ex) { } catch (SQLException e) {
System.err.println(ex.getMessage()); System.err.println(e.getMessage());
}
}
public static void query(ArrayList<String> queryList) {
try (Connection con = ds.getConnection()) {
Statement stmt = con.createStatement();
for (String query : queryList) {
send.debug(Main.plugin, query);
stmt.addBatch(query);
}
stmt.executeBatch();
stmt.close();
} catch (SQLException e) {
System.err.println(e.getMessage());
} }
} }
public static ArrayList<String> selectAll(String query) { public static HashMap<String, ArrayList<String>> selectAll(String query) {
ArrayList<String> Result = new ArrayList<>(); send.debug(Main.plugin, query);
try (Connection con = DriverManager.getConnection(url, user, password)) { HashMap<String, ArrayList<String>> Result = new HashMap<>();
try (Connection con = ds.getConnection()) {
Statement stmt = con.createStatement(); Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query); ResultSet rs = stmt.executeQuery(query);
int columns = rs.getMetaData().getColumnCount(); int columns = rs.getMetaData().getColumnCount();
while (rs.next()) { while (rs.next()) {
Result.add(rs.getString(1)); ArrayList<String> columnList = new ArrayList<>();
for (int i = 1; i <= columns; i++) {
columnList.add(rs.getString(i));
}
Result.put(rs.getString(1), columnList);
} }
rs.close(); rs.close();
stmt.close(); stmt.close();
@ -69,11 +98,11 @@ public class MySQL {
} }
public static String select(String query) { public static String select(String query) {
send.debug(Main.plugin, query);
String Ausgabe = ""; String Ausgabe = "";
try (Connection con = DriverManager.getConnection(url, user, password)) { try (Connection con = ds.getConnection()) {
Statement stmt = con.createStatement(); Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query); ResultSet rs = stmt.executeQuery(query);
int columns = rs.getMetaData().getColumnCount();
while (rs.next()) { while (rs.next()) {
Ausgabe = String.valueOf(rs.getString(1)); Ausgabe = String.valueOf(rs.getString(1));
} }
@ -86,11 +115,11 @@ public class MySQL {
} }
public static int count(String query) { public static int count(String query) {
Integer count = 0; send.debug(Main.plugin, query);
try (Connection con = DriverManager.getConnection(url, user, password)) { int count = 0;
try (Connection con = ds.getConnection()) {
Statement stmt = con.createStatement(); Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query); ResultSet rs = stmt.executeQuery(query);
int columns = rs.getMetaData().getColumnCount();
while (rs.next()) { while (rs.next()) {
count++; count++;
} }
@ -101,4 +130,28 @@ public class MySQL {
} }
return count; return count;
} }
public static ArrayList<String> selectRow(String query) {
send.debug(Main.plugin, query);
ArrayList<String> Result = new ArrayList<>();
try (Connection con = ds.getConnection()) {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
int columns = rs.getMetaData().getColumnCount();
while (rs.next()) {
for (int i = 1; i <= columns; i++) {
Result.add(rs.getString(i));
}
}
rs.close();
stmt.close();
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}
return Result;
}
public static void close() {
ds.close();
}
} }

View File

@ -5,11 +5,13 @@ import de.jatitv.commandguiv2.Spigot.Main;
import de.jatitv.commandguiv2.Spigot.cmdManagement.Commands; import de.jatitv.commandguiv2.Spigot.cmdManagement.Commands;
import de.jatitv.commandguiv2.Spigot.cmdManagement.Help; import de.jatitv.commandguiv2.Spigot.cmdManagement.Help;
import de.jatitv.commandguiv2.Spigot.config.DefaultGUICreate; import de.jatitv.commandguiv2.Spigot.config.DefaultGUICreate;
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
import de.jatitv.commandguiv2.Spigot.config.languages.SelectMessages; import de.jatitv.commandguiv2.Spigot.config.languages.SelectMessages;
import de.jatitv.commandguiv2.Spigot.system.database.Select_Database; import de.jatitv.commandguiv2.Spigot.system.database.Select_Database;
import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.messages.send;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class CGuiAPI { public class CGuiAPI {
public static Boolean JoinDisable = false; public static Boolean JoinDisable = false;
@ -17,6 +19,19 @@ public class CGuiAPI {
public static void onItemChange(Player player) { public static void onItemChange(Player player) {
ItemChange.itemChange(player, false); ItemChange.itemChange(player, false);
} }
public static boolean hasUseItemInMainHand(Player player) {
ItemStack item = player.getInventory().getItemInMainHand();
return item.hasItemMeta() && item.getItemMeta().hasDisplayName()
&& item.getItemMeta().getDisplayName().equals(SelectConfig.UseItem_Name);
}
public static boolean hasUseItemInOffHand(Player player) {
ItemStack item = player.getInventory().getItemInOffHand();
return item.hasItemMeta() && item.getItemMeta().hasDisplayName()
&& item.getItemMeta().getDisplayName().equals(SelectConfig.UseItem_Name);
}
public static void onItemChange(Player player, Boolean setCursor) { public static void onItemChange(Player player, Boolean setCursor) {
ItemChange.itemChange(player, setCursor); ItemChange.itemChange(player, setCursor);
} }

View File

@ -0,0 +1,10 @@
Manifest-Version: 1.0
Main-Class:
Class-Path: PlugmanGUI-3.0.jar spigot-1.8r3.jar spigot-1.9r1.jar spigot-
1.15r1.jar T2CodeLib-10.3.jar spigot-1.18r1.jar bungee-1615.jar spigot-
1.9r2.jar spigot-1.16r3.jar spigot-1.14r1.jar slf4j-api-1.7.25.jar Luck
yBox-API-4.2.2.jar spigot-1.10r1.jar spigot-1.16r1.jar spigot-1.13r2.ja
r HikariCP-3.4.5.jar spigot-1.11r1.jar spigot-1.13r1.jar spigot-1.8r2.j
ar spigot-1.17r1.jar spigot-1.12r1.jar spigot-1.16r2.jar spigot-1.8r1.j
ar