77import io .github .thatsmusic99 .headsplus .config .HeadsPlusMainConfig ;
88import io .github .thatsmusic99 .headsplus .reflection .NBTManager ;
99import io .github .thatsmusic99 .headsplus .util .FlagHandler ;
10+ import io .github .thatsmusic99 .headsplus .util .events .HeadsPlusEventExecutor ;
11+ import io .github .thatsmusic99 .headsplus .util .events .HeadsPlusListener ;
1012import org .bukkit .Bukkit ;
1113import org .bukkit .ChatColor ;
1214import org .bukkit .GameMode ;
1315import org .bukkit .entity .EntityType ;
1416import org .bukkit .entity .Player ;
1517import org .bukkit .event .EventHandler ;
18+ import org .bukkit .event .EventPriority ;
1619import org .bukkit .event .Listener ;
1720import org .bukkit .event .inventory .InventoryClickEvent ;
1821import org .bukkit .event .inventory .InventoryType ;
1922import org .bukkit .inventory .meta .SkullMeta ;
2023
21- public class RecipePerms implements Listener {
22-
23- @ EventHandler
24- public void onCraft (InventoryClickEvent e ) {
25- try {
26- if (e .getInventory ().getType ().equals (InventoryType .CRAFTING ) || e .getInventory ().getType ().equals (InventoryType .WORKBENCH )) {
27- Player player = (Player ) e .getWhoClicked ();
28- HeadsPlus hp = HeadsPlus .getInstance ();
29- HeadsPlusAPI hapi = hp .getAPI ();
30- HeadsPlusMainConfig c = hp .getConfiguration ();
31- if (!isValid1_14 (e )) return ;
24+ public class RecipePerms extends HeadsPlusListener <InventoryClickEvent > {
25+
26+ public RecipePerms () {
27+ Bukkit .getPluginManager ().registerEvent (InventoryClickEvent .class , this , EventPriority .NORMAL ,
28+ new HeadsPlusEventExecutor (InventoryClickEvent .class , "RecipeHandlingEvent" ), HeadsPlus .getInstance ());
29+ }
30+ public void onEvent (InventoryClickEvent e ) {
31+ addData ("player" , e .getWhoClicked ().getName ());
32+ addData ("inventory-type" , e .getInventory ().getType ().name ());
33+ addData ("slot" , e .getRawSlot ());
34+
35+ Player player = (Player ) e .getWhoClicked ();
36+ HeadsPlus hp = HeadsPlus .getInstance ();
37+ HeadsPlusMainConfig c = hp .getConfiguration ();
38+ if (e .getInventory ().getType ().equals (InventoryType .CRAFTING ) || e .getInventory ().getType ().equals (InventoryType .WORKBENCH )) {
39+ if (addData ("is-correct-slot" , isValid1_14 (e ))) {
40+ if (e .getCurrentItem () != null ) {
41+ if (e .getCurrentItem ().getItemMeta () instanceof SkullMeta ) {
42+ String type = addData ("type" , NBTManager .getType (e .getCurrentItem ()));
43+ if (type != null && !type .isEmpty ()) {
44+ // Beyond this point, we can start denying events
45+ if (addData ("enabled" , c .getPerks ().craft_heads )) {
46+ if (addData ("has-permission" , player .hasPermission ("headsplus.craft" ))) {
47+ if (addData ("has-worldguard" , Bukkit .getPluginManager ().isPluginEnabled ("WorldGuard" ))) {
48+ addData ("skull-type" , type );
49+ if (!FlagHandler .canCraft (e .getWhoClicked ().getLocation (), EntityType .valueOf (type ))) {
50+ denyPermission (e );
51+ return ;
52+ }
53+ }
54+
55+ if (c .getWorldBlacklist ().enabled ) {
56+ if (!c .getWorldBlacklist ().list .contains (player .getWorld ().getName ())
57+ || player .hasPermission ("headsplus.bypass.blacklistw" )) {
3258
33- if (c .getPerks ().craft_heads ) {
34- if (player .hasPermission ("headsplus.craft" )) {
35- if (Bukkit .getPluginManager ().isPluginEnabled ("WorldGuard" )) {
36- if (!FlagHandler .canCraft (e .getWhoClicked ().getLocation (), EntityType .valueOf (hapi .getSkullType (e .getCurrentItem ())))) {
37- denyPermission (e );
38- return ;
39- }
40- }
41- if (c .getWorldBlacklist ().enabled ) {
42- if (!c .getWorldBlacklist ().list .contains (player .getWorld ().getName ())
43- || player .hasPermission ("headsplus.bypass.blacklistw" )) {
44- if (e .getCurrentItem () != null ) {
45- if (e .getCurrentItem ().getItemMeta () instanceof SkullMeta ) {
46- if (!hapi .getSkullType (e .getCurrentItem ()).isEmpty ()) {
4759 if (c .getWorldWhitelist ().list .contains (player .getWorld ().getName ())) {
4860 fireEvent (e );
4961 return ;
@@ -61,25 +73,12 @@ public void onCraft(InventoryClickEvent e) {
6173 }
6274 }
6375 }
64- }
65- } else {
66- if (e .getInventory ().getType ().equals (InventoryType .WORKBENCH )) {
67- denyPermission (e );
68- } else if (e .getInventory ().getType ().equals (InventoryType .CRAFTING )){
6976 denyPermission (e );
7077 }
7178 }
7279 }
73- if (e .getInventory ().getType ().equals (InventoryType .WORKBENCH )) {
74- denyPermission (e );
75- } else if (e .getInventory ().getType ().equals (InventoryType .CRAFTING )){
76- denyPermission (e );
77- }
7880 }
79- } catch (Exception ex ) {
80- DebugPrint .createReport (ex , "Event (RecipeCheckers)" , false , null );
8181 }
82-
8382 }
8483
8584 private int shift (InventoryClickEvent e ) {
0 commit comments