2929import dev .espi .protectionstones .utils .RecipeUtil ;
3030import dev .espi .protectionstones .utils .UUIDCache ;
3131import dev .espi .protectionstones .utils .WGUtils ;
32+ import net .kyori .adventure .text .Component ;
33+ import net .kyori .adventure .text .format .NamedTextColor ;
3234import org .bukkit .Bukkit ;
3335import org .bukkit .ChatColor ;
3436import org .bukkit .Material ;
3739import org .bukkit .block .BlockFace ;
3840import org .bukkit .block .BlockState ;
3941import org .bukkit .block .Furnace ;
42+ import org .bukkit .block .data .type .Crafter ;
4043import org .bukkit .command .CommandSender ;
4144import org .bukkit .enchantments .Enchantment ;
4245import org .bukkit .entity .Player ;
5356import org .bukkit .event .player .PlayerJoinEvent ;
5457import org .bukkit .event .player .PlayerTeleportEvent ;
5558import org .bukkit .event .player .PlayerTeleportEvent .TeleportCause ;
56- import org .bukkit .inventory .CraftingRecipe ;
57- import org .bukkit .inventory .ItemStack ;
58- import org .bukkit .inventory .ShapedRecipe ;
59- import org .bukkit .inventory .ShapelessRecipe ;
59+ import org .bukkit .inventory .*;
6060
6161import java .util .List ;
6262
@@ -95,7 +95,7 @@ public void onPlayerJoin(PlayerJoinEvent e) {
9595 }
9696
9797 if (amount != 0 ) {
98- PSL .msg (psp , PSL .TAX_JOIN_MSG_PENDING_PAYMENTS . msg () .replace ("%money%" , "" + amount ));
98+ PSL .msg (psp . getPlayer () , PSL .TAX_JOIN_MSG_PENDING_PAYMENTS .replace ("%money%" , "" + amount ));
9999 }
100100 });
101101 }
@@ -140,7 +140,7 @@ public void onBlockPlace(BlockPlaceEvent e) {
140140
141141 // returns the error message, or "" if the player has permission to break the region
142142 // TODO: refactor and move this to PSRegion, so that /ps unclaim can use the same checks
143- private String checkPermissionToBreakProtection (Player p , PSRegion r ) {
143+ private Component checkPermissionToBreakProtection (Player p , PSRegion r ) {
144144 // check for destroy permission
145145 if (!p .hasPermission ("protectionstones.destroy" )) {
146146 return PSL .NO_PERMISSION_DESTROY .msg ();
@@ -156,7 +156,7 @@ private String checkPermissionToBreakProtection(Player p, PSRegion r) {
156156 return PSL .RENT_CANNOT_BREAK_WHILE_RENTING .msg ();
157157 }
158158
159- return "" ;
159+ return Component . empty () ;
160160 }
161161
162162 // helper method for breaking protection blocks
@@ -165,8 +165,8 @@ private boolean playerBreakProtection(Player p, PSRegion r) {
165165 PSProtectBlock blockOptions = r .getTypeOptions ();
166166
167167 // check if player has permission to break the protection
168- String error = checkPermissionToBreakProtection (p , r );
169- if (!error .isEmpty ( )) {
168+ Component error = checkPermissionToBreakProtection (p , r );
169+ if (!error .contains ( Component . empty () )) {
170170 PSL .msg (p , error );
171171 return false ;
172172 }
@@ -235,8 +235,8 @@ public void onBlockBreakLowPriority(BlockBreakEvent e) {
235235 ProtectionStones .getInstance ().debug ("Player:" + p .getName ()+", Holding:" + p .getPlayer ().getInventory ().getItemInMainHand ().getType ().name ()+", Enchants:" +p .getPlayer ().getInventory ().getItemInMainHand ().getEnchantments ());
236236
237237
238- String error = checkPermissionToBreakProtection (p , r );
239- if (!error .isEmpty ( )) {
238+ Component error = checkPermissionToBreakProtection (p , r );
239+ if (!error .contains ( Component . empty () )) {
240240 PSL .msg (p , error );
241241 e .setCancelled (true );
242242 }
@@ -318,37 +318,42 @@ public void onPrepareItemCraft(PrepareItemCraftEvent e) {
318318 }
319319 }
320320
321- @ EventHandler (priority = EventPriority .NORMAL , ignoreCancelled = true )
322- public void onCrafterCraft (CrafterCraftEvent e ) {
323- ProtectionStones .getInstance ().debug ("ListenerClass.java, onCrafterCraft" );
324-
325- CraftingRecipe recipe = e .getRecipe ();
326- if (recipe == null ) return ;
327-
328- // Shaped recipes (grid-based)
329- if (recipe instanceof ShapedRecipe shaped ) {
330- for (ItemStack ingredient : shaped .getIngredientMap ().values ()) {
331- if (ingredient != null ) {
332- PSProtectBlock options = ProtectionStones .getBlockOptions (ingredient );
333- if (options != null && !options .allowUseInCrafting ) {
334- e .setResult (new ItemStack (Material .AIR ));
335- e .setCancelled (true );
336- return ;
337- }
338- }
321+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
322+ public void onCrafterClick (InventoryClickEvent e ) {
323+ if (!(e .getInventory ().getHolder () instanceof Crafter )) return ;
324+
325+ ItemStack item = e .getCursor (); // item being placed
326+ if (item != null && ProtectionStones .getBlockOptions (item ) != null ) {
327+ e .setCancelled (true );
328+ e .getWhoClicked ().sendMessage (ChatColor .RED + "You cannot insert ProtectionStone blocks into a Crafter." );
329+ }
330+ }
331+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
332+ public void onCrafterHopperMove (InventoryMoveItemEvent e ) {
333+ if (!(e .getDestination ().getHolder () instanceof Crafter )) return ;
334+
335+ ItemStack item = e .getItem ();
336+ if (item != null ) {
337+ PSProtectBlock options = ProtectionStones .getBlockOptions (item );
338+ if (options != null && !options .allowUseInCrafting ) {
339+ e .setCancelled (true );
339340 }
340341 }
342+ }
341343
342- // Shapeless recipes (unordered list)
343- if (recipe instanceof ShapelessRecipe shapeless ) {
344- for (ItemStack ingredient : shapeless .getIngredientList ()) {
345- if (ingredient != null ) {
346- PSProtectBlock options = ProtectionStones .getBlockOptions (ingredient );
347- if (options != null && !options .allowUseInCrafting ) {
348- e .setResult (new ItemStack (Material .AIR ));
349- e .setCancelled (true );
350- return ;
344+ @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
345+ public void onCrafterDrag (InventoryDragEvent e ) {
346+ if (!(e .getInventory ().getHolder () instanceof Crafter )) return ;
347+
348+ for (ItemStack item : e .getNewItems ().values ()) {
349+ if (item != null ) {
350+ PSProtectBlock options = ProtectionStones .getBlockOptions (item );
351+ if (options != null && !options .allowUseInCrafting ) {
352+ e .setCancelled (true );
353+ if (e .getWhoClicked () instanceof Player player ) {
354+ PSL .msg (player , Component .text ("You cannot use ProtectionStones blocks in a Crafter." , NamedTextColor .RED ));
351355 }
356+ return ;
352357 }
353358 }
354359 }
0 commit comments