@@ -54,12 +54,11 @@ public abstract class IllegalItemModule extends AEFModule implements Listener {
5454
5555 protected final AEFPermission bypassPermission ;
5656 protected final IllegalHandling handling ;
57-
58- protected final Set <Listener > optionalListeners ;
5957 protected final boolean guiPluginsSupported ;
6058
61- private final Cache <Class <? extends Event >, ExpiringSet <Object >> listenerCooldowns ;
62- private final Function <Class <? extends Event >, @ PolyNull ExpiringSet <Object >> createIfAbsent ;
59+ protected final Set <Listener > optionalListeners ;
60+ protected final Cache <Class <? extends Event >, ExpiringSet <Object >> listenerCooldowns ;
61+ protected final Function <Class <? extends Event >, @ PolyNull ExpiringSet <Object >> createIfAbsent ;
6362
6463 public IllegalItemModule (String configPath , AEFPermission bypassPermission ) {
6564 this (configPath , false , bypassPermission , null );
@@ -68,7 +67,7 @@ public IllegalItemModule(String configPath, AEFPermission bypassPermission) {
6867 public IllegalItemModule (String configPath , boolean defEnabled , AEFPermission bypassPermission , String comment ) {
6968 super (configPath , defEnabled , comment );
7069 this .bypassPermission = bypassPermission ;
71- this .optionalListeners = new HashSet <>();
70+ this .optionalListeners = new HashSet <>(6 );
7271
7372 String configuredHandling = config .getString (configPath + ".handling" , IllegalHandling .PREVENT_USE_ONLY .name (),
7473 "Available options:\n " + Arrays .stream (IllegalHandling .values ())
@@ -87,7 +86,7 @@ public IllegalItemModule(String configPath, boolean defEnabled, AEFPermission by
8786 Enable this if you have problems with the plugin removing items from chest guis.""" );
8887 if (this .handling == IllegalHandling .STRICT ) {
8988 optionalListeners .add (new Listener () {
90- @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
89+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = false )
9190 private void onInventoryOpen (InventoryOpenEvent event ) {
9291 if (AnarchyExploitFixes .permissions ().permissionValue (event .getPlayer (), bypassPermission .node ()).toBoolean ()) return ;
9392 // Check if the inventory is connected to a location in the game. If it is not,
@@ -108,7 +107,7 @@ private void onInventoryOpen(InventoryOpenEvent event) {
108107 intense as the event fires in high frequencies as soon as players start using\s
109108 farms or item sorters. Recommended to leave off if not necessary.""" )) {
110109 optionalListeners .add (new Listener () {
111- @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
110+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = false )
112111 private void onItemGoesThroughHopper (InventoryMoveItemEvent event ) {
113112 if (legalityOf (event .getItem ()) != ItemLegality .LEGAL ) {
114113 event .setCancelled (true );
@@ -127,7 +126,7 @@ private void onItemGoesThroughHopper(InventoryMoveItemEvent event) {
127126 to handle items separately.""" );
128127 if (checkOnChunkload ) {
129128 optionalListeners .add (new Listener () {
130- @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
129+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = false )
131130 private void onChunkLoad (ChunkLoadEvent event ) {
132131 if (event .isNewChunk ()) return ;
133132
@@ -200,8 +199,10 @@ public ItemLegality legalityOf(@Nullable Iterable<ItemStack> itemStacks) {
200199 return ItemLegality .LEGAL ;
201200 }
202201
203- @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
202+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = false )
204203 public void onPlayerItemConsume (PlayerItemConsumeEvent event ) {
204+ if (event .isCancelled () && handling == IllegalHandling .PREVENT_USE_ONLY ) return ;
205+
205206 if (listenerCooldowns .get (event .getClass (), createIfAbsent ).contains (event .getPlayer ().getUniqueId ())) {
206207 event .setCancelled (true );
207208 return ;
@@ -215,8 +216,10 @@ public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
215216 }
216217 }
217218
218- @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
219+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = false )
219220 public void onBlockDispense (BlockDispenseEvent event ) {
221+ if (event .isCancelled () && handling == IllegalHandling .PREVENT_USE_ONLY ) return ;
222+
220223 if (listenerCooldowns .get (event .getClass (), createIfAbsent ).contains (event .getBlock ().getLocation ())) {
221224 event .setCancelled (true );
222225 return ;
@@ -228,7 +231,7 @@ public void onBlockDispense(BlockDispenseEvent event) {
228231 }
229232 }
230233
231- @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
234+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = false )
232235 public void onPlayerArmorChange (PlayerArmorChangeEvent event ) {
233236 if (handling == IllegalHandling .PREVENT_USE_ONLY ) return ; // Cant cancel this event
234237
@@ -238,8 +241,9 @@ public void onPlayerArmorChange(PlayerArmorChangeEvent event) {
238241 }
239242 }
240243
241- @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
244+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = false )
242245 public void onInventoryClick (InventoryClickEvent event ) {
246+ if (event .isCancelled () && handling == IllegalHandling .PREVENT_USE_ONLY ) return ;
243247 if (guiPluginsSupported && event .getInventory ().getLocation () == null ) return ;
244248
245249 if (listenerCooldowns .get (event .getClass (), createIfAbsent ).contains (event .getWhoClicked ().getUniqueId ())) {
@@ -264,8 +268,9 @@ public void onInventoryClick(InventoryClickEvent event) {
264268 }
265269 }
266270
267- @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
271+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = false )
268272 public void onInventoryInteract (InventoryInteractEvent event ) {
273+ if (event .isCancelled () && handling == IllegalHandling .PREVENT_USE_ONLY ) return ;
269274 if (guiPluginsSupported && event .getInventory ().getLocation () == null ) return ;
270275
271276 if (listenerCooldowns .get (event .getClass (), createIfAbsent ).contains (event .getWhoClicked ().getUniqueId ())) {
@@ -285,8 +290,10 @@ public void onInventoryInteract(InventoryInteractEvent event) {
285290 }
286291 }
287292
288- @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
293+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = false )
289294 public void onPrePlayerAttackEntity (PrePlayerAttackEntityEvent event ) {
295+ if (event .isCancelled () && handling == IllegalHandling .PREVENT_USE_ONLY ) return ;
296+
290297 if (listenerCooldowns .get (event .getClass (), createIfAbsent ).contains (event .getPlayer ().getUniqueId ())) {
291298 event .setCancelled (true );
292299 return ;
@@ -311,8 +318,10 @@ public void onPrePlayerAttackEntity(PrePlayerAttackEntityEvent event) {
311318 }
312319 }
313320
314- @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
321+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = false )
315322 public void onEntityDamageByEntity (EntityDamageByEntityEvent event ) {
323+ if (event .isCancelled () && handling == IllegalHandling .PREVENT_USE_ONLY ) return ;
324+
316325 if (event .getDamager ().getType () == EntityType .PLAYER ) {
317326 final Player player = (Player ) event .getDamager ();
318327
@@ -359,8 +368,10 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
359368 }
360369 }
361370
362- @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
371+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = false )
363372 public void onPlayerAttemptPickupItem (PlayerAttemptPickupItemEvent event ) {
373+ if (event .isCancelled () && handling == IllegalHandling .PREVENT_USE_ONLY ) return ;
374+
364375 if (listenerCooldowns .get (event .getClass (), createIfAbsent ).contains (event .getPlayer ().getUniqueId ())) {
365376 event .setCancelled (true );
366377 return ;
@@ -378,8 +389,10 @@ public void onPlayerAttemptPickupItem(PlayerAttemptPickupItemEvent event) {
378389 }
379390 }
380391
381- @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
392+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = false )
382393 public void onPlayerDropItem (PlayerDropItemEvent event ) {
394+ if (event .isCancelled () && handling == IllegalHandling .PREVENT_USE_ONLY ) return ;
395+
383396 if (listenerCooldowns .get (event .getClass (), createIfAbsent ).contains (event .getPlayer ().getUniqueId ())) {
384397 event .setCancelled (true );
385398 return ;
@@ -398,6 +411,8 @@ public void onPlayerDropItem(PlayerDropItemEvent event) {
398411
399412 @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = false )
400413 public void onPlayerInteract (PlayerInteractEvent event ) {
414+ if (event .useItemInHand () == Event .Result .DENY && handling == IllegalHandling .PREVENT_USE_ONLY ) return ;
415+
401416 if (listenerCooldowns .get (event .getClass (), createIfAbsent ).contains (event .getPlayer ().getUniqueId ())) {
402417 event .setCancelled (true );
403418 return ;
@@ -414,8 +429,10 @@ public void onPlayerInteract(PlayerInteractEvent event) {
414429 }
415430 }
416431
417- @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
432+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = false )
418433 public void onPlayerInteractEntity (PlayerInteractEntityEvent event ) {
434+ if (event .isCancelled () && handling == IllegalHandling .PREVENT_USE_ONLY ) return ;
435+
419436 if (listenerCooldowns .get (event .getClass (), createIfAbsent ).contains (event .getPlayer ().getUniqueId ())) {
420437 event .setCancelled (true );
421438 return ;
0 commit comments