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+ * Flag to enable or disable the OneBlock action bar.
94+ */
95+ public final Flag ONEBLOCK_ACTIONBAR = new Flag .Builder ("ONEBLOCK_ACTIONBAR" , Material .IRON_BARS )
96+ .mode (Mode .BASIC )
97+ .type (Type .SETTING )
98+ .listener (bossBar )
99+ .defaultSetting (true )
100+ .build ();
101+ /**
102+ * Flag to set who can break the magic block.
103+ */
104+ public final Flag MAGIC_BLOCK = new Flag .Builder ("MAGIC_BLOCK" , Material .GRASS_BLOCK )
105+ .mode (Mode .BASIC )
106+ .type (Type .PROTECTION )
107+ .defaultRank (RanksManager .COOP_RANK )
108+ .build ();
72109
73110 @ Override
74111 public void onLoad () {
@@ -94,9 +131,15 @@ public void onLoad() {
94131 getPlugin ().getFlagsManager ().registerFlag (this , START_SAFETY );
95132 // Bossbar
96133 getPlugin ().getFlagsManager ().registerFlag (this , this .ONEBLOCK_BOSSBAR );
134+ // Magic Block protection
135+ getPlugin ().getFlagsManager ().registerFlag (this , this .MAGIC_BLOCK );
97136 }
98137 }
99138
139+ /**
140+ * Loads the settings from the config file.
141+ * @return true if settings were loaded successfully, false otherwise.
142+ */
100143 private boolean loadSettings () {
101144 // Load settings again to get worlds
102145 settings = configObject .loadConfigObject ();
@@ -114,11 +157,14 @@ private boolean loadSettings() {
114157
115158 @ Override
116159 public void onEnable () {
160+ // Initialize the OneBlock manager
117161 oneBlockManager = new OneBlocksManager (this );
162+ // Load phase data
118163 if (loadData ()) {
119164 // Failed to load - don't register anything
120165 return ;
121166 }
167+ // Initialize and register listeners
122168 blockListener = new BlockListener (this );
123169 registerListener (blockListener );
124170 registerListener (new NoBlockHandler (this ));
@@ -138,12 +184,15 @@ public void onEnable() {
138184 registerListener (holoListener );
139185 }
140186
141- // Load phase data
187+ /**
188+ * Load phase data from oneblock.yml.
189+ * @return true if there was an error, false otherwise.
190+ */
142191 public boolean loadData () {
143192 try {
144193 oneBlockManager .loadPhases ();
145194 } catch (IOException e ) {
146- // Disable
195+ // Disable the addon if phase data cannot be loaded
147196 logError ("AOneBlock settings could not load (oneblock.yml error)! Addon disabled." );
148197 logError (e .getMessage ());
149198 setState (State .DISABLED );
@@ -169,6 +218,7 @@ public void onDisable() {
169218 public void onReload () {
170219 // save cache
171220 blockListener .saveCache ();
221+ // Reload settings and phase data
172222 if (loadSettings ()) {
173223 log ("Reloaded AOneBlock settings" );
174224 loadData ();
@@ -223,6 +273,7 @@ private World getWorld(String worldName2, Environment env, ChunkGeneratorWorld c
223273 worldName2 = env .equals (World .Environment .NETHER ) ? worldName2 + NETHER : worldName2 ;
224274 worldName2 = env .equals (World .Environment .THE_END ) ? worldName2 + THE_END : worldName2 ;
225275 WorldCreator wc = WorldCreator .name (worldName2 ).environment (env );
276+ // Use custom generator if configured, otherwise default
226277 World w = settings .isUseOwnGenerator () ? wc .createWorld () : wc .generator (chunkGenerator2 ).createWorld ();
227278 // Set spawn rates
228279 if (w != null ) {
@@ -232,6 +283,10 @@ private World getWorld(String worldName2, Environment env, ChunkGeneratorWorld c
232283
233284 }
234285
286+ /**
287+ * Sets the spawn rates for a given world based on the addon's settings.
288+ * @param w The world to set spawn rates for.
289+ */
235290 private void setSpawnRates (World w ) {
236291 if (getSettings ().getSpawnLimitMonsters () > 0 ) {
237292 w .setSpawnLimit (SpawnCategory .MONSTER , getSettings ().getSpawnLimitMonsters ());
@@ -298,6 +353,9 @@ public OneBlockIslands getOneBlocksIsland(@NonNull Island i) {
298353 return blockListener .getIsland (Objects .requireNonNull (i ));
299354 }
300355
356+ /**
357+ * @return The OneBlock manager.
358+ */
301359 public OneBlocksManager getOneBlockManager () {
302360 return oneBlockManager ;
303361 }
@@ -341,6 +399,10 @@ public void setIslandWorld(World world) {
341399
342400 }
343401
402+ /**
403+ * Sets the addon's settings. Used only for testing.
404+ * @param settings The settings to set.
405+ */
344406 public void setSettings (Settings settings ) {
345407 this .settings = settings ;
346408 }
0 commit comments