diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java index ea3775037c..9c1c5bac53 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java @@ -17,6 +17,7 @@ import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -39,6 +40,7 @@ import io.github.thebusybiscuit.slimefun4.core.attributes.NotConfigurable; import io.github.thebusybiscuit.slimefun4.core.attributes.Placeable; import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive; +import io.github.thebusybiscuit.slimefun4.core.commands.subcommands.GiveCommand; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; import io.github.thebusybiscuit.slimefun4.core.handlers.GlobalItemHandler; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; @@ -222,6 +224,34 @@ protected SlimefunItem(ItemGroup itemGroup, ItemStack item, String id, RecipeTyp return itemStackTemplate; } + /** + * This returns the {@link ItemStack} result when a {@link Player} + * is given this item via the {@link GiveCommand}. + * + * @param player + * The {@link Player} who will receive the item + * + * @return The {@link ItemStack} that is given to the {@link Player} + * */ + public @Nonnull ItemStack getGiveItemResult(@Nonnull Player player) { + return getItem(); + } + + /** + * This returns the {@link ItemStack} result when a {@link Player} + * in creative mode middle-clicks this {@link SlimefunItem}'s {@link Block}. + * + * @param player + * The {@link Player} who middle-clicked this {@link SlimefunItem} + * @param block + * The {@link Block} middle-clicked + * + * @return The {@link ItemStack} that is picked when middle-clicking this {@link SlimefunItem} + */ + public @Nonnull ItemStack getPickBlockResult(@Nonnull Player player, @Nonnull Block block) { + return getItem(); + } + /** * This returns the {@link ItemGroup} of our {@link SlimefunItem}, every {@link SlimefunItem} * is associated with exactly one {@link ItemGroup}. diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java index 5d56959e84..fc8cf9d6df 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java @@ -19,7 +19,7 @@ import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; -class GiveCommand extends SubCommand { +public class GiveCommand extends SubCommand { private static final String PLACEHOLDER_PLAYER = "%player%"; private static final String PLACEHOLDER_ITEM = "%item%"; @@ -65,7 +65,7 @@ private void giveItem(CommandSender sender, Player p, SlimefunItem sfItem, Strin if (amount > 0) { Slimefun.getLocalization().sendMessage(p, "messages.given-item", true, msg -> msg.replace(PLACEHOLDER_ITEM, sfItem.getItemName()).replace(PLACEHOLDER_AMOUNT, String.valueOf(amount))); - Map excess = p.getInventory().addItem(new CustomItemStack(sfItem.getItem(), amount)); + Map excess = p.getInventory().addItem(new CustomItemStack(sfItem.getGiveItemResult(p), amount)); if (Slimefun.getCfg().getBoolean("options.drop-excess-sf-give-items") && !excess.isEmpty()) { for (ItemStack is : excess.values()) { p.getWorld().dropItem(p.getLocation(), is); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MiddleClickListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MiddleClickListener.java index b35d48292b..8206cb12f6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MiddleClickListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/MiddleClickListener.java @@ -6,6 +6,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.ClickType; @@ -41,8 +42,10 @@ public void onInventoryCreativeEvent(InventoryCreativeEvent e) { * ClickType is not MIDDLE but CREATIVE (because this ClickType covers * multiple cases, we have to filter out more later on) */ - if (e.getClick() == ClickType.CREATIVE && e.getSlotType() == SlotType.QUICKBAR) { - HumanEntity player = e.getWhoClicked(); + if (e.getClick() == ClickType.CREATIVE + && e.getSlotType() == SlotType.QUICKBAR + && e.getWhoClicked() instanceof Player player + ) { // get the block the player is looking at for later Block b = player.getTargetBlockExact(5); @@ -74,7 +77,7 @@ public void onInventoryCreativeEvent(InventoryCreativeEvent e) { } // Give the item, doing it like this will not alter any other cases. - e.setCursor(sfItem.getItem().clone()); + e.setCursor(sfItem.getPickBlockResult(player, b).clone()); } }