Skip to content

Commit

Permalink
ignore gui item interactions in illegal listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 1, 2025
1 parent 132d99d commit 382aa5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public abstract class IllegalItemModule extends AEFModule implements Listener {

protected final AEFPermission bypassPermission;
protected final IllegalHandling handling;

protected final Set<Listener> optionalListeners;
protected final boolean guiPluginsSupported;

private final Cache<Class<? extends Event>, ExpiringSet<Object>> listenerCooldowns;
private final Function<Class<? extends Event>, @PolyNull ExpiringSet<Object>> createIfAbsent;

Expand All @@ -80,7 +83,7 @@ public IllegalItemModule(String configPath, boolean defEnabled, AEFPermission by
}
this.handling = handling;

final boolean guiPluginsSupported = config.getBoolean(configPath + ".gui-plugins-supported", false, """
this.guiPluginsSupported = config.getBoolean(configPath + ".gui-plugins-supported", false, """
Enable this if you have problems with the plugin removing items from chest guis.""");
if (this.handling == IllegalHandling.STRICT) {
optionalListeners.add(new Listener() {
Expand Down Expand Up @@ -237,6 +240,8 @@ public void onPlayerArmorChange(PlayerArmorChangeEvent event) {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
if (guiPluginsSupported && event.getInventory().getLocation() == null) return;

if (listenerCooldowns.get(event.getClass(), createIfAbsent).contains(event.getWhoClicked().getUniqueId())) {
event.setCancelled(true);
return;
Expand All @@ -261,6 +266,8 @@ public void onInventoryClick(InventoryClickEvent event) {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryInteract(InventoryInteractEvent event) {
if (guiPluginsSupported && event.getInventory().getLocation() == null) return;

if (listenerCooldowns.get(event.getClass(), createIfAbsent).contains(event.getWhoClicked().getUniqueId())) {
event.setCancelled(true);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public abstract class IllegalItemModule extends AEFModule implements Listener {

protected final AEFPermission bypassPermission;
protected final IllegalHandling handling;

protected final Set<Listener> optionalListeners;
protected final boolean guiPluginsSupported;

private final Cache<Class<? extends Event>, ExpiringSet<Object>> listenerCooldowns;
private final Function<Class<? extends Event>, @PolyNull ExpiringSet<Object>> createIfAbsent;

Expand All @@ -80,7 +83,7 @@ public IllegalItemModule(String configPath, boolean defEnabled, AEFPermission by
}
this.handling = handling;

final boolean guiPluginsSupported = config.getBoolean(configPath + ".gui-plugins-supported", false,
this.guiPluginsSupported = config.getBoolean(configPath + ".gui-plugins-supported", false,
"Enable this if you have problems with the plugin removing items from chest guis.");
if (this.handling == IllegalHandling.STRICT) {
optionalListeners.add(new Listener() {
Expand Down Expand Up @@ -236,6 +239,8 @@ public void onPlayerArmorChange(PlayerArmorChangeEvent event) {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
if (guiPluginsSupported && event.getInventory().getLocation() == null) return;

if (listenerCooldowns.get(event.getClass(), createIfAbsent).contains(event.getWhoClicked().getUniqueId())) {
event.setCancelled(true);
return;
Expand All @@ -260,6 +265,8 @@ public void onInventoryClick(InventoryClickEvent event) {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryInteract(InventoryInteractEvent event) {
if (guiPluginsSupported && event.getInventory().getLocation() == null) return;

if (listenerCooldowns.get(event.getClass(), createIfAbsent).contains(event.getWhoClicked().getUniqueId())) {
event.setCancelled(true);
return;
Expand Down

0 comments on commit 382aa5b

Please sign in to comment.