209 lines
9.7 KiB
Java
209 lines
9.7 KiB
Java
package net.t2code.commandguiv2.Spigot.cmdManagement;
|
|
|
|
import net.t2code.commandguiv2.Spigot.config.config.ConfigValues;
|
|
import net.t2code.commandguiv2.Spigot.config.config.ConfigSelect;
|
|
import net.t2code.commandguiv2.Spigot.config.functions.SelectFunctions;
|
|
import net.t2code.commandguiv2.Spigot.config.gui.SelectGui;
|
|
import net.t2code.commandguiv2.Spigot.function.useItem.Events;
|
|
import net.t2code.commandguiv2.Spigot.Main;
|
|
import net.t2code.commandguiv2.Spigot.objects.GuiObject;
|
|
import net.t2code.commandguiv2.Spigot.cmdManagement.register.AliasRegister;
|
|
import net.t2code.commandguiv2.Spigot.function.gui.OpenGUI;
|
|
import net.t2code.commandguiv2.Spigot.function.useItem.UseItem;
|
|
import net.t2code.commandguiv2.Spigot.config.languages.LanguagesCreate;
|
|
import net.t2code.commandguiv2.Spigot.config.languages.SelectMessages;
|
|
import net.t2code.commandguiv2.Spigot.system.Permissions;
|
|
import net.t2code.commandguiv2.Spigot.database.SelectDatabase;
|
|
import net.t2code.commandguiv2.Spigot.sound.PlaySound;
|
|
import net.t2code.commandguiv2.Spigot.enums.SoundEnum;
|
|
import net.t2code.commandguiv2.Util;
|
|
import net.t2code.commandguiv2.cache.Cache;
|
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
|
|
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import java.io.IOException;
|
|
import java.util.Objects;
|
|
|
|
public class Commands {
|
|
public static void info(CommandSender sender) {
|
|
T2Ctemplate.sendInfo(sender, Main.getPlugin(), Util.getSpigotID(), Util.getDiscord(), Util.getInfoText());
|
|
}
|
|
|
|
public static void reload(CommandSender sender) {
|
|
Bukkit.getScheduler().runTaskAsynchronously(Main.getPlugin(), new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
if (sender instanceof Player) sender.sendMessage(SelectMessages.ReloadStart);
|
|
T2Csend.console(Util.getPrefix() + "§8-------------------------------");
|
|
T2Csend.console(Util.getPrefix() + " §6Plugin reload...");
|
|
T2Csend.console(Util.getPrefix() + "§8-------------------------------");
|
|
try {
|
|
ConfigSelect.selectConfig();
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
Main.getPlugin().reloadConfig();
|
|
|
|
CmdExecuter_GUI.arg1.clear();
|
|
CmdExecuter_GUI.arg1.put(String.valueOf(ConfigValues.adminSubCommand.value), "commandgui.admin;commandgui.giveitem.other;commandgui.command.info");
|
|
|
|
if (!Objects.equals(SelectDatabase.getStorage().toString(), ConfigValues.storage.value)) {
|
|
if (sender instanceof Player) T2Csend.sender(sender, "You have changed the storage medium! To apply this change, you must restart the server!");
|
|
T2Csend.warning(Main.getPlugin(), "You have changed the storage medium! To apply this change, you must restart the server!");
|
|
}
|
|
|
|
LanguagesCreate.langCreate();
|
|
|
|
try {
|
|
SelectFunctions.onSelectFunction();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
try {
|
|
SelectGui.onSelectGui();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
SelectMessages.onSelect(Util.getPrefix());
|
|
ConfigValues.sound();
|
|
|
|
try {
|
|
AliasRegister.onRegister();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
try {
|
|
Permissions.onPermRegister();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
if (SelectLibConfig.getBungee()) {
|
|
Bukkit.getMessenger().registerOutgoingPluginChannel(Main.getPlugin(), "commandgui:bungee");
|
|
|
|
}
|
|
|
|
if (sender instanceof Player) sender.sendMessage(SelectMessages.ReloadEnd);
|
|
T2Csend.console(Util.getPrefix() + "§8-------------------------------");
|
|
T2Csend.console(Util.getPrefix() + " §2Plugin successfully reloaded.");
|
|
T2Csend.console(Util.getPrefix() + "§8-------------------------------");
|
|
}
|
|
});
|
|
}
|
|
|
|
public static void give(CommandSender sender, Player target) {
|
|
if (Bukkit.getPlayer(target.getName()) != null) {
|
|
UseItem.giveUseItem(target);
|
|
T2Csend.sender(sender, SelectMessages.Give_Sender.replace("[player]", target.getName()).replace("[item]", String.valueOf(ConfigValues.useItemName.value)));
|
|
T2Csend.player(target, SelectMessages.Give_Receiver.replace("[sender]", sender.getName()).replace("[item]", String.valueOf(ConfigValues.useItemName.value)));
|
|
PlaySound.play(target, SoundEnum.Give);
|
|
} else {
|
|
sender.sendMessage(SelectMessages.PlayerNotFond.replace("[player]", target.getName()));
|
|
if (sender instanceof Player) PlaySound.play((Player) sender, SoundEnum.PlayerNotFound);
|
|
}
|
|
}
|
|
|
|
public static void itemOn(Player player, String useItemKey) {
|
|
UseItem.removeItem(player);
|
|
Integer slot = null;
|
|
if ((Boolean) ConfigValues.useItemInventorySlotEnforce.value) {
|
|
slot = (Integer) ConfigValues.useItemInventorySlot.value;
|
|
} else {
|
|
slot = Events.useItemSlotHashMap.get(player.getName());
|
|
}
|
|
T2Csend.debug(Main.getPlugin(), String.valueOf(slot));
|
|
if (player.getInventory().getItem(slot - 1) == null) {
|
|
SelectDatabase.setItemStatus(player, useItemKey, true);
|
|
UseItem.giveUseItem(player);
|
|
} else {
|
|
boolean empty = false;
|
|
for (int i = 0; i < 9; i++) {
|
|
if (player.getInventory().getItem(i) == null) {
|
|
empty = true;
|
|
break;
|
|
}
|
|
}
|
|
if (empty) {
|
|
SelectDatabase.setItemStatus(player, useItemKey, true);
|
|
UseItem.addUseItem(player);
|
|
T2Csend.player(player, SelectMessages.ItemON);
|
|
} else {
|
|
T2Csend.player(player, SelectMessages.NoInventorySpace);
|
|
PlaySound.play(player, SoundEnum.NoInventorySpace);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void itemOff(Player player, String useItemKey) {
|
|
SelectDatabase.setItemStatus(player, useItemKey, false);
|
|
UseItem.removeItem(player);
|
|
T2Csend.player(player, SelectMessages.ItemOFF);
|
|
}
|
|
|
|
public static void onSetSlot(Player player, String useItemKey, Integer setSlot) {
|
|
if (!(Boolean) ConfigValues.useItemAllowSetSlot.value) {
|
|
T2Csend.player(player, Util.getPrefix() + " §4Function disabled");
|
|
return;
|
|
}
|
|
|
|
if (setSlot < 1) {
|
|
T2Csend.player(player, SelectMessages.ItemSlot_wrongValue);
|
|
return;
|
|
}
|
|
if (setSlot > 9) {
|
|
T2Csend.player(player, SelectMessages.ItemSlot_wrongValue);
|
|
return;
|
|
}
|
|
|
|
if (Events.useItemHashMap.get(player.getName())) {
|
|
if (Objects.equals(Events.useItemSlotHashMap.get(player.getName()), setSlot)) {
|
|
T2Csend.player(player, SelectMessages.ItemSlotAlreadySet.replace("[slot]", setSlot.toString()));
|
|
return;
|
|
}
|
|
}
|
|
|
|
if ((Boolean) ConfigValues.useItemInventorySlotEnforce.value || player.getInventory().getItem(setSlot - 1) != null) {
|
|
T2Csend.player(player, SelectMessages.ItemSlotNotEmpty.replace("[slot]", setSlot.toString()));
|
|
return;
|
|
}
|
|
|
|
UseItem.removeItem(player);
|
|
SelectDatabase.setSlot(player, useItemKey, setSlot);
|
|
Events.useItemSlotHashMap.replace(player.getName(), setSlot);
|
|
|
|
if (Events.useItemHashMap.get(player.getName())) {
|
|
UseItem.giveUseItem(player);
|
|
}
|
|
|
|
T2Csend.player(player, SelectMessages.ItemSlot.replace("[slot]", setSlot.toString()));
|
|
}
|
|
|
|
public static void gui(Player player) {
|
|
if (Cache.guiHashMap.containsKey(String.valueOf(ConfigValues.defaultGUI.value))) {
|
|
GuiObject gui = Cache.guiHashMap.get(String.valueOf(ConfigValues.defaultGUI.value));
|
|
if (gui.guiEnable || player.hasPermission("commandgui.bypass")) {
|
|
if (!gui.commandPermissionEnable || player.hasPermission("commandgui.command") || player.hasPermission("commandgui.bypass")) {
|
|
OpenGUI.openGUI(player, String.valueOf(ConfigValues.defaultGUI.value), true);
|
|
} else T2Csend.player(player, SelectMessages.NoPermissionForCommand.replace("[cmd]", "/commandgui")
|
|
.replace("[perm]", "commandgui.command"));
|
|
} else T2Csend.player(player, SelectMessages.GUIIsDisabled.replace("[gui]", gui.guiName));
|
|
}
|
|
}
|
|
|
|
public static void gui(Player player, String arg) {
|
|
if (Cache.guiHashMap.containsKey(arg)) {
|
|
GuiObject gui = Cache.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 T2Csend.player(player, SelectMessages.NoPermissionForCommand.replace("[cmd]", "/commandgui " + gui.key)
|
|
.replace("[perm]", "commandgui.command." + arg.toLowerCase()));
|
|
} else T2Csend.player(player, SelectMessages.GUIIsDisabled.replace("[gui]", gui.key));
|
|
} else T2Csend.player(player, SelectMessages.guiNotFound.replace("[gui]", arg));
|
|
}
|
|
}
|