Hello! I want to create item which can double block after click For example I clicked on grass and after that this block is removed and spawned two block of grass I don't know how to create this. I read documentation in hub.spigotmc.org about PlayerInteractEvent or BlockBreakEvent, but I didn't find any helpful infomation. This is my "logic" of plugin, but of course that is false. May you ask me in what side I need go? here is my code
I don't follow your intent. You said click grass and after block is removed and spawned two blocks of grass. So you mean if they break grass, it drops two instead of one? If so, you want to listen to BlockBreakEvent. Check if the block matches your filter (assuming you don't want every single block to drop 2x, otherwise this is unnecessary) and adjust the drops. There is a BlockBreakEvent#setDrops() you can use for that.
Here we are! I find how to fix it. here is code. But! in 38 line I have error How can i fix it? EDIT: I changed blockbroken into event, but it didn't help
@Mr_maderator_UY The error is very self explanatory, blockBroken is null. You don't need to turn it into an event, that doesn't make a shred of sense. The issue is that if the player clicks somewhere that isn't a block, then the block will be null. Add a check to make sure that blockBroken is not null, also, why not use BlockBreakEvent?
I don't use BreakBlockEvent, cuz in 41 you can see event.getItem. We can't use this method in BreakBlockEvent @CraftCreeper6
You can use BlockBreakEvent#getPlayer()#getInventory()#getHeldItemSlot() alongside a Player#getInventory()#getItem(slot) call. In any case, did you fix your original issue?
here is new code Well, what about getItem. If player have one item in slot #1 and I'll add this item in 1 slot. And there are will change. Does getItem have a const for free slot?
@Mr_maderator_UY getItem takes a slot number, so just use getPlayer()#getInventory()#getHeldItemSlot() to get the slot of the currently held item.
it didn't work here is it(with no getInventory()) and the same trouble with getInventory @CraftCreeper6
@Mr_maderator_UY I don't understand your trouble, this should work just fine. Code: ItemStack itemStack = e#getPlayer()#getInventory()#getItem(e#getPlayer()#getInventory()#getHeldItemSlot()); if (itemStack#hasItemMeta()) { if (itemStack#getItemMeta()#hasDisplayName()) { String itemName = itemStack#getItemMeta()#getDisplayName(); System#out#println("The user just clicked with a " + itemName + "!"); } }
Well, I need that after clicking or breaking block, this block dropped two items of this block For example: I broke a block of groung and this block dropped two blocks of ground @CraftCreeper6
@Mr_maderator_UY This isn't a difficult thing to do, when you post your code please use the CODE tags provided, so I don't have to keep following links to screenshots. The code I provided will print to the console if the item has a display name, simply check if the display name is the same as your base item (and some other item meta details too) then drop the block like you're doing. I don't know if you can directly compare ItemMeta's, I don't know that they contain the same information across instances, which could be the cause of your problem.
@Mr_maderator_UY Line 27 doesn't make any sense at all. Code: if (targetplayer.getInventory().equals(manager.pickAxe.getItemMeta())) { You are comparing the players inventory to some ItemMeta? This will never return true. You need to compare the players item in hand to the ItemMeta.
I don't understand)) I wanna to explain my logic ItemStack using with block and materials, so we need to use getItemMeta to copy name of a drop @CraftCreeper6
@Mr_maderator_UY Is this what you want? 1. BlockBreakEvent 2. Get the player that broke the block 3. Get the item that the player is holding 4. If the item is the same as manager.pickAxe, then drop a second item
@Mr_maderator_UY Well then re-read the post I sent. Check the display name and some other ItemMeta related information, if the information matches manager.pickAxe, then drop an extra item.
I tested your code. I added a name of pickaxe in has DisplayName and getDisplayName and there was an error. I didn't understand where I can check display name. I saw that you told me thent i need to check, but error tell me that I can not add to ItemMeta String name Code: ItemStack itemStack = event.getPlayer().getInventory().getItem(event.getPlayer().getInventory().getHeldItemSlot()); if (itemStack.hasItemMeta()) { if (itemStack.getItemMeta().hasDisplayName("pickaxe of doubling")) { String pickaxe_of_doubling = itemStack.getItemMeta().getDisplayName("pickaxe of doubling"); } } }
@Mr_maderator_UY You never check if itemStack is null hasDisplayName does not take an argument I believe.
Code: ItemStack itemStack = event.getPlayer().getInventory().getItem(event.getPlayer().getInventory().getHeldItemSlot()); if (itemStack.hasItemMeta() && itemStack != null) { if (itemStack.getItemMeta().hasDisplayName("pickaxe of doubling")) { String pickaxe_of_doubling = itemStack.getItemMeta().getDisplayName("pickaxe of doubling"); }}} So, I need add !=null