Skip to content

Commit 4a54ab8

Browse files
committed
Merge branch 'develop' of https://github.com/BentoBoxWorld/Biomes into master
2 parents bcccb81 + 5d55946 commit 4a54ab8

File tree

14 files changed

+1045
-257
lines changed

14 files changed

+1045
-257
lines changed

pom.xml

+11-4
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@
4646
<java.version>1.8</java.version>
4747
<powermock.version>2.0.2</powermock.version>
4848
<!-- More visible way how to change dependency versions -->
49-
<spigot.version>1.16.1-R0.1-SNAPSHOT</spigot.version>
50-
<bentobox.version>1.14.0-SNAPSHOT</bentobox.version>
51-
<level.version>2.4.0-SNAPSHOT</level.version>
49+
<spigot.version>1.16.4-R0.1-SNAPSHOT</spigot.version>
50+
<bentobox.version>1.15.4</bentobox.version>
51+
<level.version>2.5.0</level.version>
52+
<greenhouses.version>1.4.0-SNAPSHOT</greenhouses.version>
5253
<vault.version>1.7</vault.version>
5354
<!-- Revision variable removes warning about dynamic version -->
5455
<revision>${build.version}-SNAPSHOT</revision>
5556
<!-- This allows to change between versions and snapshots. -->
56-
<build.version>1.13.0</build.version>
57+
<build.version>1.14.0</build.version>
5758
<build.number>-LOCAL</build.number>
5859
</properties>
5960

@@ -159,6 +160,12 @@
159160
<version>${level.version}</version>
160161
<scope>provided</scope>
161162
</dependency>
163+
<dependency>
164+
<groupId>world.bentobox</groupId>
165+
<artifactId>Greenhouses</artifactId>
166+
<version>${greenhouses.version}</version>
167+
<scope>provided</scope>
168+
</dependency>
162169
<dependency>
163170
<groupId>net.milkbowl.vault</groupId>
164171
<artifactId>VaultAPI</artifactId>

src/main/java/world/bentobox/biomes/BiomesAddon.java

+107-52
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import world.bentobox.biomes.handlers.ChangeBiomeRequestHandler;
2323
import world.bentobox.biomes.listeners.ChangeOwnerListener;
2424
import world.bentobox.biomes.listeners.ChunkLoadListener;
25+
import world.bentobox.greenhouses.Greenhouses;
2526
import world.bentobox.level.Level;
2627

2728

@@ -64,16 +65,15 @@ public void onEnable()
6465
return;
6566
}
6667

67-
hookInGameModes();
68+
this.hookInGameModes();
6869

6970
if (this.hooked)
7071
{
71-
setupAddon();
72+
this.setupAddon();
7273
}
7374
else
7475
{
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!");
7777
this.setState(State.DISABLED);
7878
}
7979
}
@@ -87,11 +87,13 @@ private void setupAddon() {
8787
this.addonManager = new BiomesAddonManager(this);
8888

8989
// 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();
9195

92-
findVaultPlugin();
93-
94-
// Register the reset listener
96+
// Register the reset listener
9597
this.registerListener(new ChangeOwnerListener(this));
9698
this.registerListener(new ChunkLoadListener(this));
9799

@@ -108,79 +110,87 @@ private void setupAddon() {
108110
if (this.settings.getUpdateTickCounter() > 0)
109111
{
110112
// This task will force-load chunk every update tick if its biome is not updated.
111-
runChunkUpdatingScheduler();
113+
this.runChunkUpdatingScheduler();
112114
}
113-
114115
}
115116

116117

117118
/**
118119
* This task will force-load chunk every update tick if its biome is not updated.
119120
*/
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 =
123125
this.addonManager.getBiomeUpdaterCollection().iterator();
124126

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+
}
130132

131-
BiomeChunkUpdateObject updater = iterator.next();
133+
BiomeChunkUpdateObject updater = iterator.next();
132134

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+
}
138140

139-
World world = updater.getWorld();
141+
World world = updater.getWorld();
140142

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);
146148

147-
// force-load chunk asynchronously
148-
Util.getChunkAtAsync(world,
149+
// force-load chunk asynchronously
150+
Util.getChunkAtAsync(world,
149151
updater.getChunkX(),
150152
updater.getChunkZ());
151-
}
152-
},
153-
this.settings.getUpdateTickCounter(),
154-
this.settings.getUpdateTickCounter());
153+
}
154+
},
155155

156+
this.settings.getUpdateTickCounter(),
157+
this.settings.getUpdateTickCounter());
156158
}
157159

158160

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+
{
160167
Optional<VaultHook> vault = this.getPlugin().getVault();
161168

162169
if (!vault.isPresent() || !vault.get().hook())
163170
{
164171
this.vaultHook = null;
165172
this.logWarning(
166-
"Economy plugin not found so money requirements will be ignored!");
173+
"Economy plugin not found so money requirements will be ignored!");
167174
}
168175
else
169176
{
170-
this.economyProvided = true;
171177
this.vaultHook = vault.get();
172178
}
173-
174179
}
175180

176181

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+
{
178188
Optional<Addon> level = this.getAddonByName("Level");
179189

180190
if (!level.isPresent())
181191
{
182192
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!");
184194
this.levelAddon = null;
185195
this.levelProvided = false;
186196
}
@@ -192,7 +202,27 @@ private void findLevelAddon() {
192202
}
193203

194204

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+
{
196226
this.getPlugin().getAddonsManager().getGameModeAddons().forEach(gameModeAddon -> {
197227
if (!this.settings.getDisabledGameModes().contains(gameModeAddon.getDescription().getName()))
198228
{
@@ -304,7 +334,7 @@ public Settings getSettings()
304334
*/
305335
public boolean isEconomyProvided()
306336
{
307-
return this.economyProvided;
337+
return this.vaultHook != null && this.vaultHook.hook();
308338
}
309339

310340

@@ -338,9 +368,29 @@ public boolean isLevelProvided()
338368
}
339369

340370

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+
// ---------------------------------------------------------------------
344394

345395

346396
/**
@@ -358,11 +408,6 @@ public boolean isLevelProvided()
358408
*/
359409
private Settings settings;
360410

361-
/**
362-
* This boolean indicate if economy is enabled.
363-
*/
364-
private boolean economyProvided;
365-
366411
/**
367412
* VaultHook that process economy.
368413
*/
@@ -378,6 +423,16 @@ public boolean isLevelProvided()
378423
*/
379424
private boolean levelProvided;
380425

426+
/**
427+
* Greenhouses addon.
428+
*/
429+
private Greenhouses greenhouses;
430+
431+
/**
432+
* This indicate if greenhouses addon exists.
433+
*/
434+
private boolean greenhousesProvided;
435+
381436

382437
// ---------------------------------------------------------------------
383438
// Section: Flags

src/main/java/world/bentobox/biomes/BiomesAddonManager.java

+17
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.TreeMap;
1313
import java.util.stream.Collectors;
1414

15+
import org.bukkit.Location;
1516
import org.bukkit.World;
1617
import org.bukkit.block.Biome;
1718
import org.bukkit.configuration.ConfigurationSection;
@@ -618,6 +619,22 @@ public boolean hasAnyBiome(World world)
618619
}
619620

620621

622+
/**
623+
* This method returns true if in given location exit a greenhouse.
624+
* @param world World where greenhouse must be searched.
625+
* @param x X location.
626+
* @param y Y location.
627+
* @param z Z location.
628+
* @return {@code true} if in given location exist a greenhouse, {@code false} otherwise.
629+
*/
630+
public boolean hasGreenhouseInLocation(World world, int x, int y, int z)
631+
{
632+
return this.addon.isGreenhousesProvided() &&
633+
this.addon.getGreenhouses().getManager().getMap().
634+
inGreenhouse(new Location(world, x, y, z));
635+
}
636+
637+
621638
// ---------------------------------------------------------------------
622639
// Section: Later Biome Updater
623640
// ---------------------------------------------------------------------

src/main/java/world/bentobox/biomes/events/BiomeChangedEvent.java

+35-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.UUID;
55

66
import org.bukkit.block.Biome;
7+
import org.bukkit.event.HandlerList;
78

89
import world.bentobox.bentobox.api.events.BentoBoxEvent;
910

@@ -14,7 +15,7 @@
1415
*/
1516
public class BiomeChangedEvent extends BentoBoxEvent
1617
{
17-
/**
18+
/**
1819
* Constructor BiomeChangeEvent creates a new BiomeChangeEvent instance.
1920
*
2021
* @param biomeID of type String that represents biome unique id. May be empty.
@@ -243,6 +244,34 @@ public void setMaxY(int maxY)
243244
}
244245

245246

247+
// ---------------------------------------------------------------------
248+
// Section: Handler methods
249+
// ---------------------------------------------------------------------
250+
251+
252+
/**
253+
* Gets handlers.
254+
*
255+
* @return the handlers
256+
*/
257+
@Override
258+
public HandlerList getHandlers()
259+
{
260+
return BiomeChangedEvent.handlers;
261+
}
262+
263+
264+
/**
265+
* Gets handlers.
266+
*
267+
* @return the handlers
268+
*/
269+
public static HandlerList getHandlerList()
270+
{
271+
return BiomeChangedEvent.handlers;
272+
}
273+
274+
246275
// ---------------------------------------------------------------------
247276
// Section: Variables
248277
// ---------------------------------------------------------------------
@@ -292,5 +321,10 @@ public void setMaxY(int maxY)
292321
* Maximal Y coordinate of change range.
293322
*/
294323
private int maxY;
324+
325+
/**
326+
* Event listener list for current
327+
*/
328+
private static final HandlerList handlers = new HandlerList();
295329
}
296330

0 commit comments

Comments
 (0)