Protection plugin: Metadata or huge ArrayList?

Discussion in 'Plugin Development' started by Codex Arcanum, Sep 7, 2013.

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

    Codex Arcanum

    I'm currently coding a protection plugin. Each protected region is defined by a specific block at the center of the region that protects a cube of the surrounding area out to a certain distance. Each protected region is represented by an object in my plugin. I'm rather confused as to how Bukkit's MetaData works internally, so I don't know which of the following two approaches would be more efficient:

    Approach 1:
    When the plugin starts up, get the list of protected region objects from a flatfile, initializing each object from the stored data and storing it in an ArrayList. Every time a player breaks a block, iterate through every protected region that has ever been created, checking if the distance between the player and the center of the region is less than the region's radius. If it is, prevent the player from breaking the block.

    Approach 2:
    When the plugin starts up, get the list of protected region objects from a flatfile, initializing each object from the stored data and storing it in an ArrayList. For every block contained within each protected region, either store a reference to the protected region's object inside the block's metadata, or just store a boolean value (isProtected = true) inside the block's metadata, just so that unprotected blocks need not cause the server to have to check every region.

    TLDR version: Which is more efficient to do every time the player breaks a block, iterating through of a list of locations and determining the distance to the player, or checking a Metadata value stored for the broken block?
     
Thread Status:
Not open for further replies.

Share This Page