Added GUI Detection system with DeluxeMenus support

This commit is contained in:
Auxilor
2023-02-14 20:00:39 +00:00
parent a3a5e4df38
commit 1accad88fe
6 changed files with 88 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
package com.willfp.eco.core.display;
import com.willfp.eco.core.fast.FastItemStack;
import com.willfp.eco.core.integrations.guidetection.GUIDetectionManager;
import com.willfp.eco.util.NamespacedKeyUtils;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
@@ -71,7 +72,7 @@ public final class Display {
ItemStack original = itemStack.clone();
Inventory inventory = player == null ? null : player.getOpenInventory().getTopInventory();
boolean inInventory = inventory != null && inventory.contains(original);
boolean inGui = inventory != null && inventory.getHolder() == null;
boolean inGui = player != null && GUIDetectionManager.hasGUIOpen(player);
DisplayProperties properties = new DisplayProperties(
inInventory,

View File

@@ -0,0 +1,18 @@
package com.willfp.eco.core.integrations.guidetection;
import com.willfp.eco.core.integrations.Integration;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
/**
* Wrapper class for GUI integrations.
*/
public interface GUIDetectionIntegration extends Integration {
/**
* Determine if a player is in a GUI.
*
* @param player The player.
* @return If the player is in a GUI.
*/
boolean hasGUIOpen(@NotNull final Player player);
}

View File

@@ -0,0 +1,52 @@
package com.willfp.eco.core.integrations.guidetection;
import com.willfp.eco.util.MenuUtils;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Set;
/**
* Class to handle GUI detection.
*/
public final class GUIDetectionManager {
/**
* A set of all registered integrations.
*/
private static final Set<GUIDetectionIntegration> REGISTERED = new HashSet<>();
/**
* Register a new integration.
*
* @param integration The integration to register.
*/
public static void register(@NotNull final GUIDetectionIntegration integration) {
REGISTERED.removeIf(it -> it.getPluginName().equalsIgnoreCase(integration.getPluginName()));
REGISTERED.add(integration);
}
/**
* Get if a player is in a GUI.
*
* @param player The player.
* @return If the player has a GUI open.
*/
public static boolean hasGUIOpen(@NotNull final Player player) {
if (MenuUtils.getOpenMenu(player) != null) {
return true;
}
for (GUIDetectionIntegration integration : REGISTERED) {
if (integration.hasGUIOpen(player)) {
return true;
}
}
return false;
}
private GUIDetectionManager() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
}

View File

@@ -0,0 +1,15 @@
package com.willfp.eco.internal.spigot.integrations.guidetection
import com.extendedclip.deluxemenus.menu.Menu
import com.willfp.eco.core.integrations.guidetection.GUIDetectionIntegration
import org.bukkit.entity.Player
class GUIDetectionDeluxeMenus: GUIDetectionIntegration {
override fun hasGUIOpen(player: Player): Boolean {
return Menu.inMenu(player)
}
override fun getPluginName(): String {
return "DeluxeMenus"
}
}

View File

@@ -51,3 +51,4 @@ softdepend:
- Scyther
- ModelEngine
- PvPManager
- DeluxeMenus

Binary file not shown.