Skip to content

Commit 55fe14c

Browse files
committed
Spigot version bump for autocrafter support
1 parent bb51bdc commit 55fe14c

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>dev.espi</groupId>
55
<artifactId>protectionstones</artifactId>
6-
<version>2.10.6</version>
6+
<version>2.10.7</version>
77
<name>ProtectionStones</name>
88
<description>A grief prevention plugin for Spigot Minecraft servers.</description>
99
<url>https://github.com/espidev/ProtectionStones</url>
@@ -207,7 +207,7 @@
207207
<dependency>
208208
<groupId>org.spigotmc</groupId>
209209
<artifactId>spigot-api</artifactId>
210-
<version>1.20.6-R0.1-SNAPSHOT</version>
210+
<version>1.21.3-R0.1-SNAPSHOT</version>
211211
<scope>provided</scope>
212212
</dependency>
213213
<dependency>

src/main/java/dev/espi/protectionstones/ListenerClass.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@
5353
import org.bukkit.event.player.PlayerJoinEvent;
5454
import org.bukkit.event.player.PlayerTeleportEvent;
5555
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
56+
import org.bukkit.inventory.CraftingRecipe;
5657
import org.bukkit.inventory.ItemStack;
58+
import org.bukkit.inventory.ShapedRecipe;
59+
import org.bukkit.inventory.ShapelessRecipe;
5760

5861
import java.util.List;
5962

@@ -220,6 +223,7 @@ public void onPlayerInteract(PlayerInteractEvent e) {
220223
// thus we should cancel the event here if possible (so other plugins don't start acting upon it)
221224
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
222225
public void onBlockBreakLowPriority(BlockBreakEvent e) {
226+
ProtectionStones.getInstance().debug("ListenerClass.java, onBlockBreakLowPriority");
223227
Player p = e.getPlayer();
224228
Block pb = e.getBlock();
225229

@@ -228,6 +232,9 @@ public void onBlockBreakLowPriority(BlockBreakEvent e) {
228232
// check if player has permission to break the protection
229233
PSRegion r = PSRegion.fromLocation(pb.getLocation());
230234
if (r != null) {
235+
ProtectionStones.getInstance().debug("Player:"+ p.getName()+", Holding:"+ p.getPlayer().getInventory().getItemInMainHand().getType().name()+", Enchants:" +p.getPlayer().getInventory().getItemInMainHand().getEnchantments());
236+
237+
231238
String error = checkPermissionToBreakProtection(p, r);
232239
if (!error.isEmpty()) {
233240
PSL.msg(p, error);
@@ -238,6 +245,7 @@ public void onBlockBreakLowPriority(BlockBreakEvent e) {
238245

239246
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
240247
public void onBlockBreak(BlockBreakEvent e) {
248+
ProtectionStones.getInstance().debug("ListenerClass.java, onBlockBreak");
241249
Player p = e.getPlayer();
242250
Block pb = e.getBlock();
243251

@@ -275,6 +283,7 @@ public void onBlockBreak(BlockBreakEvent e) {
275283

276284
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
277285
public void onFurnaceSmelt(FurnaceSmeltEvent e) {
286+
ProtectionStones.getInstance().debug("ListenerClass.java, onFurnaceSmelt");
278287
// prevent protect block item to be smelt
279288
PSProtectBlock options = ProtectionStones.getBlockOptions(e.getSource());
280289
if (options != null && !options.allowSmeltItem) {
@@ -284,6 +293,7 @@ public void onFurnaceSmelt(FurnaceSmeltEvent e) {
284293

285294
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
286295
public void onFurnaceBurnItem(FurnaceBurnEvent e) {
296+
ProtectionStones.getInstance().debug("ListenerClass.java, onFurnaceBurnItem");
287297
// prevent protect block item to be smelt
288298
Furnace f = (Furnace) e.getBlock().getState();
289299
if (f.getInventory().getSmelting() != null) {
@@ -299,6 +309,7 @@ public void onFurnaceBurnItem(FurnaceBurnEvent e) {
299309

300310
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
301311
public void onPrepareItemCraft(PrepareItemCraftEvent e) {
312+
ProtectionStones.getInstance().debug("ListenerClass.java, onPrepareItemCraft");
302313
for (ItemStack s : e.getInventory().getMatrix()) {
303314
PSProtectBlock options = ProtectionStones.getBlockOptions(s);
304315
if (options != null && !options.allowUseInCrafting) {
@@ -307,12 +318,49 @@ public void onPrepareItemCraft(PrepareItemCraftEvent e) {
307318
}
308319
}
309320

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+
}
339+
}
340+
}
341+
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;
351+
}
352+
}
353+
}
354+
}
355+
}
356+
310357

311358
// -=-=-=- disable grindstone inventory to prevent infinite exp exploit with enchanted_effect option -=-=-=-
312359
// see https://github.com/espidev/ProtectionStones/issues/324
313360

314361
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
315362
public void onInventoryClickEvent(InventoryClickEvent e) {
363+
ProtectionStones.getInstance().debug("ListenerClass.java, onInventoryClickEvent");
316364
if (e.getInventory().getType() == InventoryType.GRINDSTONE) {
317365
if (ProtectionStones.isProtectBlockItem(e.getCurrentItem())) {
318366
e.setCancelled(true);
@@ -325,6 +373,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) {
325373

326374
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
327375
public void onPlayerBucketFill(PlayerBucketEmptyEvent e) {
376+
ProtectionStones.getInstance().debug("ListenerClass.java, onPlayerBucketFill");
328377
Block clicked = e.getBlockClicked();
329378
BlockFace bf = e.getBlockFace();
330379
Block check = clicked.getWorld().getBlockAt(clicked.getX() + e.getBlockFace().getModX(), clicked.getY() + bf.getModY(), clicked.getZ() + e.getBlockFace().getModZ());
@@ -335,6 +384,7 @@ public void onPlayerBucketFill(PlayerBucketEmptyEvent e) {
335384

336385
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
337386
public void onBlockIgnite(BlockIgniteEvent e) {
387+
ProtectionStones.getInstance().debug("ListenerClass.java, onBlockIgnite");
338388
if (ProtectionStones.isProtectBlock(e.getBlock())) {
339389
e.setCancelled(true);
340390
}
@@ -425,16 +475,19 @@ private void pistonUtil(List<Block> pushedBlocks, BlockPistonEvent e) {
425475

426476
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
427477
public void onBlockExplode(BlockExplodeEvent e) {
478+
ProtectionStones.getInstance().debug("ListenerClass.java, onBlockExplode");
428479
explodeUtil(e.blockList(), e.getBlock().getLocation().getWorld());
429480
}
430481

431482
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
432483
public void onEntityExplode(EntityExplodeEvent e) {
484+
ProtectionStones.getInstance().debug("ListenerClass.java, onEntityExplode");
433485
explodeUtil(e.blockList(), e.getLocation().getWorld());
434486
}
435487

436488
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
437489
public void onEntityChangeBlock(EntityChangeBlockEvent e) {
490+
ProtectionStones.getInstance().debug("ListenerClass.java, onEntityChangeBlock");
438491
if (!ProtectionStones.isProtectBlock(e.getBlock())) return;
439492

440493
// events like ender dragon block break, wither running into block break, etc.

0 commit comments

Comments
 (0)