#block break with tool
1 messages · Page 1 of 1 (latest)
If I break a cooble with hand the event doen't fire
declaration: package: org.bukkit.event.block, class: BlockBreakEvent
theres nothing about creative mode here
declaration: package: org.bukkit.event.block, class: BlockBreakEvent
erm
?
you can check the players gamemode though
If you break the block with incorrect tool the eventt doen't fire
I need to handle that
show your code
yea
well instead of not ifirng it, just cancel the event if they arent holding the right tool
is there some kind of class that has lists of all correct tools
idk, not my question
@EventHandler(ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
if (event.getBlock().getLocation().toVector().equals(OneBlockAPI.getSettings().getIslandSpawn())) {
event.setCancelled(true);
//If item is a tool damage it
ItemMeta itemMeta = event.getPlayer().getInventory().getItemInHand().getItemMeta();
if (itemMeta instanceof Damageable) ((Damageable) itemMeta).damage(1);
InfiniteBlockBreakEvent infiniteBlockEvent = new InfiniteBlockBreakEvent(
OneBlockAPI.getPlayerCache().getPlayer(event.getPlayer().getName()),
event.getBlock().getWorld().getName(),
OneBlockAPI.getPhaseLoader().getPhaseBlocks(event.getBlock().getWorld().getName()),
event.getBlock());
Bukkit.getPluginManager().callEvent(infiniteBlockEvent);
}
}```
why ignoreCancelled?
autogenerated
so the main issue is you dont want anything special to happen if they are in creative?
you want to not call the custom event if they are in creative?
I need to handle all the blocks break ignore the creative
if (!player.getGameMode().equals(GameMode.CREATIVE)) {
// stuff
}```
I reformulate the question
My code if I break stone with hand it doesn't fire
It I break dirt yes
so if they dont break it with the right tool then it wont fire
somewhere you need to define what the "right" tool is
O handle that action
yeah
gonna take a while
define each block and the tools you want
but why?
if its not the correct tool it wont drop anyway
o right
it all depends on exactly what you want @near dust
I'm making a oneblock, when the inf block if broken I need to regenerate it
yes I get this bit
And I need to Chek when the block is broken to then replace it with a new one
If I use BlockBreakEvent, and I break cobble with hand the event isn't fired
But if I break dirt yes
oh right
If you wish to have the block drop experience, you must set the experience value above 0. By default, experience will be set in the event if:
The player is not in creative or adventure mode
The player can loot the block (ie: does not destroy it completely, by using the correct tool)
The player does not have silk touch
The block drops experience in vanilla Minecraft
I look on the javadocs and it sais that if the playaer isn't using correct tool the event won't fire
well if that was the case, I expcet a dirt block wouldnt work either
!Block.getDrops(ItemStack).isEmpty()
Yes but dirt tool can be hand either
I think the code you got is too much surely, you just want to
- Cancel the event if it is the right location
- Trigger your event
I dont get all this itemmeta stuff etc
Ignore the rest there are oneblock features
I only need to know how to get when a player breaks a block with an incorrect tool
sure
Let me 1 moment
okay I just tested it
I broke a stone block
with my fist
it triggered the event
all you need to do in your event is check the location, then call your custom event if its the correct location
OK I'll try again with removing all stuff inside
i dont see anywhere in the javadoc that it says the event is not fired withut the correc tool tho
am i just blind
o
what version are you on?
I mean
I litearlly just went in game and broke a block, and it triggered me breaking a stone block with my fist
I dont know what more evidence you need
lol