22
22
import world .bentobox .biomes .handlers .ChangeBiomeRequestHandler ;
23
23
import world .bentobox .biomes .listeners .ChangeOwnerListener ;
24
24
import world .bentobox .biomes .listeners .ChunkLoadListener ;
25
+ import world .bentobox .greenhouses .Greenhouses ;
25
26
import world .bentobox .level .Level ;
26
27
27
28
@@ -64,16 +65,15 @@ public void onEnable()
64
65
return ;
65
66
}
66
67
67
- hookInGameModes ();
68
+ this . hookInGameModes ();
68
69
69
70
if (this .hooked )
70
71
{
71
- setupAddon ();
72
+ this . setupAddon ();
72
73
}
73
74
else
74
75
{
75
- this .logError (
76
- "Biomes could not hook into any GameMode so will not do anything!" );
76
+ this .logError ("Biomes could not hook into any GameMode so will not do anything!" );
77
77
this .setState (State .DISABLED );
78
78
}
79
79
}
@@ -87,11 +87,13 @@ private void setupAddon() {
87
87
this .addonManager = new BiomesAddonManager (this );
88
88
89
89
// Try to find Level addon and if it does not exist, display a warning
90
- findLevelAddon ();
90
+ this .findLevelAddon ();
91
+ // Try to find Greenhouses addon
92
+ this .findGreenhousesAddon ();
93
+ // Try to find Economy Plugin
94
+ this .findVaultPlugin ();
91
95
92
- findVaultPlugin ();
93
-
94
- // Register the reset listener
96
+ // Register the reset listener
95
97
this .registerListener (new ChangeOwnerListener (this ));
96
98
this .registerListener (new ChunkLoadListener (this ));
97
99
@@ -108,79 +110,87 @@ private void setupAddon() {
108
110
if (this .settings .getUpdateTickCounter () > 0 )
109
111
{
110
112
// This task will force-load chunk every update tick if its biome is not updated.
111
- runChunkUpdatingScheduler ();
113
+ this . runChunkUpdatingScheduler ();
112
114
}
113
-
114
115
}
115
116
116
117
117
118
/**
118
119
* This task will force-load chunk every update tick if its biome is not updated.
119
120
*/
120
- private void runChunkUpdatingScheduler () {
121
- Bukkit .getScheduler ().runTaskTimer (this .getPlugin (), () -> {
122
- Iterator <BiomeChunkUpdateObject > iterator =
121
+ private void runChunkUpdatingScheduler ()
122
+ {
123
+ Bukkit .getScheduler ().runTaskTimer (this .getPlugin (), () -> {
124
+ Iterator <BiomeChunkUpdateObject > iterator =
123
125
this .addonManager .getBiomeUpdaterCollection ().iterator ();
124
126
125
- // if there is nothing to load, then skip.
126
- if (!iterator .hasNext ())
127
- {
128
- return ;
129
- }
127
+ // if there is nothing to load, then skip.
128
+ if (!iterator .hasNext ())
129
+ {
130
+ return ;
131
+ }
130
132
131
- BiomeChunkUpdateObject updater = iterator .next ();
133
+ BiomeChunkUpdateObject updater = iterator .next ();
132
134
133
- // if chunk is already force-loaded, then skip.
134
- while (iterator .hasNext () && updater .isForceLoaded ())
135
- {
136
- updater = iterator .next ();
137
- }
135
+ // if chunk is already force-loaded, then skip.
136
+ while (iterator .hasNext () && updater .isForceLoaded ())
137
+ {
138
+ updater = iterator .next ();
139
+ }
138
140
139
- World world = updater .getWorld ();
141
+ World world = updater .getWorld ();
140
142
141
- // if chunk is loaded then skip.
142
- if (!world .isChunkLoaded (updater .getChunkX (), updater .getChunkZ ()))
143
- {
144
- // Set flag as force-loaded.
145
- updater .setForceLoaded (true );
143
+ // if chunk is loaded then skip.
144
+ if (!world .isChunkLoaded (updater .getChunkX (), updater .getChunkZ ()))
145
+ {
146
+ // Set flag as force-loaded.
147
+ updater .setForceLoaded (true );
146
148
147
- // force-load chunk asynchronously
148
- Util .getChunkAtAsync (world ,
149
+ // force-load chunk asynchronously
150
+ Util .getChunkAtAsync (world ,
149
151
updater .getChunkX (),
150
152
updater .getChunkZ ());
151
- }
152
- },
153
- this .settings .getUpdateTickCounter (),
154
- this .settings .getUpdateTickCounter ());
153
+ }
154
+ },
155
155
156
+ this .settings .getUpdateTickCounter (),
157
+ this .settings .getUpdateTickCounter ());
156
158
}
157
159
158
160
159
- private void findVaultPlugin () {
161
+ /**
162
+ * This is silly method that was introduced to reduce main method complexity, and just reports
163
+ * if economy is enabled or not.
164
+ */
165
+ private void findVaultPlugin ()
166
+ {
160
167
Optional <VaultHook > vault = this .getPlugin ().getVault ();
161
168
162
169
if (!vault .isPresent () || !vault .get ().hook ())
163
170
{
164
171
this .vaultHook = null ;
165
172
this .logWarning (
166
- "Economy plugin not found so money requirements will be ignored!" );
173
+ "Economy plugin not found so money requirements will be ignored!" );
167
174
}
168
175
else
169
176
{
170
- this .economyProvided = true ;
171
177
this .vaultHook = vault .get ();
172
178
}
173
-
174
179
}
175
180
176
181
177
- private void findLevelAddon () {
182
+ /**
183
+ * This is silly method that was introduced to reduce main method complexity, and just reports
184
+ * if level addon is enabled or not.
185
+ */
186
+ private void findLevelAddon ()
187
+ {
178
188
Optional <Addon > level = this .getAddonByName ("Level" );
179
189
180
190
if (!level .isPresent ())
181
191
{
182
192
this .logWarning (
183
- "Level add-on not found so level requirements will be ignored!" );
193
+ "Level add-on not found so level requirements will be ignored!" );
184
194
this .levelAddon = null ;
185
195
this .levelProvided = false ;
186
196
}
@@ -192,7 +202,27 @@ private void findLevelAddon() {
192
202
}
193
203
194
204
195
- private void hookInGameModes () {
205
+ /**
206
+ * This is silly method that was introduced to reduce main method complexity, and just reports
207
+ * if greenhouses is enabled or not.
208
+ */
209
+ private void findGreenhousesAddon ()
210
+ {
211
+ Optional <Addon > greenhouses = this .getAddonByName ("Greenhouses" );
212
+
213
+ if (greenhouses .isPresent ())
214
+ {
215
+ this .greenhousesProvided = true ;
216
+ this .greenhouses = (Greenhouses ) greenhouses .get ();
217
+ }
218
+ }
219
+
220
+
221
+ /**
222
+ * This method hooks commands and flags into each GameModeAddon.
223
+ */
224
+ private void hookInGameModes ()
225
+ {
196
226
this .getPlugin ().getAddonsManager ().getGameModeAddons ().forEach (gameModeAddon -> {
197
227
if (!this .settings .getDisabledGameModes ().contains (gameModeAddon .getDescription ().getName ()))
198
228
{
@@ -304,7 +334,7 @@ public Settings getSettings()
304
334
*/
305
335
public boolean isEconomyProvided ()
306
336
{
307
- return this .economyProvided ;
337
+ return this .vaultHook != null && this . vaultHook . hook () ;
308
338
}
309
339
310
340
@@ -338,9 +368,29 @@ public boolean isLevelProvided()
338
368
}
339
369
340
370
341
- // ---------------------------------------------------------------------
342
- // Section: Variables
343
- // ---------------------------------------------------------------------
371
+ /**
372
+ * This method returns the Greenhouses value.
373
+ * @return the value of Greenhouses.
374
+ */
375
+ public Greenhouses getGreenhouses ()
376
+ {
377
+ return this .greenhouses ;
378
+ }
379
+
380
+
381
+ /**
382
+ * This method returns the greenhousesProvided value.
383
+ * @return the value of greenhousesProvided.
384
+ */
385
+ public boolean isGreenhousesProvided ()
386
+ {
387
+ return this .greenhousesProvided ;
388
+ }
389
+
390
+
391
+ // ---------------------------------------------------------------------
392
+ // Section: Variables
393
+ // ---------------------------------------------------------------------
344
394
345
395
346
396
/**
@@ -358,11 +408,6 @@ public boolean isLevelProvided()
358
408
*/
359
409
private Settings settings ;
360
410
361
- /**
362
- * This boolean indicate if economy is enabled.
363
- */
364
- private boolean economyProvided ;
365
-
366
411
/**
367
412
* VaultHook that process economy.
368
413
*/
@@ -378,6 +423,16 @@ public boolean isLevelProvided()
378
423
*/
379
424
private boolean levelProvided ;
380
425
426
+ /**
427
+ * Greenhouses addon.
428
+ */
429
+ private Greenhouses greenhouses ;
430
+
431
+ /**
432
+ * This indicate if greenhouses addon exists.
433
+ */
434
+ private boolean greenhousesProvided ;
435
+
381
436
382
437
// ---------------------------------------------------------------------
383
438
// Section: Flags
0 commit comments