Minecolonies & Colonymanager rework by raycoms

View this thread on steempeak.com
· @raycoms · (edited)
$170.96
Minecolonies & Colonymanager rework
Hi everyone, as announced in my last post [here](https://steemit.com/utopian-io/@raycoms/minecolonies--a-bunch-of-fixes) I will write a bit about our recent core system rework, the colony manager.

Until now the colony manager was a singleton which provided the world with a list of colonies and also took care of the persistence of each colony.
To do this the colonies would get marked dirty on changes and the colony manager would detect that regularly and write the colonies to file for persistence. This system had three major flaws.

- If the world would crash a colony could be written only partially to file which would make it fail to load on reading.
- Regularly writing all colonies to file comes with a huge overhead.
- Due to the centralization of this system, it would be difficult to maintain different colonies in different dimensions in a world.

This made us reconsider and we decided to move the colony manager to a capability-based system.
Capabilities in the context of forge Minecraft mods are certain persistency units which can be appended to world elements as chunks, the world itself, players, etc...

The Capability:
---

Doing so involved a lot of work as you might imagine since every system which touched the colony manager somewhere would have to be adapted.

![](https://i.imgur.com/HUqQ5S9.png)

First of all, I enriched the IColony interface with the dimension to be able to use this information wherever I might need it.

![](https://i.imgur.com/NTFMGEv.png)

I then created a new constant class where I'd move all previous colony manager constants.

![](https://i.imgur.com/EiMQa6M.png)

Then I created the capability.
First by creating the constant in the main class.

![](https://i.imgur.com/DN2Jkiu.png)

Then by registering it on pre-init:

```
CapabilityManager.INSTANCE.register(IColonyManagerCapability.class, new IColonyManagerCapability.Storage(), IColonyManagerCapability.Impl::new);
```

And append it to the world.

![](https://i.imgur.com/DC5pXT9.png)

It would consist of all required methods as creating, deleting and querying colonies.

![](https://i.imgur.com/pCCKw3S.png)

As well as adding colonies, and getting information about the chunks which are missing to load yet.

![](https://i.imgur.com/OpLdjUP.png)



Since colonies are now queried by world or dimension I had to adapt all colony manager calls.

![](https://i.imgur.com/3rugO7M.png)
![](https://i.imgur.com/6RpD451.png)


Adapt all getColonies() calls to getAllColonies() to get them from multiple worlds.

![](https://i.imgur.com/TSVeoJM.png)

The implementation would be in the same file and would have the data which previously the colony manager had and implement the methods of the interface.

![](https://i.imgur.com/aEZwSle.png)

The persistence would then be handled by the storage itself.

![](https://i.imgur.com/6YXyLno.png)

All that would also require a factory which sets these bits and pieces together.

![](https://i.imgur.com/xStKrGS.png)

In the old colony manager:
---

Within the old colony manager, we'd be able to extract this information then and also adapt the methods required to query the colonies.

As getting the colony by world or dimension from the capability.

![](https://i.imgur.com/HMna5U5.png)

Or getting all colonies from all possible worlds.

![](https://i.imgur.com/Q8jSTuA.png)


Besides that, I created a new command to be able to load colony backups which was previously only done by using a backed up file and replacing the existing file with it.

New Command:
---

It would be the load backup command for OPs only.

![](https://i.imgur.com/wW1Omvd.png)

Which would get the colony id and the dimension.

![](https://i.imgur.com/OMNhwjb.png)

And then call the backup handler.

![](https://i.imgur.com/gL6BG3n.png)


Additionally, I created two new helper classes:

- Chunk helper
- Backup helper

New Chunk Helper:
---

The chunk helper would help to reduce the size and complexity of the colony manager java class and englobe all code related to storing the colony claim within the chunks as well as retrieving it.

![](https://i.imgur.com/Ayjuxsy.png)


The Backup Handler:
---

The backup handler would get the old backup related code from the colony manager and some new code related to loading the backups.

![](https://i.imgur.com/lm7qFC6.png)

Where it would start by loading the world save dir to get compound of the file which matches the dimension and colony id.

Then it would check if the colony exists and load its backed up data or if not existing create a new one matching this data.

![](https://i.imgur.com/grv06mk.png)


Extras:
---


Finally, I also moved the structure load to init to be world independent.

![](https://i.imgur.com/QuD6Huv.png)

Besides that, we changed the schematic folder to be world independent but server dependent.

![](https://i.imgur.com/yW1IH65.png)

Since players might want to build schematics in all worlds on the server.


#### Repository: 
https://github.com/ldtteam/minecolonies

#### Pull Requests:
https://github.com/ldtteam/minecolonies/pull/2900
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 35 others
properties (23)
post_id63,989,580
authorraycoms
permlinkminecolonies--colonymanager-rework
categoryutopian-io
json_metadata{"format":"markdown","app":"steemit\/0.1","image":["https:\/\/i.imgur.com\/HUqQ5S9.png"],"tags":["utopian-io","development","gaming","technology","programming"],"links":["https:\/\/steemit.com\/utopian-io\/@raycoms\/minecolonies--a-bunch-of-fixes","https:\/\/github.com\/ldtteam\/minecolonies","https:\/\/github.com\/ldtteam\/minecolonies\/pull\/2900"]}
created2018-10-10 11:27:45
last_update2018-10-10 11:56:30
depth0
children6
net_rshares125,477,451,774,178
last_payout2018-10-17 11:27:45
cashout_time1969-12-31 23:59:59
total_payout_value127.664 SBD
curator_payout_value43.292 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length5,061
author_reputation120,534,427,956,805
root_title"Minecolonies & Colonymanager rework"
beneficiaries
0.
accountsteemplus-pay
weight100
1.
accountutopian.pay
weight500
max_accepted_payout100,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (99)
@helo ·
$9.63
* I really like how your contributions posts read like a story, it's also very educational for me as we get to see your thought process going trough the rework.
* Many changes of function names, they were everywhere!
* Is this a legit comment from the codacy-bot?
 ![](https://cdn.steemitimages.com/DQmeCppCPj13XnqPCTwrvCpidvwrJtQ3Ht8WE9wgiZhP8rd/image.png)


Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/3/1211111).

---- 
Need help? Write a ticket on https://support.utopian.io/. 
Chat with us on [Discord](https://discord.gg/uTyJkNm). 
[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , , , , , , , , , , , , ,
properties (23)
post_id63,994,426
authorhelo
permlinkre-raycoms-minecolonies--colonymanager-rework-20181010t131025473z
categoryutopian-io
json_metadata{"app":"steemit\/0.1","image":["https:\/\/cdn.steemitimages.com\/DQmeCppCPj13XnqPCTwrvCpidvwrJtQ3Ht8WE9wgiZhP8rd\/image.png"],"tags":["utopian-io"],"links":["https:\/\/join.utopian.io\/guidelines","https:\/\/review.utopian.io\/result\/3\/1211111","https:\/\/support.utopian.io\/","https:\/\/discord.gg\/uTyJkNm","https:\/\/join.utopian.io\/"]}
created2018-10-10 13:10:24
last_update2018-10-10 13:10:24
depth1
children2
net_rshares6,753,329,267,876
last_payout2018-10-17 13:10:24
cashout_time1969-12-31 23:59:59
total_payout_value7.272 SBD
curator_payout_value2.356 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length849
author_reputation119,612,833,307,875
root_title"Minecolonies & Colonymanager rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (14)
@raycoms ·
Thanks for the review. While yes it is not threadsafe we do not access it from different threads since Minecraft is single threaded anyway.
πŸ‘  
properties (23)
post_id63,996,523
authorraycoms
permlinkre-helo-re-raycoms-minecolonies--colonymanager-rework-20181010t134526265z
categoryutopian-io
json_metadata{"app":"steemit\/0.1","tags":["utopian-io"]}
created2018-10-10 13:45:27
last_update2018-10-10 13:45:27
depth2
children0
net_rshares71,178,028
last_payout2018-10-17 13:45:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length139
author_reputation120,534,427,956,805
root_title"Minecolonies & Colonymanager rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@utopian-io ·
Thank you for your review, @helo!

So far this week you've reviewed 1 contributions. Keep up the good work!
properties (22)
post_id64,284,278
authorutopian-io
permlinkre-re-raycoms-minecolonies--colonymanager-rework-20181010t131025473z-20181015t105539z
categoryutopian-io
json_metadata{"app":"beem\/0.20.1"}
created2018-10-15 10:55:42
last_update2018-10-15 10:55:42
depth2
children0
net_rshares0
last_payout2018-10-22 10:55:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length107
author_reputation152,913,012,544,965
root_title"Minecolonies & Colonymanager rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@steem-ua ·
#### Hi @raycoms!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
**Feel free to join our [@steem-ua Discord server](https://discord.gg/KpBNYGz)**
properties (22)
post_id64,000,494
authorsteem-ua
permlinkre-minecolonies--colonymanager-rework-20181010t145129z
categoryutopian-io
json_metadata{"app":"beem\/0.20.7"}
created2018-10-10 14:51:30
last_update2018-10-10 14:51:30
depth1
children0
net_rshares0
last_payout2018-10-17 14:51:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length286
author_reputation23,203,609,903,979
root_title"Minecolonies & Colonymanager rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@steem-plus ·
SteemPlus upvote
Hi, @raycoms!

You just got a **36.51%** upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in [here](https://steemit.com/@steem-plus) to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.
properties (22)
post_id64,026,278
authorsteem-plus
permlinkminecolonies--colonymanager-rework---vote-steemplus
categoryutopian-io
json_metadata{}
created2018-10-11 01:30:51
last_update2018-10-11 01:30:51
depth1
children0
net_rshares0
last_payout2018-10-18 01:30:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length435
author_reputation247,995,867,762,997
root_title"Minecolonies & Colonymanager rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@utopian-io ·
Hey, @raycoms!

**Thanks for contributing on Utopian**.
We’re already looking forward to your next contribution!

**Get higher incentives and support Utopian.io!**
 Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via [SteemPlus](https://chrome.google.com/webstore/detail/steemplus/mjbkjgcplmaneajhcbegoffkedeankaj?hl=en) or [Steeditor](https://steeditor.app)).

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
post_id64,324,938
authorutopian-io
permlinkre-minecolonies--colonymanager-rework-20181016t013512z
categoryutopian-io
json_metadata{"app":"beem\/0.20.1"}
created2018-10-16 01:35:15
last_update2018-10-16 01:35:15
depth1
children0
net_rshares0
last_payout2018-10-23 01:35:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length589
author_reputation152,913,012,544,965
root_title"Minecolonies & Colonymanager rework"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000