2.7.0_Snapshot-6 | Fix
Fixes: - If there was a function in the GUI that did not exist, then an error occurred in the console and the GUI could not be opened, this was fixed. - If you changed the slot of the UseItem, the Protection (RemoveItemWhenItIsDisabled) was ignored and you got the item.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package de.jatitv.commandguiv2.Spigot.system;
|
||||
|
||||
import de.jatitv.commandguiv2.Spigot.Listener.GUI_Listener;
|
||||
import de.jatitv.commandguiv2.Spigot.Listener.UseItem_Listener.Events_from1_10;
|
||||
import de.jatitv.commandguiv2.Spigot.Listener.GUIListener;
|
||||
import de.jatitv.commandguiv2.Spigot.Listener.UseItem_Listener.EventsFrom110;
|
||||
import de.jatitv.commandguiv2.Spigot.cmdManagement.CmdExecuter_GUITab;
|
||||
import de.jatitv.commandguiv2.Spigot.cmdManagement.CmdExecuter_GUIItem;
|
||||
import de.jatitv.commandguiv2.Spigot.cmdManagement.CmdExecuter_Help;
|
||||
@@ -18,8 +18,8 @@ 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.SelectDatabase;
|
||||
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;
|
||||
@@ -112,46 +112,9 @@ public class Load {
|
||||
}
|
||||
|
||||
send.console(prefix + " §8-------------------------------");
|
||||
switch (SelectConfig.Storage) {
|
||||
case MYSQL:
|
||||
MySQL.main();
|
||||
send.console(prefix + " §2Storage medium §6MySQL §2is used.");
|
||||
try {
|
||||
MySQL.query("CREATE TABLE IF NOT EXISTS `gui-item` (" +
|
||||
" `UUID` VARCHAR(191) NOT NULL COLLATE 'utf8mb4_general_ci'," +
|
||||
" `Name` TINYTEXT NOT NULL COLLATE 'utf8mb4_general_ci'," +
|
||||
" `Status` INT(1) NOT NULL DEFAULT '1'," +
|
||||
" `Slot` INT(1) NULL DEFAULT NULL," +
|
||||
" UNIQUE INDEX `UUID` (`UUID`)" +
|
||||
")" +
|
||||
"COLLATE='utf8mb4_general_ci'" +
|
||||
"ENGINE=InnoDB" +
|
||||
";");
|
||||
MySQL.query("ALTER TABLE `gui-item` ADD COLUMN IF NOT EXISTS `Slot` INT(1) NULL DEFAULT NULL AFTER `Status`;");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
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;
|
||||
}
|
||||
loadStorage(prefix);
|
||||
send.console(prefix + " §8-------------------------------");
|
||||
|
||||
if (Main.PaPi) {
|
||||
send.console(prefix + " §2PlaceholderAPI successfully connected!");
|
||||
} else {
|
||||
@@ -179,13 +142,13 @@ public class Load {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new GUI_Listener(), plugin);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new GUIListener(), plugin);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new PluginEvent(), plugin);
|
||||
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new Events(), Main.plugin);
|
||||
|
||||
if (!MCVersion.minecraft1_8 && !MCVersion.minecraft1_9) {
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new Events_from1_10(), plugin);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new EventsFrom110(), plugin);
|
||||
}
|
||||
|
||||
UpdateAPI.onUpdateCheck(plugin, prefix, spigot, spigotID, discord);
|
||||
@@ -193,4 +156,55 @@ public class Load {
|
||||
Main.addonLoad();
|
||||
T2CodeTemplate.onLoadFooter(prefix, long_);
|
||||
}
|
||||
|
||||
private static void loadStorage(String prefix) {
|
||||
try {
|
||||
SelectDatabase.setStorage(StorageType.valueOf(SelectConfig.storage));
|
||||
} catch (Exception ignored) {
|
||||
send.error(Main.plugin, "The storage medium " + SelectConfig.storage + " is not supported!");
|
||||
send.error(Main.plugin, "Storage medium " + StorageType.SQLITE + " is used.");
|
||||
SelectDatabase.setStorage(StorageType.SQLITE);
|
||||
}
|
||||
|
||||
switch (SelectDatabase.getStorage()) {
|
||||
case MYSQL:
|
||||
send.console(prefix + " §2Storage medium §6" + SelectDatabase.getStorage() + " §2is used.");
|
||||
MySQL.main();
|
||||
try {
|
||||
MySQL.query("CREATE TABLE IF NOT EXISTS `gui-item` (" +
|
||||
" `UUID` VARCHAR(191) NOT NULL COLLATE 'utf8mb4_general_ci'," +
|
||||
" `Name` TINYTEXT NOT NULL COLLATE 'utf8mb4_general_ci'," +
|
||||
" `Status` INT(1) NOT NULL DEFAULT '1'," +
|
||||
" `Slot` INT(1) NULL DEFAULT NULL," +
|
||||
" UNIQUE INDEX `UUID` (`UUID`)" +
|
||||
")" +
|
||||
"COLLATE='utf8mb4_general_ci'" +
|
||||
"ENGINE=InnoDB" +
|
||||
";");
|
||||
MySQL.query("ALTER TABLE `gui-item` ADD COLUMN IF NOT EXISTS `Slot` INT(1) NULL DEFAULT NULL AFTER `Status`;");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case YML:
|
||||
send.console(prefix + " §2Storage medium §6" + SelectDatabase.getStorage() + " §2is used.");
|
||||
break;
|
||||
default:
|
||||
case SQLITE:
|
||||
send.console(prefix + " §2Storage medium §6" + SelectDatabase.getStorage() + " §2is used.");
|
||||
try {
|
||||
SQLITE.main();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,8 @@ package de.jatitv.commandguiv2.Spigot.system;
|
||||
|
||||
import de.jatitv.commandguiv2.Spigot.Main;
|
||||
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
|
||||
import de.jatitv.commandguiv2.Spigot.system.database.SelectDatabase;
|
||||
import de.jatitv.commandguiv2.Spigot.system.database.StorageType;
|
||||
import de.jatitv.commandguiv2.Util;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@@ -35,6 +37,13 @@ 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 DrilldownPie("storage_type_mysql", () -> {
|
||||
Map<String, Map<String, Integer>> map = new HashMap<>();
|
||||
String storage = SelectDatabase.getStorage().toString();
|
||||
Map<String, Integer> entry = new HashMap<>();
|
||||
entry.put(storage, 1); map.put(storage, entry);
|
||||
return map;
|
||||
}));
|
||||
}
|
||||
|
||||
private final Plugin plugin;
|
||||
|
@@ -2,11 +2,8 @@ package de.jatitv.commandguiv2.Spigot.system;
|
||||
|
||||
import de.jatitv.commandguiv2.Spigot.Main;
|
||||
import de.jatitv.commandguiv2.Spigot.objects.guis.Gui;
|
||||
import de.jatitv.commandguiv2.Spigot.objects.functions.Function;
|
||||
import de.jatitv.commandguiv2.Spigot.objects.slots.Slot;
|
||||
import net.t2code.lib.Spigot.Lib.register.Register;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
@@ -67,8 +64,8 @@ public class RegisterPermissions {
|
||||
|
||||
|
||||
for (Gui gui : Main.guiHashMap.values()) {
|
||||
Register.permission("commandgui.command." + gui.Command_Command, op, plugin);
|
||||
Register.permission(admin, op, "commandgui.command." + gui.Command_Command, true, plugin);
|
||||
Register.permission("commandgui.command." + gui.key, op, plugin);
|
||||
Register.permission(admin, op, "commandgui.command." + gui.key, true, plugin);
|
||||
for (Slot slot : gui.slots) {
|
||||
Register.permission(slot.permissionToUse, op, plugin);
|
||||
Register.permission(admin, op, slot.permissionToUse, true, plugin);
|
||||
|
@@ -5,7 +5,7 @@ import com.mojang.authlib.properties.Property;
|
||||
import de.jatitv.commandguiv2.Spigot.Listener.UseItem_Listener.Events;
|
||||
import de.jatitv.commandguiv2.Spigot.Main;
|
||||
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
|
||||
import de.jatitv.commandguiv2.Spigot.system.database.Select_Database;
|
||||
import de.jatitv.commandguiv2.Spigot.config.languages.SelectMessages;
|
||||
import de.jatitv.commandguiv2.Util;
|
||||
import net.t2code.lib.Spigot.Lib.items.ItemVersion;
|
||||
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||
@@ -20,15 +20,16 @@ import org.bukkit.inventory.meta.SkullMeta;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Give_UseItem {
|
||||
public class UseItem {
|
||||
|
||||
|
||||
public static void onGive(Player player) {
|
||||
public static void giveUseItem(Player player) {
|
||||
Integer slot;
|
||||
if (SelectConfig.UseItem_InventorySlotEnforce){
|
||||
if (protection(player, false)) return;
|
||||
if (SelectConfig.UseItem_InventorySlotEnforce) {
|
||||
slot = SelectConfig.UseItem_InventorySlot;
|
||||
} else {
|
||||
if (Events.useItemSlotHashMap.get(player)== null) {
|
||||
if (Events.useItemSlotHashMap.get(player) == null) {
|
||||
slot = SelectConfig.UseItem_InventorySlot;
|
||||
} else {
|
||||
slot = Events.useItemSlotHashMap.get(player);
|
||||
@@ -37,12 +38,13 @@ public class Give_UseItem {
|
||||
if (SelectConfig.UseItem_InventorySlot_FreeSlot) {
|
||||
player.getInventory().addItem(itemStack(player));
|
||||
} else {
|
||||
send.debug(Main.plugin,"setUseItem: " + player.getName() + " Slot: "+ Integer.parseInt(String.valueOf(slot-1)));
|
||||
send.debug(Main.plugin, "setUseItem: " + player.getName() + " Slot: " + Integer.parseInt(String.valueOf(slot - 1)));
|
||||
player.getInventory().setItem(slot - 1, itemStack(player));
|
||||
}
|
||||
}
|
||||
|
||||
public static void onGiveADD(Player player) {
|
||||
public static void addUseItem(Player player) {
|
||||
if (protection(player, false)) return;
|
||||
if (SelectConfig.UseItem_InventorySlot_FreeSlot) {
|
||||
player.getInventory().addItem(itemStack(player));
|
||||
} else player.getInventory().addItem(itemStack(player));
|
||||
@@ -96,4 +98,52 @@ public class Give_UseItem {
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static boolean protection(Player player, Boolean interact) {
|
||||
if (SelectConfig.UseItemGameModeProtection) {
|
||||
if (SelectConfig.UseItemGameModeMode.equalsIgnoreCase("blacklist") && SelectConfig.UseItemGameModeList.contains(player.getGameMode().toString())) {
|
||||
if (interact) {
|
||||
send.player(player, SelectMessages.UseItemDisabledInGameMode);
|
||||
} else if (!SelectConfig.UseItemWorldRemoveItemWhenItIsDisabled) removeItem(player);
|
||||
return true;
|
||||
}
|
||||
if (SelectConfig.UseItemGameModeMode.equalsIgnoreCase("whitelist") && !SelectConfig.UseItemGameModeList.contains(player.getGameMode().toString())) {
|
||||
if (interact) {
|
||||
send.player(player, SelectMessages.UseItemDisabledInGameMode);
|
||||
} else if (!SelectConfig.UseItemWorldRemoveItemWhenItIsDisabled) removeItem(player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (SelectConfig.UseItemWorldProtection) {
|
||||
if (SelectConfig.UseItemWorldMode.equalsIgnoreCase("blacklist") && SelectConfig.UseItemWorldList.contains(player.getWorld().getName())) {
|
||||
if (interact) {
|
||||
send.player(player, SelectMessages.UseItemDisabledInWorld);
|
||||
} else if (!SelectConfig.UseItemWorldRemoveItemWhenItIsDisabled) removeItem(player);
|
||||
return true;
|
||||
}
|
||||
if (SelectConfig.UseItemWorldMode.equalsIgnoreCase("whitelist") && !SelectConfig.UseItemWorldList.contains(player.getWorld().getName())) {
|
||||
if (interact) {
|
||||
send.player(player, SelectMessages.UseItemDisabledInWorld);
|
||||
} else if (!SelectConfig.UseItemWorldRemoveItemWhenItIsDisabled) removeItem(player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void removeItem(Player player) {
|
||||
send.debug(Main.plugin, "World disabled: " + player.getName() + " " + player.getWorld().toString());
|
||||
for (int iam = 0; iam < player.getInventory().getSize() - 5; iam++) {
|
||||
ItemStack itm = player.getInventory().getItem(iam);
|
||||
if (itm != null) {
|
||||
if (itm.getType() == Material.valueOf(SelectConfig.UseItem_Material) || itm.getType() == ItemVersion.getHead()) {
|
||||
if (itm.getItemMeta().getDisplayName().equals(SelectConfig.UseItem_Name)) {
|
||||
player.getInventory().remove(itm);
|
||||
player.updateInventory();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -35,9 +35,9 @@ public class MySQL {
|
||||
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
||||
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||
ds = new HikariDataSource(config);
|
||||
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_) + "ms");
|
||||
} catch (Exception 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_) + "ms");
|
||||
send.error(Main.plugin, ex.getMessage() + " --- " + (System.currentTimeMillis() - long_) + "ms");
|
||||
}
|
||||
//Bukkit.getConsoleSender().sendMessage((System.currentTimeMillis() - long_) + "ms");
|
||||
|
@@ -22,7 +22,7 @@ public class SQLITE {
|
||||
}
|
||||
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");
|
||||
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §2SQLITE successfully connected." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||
DatabaseMetaData dbmd = con.getMetaData();
|
||||
}
|
||||
|
||||
|
@@ -4,10 +4,20 @@ import de.jatitv.commandguiv2.Spigot.Listener.UseItem_Listener.Events;
|
||||
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Select_Database {
|
||||
public class SelectDatabase {
|
||||
|
||||
private static StorageType Storage;
|
||||
|
||||
public static StorageType getStorage() {
|
||||
return Storage;
|
||||
}
|
||||
|
||||
public static void setStorage(StorageType storage) {
|
||||
Storage = storage;
|
||||
}
|
||||
|
||||
public static void nameCheck(Player player) {
|
||||
switch (SelectConfig.Storage){
|
||||
switch (Storage){
|
||||
case MYSQL:
|
||||
MySQL.query("UPDATE `gui-item` SET Name='" + player.getName() + "' WHERE UUID='" + player.getUniqueId() + "';");
|
||||
break;
|
||||
@@ -24,7 +34,7 @@ public class Select_Database {
|
||||
}
|
||||
|
||||
public static void setSlot(Player player, Integer slot) {
|
||||
switch (SelectConfig.Storage) {
|
||||
switch (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 + "';");
|
||||
@@ -42,7 +52,7 @@ public class Select_Database {
|
||||
|
||||
public static void setItemStatusTrue(Player player) {
|
||||
Events.useItemHashMap.replace(player, true);
|
||||
switch (SelectConfig.Storage) {
|
||||
switch (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';");
|
||||
@@ -60,7 +70,7 @@ public class Select_Database {
|
||||
|
||||
public static void setItemStatusFalse(Player player) {
|
||||
Events.useItemHashMap.replace(player, false);
|
||||
switch (SelectConfig.Storage) {
|
||||
switch (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';");
|
||||
@@ -77,7 +87,7 @@ public class Select_Database {
|
||||
}
|
||||
|
||||
public static Boolean selectItemStatus(Player player) {
|
||||
switch (SelectConfig.Storage) {
|
||||
switch (Storage) {
|
||||
case MYSQL:
|
||||
String result = MySQL.select("SELECT `Status` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';");
|
||||
if(result == null || result.equals("")){
|
||||
@@ -97,7 +107,7 @@ public class Select_Database {
|
||||
}
|
||||
|
||||
public static Integer selectSlot(Player player) {
|
||||
switch (SelectConfig.Storage) {
|
||||
switch (Storage) {
|
||||
case MYSQL:
|
||||
String result = MySQL.select("SELECT `Slot` FROM `gui-item` WHERE `UUID`='" + player.getUniqueId() + "';");
|
||||
if(result == null || result.equals("")|| result.equals("null")){
|
Reference in New Issue
Block a user