2.7.0 #8

Merged
JaTiTV merged 16 commits from 2.7.0 into main 2022-04-28 17:55:34 +00:00
13 changed files with 309 additions and 67 deletions
Showing only changes of commit c5bc880ab1 - Show all commits

View File

@ -6,7 +6,7 @@
<groupId>net.t2code</groupId>
<artifactId>CommandGUI_V2</artifactId>
<version>2.7.0_Snapshot-3</version>
<version>2.7.0_Snapshot-5</version>
<packaging>jar</packaging>
<name>CommandGUI</name>

View File

@ -30,6 +30,7 @@ import org.bukkit.scheduler.BukkitRunnable;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
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() ||
e.getCurrentItem().getType() == ItemVersion.getRedWool().getType() ||
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))
.replace("[perm]", slot.permissionToUse));
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.command_Enable || function.message_Enable || function.openGUI_Enable || function.serverChange) {
if (!Vault.buy(prefix, player, function.price)) {
new BukkitRunnable() {
@Override
@ -78,7 +80,9 @@ public class GUI_Listener implements Listener {
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) {
if (function.togglePermission) togglePerm(function, player);
if (function.toggleUseItem) toggleUseItem(player);
if (function.togglePermission) togglePerm(function, gui, player);
if (function.toggleUseItem) toggleUseItem(player, gui);
if (function.command_Enable) command(function, player);
if (function.openGUI_Enable) openGUI(function, player);
if (function.message_Enable) message(function, player);
@ -131,7 +135,7 @@ public class GUI_Listener implements Listener {
new BukkitRunnable() {
@Override
public void run() {
OpenGUI.openGUI(player, slot.openGUI);
OpenGUI.openGUI(player, slot.openGUI, true);
}
}.runTaskLater(plugin, 1L);
}
@ -227,7 +231,6 @@ public class GUI_Listener implements Listener {
if (!function.customSound_NoSound) {
try {
player.playSound(player.getLocation(), Sound.valueOf(function.customSound_Sound.toUpperCase().replace(".", "_")), 3, 1);
} catch (Exception e1) {
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));
@ -237,16 +240,39 @@ public class GUI_Listener implements Listener {
} else player.playSound(player.getLocation(), SelectConfig.Sound_Click, 3, 1);
}
private static void togglePerm(Function slot, Player player) {
if (player.hasPermission(slot.togglePermissionPerm)) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), SelectConfig.togglePermFalse.replace("[player]", player.getName()).replace("[perm]", slot.togglePermissionPerm));
private static void togglePerm(Function function, Gui gui, Player player) {
if (player.hasPermission(function.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
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)) {
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")) {
OpenGUI.openGUI(p, SelectConfig.UseItem_OpenGUI);
OpenGUI.openGUI(p, SelectConfig.UseItem_OpenGUI, true);
} else {
p.sendMessage(SelectMessages.NoPermissionForUseItem.replace("[perm]", "commandgui.useitem")
.replace("[gui]", SelectConfig.UseItem_OpenGUI));

View File

@ -186,7 +186,7 @@ public class Commands {
send.player(player, SelectMessages.ItemSlot_wrongValue);
return;
}
ItemStack itm1 = player.getInventory().getItem(setSlot - 1);
ItemStack itm1 = player.getInventory().getItem(setSlot + 1);
if (itm1 != null) {
if (itm1.getType() == Material.valueOf(SelectConfig.UseItem_Material) || itm1.getType() == ItemVersion.getHead()) {
if (itm1.getItemMeta().getDisplayName().equals(SelectConfig.UseItem_Name)) {
@ -212,6 +212,7 @@ public class Commands {
}
}
Select_Database.setSlot(player, setSlot);
Events.useItemSlotHashMap.replace(player,setSlot);
if (Events.useItemHashMap.get(player)) {
Give_UseItem.onGive(player);
}
@ -224,7 +225,7 @@ public class Commands {
Gui gui = Main.guiHashMap.get(SelectConfig.DefaultGUI);
if (gui.GUI_Enable || 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")
.replace("[perm]", "commandgui.command"));
} else player.sendMessage(SelectMessages.GUIIsDisabled.replace("[gui]", gui.GUI_Name));
@ -236,7 +237,7 @@ public class Commands {
Gui gui = Main.guiHashMap.get(arg);
if (gui.GUI_Enable || 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)
.replace("[perm]", "commandgui.command." + arg.toLowerCase()));
} 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);
if (gui.GUI_Enable || 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)
.replace("[perm]", "commandgui.command." + alias));
} 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.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.Port", 3306, 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.languages.SelectMessages;
import de.jatitv.commandguiv2.Spigot.system.database.MySQL;
import de.jatitv.commandguiv2.Spigot.system.database.StorageType;
import de.jatitv.commandguiv2.Util;
import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
@ -29,7 +30,7 @@ public class SelectConfig {
public static String Currency;
public static List<String> mainCommands;
public static String Storage;
public static StorageType Storage;
public static Boolean Bungee;
public static String thisServer;
@ -139,7 +140,7 @@ public class SelectConfig {
Currency = yamlConfiguration.getString("Plugin.Currency");
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.port = yamlConfiguration.getInt("Storage.MySQL.Port");

View File

@ -26,7 +26,7 @@ public class OpenGUI {
private static Plugin plugin = Main.plugin;
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);
Long long_ = Long.valueOf(System.currentTimeMillis());
switch (guiString) {
@ -76,7 +76,9 @@ public class OpenGUI {
}
for (Slot slot : gui.slots) {
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 (function.empty) {
ItemStack air = new ItemStack(Material.AIR);
@ -121,9 +123,11 @@ public class OpenGUI {
}
}
if (sound) {
if (SelectConfig.Sound_Enable && SelectConfig.Sound_OpenInventory_Enable) {
player.playSound(player.getLocation(), SelectConfig.Sound_OpenInventory, 3, 1);
}
}
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");
} else player.sendMessage(SelectMessages.GUIIsDisabled.replace("[gui]", Replace.replace(prefix, gui.GUI_Name)));

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.config.config.ConfigCreate;
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.send;
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
@ -26,6 +29,7 @@ import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import java.io.*;
import java.sql.SQLException;
import java.util.List;
public class Load {
@ -108,7 +112,8 @@ public class Load {
}
send.console(prefix + " §8-------------------------------");
if (SelectConfig.Storage.equals("MYSQL")) {
switch (SelectConfig.Storage) {
case MYSQL:
MySQL.main();
send.console(prefix + " §2Storage medium §6MySQL §2is used.");
try {
@ -126,9 +131,26 @@ public class Load {
} catch (Exception e) {
e.printStackTrace();
}
} else {
break;
case YML:
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) {
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!
Metrics metrics = new Metrics(Main.plugin, pluginId);
metrics.addCustomChart(new Metrics.SimplePie("updatecheckonjoin", () -> String.valueOf(SelectConfig.UpdateCheckOnJoin)));
metrics.addCustomChart(new Metrics.SimplePie("storage_type_mysql", () -> SelectConfig.Storage));
}
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 static void nameCheck(Player player) {
if (SelectConfig.Storage.equals("MYSQL")) {
switch (SelectConfig.Storage){
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) {
if (SelectConfig.Storage.equals("MYSQL")) {
switch (SelectConfig.Storage) {
case MYSQL:
MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Slot`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
+ "','" + slot + "') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Slot` = '" + slot + "';");
} else {
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) {
Events.useItemHashMap.replace(player, true);
if (SelectConfig.Storage.equals("MYSQL")) {
switch (SelectConfig.Storage) {
case MYSQL:
MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
+ "') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Status` = '1';");
} else {
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) {
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()
+ "', '0') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Status` = '0';");
} else {
break;
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) {
if (SelectConfig.Storage.equals("MYSQL")) {
if (MySQL.count("SELECT * FROM `gui-item` WHERE BINARY UUID='" + player.getUniqueId() + "'") > 0) {
if (MySQL.select("SELECT `Status` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';").equals("1")) {
return true;
} else return false;
} else {
switch (SelectConfig.Storage) {
case MYSQL:
String result = MySQL.select("SELECT `Status` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';");
if(result == null || result.equals("")){
return true;
}
} else {
return result.equals("1");
case YML:
return YML.selectGuiitemOn(player);
case SQLITE:
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) {
if (SelectConfig.Storage.equals("MYSQL")) {
if (MySQL.count("SELECT * FROM `gui-item` WHERE BINARY UUID='" + player.getUniqueId() + "'") > 0) {
if (MySQL.select("SELECT `Slot` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';") != "null") {
return Integer.valueOf(MySQL.select("SELECT `Slot` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';"));
} else return null;
} else return null;
} else {
switch (SelectConfig.Storage) {
case MYSQL:
String result = MySQL.select("SELECT `Slot` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';");
if(result == null || result.equals("")|| result.equals("null")){
return null;
}
return Integer.parseInt(result);
case YML:
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
}