Change:
- The plugin reload now runs asyncron and therefore no longer causes the server to freeze briefly during a plugin reload.
This commit is contained in:
JaTiTV 2022-12-22 01:48:57 +01:00
parent 893f99c3e5
commit 82cc31d41f
3 changed files with 198 additions and 5 deletions

View File

@ -6,7 +6,11 @@
<groupId>net.t2code</groupId>
<artifactId>CommandGUI_V2</artifactId>
<<<<<<< Updated upstream
<version>2.8.9</version>
=======
<version>2.8.13</version>
>>>>>>> Stashed changes
<packaging>jar</packaging>
<name>CommandGUI</name>

View File

@ -20,7 +20,10 @@ public class CGuiAPI {
public static Boolean JoinDisable = false;
public static void onItemChange(Player player) {
ItemChange.itemChange(player, false);
onItemChange(player,false);
}
public static void onItemChange(Player player, Boolean setCursor) {
ItemChange.itemChange(player, setCursor);
}
public static boolean hasUseItemInMainHand(Player player) {
@ -35,10 +38,6 @@ public class CGuiAPI {
&& item.getItemMeta().getDisplayName().equals(SelectConfig.getUseItem_Name());
}
public static void onItemChange(Player player, Boolean setCursor) {
ItemChange.itemChange(player, setCursor);
}
public static void disableItemGiveOnJoin(Boolean disableItemGiveOnJoin) {
send.debug(Main.getPlugin(), "CGuiAPI: " + disableItemGiveOnJoin);
JoinDisable = disableItemGiveOnJoin;

View File

@ -0,0 +1,190 @@
package net.t2code.commandguiv2.Spigot.cmdManagement;
import net.t2code.commandguiv2.Spigot.useItem.Events;
import net.t2code.commandguiv2.Spigot.Main;
import net.t2code.commandguiv2.Spigot.objects.Obj_Select;
import net.t2code.commandguiv2.Spigot.objects.guis.Gui;
import net.t2code.commandguiv2.Spigot.cmdManagement.register.AliasRegister;
import net.t2code.commandguiv2.Spigot.gui.OpenGUI;
import net.t2code.commandguiv2.Spigot.useItem.UseItem;
import net.t2code.commandguiv2.Spigot.config.config.SelectConfig;
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.Sound;
import net.t2code.commandguiv2.Spigot.enums.SoundEnum;
import net.t2code.commandguiv2.Util;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
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-------------------------------");
SelectConfig.onSelect();
Main.getPlugin().reloadConfig();
CmdExecuter_GUI.arg1.clear();
CmdExecuter_GUI.arg1.put(SelectConfig.getAdminSubCommand(), "commandgui.admin;commandgui.giveitem.other;commandgui.command.info");
if (!Objects.equals(SelectDatabase.getStorage().toString(), SelectConfig.getStorage())) {
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();
Obj_Select.onSelect();
SelectMessages.onSelect(Util.getPrefix());
SelectConfig.sound(Util.getPrefix());
try {
AliasRegister.onRegister();
} catch (Exception e) {
e.printStackTrace();
}
try {
Permissions.onPermRegister();
} catch (Exception e) {
e.printStackTrace();
}
if (SelectConfig.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]", SelectConfig.getUseItem_Name()));
T2Csend.player(target, SelectMessages.Give_Receiver.replace("[sender]", sender.getName()).replace("[item]", SelectConfig.getUseItem_Name()));
Sound.play(target, SoundEnum.Give);
} else {
sender.sendMessage(SelectMessages.PlayerNotFond.replace("[player]", target.getName()));
if (sender instanceof Player) Sound.play((Player) sender, SoundEnum.PlayerNotFound);
}
}
public static void itemOn(Player player) {
UseItem.removeItem(player);
Integer slot = null;
if (SelectConfig.getUseItem_InventorySlotEnforce()) {
slot = SelectConfig.getUseItem_InventorySlot();
} else {
slot = Events.useItemSlotHashMap.get(player.getName());
}
T2Csend.debug(Main.getPlugin(), String.valueOf(slot));
if (player.getInventory().getItem(slot - 1) == null) {
SelectDatabase.setItemStatusTrue(player);
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.setItemStatusTrue(player);
UseItem.addUseItem(player);
T2Csend.player(player, SelectMessages.ItemON);
} else {
T2Csend.player(player, SelectMessages.NoInventorySpace);
Sound.play(player, SoundEnum.NoInventorySpace);
}
}
}
public static void itemOff(Player player) {
SelectDatabase.setItemStatusFalse(player);
UseItem.removeItem(player);
T2Csend.player(player, SelectMessages.ItemOFF);
}
public static void onSetSlot(Player player, Integer setSlot) {
if (!SelectConfig.getUseItem_AllowSetSlot()) {
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 (SelectConfig.getUseItem_InventorySlotEnforce() || player.getInventory().getItem(setSlot - 1) != null) {
T2Csend.player(player, SelectMessages.ItemSlotNotEmpty.replace("[slot]", setSlot.toString()));
return;
}
UseItem.removeItem(player);
SelectDatabase.setSlot(player, 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 (Main.guiHashMap.containsKey(SelectConfig.getDefaultGUI())) {
Gui gui = Main.guiHashMap.get(SelectConfig.getDefaultGUI());
if (gui.guiEnable || player.hasPermission("commandgui.bypass")) {
if (!gui.commandPermissionEnable || player.hasPermission("commandgui.command") || player.hasPermission("commandgui.bypass")) {
OpenGUI.openGUI(player, SelectConfig.getDefaultGUI(), 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 (Main.guiHashMap.containsKey(arg)) {
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 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);
}
}