#block break with tool

1 messages · Page 1 of 1 (latest)

alpine saddle
#

I do this in my plugin, what is it your having issues with exactly?

near dust
#

If I break a cooble with hand the event doen't fire

tulip falcon
#

theres nothing about creative mode here

near dust
tulip falcon
#

erm

fallow wraith
#

?

alpine saddle
#

you can check the players gamemode though

near dust
#

If you break the block with incorrect tool the eventt doen't fire

#

I need to handle that

fallow wraith
#

show your code

tulip falcon
#

yea

alpine saddle
#

well instead of not ifirng it, just cancel the event if they arent holding the right tool

tulip falcon
alpine saddle
#

idk, not my question

near dust
#
@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);
        }
    }```
fallow wraith
#

why ignoreCancelled?

near dust
#

autogenerated

alpine saddle
#

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?

near dust
#

I need to handle all the blocks break ignore the creative

tulip falcon
#
if (!player.getGameMode().equals(GameMode.CREATIVE)) {
            // stuff
        }```
near dust
#

I reformulate the question

#

My code if I break stone with hand it doesn't fire

#

It I break dirt yes

tulip falcon
#

so if they dont break it with the right tool then it wont fire

near dust
#

that's the point

#

I need to fire the event there

alpine saddle
#

somewhere you need to define what the "right" tool is

near dust
#

O handle that action

tulip falcon
#

gonna take a while

#

define each block and the tools you want

#

but why?

#

if its not the correct tool it wont drop anyway

alpine saddle
#

maybe he means a special pickaxe

#

or tool etc

#

rather than any default one

tulip falcon
#

o right

alpine saddle
#

it all depends on exactly what you want @near dust

tulip falcon
#

dont ask some abstract thing i guess

#

ask exactly what you want with the context

near dust
#

I'm making a oneblock, when the inf block if broken I need to regenerate it

near dust
#

And I need to Chek when the block is broken to then replace it with a new one

alpine saddle
#

yes

#

and what do they need to break the block with?

near dust
#

It does mater

#

Hand, tools...

#

If it's broken it's broken

alpine saddle
#

okay

#

so whats the issue atm?

near dust
#

If I use BlockBreakEvent, and I break cobble with hand the event isn't fired

#

But if I break dirt yes

alpine saddle
#

oh right

tulip falcon
#

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

near dust
#

I look on the javadocs and it sais that if the playaer isn't using correct tool the event won't fire

alpine saddle
#

well if that was the case, I expcet a dirt block wouldnt work either

tulip falcon
#

!Block.getDrops(ItemStack).isEmpty()

near dust
alpine saddle
#

I think the code you got is too much surely, you just want to

  1. Cancel the event if it is the right location
  2. Trigger your event

I dont get all this itemmeta stuff etc

near dust
#

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

alpine saddle
#

1 sec

#

I need to test this

near dust
#

Ok

#

I can screen share you if you want

tulip falcon
#

sure

near dust
#

Let me 1 moment

alpine saddle
#

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

near dust
#

OK I'll try again with removing all stuff inside

tulip falcon
#

i dont see anywhere in the javadoc that it says the event is not fired withut the correc tool tho

#

am i just blind

alpine saddle
#

nah

#

it does

#

I just tried it

tulip falcon
#

o

near dust
#

@tulip falcon

tulip falcon
#

where

#

im literlaly blind as

alpine saddle
#

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

tulip falcon