From e39c2b661c0ac7663bebea978335659af43d2c37 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sun, 14 Mar 2021 11:02:47 +0100 Subject: [PATCH] Fixes #2883 --- CHANGELOG.md | 5 ++-- .../events/ExplosiveToolBreakBlocksEvent.java | 29 +++++++++++++++---- .../slimefun4/api/items/ItemSetting.java | 4 +-- .../electric/machines/ElectricSmeltery.java | 7 ++++- .../items/tools/ExplosiveTool.java | 7 +++-- .../settings/ClimbableSurface.java | 2 ++ 6 files changed, 39 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7af0bc45..e08042d92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # Table of contents -- [Release Candidate 21 (TBD)](#release-candidate-21-tbd) +- [Release Candidate 21 (14 Mar 2021)](#release-candidate-21-14-mar-2021) - [Release Candidate 20 (30 Jan 2021)](#release-candidate-20-30-jan-2021) - [Release Candidate 19 (11 Jan 2021)](#release-candidate-19-11-jan-2021) - [Release Candidate 18 (03 Dec 2020)](#release-candidate-18-03-dec-2020) @@ -21,7 +21,7 @@ - [Release Candidate 2 (29 Sep 2019)](#release-candidate-2-29-sep-2019) - [Release Candidate 1 (26 Sep 2019)](#release-candidate-1-26-sep-2019) -## Release Candidate 21 (TBD) +## Release Candidate 21 (14 Mar 2021) #### Additions * Nether Wart Blocks can now be turned into Nether Warts using a Grind Stone @@ -62,6 +62,7 @@ * Fixed #2877 * Fixed #2878 * Fixed Mining Androids being broken +* Fixed #2883 ## Release Candidate 20 (30 Jan 2021) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ExplosiveToolBreakBlocksEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ExplosiveToolBreakBlocksEvent.java index 5ebf4fd49..0d5e8f75c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ExplosiveToolBreakBlocksEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ExplosiveToolBreakBlocksEvent.java @@ -18,6 +18,8 @@ import java.util.List; * This {@link Event} is called when an {@link ExplosiveTool} is used to break blocks. * * @author GallowsDove + * + * @see ExplosiveTool * */ public class ExplosiveToolBreakBlocksEvent extends PlayerEvent implements Cancellable { @@ -26,30 +28,45 @@ public class ExplosiveToolBreakBlocksEvent extends PlayerEvent implements Cancel private final ItemStack itemInHand; private final ExplosiveTool explosiveTool; - private final List blocks; + private final Block mainBlock; + private final List additionalBlocks; private boolean cancelled; @ParametersAreNonnullByDefault - public ExplosiveToolBreakBlocksEvent(Player player, List blocks, ItemStack item, ExplosiveTool explosiveTool) { + public ExplosiveToolBreakBlocksEvent(Player player, Block block, List blocks, ItemStack item, ExplosiveTool explosiveTool) { super(player); - Validate.notEmpty(blocks, "Blocks cannot be null or empty"); + Validate.notNull(block, "The center block cannot be null!"); + Validate.notNull(blocks, "Blocks cannot be null"); Validate.notNull(item, "Item cannot be null"); Validate.notNull(explosiveTool, "ExplosiveTool cannot be null"); - this.blocks = blocks; + this.mainBlock = block; + this.additionalBlocks = blocks; this.itemInHand = item; this.explosiveTool = explosiveTool; } + /** + * This returns the primary {@link Block} that was broken. + * This {@link Block} triggered this {@link Event} and is not included + * in {@link #getAdditionalBlocks()}. + * + * @return The primary broken {@link Block} + */ + @Nonnull + public Block getPrimaryBlock() { + return this.mainBlock; + } + /** * Gets the {@link Block} {@link List} of blocks destroyed in this event. * * @return The broken blocks */ @Nonnull - public List getBlocks() { - return this.blocks; + public List getAdditionalBlocks() { + return this.additionalBlocks; } /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java index 32f327db4..b601d6f83 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java @@ -158,8 +158,6 @@ public class ItemSetting { * This method is called by a {@link SlimefunItem} which wants to load its {@link ItemSetting} * from the {@link Config} file. * - * @param item - * The {@link SlimefunItem} who called this method */ @SuppressWarnings("unchecked") public void reload() { @@ -169,7 +167,7 @@ public class ItemSetting { Object configuredValue = SlimefunPlugin.getItemCfg().getValue(item.getId() + '.' + getKey()); if (defaultValue.getClass().isInstance(configuredValue)) { - // We can unsafe cast here, we did an isInstance(...) check before! + // We can do an unsafe cast here, we did an isInstance(...) check before! T newValue = (T) configuredValue; if (validateInput(newValue)) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricSmeltery.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricSmeltery.java index aac0dc718..464c42922 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricSmeltery.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricSmeltery.java @@ -29,6 +29,9 @@ import java.util.Comparator; import java.util.LinkedList; import java.util.List; +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + /** * The {@link ElectricSmeltery} is an electric version of the standard {@link Smeltery}. * @@ -41,6 +44,7 @@ public class ElectricSmeltery extends AContainer implements NotHopperable { private static final int[] inputBorder = { 0, 1, 2, 3, 9, 12, 18, 21, 27, 30, 36, 37, 38, 39 }; private static final int[] outputBorder = { 14, 15, 16, 17, 23, 26, 32, 33, 34, 35 }; + @ParametersAreNonnullByDefault public ElectricSmeltery(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); @@ -113,7 +117,8 @@ public class ElectricSmeltery extends AContainer implements NotHopperable { }); } - private Comparator compareSlots(DirtyChestMenu menu) { + @Nonnull + private Comparator compareSlots(@Nonnull DirtyChestMenu menu) { return Comparator.comparingInt(slot -> menu.getItemInSlot(slot).getAmount()); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java index b450232f8..4bb51e450 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java @@ -91,7 +91,7 @@ public class ExplosiveTool extends SimpleSlimefunItem implements } } - ExplosiveToolBreakBlocksEvent event = new ExplosiveToolBreakBlocksEvent(p, blocksToDestroy, item, this); + ExplosiveToolBreakBlocksEvent event = new ExplosiveToolBreakBlocksEvent(p, b, blocksToDestroy, item, this); Bukkit.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { @@ -101,7 +101,8 @@ public class ExplosiveTool extends SimpleSlimefunItem implements } } - private List findBlocks(Block b) { + @Nonnull + private List findBlocks(@Nonnull Block b) { List blocks = new ArrayList<>(26); for (int x = -1; x <= 1; x++) { @@ -125,7 +126,7 @@ public class ExplosiveTool extends SimpleSlimefunItem implements return damageOnUse.getValue(); } - protected boolean canBreak(Player p, Block b) { + protected boolean canBreak(@Nonnull Player p, @Nonnull Block b) { if (b.isEmpty() || b.isLiquid()) { return false; } else if (SlimefunTag.UNBREAKABLE_MATERIALS.isTagged(b.getType())) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/settings/ClimbableSurface.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/settings/ClimbableSurface.java index 59be5c6e2..1e850c962 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/settings/ClimbableSurface.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/settings/ClimbableSurface.java @@ -26,6 +26,8 @@ public class ClimbableSurface extends DoubleRangeSetting { /** * This creates a new {@link ClimbableSurface} for the given {@link Material}. * + * @param climbingPick + * The {@link ClimbingPick} instance * @param surface * The {@link Material} of this surface * @param defaultValue