3838import world .bentobox .bentobox .api .flags .Flag .Mode ;
3939import world .bentobox .bentobox .api .flags .Flag .Type ;
4040import world .bentobox .bentobox .database .objects .Island ;
41+ import world .bentobox .bentobox .managers .RanksManager ;
4142
4243/**
4344 * Main OneBlock class - provides an island minigame in the sky
4647 */
4748public class AOneBlock extends GameModeAddon {
4849
50+ /** Suffix for the nether world */
4951 private static final String NETHER = "_nether" ;
52+ /** Suffix for the end world */
5053 private static final String THE_END = "_the_end" ;
54+ /** Whether ItemsAdder is present on the server */
5155 private boolean hasItemsAdder = false ;
5256
53- // Settings
57+ /** The addon settings */
5458 private Settings settings ;
59+ /** The custom chunk generator for OneBlock worlds */
5560 private ChunkGeneratorWorld chunkGenerator ;
61+ /** The configuration object for settings */
5662 private final Config <Settings > configObject = new Config <>(this , Settings .class );
63+ /** The listener for block-related events */
5764 private BlockListener blockListener ;
65+ /** The manager for OneBlock phases and blocks */
5866 private OneBlocksManager oneBlockManager ;
67+ /** The placeholder manager for AOneBlock */
5968 private AOneBlockPlaceholders phManager ;
69+ /** The listener for hologram-related events */
6070 private HoloListener holoListener ;
6171
62- // Flag
72+ /**
73+ * Flag to enable or disable start safety for players.
74+ */
6375 public final Flag START_SAFETY = new Flag .Builder ("START_SAFETY" , Material .BAMBOO_BLOCK )
6476 .mode (Mode .BASIC )
6577 .type (Type .WORLD_SETTING )
6678 .listener (new StartSafetyListener (this ))
6779 .defaultSetting (false )
6880 .build ();
81+ /** The listener for the boss bar */
6982 private BossBarListener bossBar = new BossBarListener (this );
70- public final Flag ONEBLOCK_BOSSBAR = new Flag .Builder ("ONEBLOCK_BOSSBAR" , Material .DRAGON_HEAD ).mode (Mode .BASIC )
71- .type (Type .SETTING ).listener (bossBar ).defaultSetting (true ).build ();
83+ /**
84+ * Flag to enable or disable the OneBlock boss bar.
85+ */
86+ public final Flag ONEBLOCK_BOSSBAR = new Flag .Builder ("ONEBLOCK_BOSSBAR" , Material .DRAGON_HEAD )
87+ .mode (Mode .BASIC )
88+ .type (Type .SETTING )
89+ .listener (bossBar )
90+ .defaultSetting (true )
91+ .build ();
92+
93+ /**
94+ * Flag to set who can break the magic block.
95+ */
96+ public final Flag MAGIC_BLOCK = new Flag .Builder ("MAGIC_BLOCK" , Material .GRASS_BLOCK )
97+ .mode (Mode .BASIC )
98+ .type (Type .PROTECTION )
99+ .defaultRank (RanksManager .COOP_RANK )
100+ .build ();
72101
73102 @ Override
74103 public void onLoad () {
@@ -94,9 +123,15 @@ public void onLoad() {
94123 getPlugin ().getFlagsManager ().registerFlag (this , START_SAFETY );
95124 // Bossbar
96125 getPlugin ().getFlagsManager ().registerFlag (this , this .ONEBLOCK_BOSSBAR );
126+ // Magic Block protection
127+ getPlugin ().getFlagsManager ().registerFlag (this , this .MAGIC_BLOCK );
97128 }
98129 }
99130
131+ /**
132+ * Loads the settings from the config file.
133+ * @return true if settings were loaded successfully, false otherwise.
134+ */
100135 private boolean loadSettings () {
101136 // Load settings again to get worlds
102137 settings = configObject .loadConfigObject ();
@@ -114,11 +149,14 @@ private boolean loadSettings() {
114149
115150 @ Override
116151 public void onEnable () {
152+ // Initialize the OneBlock manager
117153 oneBlockManager = new OneBlocksManager (this );
154+ // Load phase data
118155 if (loadData ()) {
119156 // Failed to load - don't register anything
120157 return ;
121158 }
159+ // Initialize and register listeners
122160 blockListener = new BlockListener (this );
123161 registerListener (blockListener );
124162 registerListener (new NoBlockHandler (this ));
@@ -138,12 +176,15 @@ public void onEnable() {
138176 registerListener (holoListener );
139177 }
140178
141- // Load phase data
179+ /**
180+ * Load phase data from oneblock.yml.
181+ * @return true if there was an error, false otherwise.
182+ */
142183 public boolean loadData () {
143184 try {
144185 oneBlockManager .loadPhases ();
145186 } catch (IOException e ) {
146- // Disable
187+ // Disable the addon if phase data cannot be loaded
147188 logError ("AOneBlock settings could not load (oneblock.yml error)! Addon disabled." );
148189 logError (e .getMessage ());
149190 setState (State .DISABLED );
@@ -169,6 +210,7 @@ public void onDisable() {
169210 public void onReload () {
170211 // save cache
171212 blockListener .saveCache ();
213+ // Reload settings and phase data
172214 if (loadSettings ()) {
173215 log ("Reloaded AOneBlock settings" );
174216 loadData ();
@@ -223,6 +265,7 @@ private World getWorld(String worldName2, Environment env, ChunkGeneratorWorld c
223265 worldName2 = env .equals (World .Environment .NETHER ) ? worldName2 + NETHER : worldName2 ;
224266 worldName2 = env .equals (World .Environment .THE_END ) ? worldName2 + THE_END : worldName2 ;
225267 WorldCreator wc = WorldCreator .name (worldName2 ).environment (env );
268+ // Use custom generator if configured, otherwise default
226269 World w = settings .isUseOwnGenerator () ? wc .createWorld () : wc .generator (chunkGenerator2 ).createWorld ();
227270 // Set spawn rates
228271 if (w != null ) {
@@ -232,6 +275,10 @@ private World getWorld(String worldName2, Environment env, ChunkGeneratorWorld c
232275
233276 }
234277
278+ /**
279+ * Sets the spawn rates for a given world based on the addon's settings.
280+ * @param w The world to set spawn rates for.
281+ */
235282 private void setSpawnRates (World w ) {
236283 if (getSettings ().getSpawnLimitMonsters () > 0 ) {
237284 w .setSpawnLimit (SpawnCategory .MONSTER , getSettings ().getSpawnLimitMonsters ());
@@ -298,6 +345,9 @@ public OneBlockIslands getOneBlocksIsland(@NonNull Island i) {
298345 return blockListener .getIsland (Objects .requireNonNull (i ));
299346 }
300347
348+ /**
349+ * @return The OneBlock manager.
350+ */
301351 public OneBlocksManager getOneBlockManager () {
302352 return oneBlockManager ;
303353 }
@@ -341,6 +391,10 @@ public void setIslandWorld(World world) {
341391
342392 }
343393
394+ /**
395+ * Sets the addon's settings. Used only for testing.
396+ * @param settings The settings to set.
397+ */
344398 public void setSettings (Settings settings ) {
345399 this .settings = settings ;
346400 }
0 commit comments