How to check wether a block is natural or has been placed by a player?

Discussion in 'Plugin Development' started by gabrielmaennl555, Sep 24, 2017.

Thread Status:
Not open for further replies.
  1. Hey! I am trying to figure out how to check wether a block is natural or has been placed by a player or not. Im making a job plugin, and I don't want players to keep placing iron ores to keep breaking them for money.
    Thanks in advance!
     
  2. Offline

    dNiym

    You could track the block place event and if it’s an iron ore add it to a list, then if they mine it don’t give them credit and remove the block from the list.

    You could write the blocks to file but I would venture to say once they figure out they don’t get credit for placed blocks they’ll probably stop trying and saving them to disk won’t be needed.


    Sent from my iPhone using Tapatalk
     
  3. Offline

    Zombie_Striker

    @dNiym
    Although not saving to disk will save some memoryspace, but you're talking about less than a Mb of data difference at most.

    @gabrielmaennl555
    Create an ArrayList<Location>. In it, store all the locations of the iron blocks. When an iron block is broken, check if it is in the arraylist. If so, it was already placed by someone else. In this case, remove the location from the hashmap in order to save memory space. However, if the location is not in the arraylist, then it is natural.

    In the onDisable, save the list of locations to the config. Then, in the on enable, get the list from the config and set the arraylist equal to that from the config.
     
  4. @gabrielmaennl555
    try to make event PlaceBlock material water ... than save to the config... you can save the player who placed .. it can be log or you can make it reload by onenable event ... it will check it is water still here
     
  5. Offline

    Side8StarLite

    I remember watching a YouTube vid on this

    He adds metadata on ores when they're placed, and then checks for said metadata during break events. Here's a screenshot of the code used
    bukkit.jpg
    If you want to know the time it's 3:04. I don't know if this is still applicable in recent updates, but it's something
     
  6. @Side8StarLite
    Well, metadata is not persistent, meaning it does not save between restarts. If someone placed a block, and then restarted the server, the metadata would be cleared.

    @gabrielmaennl555
    I think the best way would probably be to hook into a plugin that already logs block placements, like CoreProtect. That way you do not have to worry about saving everything to disk in an efficient manner.
     
Thread Status:
Not open for further replies.

Share This Page