-
Notifications
You must be signed in to change notification settings - Fork 17
Coding guide
OtherDrops coding guide.
Style
Code path
Packages/Classes overview
History
OtherDrops uses standard Eclipse formatting with one change: 4 spaces rather than tabs.
#Code pathI've tried to keep the main "path" of the code as short as possible.
* block break event is triggered (note: blockbreak listener is not registered unless a block custom drop is configured)
* if event is cancelled - exit
* if creativemode - exit
* set up "OccuredEvent" class (see below - room to optimise)
* perform the drop (see below - room to optimise)
--OccuredEvent--
* create new BlockTarget
* save event to local variable
* save block
* save tool, location, world, biome, light, weather, time, height, attackrange, regions <- (1)
--PerformDrop--
* get "DropsList" from a HashMap based on Action & Target
* if no drops, return
* check if a block is "excepted" (for little used "ANY_BLOCK except <BLAH>" config - looking to shift this check from runtime to startup
* loop through DropsList, check conditions & save matched drops ("MatchedDrops")
* loop through MatchedDrops and filter for "unique" drops (as these, if they pass conditions, will cancel other drops)
* loop through filtered droplist again checking for "DEFAULT" drops <- (2) (this should be able to be checked in an earlier loop)
* ScheduleDrop (see below) "schedule" the drop to occur (with possible delay) - passing "OccurredEvent" & the custom drop.
* for successful drops, cancel the event (no other way override default blockbreak drop) if necesary (eg. if no DEFAULT option was there)
* if cancelled due to custom drop report blockbreak to logging plugins
--ScheduleDrop-- * store a copy of the player & playerlocation
# Packages/Classes overviewOtherDrops: classes relating to startup/core classes.
Common: stores some functions common to most of my plugins.
Data: classes for parsing/storing data.
Data/Entities: specific entity data (eg. baby, village professions, mob equipment, etc)
Data/ItemMeta: specific item metadata (eg. leatherarmor color, skulls, books)
Drop: Core drop code and classes for specific types of drops
Event: OtherDrops event handlers - classes for storing config sections and parsing the Bukkit events that occur.
Listener: Bukkit event listeners
Options: important class here is Action (stores trigger types/names).
Parameters/Actions:
Parameters/Conditions:
Special & ODSpecialEvents: for the "event" parameter (created as plugins - separate jars)
Subject: subjects and targets (eg. creature/player/projectile/blocktarget)
As in introduction OtherDrops started life about 2 years ago as OtherBlocks. It allowed server admins to customise what drops from blocks or mobs and had a couple of conditions: chance, world, tool, color (data).
I (Zarius) was using the plugin on a server I was running at the time when OtherBlocks became inactive. I then took up development and added many more conditions (time, weather, biome, attackrange, worldguard region, height, lightlevel, permissions, etc) and some actions that could take effect in addition to the drop itself (eg. message, damageattacker, explosion, run command, etc). Support for newer blocks, creatures & associated data values has been added as well as more advanced drop-lists (eg. exclusive drop, {EGG/40%, DIAMOND/60%} means drop just one from within the list based on the included chance %'s). The plugin was also renamed to OtherDrops to better reflect it's core goals.
Support for Vault (money drops), MobArena, logging plugins (eg. LogBlock) was added.
In summary - OtherDrops has become a lot more complicated! It's gone from just under 1,000 lines of code to over 17,000. A lot of that is due to abstraction and extra comments however it's also got a lot more code just to handle the extra features.