Solved Breaking block for a first time

Discussion in 'Spigot Plugin Help' started by KindGuy, Mar 4, 2020.

  1. Hey , im new on this forum so Hello Community ^^

    I'm also new in developing minecraft plugins( started 1 day ago ) and i'm working on kind of jobs plugin. What i would like to do here is for example " Lumberjack" and he of course can gather wood. Problem is that i want allow only them to chop trees. I already get no drop if u dont have Lumberjack permission but i don't know how to allow other users place and gather log which was gathered by Lumberjack ( for example in building ) . I was thinking about adding lore but i read somewhere that placed block doesn't store ItemMeta :/
    Thank you in advance for your help :)
    #1 KindGuy, Mar 4, 2020
    Last edited: Mar 4, 2020
  2. You could have a List<Location> (or store Blocks if you need to know the material as well) to store all the blocks placed by a lumberjack, then listen to break and place events to add/remove to the list.
  3. Let me be more precise. There is a lumberjack who gather some logs . He went to market and sold logs to Miner who can't chop down trees. I want allow him to use the wood which he bought from lumberjack in for example building his own house.
  4. Hmm okay, so how exactly are you preventing people who arent lumberjacks from using logs? Because from my understanding, you are listening to a block break event, if they're not a lumberjack and its a log block then cancel the event. Then you are wondering how to allow already gathered blocks from the lumberjack could be broken and placed by other job professions?

    If I understand correctly, you can simply listen for blocks placed --> if the block is a log and the player is a lumberjack --> store that location in a list of blocks already harvested by a lumberjack

    Then, listening for blocks broken, if the block's location is in that list, don't cancel as it has in fact been harvested by a lumberjack. Sorry if I have misunderstood.

    Also, you said you have been developing for only 1 day, you might struggle with a project like this, however, this shouldn't be discouragement, as you can still learn a lot going into it, it may just be hard
  5. Im very happy as u decided to help me :)


    Store location where the block was gathered? I don't see how it could work >< When lumberjack get logs from forest and sell it to our Miner the location where Miner can place(use) them will be completely different
  6. I was actually referring to if the lumberjack placed a block he gathered, and someone went to grab it after it had been replaced.

    However, you also want to deal with the actual item itself in an inventory, that would take a different approach. How are you "selling" the item to a miner? Like is it a manual payment, in which miner pays lumberjack, then lumberjack player throws item? In which case that would work fine without any extra code? Since log items can only be gained by breaking, and only lumberjack can break logs, then it should be clear that any log items placed/gained by non-lumberjacks have been originally obtained by lumberjacks.

    Have you got some code going? Have you tried anything?
  7. I have essentials plugins,vault + chestshop so i was thinking about chestshops and /pay command but i dont know if it will work as i didn't reach this step.

    This is how this case looks.
    Code (Text):

    case BIRCH_LOG:
                        player.sendMessage("You are not a lumberjack");
    It works good but when miner bought this log and want use this log for a wall and missplaced it this won't allow him to gather it.
    On the other hand i don't want touch Miner recipes at least for now ( log to planks ) .
  8. Okay okay so I was right with the list<Location>

    Essentially create a list of locations that can be accessed across both your block break event and you'll also need a block place event

    When a user attempts to place a log, if they're NOT a lumberjack, shove that block location in the list

    When a user attempts to break a log, allow the event if the block broken is in the list, and then make sure to remove that location from the list

    If a non-lumberjack attempts to break a log that doesnt exist in the list, then the event will be cancelled as that log wouldn't have been placed by a non-lumberjack (if that makes sense aha)

    Since you can't hold data in blocks that are broken/placed, you have to keep track of them with a list of current locations of logs placed by non-lumberjacks. If you restart the server, this list won't remain, so you might need to store it in a config between restarts but I wouldn't worry about that for now
  9. I see it now, thanks for help !

    After adding other jobs this will be my next step :p
    • Like Like x 1