T2C-CommandGUI/CommandGUI V2/src/main/java/de/jatitv/commandguiv2/Spigot/cmdManagement/Commands.java

220 lines
11 KiB
Java
Raw Normal View History

2021-12-21 04:57:29 +00:00
package de.jatitv.commandguiv2.Spigot.cmdManagement;
2022-04-16 12:32:22 +00:00
import de.jatitv.commandguiv2.Spigot.Listener.UseItem_Listener.Events;
2021-12-21 04:57:29 +00:00
import de.jatitv.commandguiv2.Spigot.Main;
2.7.0 Snapshot 1 In this update some functions were rewritten, changed and added. Also some minor bugs have been fixed. The GUIs files have been split into GUI files and function files, this provides more clarity in the complete plugin structure and offers the possibility to access a function from multiple GUIs. Thus, for example, you can create a back button as a function and open it from 3 GUIs, the item, the function can also be in different places, because the slot is set in the GUI file. In the GUI files is thus specified on which slot which function should be located. In addition, the permission for See and for Use of the functions can now be set individually in the GUI Config. In the functions also 2 new functions were added, with which players can switch permissions on and off and an option to switch the UseItem on and off. Placeholders have been added. This update includes a converter that builds the new structure from the old config structure. Your options should be taken over. For security reasons your old GUI files are saved under the path 'plugins/CommandGUI/OldConfig/GUIs/Version4'. Bug fixes: - Fixed a bug that prevented GUIs from opening. - The OpenGUI option, the command '/cgui <guiname>' did not work. The GUI that was set as default GUI in UseItem was always opened. This was fixed New features: - Placeholders - %commandgui_useitem% - Shows if you have activated or deactivated the UseItem (in color, customizable in config.yml) - %commandgui_useitem_boolean% - Shows if you have enabled or disabled the UseItem - %commandgui_useitem_slot% - shows on which slot you have set the UseItem - ToggleUseItem as new option for slots - TogglePermission as new option for slots Changes: - The config structure has been revised.
2022-04-19 05:08:33 +00:00
import de.jatitv.commandguiv2.Spigot.objects.Obj_Select;
import de.jatitv.commandguiv2.Spigot.objects.guis.Gui;
2021-12-21 04:57:29 +00:00
import de.jatitv.commandguiv2.Spigot.cmdManagement.register.AliasRegister;
import de.jatitv.commandguiv2.Spigot.gui.OpenGUI;
import de.jatitv.commandguiv2.Spigot.system.UseItem;
2022-01-06 01:21:27 +00:00
import de.jatitv.commandguiv2.Spigot.config.config.ConfigCreate;
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
import de.jatitv.commandguiv2.Spigot.config.languages.LanguagesCreate;
import de.jatitv.commandguiv2.Spigot.config.languages.SelectMessages;
2022-04-22 17:05:34 +00:00
import de.jatitv.commandguiv2.Spigot.system.Permissions;
import de.jatitv.commandguiv2.Spigot.system.database.SelectDatabase;
2021-12-21 04:57:29 +00:00
import de.jatitv.commandguiv2.Util;
import net.t2code.lib.Spigot.Lib.items.ItemVersion;
import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.Lib.update.UpdateAPI;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Objects;
2021-12-21 04:57:29 +00:00
public class Commands {
public static void info(CommandSender sender) {
if (sender instanceof Player) {
Player player = (Player) sender;
2022-01-01 02:40:54 +00:00
send.player(player, Util.getPrefix() + "§4======= §8[§4Command§9GUI§8] §4=======");
2022-02-09 21:53:18 +00:00
send.player(player, Util.getPrefix() + " §2Autor: §6" + String.valueOf(Main.autor).replace("[", "").replace("]", ""));
2021-12-21 04:57:29 +00:00
2022-01-01 02:40:54 +00:00
if (UpdateAPI.PluginVersionen.get(Main.plugin.getName()).publicVersion.equalsIgnoreCase(Main.version)) {
send.player(player, Util.getPrefix() + " §2Version: §6" + Main.version);
2021-12-21 04:57:29 +00:00
} else {
2022-01-01 02:40:54 +00:00
UpdateAPI.sendUpdateMsg(Util.getPrefix(), Util.getSpigot(), Util.getDiscord(), Main.version, UpdateAPI.PluginVersionen.get(Main.plugin.getName()).publicVersion, player);
2021-12-21 04:57:29 +00:00
}
2022-01-01 02:40:54 +00:00
send.player(player, Util.getPrefix() + " §2Spigot: §6" + Util.getSpigot());
send.player(player, Util.getPrefix() + " §2Discord: §6" + Util.getDiscord());
send.player(player, Util.getPrefix() + "§4======= §8[§4Command§9GUI§8] §4=======");
2021-12-21 04:57:29 +00:00
} else {
2022-01-01 02:40:54 +00:00
send.sender(sender, Util.getPrefix() + "§4======= §8[§4Command§9GUI§8] §4=======");
send.sender(sender, Util.getPrefix() + " §2String.valueOf(Main.autor): §6" + String.valueOf(String.valueOf(Main.autor)).replace("[", "").replace("]", ""));
2021-12-21 04:57:29 +00:00
2022-01-01 02:40:54 +00:00
if (UpdateAPI.PluginVersionen.get(Main.plugin.getName()).publicVersion.equalsIgnoreCase(Main.version)) {
send.sender(sender, Util.getPrefix() + " §2Version: §6" + Main.version);
2021-12-21 04:57:29 +00:00
} else {
2022-01-01 02:40:54 +00:00
UpdateAPI.sendUpdateMsg(Util.getPrefix(), Util.getSpigot(), Util.getDiscord(), Main.version, UpdateAPI.PluginVersionen.get(Main.plugin.getName()).publicVersion);
2021-12-21 04:57:29 +00:00
}
2022-01-01 02:40:54 +00:00
send.sender(sender, Util.getPrefix() + " §2Spigot: §6" + Util.getSpigot());
send.sender(sender, Util.getPrefix() + " §2Discord: §6" + Util.getDiscord());
send.sender(sender, Util.getPrefix() + "§4======= §8[§4Command§9GUI§8] §4=======");
2021-12-21 04:57:29 +00:00
}
}
public static void reload(CommandSender sender) {
if (sender instanceof Player) sender.sendMessage(SelectMessages.ReloadStart);
2022-01-01 02:40:54 +00:00
send.console(Util.getPrefix() + "§8-------------------------------");
send.console(Util.getPrefix() + " §6Plugin reload...");
send.console(Util.getPrefix() + "§8-------------------------------");
2021-12-21 04:57:29 +00:00
2022-04-16 12:32:22 +00:00
CmdExecuter_GUITab.arg1.clear();
CmdExecuter_GUITab.arg1.put("admin", "commandgui.admin;commandgui.giveitem.other;commandgui.command.info");
2021-12-21 04:57:29 +00:00
ConfigCreate.configCreate();
SelectConfig.onSelect();
Main.plugin.reloadConfig();
if (!Objects.equals(SelectDatabase.getStorage().toString(), SelectConfig.storage)) {
if (sender instanceof Player) send.sender(sender, "You have changed the storage medium! To apply this change, you must restart the server!");
send.console("You have changed the storage medium! To apply this change, you must restart the server!");
}
2021-12-21 04:57:29 +00:00
LanguagesCreate.langCreate();
Obj_Select.onSelect();
2022-01-01 02:40:54 +00:00
SelectMessages.onSelect(Util.getPrefix());
SelectConfig.sound(Util.getPrefix());
2022-04-16 12:32:22 +00:00
2021-12-21 04:57:29 +00:00
try {
AliasRegister.onRegister();
2022-04-19 07:32:18 +00:00
} catch (Exception e) {
e.printStackTrace();
}
try {
2022-04-22 17:05:34 +00:00
Permissions.onPermRegister();
2021-12-21 04:57:29 +00:00
} catch (Exception e) {
e.printStackTrace();
}
2022-04-16 12:32:22 +00:00
2022-01-01 02:40:54 +00:00
if (SelectConfig.Bungee) {
2021-12-21 04:57:29 +00:00
Bukkit.getMessenger().registerOutgoingPluginChannel(Main.plugin, "commandgui:bungee");
}
if (sender instanceof Player) sender.sendMessage(SelectMessages.ReloadEnd);
2022-01-01 02:40:54 +00:00
send.console(Util.getPrefix() + "§8-------------------------------");
send.console(Util.getPrefix() + " §2Plugin successfully reloaded.");
send.console(Util.getPrefix() + "§8-------------------------------");
2021-12-21 04:57:29 +00:00
}
public static void give(CommandSender sender, Player target) {
if (Bukkit.getPlayer(target.getName()) != null) {
UseItem.giveUseItem(target);
2021-12-21 04:57:29 +00:00
send.sender(sender, SelectMessages.Give_Sender.replace("[player]", target.getName()).replace("[item]", SelectConfig.UseItem_Name));
send.player(target, SelectMessages.Give_Receiver.replace("[sender]", sender.getName()).replace("[item]", SelectConfig.UseItem_Name));
if (SelectConfig.Sound_Give_Enable && SelectConfig.Sound_Enable) {
target.playSound(target.getLocation(), SelectConfig.Sound_Give, 3, 1);
}
} else {
sender.sendMessage(SelectMessages.PlayerNotFond.replace("[player]", target.getName()));
if (SelectConfig.Sound_PlayerNotFound_Enable && SelectConfig.Sound_Enable) {
if (sender instanceof Player)
((Player) sender).playSound(((Player) sender).getLocation(), SelectConfig.Sound_PlayerNotFound, 3, 1);
}
}
}
public static void itemOn(Player player) {
UseItem.removeItem(player);
2021-12-21 04:57:29 +00:00
Integer slot = null;
2022-01-01 02:40:54 +00:00
if (SelectConfig.UseItem_InventorySlotEnforce) {
2021-12-21 04:57:29 +00:00
slot = SelectConfig.UseItem_InventorySlot;
} else {
2022-04-16 12:32:22 +00:00
if (Events.useItemSlotHashMap.get(player) == null) {
2021-12-29 05:34:29 +00:00
slot = SelectConfig.UseItem_InventorySlot;
} else {
2022-04-16 12:32:22 +00:00
slot = Events.useItemSlotHashMap.get(player);
2021-12-29 05:34:29 +00:00
}
2021-12-21 04:57:29 +00:00
}
2022-01-01 02:40:54 +00:00
send.debug(Main.plugin, String.valueOf(slot));
2021-12-21 04:57:29 +00:00
if (player.getInventory().getItem(slot - 1) == null) {
SelectDatabase.setItemStatusTrue(player);
UseItem.giveUseItem(player);
2021-12-21 04:57:29 +00:00
} else {
boolean empty = false;
for (int i = 0; i < 9; i++) {
if (player.getInventory().getItem(i) == null) {
empty = true;
break;
}
}
if (empty) {
SelectDatabase.setItemStatusTrue(player);
UseItem.addUseItem(player);
2021-12-21 04:57:29 +00:00
send.player(player, SelectMessages.ItemON);
} else {
player.sendMessage(SelectMessages.NoInventorySpace);
if (SelectConfig.Sound_NoInventorySpace_Enable && SelectConfig.Sound_Enable) {
player.playSound(player.getLocation(), SelectConfig.Sound_NoInventorySpace, 3, 1);
}
}
}
}
public static void itemOff(Player player) {
SelectDatabase.setItemStatusFalse(player);
UseItem.removeItem(player);
2021-12-21 04:57:29 +00:00
}
public static void onSetSlot(Player player, Integer setSlot) {
if (SelectConfig.UseItem_AllowSetSlot) {
if (setSlot < 1) {
send.player(player, SelectMessages.ItemSlot_wrongValue);
return;
}
if (setSlot > 9) {
send.player(player, SelectMessages.ItemSlot_wrongValue);
return;
}
ItemStack itm1 = player.getInventory().getItem(setSlot + 1);
2021-12-21 04:57:29 +00:00
if (itm1 != null) {
2021-12-22 19:18:50 +00:00
if (itm1.getType() == Material.valueOf(SelectConfig.UseItem_Material) || itm1.getType() == ItemVersion.getHead()) {
2021-12-21 04:57:29 +00:00
if (itm1.getItemMeta().getDisplayName().equals(SelectConfig.UseItem_Name)) {
player.sendMessage(SelectMessages.ItemSlotAlreadySet.replace("[slot]", setSlot.toString()));
return;
}
}
}
if (SelectConfig.UseItem_InventorySlotEnforce || player.getInventory().getItem(setSlot - 1) != null) {
send.player(player, SelectMessages.ItemSlotNotEmpty.replace("[slot]", setSlot.toString()));
return;
}
UseItem.removeItem(player);
SelectDatabase.setSlot(player, setSlot);
Events.useItemSlotHashMap.replace(player, setSlot);
2022-04-16 12:32:22 +00:00
if (Events.useItemHashMap.get(player)) {
UseItem.giveUseItem(player);
2021-12-21 04:57:29 +00:00
}
send.player(player, SelectMessages.ItemSlot.replace("[slot]", setSlot.toString()));
2022-01-01 02:40:54 +00:00
} else player.sendMessage(Util.getPrefix() + " §4Function disabled");
2021-12-21 04:57:29 +00:00
}
public static void gui(Player player) {
if (Main.guiHashMap.containsKey(SelectConfig.DefaultGUI)) {
2.7.0 Snapshot 1 In this update some functions were rewritten, changed and added. Also some minor bugs have been fixed. The GUIs files have been split into GUI files and function files, this provides more clarity in the complete plugin structure and offers the possibility to access a function from multiple GUIs. Thus, for example, you can create a back button as a function and open it from 3 GUIs, the item, the function can also be in different places, because the slot is set in the GUI file. In the GUI files is thus specified on which slot which function should be located. In addition, the permission for See and for Use of the functions can now be set individually in the GUI Config. In the functions also 2 new functions were added, with which players can switch permissions on and off and an option to switch the UseItem on and off. Placeholders have been added. This update includes a converter that builds the new structure from the old config structure. Your options should be taken over. For security reasons your old GUI files are saved under the path 'plugins/CommandGUI/OldConfig/GUIs/Version4'. Bug fixes: - Fixed a bug that prevented GUIs from opening. - The OpenGUI option, the command '/cgui <guiname>' did not work. The GUI that was set as default GUI in UseItem was always opened. This was fixed New features: - Placeholders - %commandgui_useitem% - Shows if you have activated or deactivated the UseItem (in color, customizable in config.yml) - %commandgui_useitem_boolean% - Shows if you have enabled or disabled the UseItem - %commandgui_useitem_slot% - shows on which slot you have set the UseItem - ToggleUseItem as new option for slots - TogglePermission as new option for slots Changes: - The config structure has been revised.
2022-04-19 05:08:33 +00:00
Gui gui = Main.guiHashMap.get(SelectConfig.DefaultGUI);
if (gui.guiEnable || player.hasPermission("commandgui.bypass")) {
if (!gui.commandPermissionEnable || player.hasPermission("commandgui.command") || player.hasPermission("commandgui.bypass")) {
OpenGUI.openGUI(player, SelectConfig.DefaultGUI, true);
2021-12-21 04:57:29 +00:00
} else player.sendMessage(SelectMessages.NoPermissionForCommand.replace("[cmd]", "/commandgui")
.replace("[perm]", "commandgui.command"));
} else player.sendMessage(SelectMessages.GUIIsDisabled.replace("[gui]", gui.guiName));
2021-12-21 04:57:29 +00:00
}
}
2022-01-01 02:40:54 +00:00
public static void gui(Player player, String arg) {
2021-12-21 04:57:29 +00:00
if (Main.guiHashMap.containsKey(arg)) {
2.7.0 Snapshot 1 In this update some functions were rewritten, changed and added. Also some minor bugs have been fixed. The GUIs files have been split into GUI files and function files, this provides more clarity in the complete plugin structure and offers the possibility to access a function from multiple GUIs. Thus, for example, you can create a back button as a function and open it from 3 GUIs, the item, the function can also be in different places, because the slot is set in the GUI file. In the GUI files is thus specified on which slot which function should be located. In addition, the permission for See and for Use of the functions can now be set individually in the GUI Config. In the functions also 2 new functions were added, with which players can switch permissions on and off and an option to switch the UseItem on and off. Placeholders have been added. This update includes a converter that builds the new structure from the old config structure. Your options should be taken over. For security reasons your old GUI files are saved under the path 'plugins/CommandGUI/OldConfig/GUIs/Version4'. Bug fixes: - Fixed a bug that prevented GUIs from opening. - The OpenGUI option, the command '/cgui <guiname>' did not work. The GUI that was set as default GUI in UseItem was always opened. This was fixed New features: - Placeholders - %commandgui_useitem% - Shows if you have activated or deactivated the UseItem (in color, customizable in config.yml) - %commandgui_useitem_boolean% - Shows if you have enabled or disabled the UseItem - %commandgui_useitem_slot% - shows on which slot you have set the UseItem - ToggleUseItem as new option for slots - TogglePermission as new option for slots Changes: - The config structure has been revised.
2022-04-19 05:08:33 +00:00
Gui gui = Main.guiHashMap.get(arg);
if (gui.guiEnable || player.hasPermission("commandgui.bypass")) {
if (!gui.commandPermissionEnable || player.hasPermission("commandgui.command." + gui.key) || player.hasPermission("commandgui.bypass")) {
OpenGUI.openGUI(player, arg, true);
} else player.sendMessage(SelectMessages.NoPermissionForCommand.replace("[cmd]", "/commandgui " + gui.key)
2021-12-21 04:57:29 +00:00
.replace("[perm]", "commandgui.command." + arg.toLowerCase()));
} else player.sendMessage(SelectMessages.GUIIsDisabled.replace("[gui]", gui.key));
2021-12-21 04:57:29 +00:00
} else player.sendMessage(SelectMessages.GUInotFound);
}
}