Add SQLITE & Bugfix

Add: SQLITE as storage medium
Change: The MYSQL connection has been slightly optimized
Fix: The command 'gui-item slot <number>' dat not set the item to the right place?
This commit is contained in:
JaTiTV 2022-04-19 18:03:44 +02:00
parent 3bd0662273
commit c5bc880ab1
13 changed files with 309 additions and 67 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.7.0_Snapshot-3</version> <version>2.7.0_Snapshot-5</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>CommandGUI</name> <name>CommandGUI</name>

View File

@ -30,6 +30,7 @@ import org.bukkit.scheduler.BukkitRunnable;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Objects;
public class GUI_Listener implements Listener { public class GUI_Listener implements Listener {
@ -53,15 +54,16 @@ public class GUI_Listener implements Listener {
if (e.getCurrentItem().getType() == ItemVersion.getHead() || e.getCurrentItem().getType() == ItemVersion.getGreenWool().getType() || if (e.getCurrentItem().getType() == ItemVersion.getHead() || e.getCurrentItem().getType() == ItemVersion.getGreenWool().getType() ||
e.getCurrentItem().getType() == ItemVersion.getRedWool().getType() || e.getCurrentItem().getType() == ItemVersion.getRedWool().getType() ||
e.getCurrentItem().getType() == Material.valueOf(function.item.toUpperCase().replace(".", "_"))) { e.getCurrentItem().getType() == Material.valueOf(function.item.toUpperCase().replace(".", "_"))) {
if (slot.permission || !player.hasPermission(slot.permissionToUse)) { if (slot.permission && !player.hasPermission(slot.permissionToUse)) {
player.sendMessage(SelectMessages.NoPermissionForItem.replace("[item]", Replace.replace(prefix, function.name)) player.sendMessage(SelectMessages.NoPermissionForItem.replace("[item]", Replace.replace(prefix, function.name))
.replace("[perm]", slot.permissionToUse)); .replace("[perm]", slot.permissionToUse));
continue; continue;
} }
if (!slot.enable) continue; if (!slot.enable) continue;
if (!e.getCurrentItem().getItemMeta().getDisplayName().equals(Replace.replace(prefix, function.name))) continue; send.debugmsg(Main.plugin, function.name);
if (function.cost_Enable) { if (function.cost_Enable) {
if (function.command_Enable || function.message_Enable || function.openGUI_Enable || function.serverChange) { if (function.command_Enable || function.message_Enable || function.openGUI_Enable || function.serverChange) {
if (!Vault.buy(prefix, player, function.price)) { if (!Vault.buy(prefix, player, function.price)) {
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
@ -78,7 +80,9 @@ public class GUI_Listener implements Listener {
execute(function, slot, player, e, gui); execute(function, slot, player, e, gui);
} }
} }
} else execute(function, slot, player, e, gui); } else {
execute(function, slot, player, e, gui);
}
} }
} }
} }
@ -86,8 +90,8 @@ public class GUI_Listener implements Listener {
} }
private static void execute(Function function, Slot slot, Player player, InventoryClickEvent e, Gui gui) { private static void execute(Function function, Slot slot, Player player, InventoryClickEvent e, Gui gui) {
if (function.togglePermission) togglePerm(function, player); if (function.togglePermission) togglePerm(function, gui, player);
if (function.toggleUseItem) toggleUseItem(player); if (function.toggleUseItem) toggleUseItem(player, gui);
if (function.command_Enable) command(function, player); if (function.command_Enable) command(function, player);
if (function.openGUI_Enable) openGUI(function, player); if (function.openGUI_Enable) openGUI(function, player);
if (function.message_Enable) message(function, player); if (function.message_Enable) message(function, player);
@ -131,7 +135,7 @@ public class GUI_Listener implements Listener {
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
OpenGUI.openGUI(player, slot.openGUI); OpenGUI.openGUI(player, slot.openGUI, true);
} }
}.runTaskLater(plugin, 1L); }.runTaskLater(plugin, 1L);
} }
@ -227,7 +231,6 @@ public class GUI_Listener implements Listener {
if (!function.customSound_NoSound) { if (!function.customSound_NoSound) {
try { try {
player.playSound(player.getLocation(), Sound.valueOf(function.customSound_Sound.toUpperCase().replace(".", "_")), 3, 1); player.playSound(player.getLocation(), Sound.valueOf(function.customSound_Sound.toUpperCase().replace(".", "_")), 3, 1);
} catch (Exception e1) { } catch (Exception e1) {
send.console("§4\n§4\n§4\n" + SelectMessages.SoundNotFound.replace("[prefix]", prefix) send.console("§4\n§4\n§4\n" + SelectMessages.SoundNotFound.replace("[prefix]", prefix)
.replace("[sound]", "§6GUI: §e" + Replace.replace(prefix, gui.GUI_Name) + "§r §6Slot: §e" + slot.slot + " §6CustomSound: §9" + function.customSound_Sound)); .replace("[sound]", "§6GUI: §e" + Replace.replace(prefix, gui.GUI_Name) + "§r §6Slot: §e" + slot.slot + " §6CustomSound: §9" + function.customSound_Sound));
@ -237,16 +240,39 @@ public class GUI_Listener implements Listener {
} else player.playSound(player.getLocation(), SelectConfig.Sound_Click, 3, 1); } else player.playSound(player.getLocation(), SelectConfig.Sound_Click, 3, 1);
} }
private static void togglePerm(Function slot, Player player) { private static void togglePerm(Function function, Gui gui, Player player) {
if (player.hasPermission(slot.togglePermissionPerm)) { if (player.hasPermission(function.togglePermissionPerm)) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), SelectConfig.togglePermFalse.replace("[player]", player.getName()).replace("[perm]", slot.togglePermissionPerm)); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), SelectConfig.togglePermFalse.replace("[player]", player.getName()).replace("[perm]", function.togglePermissionPerm));
new BukkitRunnable() {
@Override
public void run() {
player.closeInventory();
OpenGUI.openGUI(player, gui.Command_Command, false);
}
}.runTaskLater(plugin, 4L);
} else } else
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), SelectConfig.togglePermTrue.replace("[player]", player.getName()).replace("[perm]", slot.togglePermissionPerm)); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), SelectConfig.togglePermTrue.replace("[player]", player.getName()).replace("[perm]", function.togglePermissionPerm));
new BukkitRunnable() {
@Override
public void run() {
player.closeInventory();
OpenGUI.openGUI(player, gui.Command_Command, false);
}
}.runTaskLater(plugin, 4L);
} }
private static void toggleUseItem(Player player) { private static void toggleUseItem(Player player, Gui gui) {
if (Events.useItemHashMap.get(player)) { if (Events.useItemHashMap.get(player)) {
Commands.itemOff(player); Commands.itemOff(player);
} else Commands.itemOn(player); } else {
Commands.itemOn(player);
}
new BukkitRunnable() {
@Override
public void run() {
player.closeInventory();
OpenGUI.openGUI(player, gui.Command_Command, false);
}
}.runTaskLater(plugin, 2L);
} }
} }

View File

@ -201,7 +201,7 @@ public class Events implements Listener {
} }
} }
if (!SelectConfig.UseItem_Permission || p.hasPermission("commandgui.useitem")) { if (!SelectConfig.UseItem_Permission || p.hasPermission("commandgui.useitem")) {
OpenGUI.openGUI(p, SelectConfig.UseItem_OpenGUI); OpenGUI.openGUI(p, SelectConfig.UseItem_OpenGUI, true);
} else { } else {
p.sendMessage(SelectMessages.NoPermissionForUseItem.replace("[perm]", "commandgui.useitem") p.sendMessage(SelectMessages.NoPermissionForUseItem.replace("[perm]", "commandgui.useitem")
.replace("[gui]", SelectConfig.UseItem_OpenGUI)); .replace("[gui]", SelectConfig.UseItem_OpenGUI));

View File

@ -186,7 +186,7 @@ public class Commands {
send.player(player, SelectMessages.ItemSlot_wrongValue); send.player(player, SelectMessages.ItemSlot_wrongValue);
return; return;
} }
ItemStack itm1 = player.getInventory().getItem(setSlot - 1); ItemStack itm1 = player.getInventory().getItem(setSlot + 1);
if (itm1 != null) { if (itm1 != null) {
if (itm1.getType() == Material.valueOf(SelectConfig.UseItem_Material) || itm1.getType() == ItemVersion.getHead()) { if (itm1.getType() == Material.valueOf(SelectConfig.UseItem_Material) || itm1.getType() == ItemVersion.getHead()) {
if (itm1.getItemMeta().getDisplayName().equals(SelectConfig.UseItem_Name)) { if (itm1.getItemMeta().getDisplayName().equals(SelectConfig.UseItem_Name)) {
@ -212,6 +212,7 @@ public class Commands {
} }
} }
Select_Database.setSlot(player, setSlot); Select_Database.setSlot(player, setSlot);
Events.useItemSlotHashMap.replace(player,setSlot);
if (Events.useItemHashMap.get(player)) { if (Events.useItemHashMap.get(player)) {
Give_UseItem.onGive(player); Give_UseItem.onGive(player);
} }
@ -224,7 +225,7 @@ public class Commands {
Gui gui = Main.guiHashMap.get(SelectConfig.DefaultGUI); Gui gui = Main.guiHashMap.get(SelectConfig.DefaultGUI);
if (gui.GUI_Enable || player.hasPermission("commandgui.bypass")) { if (gui.GUI_Enable || player.hasPermission("commandgui.bypass")) {
if (!gui.Command_Permission_Enable || player.hasPermission("commandgui.command") || player.hasPermission("commandgui.bypass")) { if (!gui.Command_Permission_Enable || player.hasPermission("commandgui.command") || player.hasPermission("commandgui.bypass")) {
OpenGUI.openGUI(player, SelectConfig.DefaultGUI); OpenGUI.openGUI(player, SelectConfig.DefaultGUI, true);
} else player.sendMessage(SelectMessages.NoPermissionForCommand.replace("[cmd]", "/commandgui") } else player.sendMessage(SelectMessages.NoPermissionForCommand.replace("[cmd]", "/commandgui")
.replace("[perm]", "commandgui.command")); .replace("[perm]", "commandgui.command"));
} else player.sendMessage(SelectMessages.GUIIsDisabled.replace("[gui]", gui.GUI_Name)); } else player.sendMessage(SelectMessages.GUIIsDisabled.replace("[gui]", gui.GUI_Name));
@ -236,7 +237,7 @@ public class Commands {
Gui gui = Main.guiHashMap.get(arg); Gui gui = Main.guiHashMap.get(arg);
if (gui.GUI_Enable || player.hasPermission("commandgui.bypass")) { if (gui.GUI_Enable || player.hasPermission("commandgui.bypass")) {
if (!gui.Command_Permission_Enable || player.hasPermission("commandgui.command." + gui.Command_Command) || player.hasPermission("commandgui.bypass")) { if (!gui.Command_Permission_Enable || player.hasPermission("commandgui.command." + gui.Command_Command) || player.hasPermission("commandgui.bypass")) {
OpenGUI.openGUI(player, arg); OpenGUI.openGUI(player, arg, true);
} else player.sendMessage(SelectMessages.NoPermissionForCommand.replace("[cmd]", "/commandgui " + gui.Command_Command) } else player.sendMessage(SelectMessages.NoPermissionForCommand.replace("[cmd]", "/commandgui " + gui.Command_Command)
.replace("[perm]", "commandgui.command." + arg.toLowerCase())); .replace("[perm]", "commandgui.command." + arg.toLowerCase()));
} else player.sendMessage(SelectMessages.GUIIsDisabled.replace("[gui]", gui.Command_Command)); } else player.sendMessage(SelectMessages.GUIIsDisabled.replace("[gui]", gui.Command_Command));

View File

@ -26,7 +26,7 @@ public class RegisterCommand extends Command {
Gui gui = Main.guiHashMap.get(alias); Gui gui = Main.guiHashMap.get(alias);
if (gui.GUI_Enable || player.hasPermission("commandgui.bypass")) { if (gui.GUI_Enable || player.hasPermission("commandgui.bypass")) {
if (!gui.Command_Permission_Enable || player.hasPermission("commandgui.command." + alias) || player.hasPermission("commandgui.bypass")) { if (!gui.Command_Permission_Enable || player.hasPermission("commandgui.command." + alias) || player.hasPermission("commandgui.bypass")) {
OpenGUI.openGUI(player, alias); OpenGUI.openGUI(player, alias, true);
} else player.sendMessage(SelectMessages.NoPermissionForCommand.replace("[cmd]", "/commandgui " + alias) } else player.sendMessage(SelectMessages.NoPermissionForCommand.replace("[cmd]", "/commandgui " + alias)
.replace("[perm]", "commandgui.command." + alias)); .replace("[perm]", "commandgui.command." + alias));
} else player.sendMessage(SelectMessages.GUIIsDisabled.replace("[gui]", gui.GUI_Name)); } else player.sendMessage(SelectMessages.GUIIsDisabled.replace("[gui]", gui.GUI_Name));

View File

@ -34,7 +34,7 @@ public class ConfigCreate {
Config.set("Plugin.Currency", "$", yamlConfiguration); Config.set("Plugin.Currency", "$", yamlConfiguration);
Config.set("Plugin.DefaultGUI", "default", yamlConfiguration); Config.set("Plugin.DefaultGUI", "default", yamlConfiguration);
Config.set("Storage.Type", "YML", yamlConfiguration); Config.set("Storage.Type", "SQLITE", yamlConfiguration);
Config.set("Storage.MySQL.IP", "localhost", yamlConfiguration); Config.set("Storage.MySQL.IP", "localhost", yamlConfiguration);
Config.set("Storage.MySQL.Port", 3306, yamlConfiguration); Config.set("Storage.MySQL.Port", 3306, yamlConfiguration);
Config.set("Storage.MySQL.Database", "database", yamlConfiguration); Config.set("Storage.MySQL.Database", "database", yamlConfiguration);

View File

@ -4,6 +4,7 @@ import de.jatitv.commandguiv2.Spigot.Main;
import de.jatitv.commandguiv2.Spigot.config.configConverter.ConfigConverterUnderV5; import de.jatitv.commandguiv2.Spigot.config.configConverter.ConfigConverterUnderV5;
import de.jatitv.commandguiv2.Spigot.config.languages.SelectMessages; import de.jatitv.commandguiv2.Spigot.config.languages.SelectMessages;
import de.jatitv.commandguiv2.Spigot.system.database.MySQL; import de.jatitv.commandguiv2.Spigot.system.database.MySQL;
import de.jatitv.commandguiv2.Spigot.system.database.StorageType;
import de.jatitv.commandguiv2.Util; import de.jatitv.commandguiv2.Util;
import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion; import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
@ -29,7 +30,7 @@ public class SelectConfig {
public static String Currency; public static String Currency;
public static List<String> mainCommands; public static List<String> mainCommands;
public static String Storage; public static StorageType Storage;
public static Boolean Bungee; public static Boolean Bungee;
public static String thisServer; public static String thisServer;
@ -139,7 +140,7 @@ public class SelectConfig {
Currency = yamlConfiguration.getString("Plugin.Currency"); Currency = yamlConfiguration.getString("Plugin.Currency");
DefaultGUI = yamlConfiguration.getString("Plugin.DefaultGUI"); DefaultGUI = yamlConfiguration.getString("Plugin.DefaultGUI");
Storage = yamlConfiguration.getString("Storage.Type").toUpperCase(); Storage = StorageType.valueOf(yamlConfiguration.getString("Storage.Type").toUpperCase());
MySQL.ip = yamlConfiguration.getString("Storage.MySQL.IP"); MySQL.ip = yamlConfiguration.getString("Storage.MySQL.IP");
MySQL.port = yamlConfiguration.getInt("Storage.MySQL.Port"); MySQL.port = yamlConfiguration.getInt("Storage.MySQL.Port");

View File

@ -26,7 +26,7 @@ public class OpenGUI {
private static Plugin plugin = Main.plugin; private static Plugin plugin = Main.plugin;
private static String prefix = Util.getPrefix(); private static String prefix = Util.getPrefix();
public static void openGUI(Player player, String guiString) { public static void openGUI(Player player, String guiString, Boolean sound) {
Gui gui = Main.guiHashMap.get(guiString); Gui gui = Main.guiHashMap.get(guiString);
Long long_ = Long.valueOf(System.currentTimeMillis()); Long long_ = Long.valueOf(System.currentTimeMillis());
switch (guiString) { switch (guiString) {
@ -76,7 +76,9 @@ public class OpenGUI {
} }
for (Slot slot : gui.slots) { for (Slot slot : gui.slots) {
Function function = Main.functionHashMap.get(slot.function); Function function = Main.functionHashMap.get(slot.function);
if (slot.permission || !player.hasPermission(slot.permissionToSee)) continue; if (slot.permission && !player.hasPermission(slot.permissionToSee)) continue;
if (slot.slot < 0 || slot.slot > gui.GUI_Lines * 9) continue;
if (slot.enable) { if (slot.enable) {
if (function.empty) { if (function.empty) {
ItemStack air = new ItemStack(Material.AIR); ItemStack air = new ItemStack(Material.AIR);
@ -121,8 +123,10 @@ public class OpenGUI {
} }
} }
if (SelectConfig.Sound_Enable && SelectConfig.Sound_OpenInventory_Enable) { if (sound) {
player.playSound(player.getLocation(), SelectConfig.Sound_OpenInventory, 3, 1); if (SelectConfig.Sound_Enable && SelectConfig.Sound_OpenInventory_Enable) {
player.playSound(player.getLocation(), SelectConfig.Sound_OpenInventory, 3, 1);
}
} }
player.openInventory(inventory); player.openInventory(inventory);
send.debug(plugin, "§6" + player.getName() + " §5Open §6" + Replace.replace(prefix, gui.GUI_Name) + " §5" + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms"); send.debug(plugin, "§6" + player.getName() + " §5Open §6" + Replace.replace(prefix, gui.GUI_Name) + " §5" + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms");

View File

@ -17,6 +17,9 @@ import de.jatitv.commandguiv2.Spigot.Main;
import de.jatitv.commandguiv2.Spigot.objects.Obj_Select; import de.jatitv.commandguiv2.Spigot.objects.Obj_Select;
import de.jatitv.commandguiv2.Spigot.config.config.ConfigCreate; import de.jatitv.commandguiv2.Spigot.config.config.ConfigCreate;
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig; import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
import de.jatitv.commandguiv2.Spigot.system.database.SQLITE;
import de.jatitv.commandguiv2.Spigot.system.database.StorageType;
import de.jatitv.commandguiv2.Spigot.system.database.YML;
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;
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion; import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
@ -26,6 +29,7 @@ import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import java.io.*; import java.io.*;
import java.sql.SQLException;
import java.util.List; import java.util.List;
public class Load { public class Load {
@ -108,7 +112,8 @@ public class Load {
} }
send.console(prefix + " §8-------------------------------"); send.console(prefix + " §8-------------------------------");
if (SelectConfig.Storage.equals("MYSQL")) { switch (SelectConfig.Storage) {
case MYSQL:
MySQL.main(); MySQL.main();
send.console(prefix + " §2Storage medium §6MySQL §2is used."); send.console(prefix + " §2Storage medium §6MySQL §2is used.");
try { try {
@ -126,9 +131,26 @@ public class Load {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
break;
} else { case YML:
send.console(prefix + " §2Storage medium §6YML §2is used."); send.console(prefix + " §2Storage medium §6YML §2is used.");
break;
default:
case SQLITE:
try {
SQLITE.main();
send.console(prefix + " §2Storage medium §6SQLITE §2is used.");
SQLITE.query("CREATE TABLE IF NOT EXISTS `gui-item` (" +
"UUID TEXT NOT NULL," +
"Name TEXT NOT NULL," +
"Status INTEGER NOT NULL DEFAULT 1," +
"Slot INTEGER," +
"PRIMARY KEY(UUID)" +
");");
} catch (SQLException e) {
e.printStackTrace();
}
break;
} }
if (Main.PaPi) { if (Main.PaPi) {
send.console(prefix + " §2PlaceholderAPI successfully connected!"); send.console(prefix + " §2PlaceholderAPI successfully connected!");

View File

@ -35,7 +35,6 @@ public class Metrics {
int pluginId = Util.getBstatsID(); // <-- Replace with the id of your plugin! int pluginId = Util.getBstatsID(); // <-- Replace with the id of your plugin!
Metrics metrics = new Metrics(Main.plugin, pluginId); Metrics metrics = new Metrics(Main.plugin, pluginId);
metrics.addCustomChart(new Metrics.SimplePie("updatecheckonjoin", () -> String.valueOf(SelectConfig.UpdateCheckOnJoin))); metrics.addCustomChart(new Metrics.SimplePie("updatecheckonjoin", () -> String.valueOf(SelectConfig.UpdateCheckOnJoin)));
metrics.addCustomChart(new Metrics.SimplePie("storage_type_mysql", () -> SelectConfig.Storage));
} }
private final Plugin plugin; private final Plugin plugin;

View File

@ -0,0 +1,135 @@
package de.jatitv.commandguiv2.Spigot.system.database;
import de.jatitv.commandguiv2.Spigot.Main;
import de.jatitv.commandguiv2.Util;
import net.t2code.lib.Spigot.Lib.messages.send;
import org.bukkit.Bukkit;
import java.io.File;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
public class SQLITE {
protected static String url;
private static Connection con;
public static void main() throws SQLException {
long long_ = System.currentTimeMillis();
File directory = new File(Main.getPath() + "/Storage");
if (!directory.exists()) {
directory.mkdir();
}
url = "jdbc:sqlite:" + Main.plugin.getDataFolder() + "/Storage/data.db";
con = DriverManager.getConnection(url);
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §2Datenbank erfolgreich verbunden." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
DatabaseMetaData dbmd = con.getMetaData();
}
public static void query(String query) {
send.debug(Main.plugin, query);
try {
Statement stmt = con.createStatement();
stmt.execute(query);
stmt.close();
} catch (SQLException e) {
System.err.println(e.getMessage());
}
}
public static void query(ArrayList<String> queryList) {
try {
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 HashMap<String, ArrayList<String>> selectAll(String query) {
send.debug(Main.plugin, query);
HashMap<String, ArrayList<String>> Result = new HashMap<>();
try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
int columns = rs.getMetaData().getColumnCount();
while (rs.next()) {
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();
stmt.close();
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}
return Result;
}
public static String select(String query) {
send.debug(Main.plugin, query);
String Ausgabe = "";
try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
Ausgabe = String.valueOf(rs.getString(1));
}
rs.close();
stmt.close();
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}
return Ausgabe;
}
public static int count(String query) {
send.debug(Main.plugin, query);
int count = 0;
try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
count++;
}
rs.close();
stmt.close();
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}
return count;
}
public static ArrayList<String> selectRow(String query) {
send.debug(Main.plugin, query);
ArrayList<String> Result = new ArrayList<>();
try {
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() throws SQLException {
if (con != null) con.close();
}
}

View File

@ -7,65 +7,112 @@ import org.bukkit.entity.Player;
public class Select_Database { public class Select_Database {
public static void nameCheck(Player player) { public static void nameCheck(Player player) {
if (SelectConfig.Storage.equals("MYSQL")) { switch (SelectConfig.Storage){
MySQL.query("UPDATE `gui-item` SET Name='" + player.getName() + "' WHERE UUID='" + player.getUniqueId() + "';"); case MYSQL:
} MySQL.query("UPDATE `gui-item` SET Name='" + player.getName() + "' WHERE UUID='" + player.getUniqueId() + "';");
break;
case YML:
break;
case SQLITE:
default:
SQLITE.query("UPDATE `gui-item` SET Name='" + player.getName() + "' WHERE UUID='" + player.getUniqueId() + "';");
break;
} }
}
public static void setSlot(Player player, Integer slot) { public static void setSlot(Player player, Integer slot) {
if (SelectConfig.Storage.equals("MYSQL")) { switch (SelectConfig.Storage) {
MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Slot`) VALUES ('" + player.getUniqueId() + "', '" + player.getName() case MYSQL:
+ "','" + slot + "') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Slot` = '" + slot + "';"); MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Slot`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
} else { + "','" + slot + "') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Slot` = '" + slot + "';");
YML.setGuiitemSlot(player, slot); break;
case YML:
YML.setGuiitemSlot(player, slot);
break;
case SQLITE:
default:
SQLITE.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Slot`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
+ "','" + slot + "') ON CONFLICT(UUID) DO UPDATE SET `Name` = '" + player.getName() + "', `Slot` = '" + slot + "';");
break;
} }
} }
public static void setItemStatusTrue(Player player) { public static void setItemStatusTrue(Player player) {
Events.useItemHashMap.replace(player, true); Events.useItemHashMap.replace(player, true);
if (SelectConfig.Storage.equals("MYSQL")) { switch (SelectConfig.Storage) {
MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`) VALUES ('" + player.getUniqueId() + "', '" + player.getName() case MYSQL:
+ "') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Status` = '1';"); MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
} else { + "') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Status` = '1';");
YML.setGuiitemOn(player); break;
case YML:
YML.setGuiitemOn(player);
break;
case SQLITE:
default:
SQLITE.query("INSERT INTO `gui-item` (`UUID`, `Name`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
+ "') ON CONFLICT(UUID) DO UPDATE SET `Name` = '" + player.getName() + "', `Status` = '1';");
break;
} }
} }
public static void setItemStatusFalse(Player player) { public static void setItemStatusFalse(Player player) {
Events.useItemHashMap.replace(player, false); Events.useItemHashMap.replace(player, false);
if (SelectConfig.Storage.equals("MYSQL")) { switch (SelectConfig.Storage) {
case MYSQL:
MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Status`) VALUES ('" + player.getUniqueId() + "', '" + player.getName() MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Status`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
+ "', '0') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Status` = '0';"); + "', '0') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Status` = '0';");
} else { break;
YML.setGuiitemOff(player); case YML:
YML.setGuiitemOff(player);
break;
case SQLITE:
default:
SQLITE.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Status`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
+ "', '0') ON CONFLICT(UUID) DO UPDATE SET `Name` = '" + player.getName() + "', `Status` = '0';");
break;
} }
} }
public static Boolean selectItemStatus(Player player) { public static Boolean selectItemStatus(Player player) {
if (SelectConfig.Storage.equals("MYSQL")) { switch (SelectConfig.Storage) {
if (MySQL.count("SELECT * FROM `gui-item` WHERE BINARY UUID='" + player.getUniqueId() + "'") > 0) { case MYSQL:
if (MySQL.select("SELECT `Status` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';").equals("1")) { String result = MySQL.select("SELECT `Status` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';");
if(result == null || result.equals("")){
return true; return true;
} else return false; }
} else { return result.equals("1");
return true; case YML:
} return YML.selectGuiitemOn(player);
} else { case SQLITE:
return YML.selectGuiitemOn(player); default:
String result2 = SQLITE.select("SELECT `Status` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';");
if(result2 == null || result2.equals("")){
return true;
}
return result2.equals("1");
} }
} }
public static Integer selectSlot(Player player) { public static Integer selectSlot(Player player) {
if (SelectConfig.Storage.equals("MYSQL")) { switch (SelectConfig.Storage) {
if (MySQL.count("SELECT * FROM `gui-item` WHERE BINARY UUID='" + player.getUniqueId() + "'") > 0) { case MYSQL:
if (MySQL.select("SELECT `Slot` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';") != "null") { String result = MySQL.select("SELECT `Slot` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';");
return Integer.valueOf(MySQL.select("SELECT `Slot` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';")); if(result == null || result.equals("")|| result.equals("null")){
} else return null; return null;
} else return null; }
return Integer.parseInt(result);
} else { case YML:
return YML.selectSlot(player); return YML.selectSlot(player);
case SQLITE:
default:
String result2 = SQLITE.select("SELECT `Slot` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';");
if(result2 == null || result2.equals("") || result2.equals("null")){
return null;
}
return Integer.parseInt(result2);
} }
} }

View File

@ -0,0 +1,7 @@
package de.jatitv.commandguiv2.Spigot.system.database;
public enum StorageType {
MYSQL,
SQLITE,
YML
}