Solved how to lock blocks efficiently?

Discussion in 'Plugin Development' started by mr_nice1107, Nov 20, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    mr_nice1107

    Hey there!

    I was writing a plugin to lock blocks (like WorldGuard), but I just want to lock single blocks

    It works like that:

    Every locked block is saved in a config file (.yml)

    So the config looks like that:


    Code:
    File 1:
    block1:
      owner: player1
      members:
        - member1
        - member2
      locked: true
      location: loc...
    
    File 2:
    block2....
    and so on

    And then every time when a player builds/breaks or interacts with a block I check if the block is in this config files

    But somehow it takes very long when I have many blocks

    So my question is : Is there a smart whay to lock this blocks efficiently ?

    When yes I have a nother question ;D Is it possible to have more layers of locked blocks?

    So for example I have a chest the is locked but the block was already locked
    not the lock from the chest overwrites the old lock
    But then I break the chest the old lock should be there again?

    Thanks for your arwnsers! And sorry for my bad english
     
  2. Offline

    CraftCreeper6

    @mr_nice1107
    I would have the key of the block be the location that it's at, including the world.

    For example:
    128,64,98: // this would be at X:128 Y:64 Z:98

    and then when you want to check if a block is locked, try and index the config at that key, if the config returns null, it's not locked. If it returns a value, then it's a locked block.
     
  3. Offline

    mr_nice1107

    thanks for the awnser that helped alot... Sometimes I'm such an idiod... 1 file for all blocks is mutch simpler and faster!
    Any idea how to fix the secound issue I asked?
     
  4. Offline

    CraftCreeper6

    @mr_nice1107
    Don't index the locks by their block type, index it by their location. That way, even if you break the chest (in your example), you will still have that location as a "locked block". Just make sure not to remove the location from the config.
     
  5. Offline

    mr_nice1107

    jea thats an idea thanks!
     
    CraftCreeper6 likes this.
Thread Status:
Not open for further replies.

Share This Page